Code: Select all
# =======================
# reactOnActor v.1.0.0
# =======================
# This plugin is licensed under the GNU GPL
# Copyright 2006 by hakore
#
#
package reactOnActor;
use strict;
use Plugins;
use Globals;
use Utils;
use Commands;
use Misc;
use Log qw(message debug);
Plugins::register('reactOnActor', 'automatically react on certain actors', \&Unload);
my $hooks = Plugins::addHooks(
['packet/actor_display', \&onActorDisplay, undef],
['packet/actor_exists', \&onActorDisplay, undef],
['packet/actor_connected', \&onActorDisplay, undef],
['packet/actor_moved', \&onActorDisplay, undef],
['packet/actor_status_active', \&onActorDisplay, undef],
['packet/actor_spawned', \&onActorDisplay, undef]);
sub Unload
{
Plugins::delHooks($hooks);
};
sub onActorDisplay {
my ($self, $args) = @_;
my $ID = unpack("V1", $args->{ID});
debug "[reactOnActor] Actor ($ID) detected on screen.\n", "reactOnActor";
my $useActorList = (substr($Settings::VERSION, 4) >= 1);
my $type;
my $actor;
if ($jobs_lut{$args->{type}}) {
# Actor is a player
$type = 'player';
$actor = ($useActorList) ? $Globals::playersList->getByID($args->{ID}) : $Globals::players{$args->{ID}};
} elsif ($args->{type} == 45) {
# Actor is a portal
$type = 'portal';
$actor = ($useActorList) ? $Globals::portalsList->getByID($args->{ID}) : $Globals::portals{$args->{ID}};
} elsif ($args->{type} >= 1000) {
# Actor might be a monster
if (($args->{hair_style} == 0x64) || $args->{pet}) {
# Actor is a pet or a homunculus
$type = 'pet';
$actor = ($useActorList) ? $Globals::petsList->getByID($args->{ID}) : $Globals::pets{$args->{ID}};
} else {
# Actor really is a monster
$type = 'monster';
$actor = ($useActorList) ? $Globals::monstersList->getByID($args->{ID}) : $Globals::monsters{$args->{ID}};
}
} else { # ($args->{type} < 1000 && $args->{type} != 45 && !$jobs_lut{$args->{type}})
# Actor is an NPC
$type = 'npc';
$actor = ($useActorList) ? $Globals::npcsList->getByID($args->{ID}) : $Globals::npcs{$args->{ID}};
}
# v.1.9.0 doesn't have complete actor info
$actor->{lv} = $args->{lv} if (!$actor->{lv} && $args->{lv});
my $i = 0;
while ((exists $config{"reactOnActor_$i"}) && $actor) {
debug "[reactOnActor] > Checking reactOnActor_$i block...\n", "reactOnActor";
if (
(my $cmd = $config{"reactOnActor_$i"})
&& main::checkSelfCondition("reactOnActor_$i")
&& checkActorCondition("reactOnActor_${i}_actor", $actor, $type)
) {
debug "[reactOnActor] > Check successful.\n", "reactOnActor";
my %replace;
$replace{ID} = $actor->{ID};
$replace{binID} = $actor->{binID};
$replace{name} = $actor->{name};
$replace{type} = $type;
my $pos = $actor->{pos_to};
$replace{x} = $pos->{x};
$replace{y} = $pos->{y};
$replace{'$'} = '$';
$cmd =~ s/\$(?:(\$)|actor->{(ID|binID|name|type|x|y)})/$replace{$1}$replace{$2}/g;
message "[reactOnActor] Reacting to Actor ($ID) using command \"$cmd\".\n", "success";
Commands::run($cmd);
last;
} else {
debug "[reactOnActor] > Check failed.\n", "reactOnActor";
}
$i++;
}
}
sub checkActorCondition
{
my ($prefix, $actor, $type) = @_;
my $ID = unpack("V1", $actor->{ID});
if ($config{$prefix . "_id"}) {
debug "[reactOnActor] > _id " . $config{$prefix . "_id"} . " [$ID].\n", "reactOnActor";
return 0 unless (existsInList($config{$prefix . "_id"}, $ID)); }
if ($config{$prefix . "_type"}) {
debug "[reactOnActor] > _type " . $config{$prefix . "_type"} . " [$type].\n", "reactOnActor";
return 0 unless (existsInList($config{$prefix . "_type"}, $type)); }
if ($actor->{walk_speed} && $config{$prefix . "_walkSpeed"}) {
debug "[reactOnActor] > _walkSpeed " . $config{$prefix . "_walkSpeed"} . " [$actor->{walk_speed}].\n", "reactOnActor";
return 0 unless (inRange($actor->{walk_speed}, $config{$prefix . "_walkSpeed"})); }
if ($config{$prefix . "_whenStatusActive"}) {
debug "[reactOnActor] > _whenStatusActive " . $config{$prefix . "_whenStatusActive"} . " [??].\n", "reactOnActor";
return 0 unless (whenStatusActiveActor($actor, $config{$prefix . "_whenStatusActive"})); }
if ($config{$prefix . "_whenStatusInactive"}) {
debug "[reactOnActor] > _whenStatusInactive " . $config{$prefix . "_whenStatusInactive"} . " [??].\n", "reactOnActor";
return 0 if (whenStatusActiveActor($actor, $config{$prefix . "_whenStatusInactive"})); }
return $actor;
}
sub whenStatusActiveActor {
my ($actor, $statuses) = @_;
my @arr = split /[, ]*,[, ]*/, $statuses;
foreach (@arr) {
return 1 if $actor->{statuses}{$_};
}
return 0;
}
return 1;
Code: Select all
reactOnActor quit {
actor_type player
actor_whenStatusActive Support Warg, Blessing
inMap prontera
}