[Crossfire-wiki] [Crossfire DokuWiki] page added: user:mhoram:scripts:watch_food

no-reply_wiki at metalforge.org no-reply_wiki at metalforge.org
Thu Dec 28 05:53:37 CST 2006


A page in your DokuWiki was added or changed. Here are the details:

Date        : 2006/12/28 05:53
User        : 
Edit Summary: created

====== Introduction ======

This is a client-side [[wp>perl]] script for Crossfire, which attempts
to eat a normal food or waybread when the player gets hungry.
**WARNING**: Special identified foods like a "food of Poison" should
not be used, but unidentified ones may be, so use at your own risk.

====== Requirements ======

  * Perl

====== Code ======
<code perl>
#!/usr/bin/perl
use warnings;
use strict;
$| = 1;

my $last_meal = time;
my $hungry = 250;     # Set this to your "hunger" preference

print "watch stats\n";

while(<STDIN>){
  if( ( time - $last_meal ) > 60  and /food (\d+)/ ){
    my $food = $1;
    next unless $food < $hungry;
    print "request items inv\n";
    my $foods; my $waybreads;
    while(<STDIN>){
      last if /request items inv end/;
      if( /request items inv .* foods?$/ ){
	$foods = 1;
	last;
      } elsif( /request items inv .* waybreads?$/ ){
	$waybreads = 1;
      }
    }
    if( $foods ){
      print "issue 1 1 apply food\n";
      print "draw 3 Hungry, eating a food.\n";
    } elsif( $waybreads ){
      print "issue 1 1 apply waybread\n";
      print "draw 3 Hungry, eating a waybread.\n";
    } else {
      print "draw 3 Hungry, out of food and waybread!!!\n";
    }
    $last_meal = time;
  }
}
</code>

====== Notes & Comments ======

I've been using this for a couple days, and it seems to work fine, but
I'm waiting to see what happens if I happen to have an exotic food in
my inventory.  I may eventually expand it to eat other edible items,
but those are usually more chancy in the poisonous department, and I
wanted to keep it as safe as possible.

====== References =======

  * [[:user:mhoram|Mhoram's Page]]
  * [[:Client_Side_Scripting]]


IP-Address  : 206.71.197.56
Old Revision: none
New Revision: http://wiki.metalforge.net/doku.php/user:mhoram:scripts:watch_food

-- 
This mail was generated by DokuWiki at
http://wiki.metalforge.net/




More information about the crossfire-wiki mailing list