The increment happened even if the next monster to check ($monster->name) is far away from our targeted monster. Which seems its not logic to me since the target monster risk shud not increase if the monster is far away from the target, rught?
So, now I've tried to do the increment if the distance from $monsters{$_} (target) to $monster (in sight) is below 12 blocks. Here is the code...
monster Female Thief Bug,Thief Bug, 12
Code: Select all
sub checkMonster {
my ($monsterList, $mondist) = $_[0] =~ /^(.*),?\s(\d+)\s*$/;
return 0 if (!defined $mondist || $mondist < 1);
foreach (@monstersID) {
next unless defined $_;
if (existsInList($monsterList, $monsters{$_}->{name})) {
my $counter;
my $mypos = calcPosition($char);
my $pos = calcPosition($monsters{$_});
my $dist = sprintf("%.1f", distance($mypos, $pos));
my $val = sprintf("%d %d %s", $pos->{x}, $pos->{y}, $field->{name});
$varStack{".lastMonster"} = $monsters{$_}->{name};
$varStack{".lastMonsterPos"} = $val;
$varStack{".lastMonsterDist"} = $dist;
$varStack{".lastMonsterID"} = $monsters{$_}->{binID};
for (my $i = 0; $i < @::monstersID; $i++) {
next if $::monstersID[$i] eq "";
my $monster = Actor::get($::monstersID[$i]);
if ($monster->name eq $monsters{$_}->{name}) {
if ($monster->{binID} eq $monsters{$_}->{binID}) {
$counter++;
next;
} else {
my $monsToMonDist = sprintf("%.1f",distance($pos, $monster->{pos_to}));
$counter++ if $monsToMonDist < 12;
next;
}
}
next;
}
$varStack{".lastMonsterCount"} = $counter;
return $dist <= $mondist ?1:0
}
}
return 0
}
Question:-
1. Is my distance between the 2 monsters (target and insight monster) correct by using below code?
Code: Select all
if ($monster->name eq $monsters{$_}->{name}) {
if ($monster->{binID} eq $monsters{$_}->{binID}) {
$counter++;
next;
} else {
my $monsToMonDist = sprintf("%.1f",distance($pos, $monster->{pos_to}));
$counter++ if $monsToMonDist < 12;
next;
}
}
p.s: Thanks in advance...