1. If there is a monster attacking the priest, the priest will PM the master the monster's location
2. The master, after receiving the monster's location will calculate and get the monster's ID nearest to that location. (Attacking the monster nearest the Priest is another option, but if the attacking monster is using ranged attack or there are too many monsters near the master and the priest, this will not work)
Note: That this is still not tested so use it at your own risk. Update to the latest macro version first since subroutine functionality is needed.
Code: Select all
################################
######PROTECT ME################
################################
automacro ProtectMe {
timeout 8
console /Monster (.*) \((\d+)\) attacks you/
call {
$mymap = $.map
$lockmap = @config (lockMap)
$master = @config (followTarget)
$mon = $.lastMatch2
$monlocation = 0
if ($mymap == $lockmap) goto help
:help
#get monster's location
$monlocation = get_monster_location("$mon")
do pm "$master" xd $monlocation
if ($mymap != $lockmap) goto stop
:stop
stop
}
}
#get monster location
sub get_monster_location {
my ($target_id) = @_;
foreach (@{$monstersList->getItems()}) {
if ($_->{binID} == $target_id) {
return "$_->{pos_to}{x} $_->{pos_to}{y}";
}
}
}
################################
######COMMAND###################
################################
automacro Command {
console /\(From: (.*)\) : xd (\d+) (\d+)/
call {
#####NOTE : edit $town to the map you are using storage and auto buys!####
$town = Geffen #edit this!
$mymap = $.map
$xd = $.lastMatch1
$xd2 = $.lastMatch2
$xd3 = $.lastMatch3
#get the monster nearest to the pm'ed location
$targetmon = monster_near_loc("$xd2", "$xd3")
if ($mymap == $town) goto DeadMa
do a $targetmon
pause 0.5
do pm "$xd" I'll protect you..
stop
:DeadMa
stop
}
}
sub monster_near_loc {
my ($target_x, $target_y) = @_;
my $min_distance = 20;
my $distance;
my $target_monster = 0;
foreach (@{$monstersList->getItems()}) {
$distance = get_distance("$target_x", "$target_y", "$_->{pos_to}{x}", "$->{pos_to}{y}");
if ($distance < $min_distance) {
$min_distance = $distance;
$target_monster = $_->{binID};
}
}
return $target_monster;
}
sub get_distance {
my ($x1, $y1, $x2, $y2) = @_;
my $line_x = abs($x1 - $x2);
my $line_y = abs($y1 - $y2);
my $distance = sqrt($line_x ** 2 + $line_y ** 2);
return $distance;
}
changed
Code: Select all
my ($x1, $y1, $x1, $y2) = @_;
Code: Select all
my ($x1, $y1, $x2, $y2) = @_;
I guess this is the problem why sub monster_near_loc failed