Log in

View Full Version : Hatelist Aggro Issues


Neiv
11-29-2008, 09:03 PM
I'm trying to get four mobs in a zone to attack the client after acquiring an item from an NPC. The hate script is triggered by a timer associated with a SAY event. Here is the SAY, followed by the TIMER:

sub EVENT_SAY
{
if($text=~/accept/i)
{
quest::say("Very well, here it is. But have a care, $name, and treat it with caution. It has magical properties that can help or hinder the bearer. Go and practice your new skills.");
quest::settimer("aggro",10);
quest::summonitem(13732);
$client->Message(257, "A strange, unsettled feeling falls upon you.");
$client->Message(257, "You feel . . . heavy.");
}
}


I placed checkmark emotes throughout the following TIMER script to see where it is breaking, and it makes it to "ticking 5," then starts over.

sub EVENT_TIMER
{
quest::emote("sees that his timer is ticking 1");
if($timer eq "aggro")
{
quest::emote("sees that his timer is ticking 2");
quest::rebind(183,21,36,8);

my $guard_one = $entity_list->GetMobByNpcTypeID(999287);
my $guard_two = $entity_list->GetMobByNpcTypeID(999288);
my $guard_three = $entity_list->GetMobByNpcTypeID(999289);
my $guard_four = $entity_list->GetMobByNpcTypeID(999290);
quest::emote("sees that his timer is ticking 3");

if ($guard_one)
{
quest::emote("sees that his timer is ticking 4");
my $hate_guard_one = $guard_one->CastToNPC();
quest::emote("sees that his timer is ticking 5");
$hate_guard_one->AddToHateList($client, 1);
quest::emote("sees that his timer is ticking 6");
}
if ($guard_two)
{
quest::emote("sees that his timer is ticking 7");
my $hate_guard_two = $guard_two->CastToNPC();
$hate_guard_two->AddToHateList($client, 1);
}
if ($guard_three)
{
quest::emote("sees that his timer is ticking 8");
my $hate_guard_three = $guard_three->CastToNPC();
$hate_guard_three->AddToHateList($client, 1);
}
if ($guard_four)
{
quest::emote("sees that his timer is ticking 9");
my $hate_guard_four = $guard_four->CastToNPC();
$hate_guard_four->AddToHateList($client, 1);
}
quest::emote("sees that his timer is ticking 10");
quest::stoptimer("aggro");
}
}


Since it's not making it to "ticking 6," I assume the problem is with the object $hate_guard_one->AddToHateList($client, 1); . I have used this in its exact form in another quest script where it works just fine (in fact, I simply copied and pasted it), so I am at a loss as to why it is not working. The only difference is that the working script is a "player.pl" whereas the non-working one is an NPC script that references other mobs and the client. But this seems to be identical to the Cazic Thule and Tunare scripts (both of those add the client to third-party mob hatelists), so I don't understand why it's not working here.

AndMetal
12-01-2008, 04:10 AM
I don't think sub EVENT_TIMER exports $client, because it's not triggered by a client, where sub EVENT_AGGRO (from the Tunare script) does (the client that aggroed it).

I think you might be able to define a variable outside of the subs so that all of them have access to it, set it to $client in EVENT_SAY, and then reference it in EVENT_TIMER. However, I'm pretty sure if a 2nd person talks to the NPC, it will overwrite your variable, unless you check to see if it's already being done.

I guess I'm thinking something like this (untested):

my $client_hating = false;

sub EVENT_SAY
{
if($text=~/accept/i)
{
if (!$client_hating)
{
quest::say("Very well, here it is. But have a care, $name, and treat it with caution. It has magical properties that can help or hinder the bearer. Go and practice your new skills.");
$client_hating = $client;
quest::settimer("aggro",10);
quest::summonitem(13732);
$client->Message(257, "A strange, unsettled feeling falls upon you.");
$client->Message(257, "You feel . . . heavy.");
} else {
quest::say("Wait your turn, jerk!");
}
}
}

sub EVENT_TIMER
{
quest::emote("sees that his timer is ticking 1");
if($timer eq "aggro")
{
quest::emote("sees that his timer is ticking 2");
quest::rebind(183,21,36,8);

my $guard_one = $entity_list->GetMobByNpcTypeID(999287);
my $guard_two = $entity_list->GetMobByNpcTypeID(999288);
my $guard_three = $entity_list->GetMobByNpcTypeID(999289);
my $guard_four = $entity_list->GetMobByNpcTypeID(999290);
quest::emote("sees that his timer is ticking 3");

if ($guard_one)
{
quest::emote("sees that his timer is ticking 4");
my $hate_guard_one = $guard_one->CastToNPC();
quest::emote("sees that his timer is ticking 5");
$hate_guard_one->AddToHateList($client_hating, 1);
quest::emote("sees that his timer is ticking 6");
}
if ($guard_two)
{
quest::emote("sees that his timer is ticking 7");
my $hate_guard_two = $guard_two->CastToNPC();
$hate_guard_two->AddToHateList($client_hating, 1);
}
if ($guard_three)
{
quest::emote("sees that his timer is ticking 8");
my $hate_guard_three = $guard_three->CastToNPC();
$hate_guard_three->AddToHateList($client_hating, 1);
}
if ($guard_four)
{
quest::emote("sees that his timer is ticking 9");
my $hate_guard_four = $guard_four->CastToNPC();
$hate_guard_four->AddToHateList($client_hating, 1);
}
quest::emote("sees that his timer is ticking 10");
quest::stoptimer("aggro");
quest::emote("sees that his timer is ticking 11");
$client_hating = false;
}
}


On a side note, can't we simplify this

my $hate_guard_one = $guard_one->CastToNPC();
$hate_guard_one->AddToHateList($client, 1);

to this

$guard_one->CastToNPC()->AddToHateList($client, 1);

or even better yet, just do everything on 1 line?
$entity_list->GetMobByNpcTypeID(999287)->CastToNPC()->AddToHateList($client, 1);
Since we're not really evaluating whether or not something's happening, you can just put your checks in-between them:

sub EVENT_TIMER
{
quest::emote("sees that his timer is ticking 1");
if($timer eq "aggro")
{
quest::emote("sees that his timer is ticking 2");
quest::rebind(183,21,36,8);

quest::emote("sees that his timer is ticking 3");
$entity_list->GetMobByNpcTypeID(999287)->CastToNPC()->AddToHateList($client_hating, 1);

quest::emote("sees that his timer is ticking 4");
$entity_list->GetMobByNpcTypeID(999288)->CastToNPC()->AddToHateList($client_hating, 1);

quest::emote("sees that his timer is ticking 5");
$entity_list->GetMobByNpcTypeID(999289)->CastToNPC()->AddToHateList($client_hating, 1);

quest::emote("sees that his timer is ticking 6");
$entity_list->GetMobByNpcTypeID(999290)->CastToNPC()->AddToHateList($client_hating, 1);

quest::emote("sees that his timer is ticking 10");
quest::stoptimer("aggro");
}
}

Hope this helps at least point you in the right direction.

Neiv
12-01-2008, 11:37 PM
Wow. It works like a charm now. I'm impressed. Thanks AndMetal!

Neiv
12-02-2008, 01:00 AM
Well, it worked at least the first time I tried it; then it broke and now gives me only the "wait your turn" message (I'm the only one in the world).

Neiv
12-04-2008, 08:11 AM
I decided just to add an additional zone, have the main npc port me there, and transfer the aggro script to my player.pl in the new zone, triggered by an ENTERZONE event. It's working now.