User Tools

Site Tools


user:mhoram:scripts:watch_food

Introduction

This is a client-side 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

#!/usr/bin/perl
use warnings;
use strict;
require "./subs.pl"; # get some subs to use
$| = 1;
 
my $last_meal = time;
my $hungry = 500;
my $praycount = 1;
 
print "draw 4 Watching food...\n";
 
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; my $orcchops;
	while (<STDIN>) {
	    last if /request items inv end/;
	    if ( /request items inv .* foods?$/ ) {
		$foods = 1;
		last;
	    } elsif ( /request items inv .* waybreads?$/ ) {
		$waybreads = 1;
	    } elsif ( /request items inv .* orc chops?$/ ) {
		$orcchops = 1;
	    }
	}
	if ( $orcchops ) {
	    issue('apply orc chop');
	    draw(3, 'Hungry, eating an orc chop.');
	} elsif ( $foods ) {
	    issue('apply food');
	    draw(3, 'Hungry, eating a food.');
	} elsif ( $waybreads ) {
	    issue('apply waybread');
	    draw(3, 'Hungry, eating a waybread.');
	} else {
	    draw( 3, 'Hungry, out of food and waybread!!!');
	}
	$last_meal = time;
    }
    unless($praycount++ % 100){
	$praycount = 1;
	my @hp = request_line('stat hp');
	my( $grace, $maxgrace ) = @hp[4,5];
	if ( $grace < $maxgrace ) {
	    draw(3, "Extra Prayer $praycount");
	    issue('use_skill praying');
	}
    }
}

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.

New version adds: orc chops as another food choice; uses my subs.pl for some common commands.

References

user/mhoram/scripts/watch_food.txt · Last modified: 2007/02/19 15:13 (external edit)