User Tools

Site Tools


client_side_scripting:scripts:perl:travel

Travel Script

This is an initial quick hack of a travel script. It is designed to walk a character from the sign in Euthville to the fountain in Scorn, while staying on the roads for safety and speed. The timing isn't quite right on getting through the gates, so you may get stopped there, but it should get you to the gates of Scorn, at least, unless you bump into someone. There's no collision detection or recovery from that sort of thing yet, so anything that blocks your movement will throw off the rest of the directions and send you who-knows-where.

If this sort of thing turns out to be useful, I'd probably move the “steps” pairs into a separate text file, and have one script that could read multiple “steps” files for different voyages.

Here's the code, for anyone who would like to try it out. Simply save it as a file, and execute the script with the command: 'script perl /path/to/this/script

#!/usr/bin/perl
use strict;
use warnings;
$| = 1;        # unbuffered stdout
 
 
# The following instructions will lead a player on the road from
#   the sign in Euthville to the fountain in Scorn
 
my @paces = (
	      northeast => 4 ,
	      east => 12,
	      southeast => 6 ,
	      south => 2 ,
	      southeast => 3 ,
	      east => 4 ,
	      southeast => 4 ,
	      south => 10,
	      southeast => 5 ,
	      south => 13,
	      southeast => 2 ,
	      south => 1 ,
	      southeast => 2 ,
	      east => 1 ,
	      southeast => 2 ,
	      south => 3 ,
	      southwest => 4 ,
	      south => 3 ,
	      southeast => 1 ,
	      south => 8 ,
	      southwest => 8 ,
	      south => 4 ,
	      southeast => 3 ,
	      south => 12,
	      southwest => 2 ,
	      south => 6 ,
	      southwest => 7 ,
	      south => 3 ,
	      southwest => 3 ,
	      south => 4 ,
	      southwest => 2 ,
	      west => 16,
	      stay => 5 ,
	      west => 14,
	      southwest => 1 ,
	      command => 'apply' ,
	      stay => 5 ,
	      northwest => 1 ,
	      west => 16,
	      northwest => 2 ,
);
 
while(1){
  my $key   = shift @paces;
  my $value = shift @paces;
  last unless ( defined $key and defined $value );
  if( $key eq 'command' ){
    print "issue 1 1 $value\n";
    wait_for_server();
  } elsif( $key eq 'stay' ){
    sleep $value;
    next;
  } else {
    for my $steps (1..$value){
      print "issue 1 1 $key\n";
      wait_for_server();
    }
  }
}
 
sub wait_for_server {
  print "watch map2\n";
  my $res = <STDIN>;
  print "unwatch map2\n";
  print STDERR $res;
}

ChangeLog

  • 2006.12.19 – Added wait_for_server subroutine, which waits for a map2 command from server. This is an attempt to keep the client from getting ahead of the server and losing commands.

Notes & Comments

  • As said above, this script is very primitive, and created mostly as a learning exercise. Suggestions for more useful scripts are welcome.

References

client_side_scripting/scripts/perl/travel.txt · Last modified: 2006/12/20 08:40 (external edit)