Waypoints POC (sorta)

Other plugins for extending OpenKore's functionality. This forum is only for posting new plugins and commenting on existing plugins. For support, use the Support forum.

Moderator: Moderators

sli
Perl Monk
Perl Monk
Posts: 810
Joined: 04 Apr 2008, 17:26
Noob?: No

Waypoints POC (sorta)

#1 Post by sli »

In case you don't know what "POC" means, it's "proof of concept." This plugin does not work as is, it's just a base in case someone wants to write a waypoint plugin. Right now, the waypoint sub blocks (read: breaks your bot), and I didn't even test the file parsing code. It also uses cmdMove, which it shouldn't do. But I couldn't be arsed to work with the Task framework because I never have. Replace that part with correct Task code. Regardless, here's a sample waypoint file:

Code: Select all

[pay_dun01]
126,214
201,130
251,145

[moc_pryd01]
132,131
213,211
43,137
150,122
23,50
And it uses two config variables. waypoints is the toggle, it can be 0 or 1 (of course). waypoints_pause is the delay between waypoints. You bot will stop at each waypoint for the number of seconds specified here. The default is five seconds.

Code: Select all

use Plugins;
use Global qw(%config);
use Commands qw(cmdMove);

Plugins::register('Waypoints', 'POC waypoint implementation.', undef);
my $hooks = Plugins::addHooks(
	['start3', \&onLoad, undef],
	['in_game', \&waypoint, undef],
	['Network::Receive::map_changed', \&waypoint, undef]
);

our %waypoints;

sub onLoad {
	my $section;

	open WP, "<waypoints.txt" or die $!;
	while (my $line = <WP>) {
		
		next if ($line =~ /^#/);
		$line =~ s/[\r\n]//g;
		$line =~ s/\s+$//g;
		next if ($line eq "");
			
		if ($line =~ /^\[(.*)\]$/i) {
			$section = $1;
			$waypoints{$section} = ()
			next;
		} else {
			if ($line =~ /(\d),(\d)/) {
				push @waypoints{$section}, ($1, $2)
			}
		}
	}
}

sub waypoint {
	if ($config{waypoints} == 1) {
		if (!defined $config{waypoints_pause}) {
			$config{waypoints_pause} = 5000;
		} else {
		$config{waypoints_pause} = $config{waypoints_pause} * 1000;
		}
		
		if (defined $waypoints{$char{map}}) {
			foreach (@waypoints{$char{map}}) {
				cmdMove("$_[0] $_[1]");
				sleep $config{waypoints_pause};
			}
		} else {
			return;
		}
	}
}
cs : ee : realist