View Full Version : Mob attacks everything on hate list
Randymarsh9
09-16-2012, 03:07 AM
I'm trying to think of a way for a monster to attack everything on its hate list like the title of the post says. I don't want to have it cast a PBAE, but rather cast a single target spell on each one of the people it is fighting. Is there anyway to do this? Also, if that wouldn't work, is there a way to count how many people are on a monster's hate list and store it as a variable? That might work as well.
c0ncrete
09-16-2012, 09:33 AM
something like
foreach $ent ($npc->GetHateList()) {
$npc->CastSpell($spellID, $ent->GetID());
}
should work, triggered via a timer or hp event
c0ncrete
09-16-2012, 11:40 AM
meh. try this instead. syntax got me.
foreach $ent (@{$npc->GetHateList()}) {
$npc->CastSpell($spellID, $ent->GetID());
}
ChaosSlayerZ
09-16-2012, 11:51 PM
I have a related question on this.
Same idea, but I would like npc to a pick a RANDOM person from his hate list.
How would it modify the code?
thanks!
Caryatis
09-17-2012, 09:32 AM
Surprisingly people use perl for non eq related things, which makes searching for coding questions pretty easy (http://www.perlmonks.org/?node_id=1870)
c0ncrete
09-17-2012, 10:09 AM
or you could use GetHateRandom()
ChaosSlayerZ
09-18-2012, 11:34 AM
thanks! ;)
Randymarsh9
09-18-2012, 03:21 PM
foreach $ent (@{$npc->GetHateList()}) {
$npc->CastSpell($spellID, $ent->GetID());
}
This code doesn't seem to work. Quest stops working after "foreach $ent (@{$npc->GetHateList()}) {"
Caryatis
09-18-2012, 04:26 PM
Thats where alittle perl knowledge comes in handy...
@npcArray = $npc->GetHateList();
foreach $ent (@npcArray)
{
}
Having never used the syntax Concrete used, I can't comment on its correctness however the above works.
Randymarsh9
09-18-2012, 07:11 PM
And now what would you use as the client ID in a cast spell command using that syntax? $ent->GetID() did not work as a target type.
Caryatis
09-18-2012, 07:59 PM
I cant remember since its been forever since I last did that. Think you need to cast it to mob though: $ent->CastToMob()->GetID();
c0ncrete
09-18-2012, 08:37 PM
it's what i get for second guessing myself. the data returned from GetHateList() doesn't need the be enclosed in @{} as it isn't a reference to an array. you might have to get the entity itself by using $ent->GetEnt()->GetID() or something of that nature first (see bottom of http://www.eqemulator.net/wiki/wikka.php?wakka=ListIterations for example). i wasn't at a computer with the emulator installed for testing and only had access to perl at the time of my posting(s), so i wrote a test class to emulate the $npc object.
as to creating an array for capturing the list of entities in the npc's hate list before iterating through them... i just have a habit of not storing returned values into individual variables if they're only going to be used once. it's just a preference. it should work either way, as long as you don't try to use the @{} as i did in my second post.
Randymarsh9
09-18-2012, 09:56 PM
if ($hpevent == 90)
{
foreach $ent ($npc->GetHateList())
{
$npc->CastSpell(6799, $ent->GetEnt()->GetID());
}
quest::setnexthpevent(80);
}
This is my current code. It only casts the selected spell on the player that it is directly attacking though.
@npcArray = $npc->GetHateList();
foreach $ent (@npcArray)
{
$npc->CastSpell(6799, $ent->GetEnt()->GetID());
}
Also just casts on the target.
c0ncrete
09-18-2012, 10:30 PM
that's because both of those snippets do the same thing. the only difference is that you aren't storing the hate list returned into a array variable, you're just using it directly from GetHateList().
not sure why CastSpell() isn't landing on the target specified.
Randymarsh9
09-18-2012, 10:57 PM
Interestingly, if I do something like having the monster shout a line saying the client's name and ID, it will do it for each person on the hate list, but the castspell will only affect the monster's target even if it is recognizing there are other people on its hate list.
Note:
quest::castspell(spellid, entid) works. It will cast a spell on every client on its list.
c0ncrete
09-18-2012, 11:15 PM
i just realized that it's likely because the npc's target is at the top of the hate list (the first entity in the array), and the loop you have is trying to get the npc to cast the spell on a new target while he's still casting on the first one.
you could attempt to address this by putting a delay (sleep($seconds)) equal to the cast time of the spell in the loop (you'd want to place it after the casting has begun). you could also check $npc->IsCasting() periodically to see if you needed to continue on to the next target. that way you wouldn't have a lengthy delay between casts if the cast was ever interrupted by the players. i'm not sure what sort of load that would cause on the server, however.
DUH.
or you could set the cast time to 0 in CastSpell()... i forgot that one. :)
CastSpell(spell_id, target_id, slot= 10, casttime= -1, mana_cost= -1)
Randymarsh9
09-19-2012, 01:52 AM
The spell didn't have a cast time in the first place. I couldn't get it to work with npc->CastSpell, but for some reason, quest::castspell works perfectly.
c0ncrete
09-19-2012, 10:45 AM
in the source code, quest::castspell() calls Mob::SpellFinished() while $npc->CastSpell() calls Mob::CastSpell(). i haven't looked over the source to be able to tell you exactly what the difference is, nor do i know the benefits of using one instead of the other (except for the fact that only one is working for you).
c0ncrete
09-19-2012, 11:53 AM
looks like quest::castspell() skips a lot of the validation checks (movement, stun, combat, etc) and timers involved with spell casting. i'm going to have to guess that the problem with using $npc->CastSpell() is still timer related, since it hits one target when you use it. otherwise, clients would probably see interruption messages while in combat with the npc in question.
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.