View Full Version : Passing a random player on bosses hate list to another npc?
Astal
05-16-2011, 08:46 PM
Can this be done?
I have 4 mobs which im going to have cast a spell at random times between every 60 - 120 seconds.
I want them to cast them on random targets on the mobs hate list.
Im not too sure how to go about doing that.
This is the code for the mobs which will be casting the spells.
I assume ill use GetHateList(); on the main mobs script when hes attacked or?
Im not sure how I would store the hate list, ive never done much with arrays ect..
I assume how it would work is get the hate list and store each person on it as a variable, then randomly pick a variable each time the timer triggers and have the mob cast the spell on that person
Any help will be appreciated
##Child of Laiboch
sub EVENT_SPAWN {
quest::settimer("CastPlague", 60);
}
sub EVENT_TIMER {
my $range = 120; #maximum number
my $minimum = 60; #minimum number
my $random_number = int(rand($range)) + $minimum; #generate a number between $minimum and $range
if (($timer eq "CastPlague" ) && (defined($entity_list->GetNPCByNPCTypeID(999426))))
{
plugin::CastOnTarget(21480); #Virulent Plague
quest::shout("You cannot defeat our mother!!!");
quest::settimer("CastPlague", $random_number);
}
}
Astal
05-16-2011, 08:59 PM
Would this be on the right track
sub EVENT_ATTACK {
$entity_list->@GetHateList($c1->GetClientByID(1),$c2->GetClientByID(2),$c3->GetClientByID(3),$c4->GetClientByID(4),$c5->GetClientByID(5),$c6->GetClientByID(6));
}
joligario
05-16-2011, 09:33 PM
Actually, there is a Mob::GetHateRandom()
What Joligario says is the best solution. Get your npc with the entity list and hate random.
That said here is some quick untested code for manual hate list manipulation...
#hate_clone(npc1, npc2) = npc2 gains npc1's hate list
sub hate_clone
{
my $cloned = shift;
my $other = shift;
my @hatelist1 = $cloned->GetHateList();
foreach $ent (@hatelist)
{
my $h_ent = $ent->GetEnt();
my $h_dmg = $ent->GetDamage();
my $h_hate = $ent->GetHate();
if($h_ent)
{
if($other->CheckAggro($h_ent)) {
$other->SetHate($h_ent, $h_hate, $h_dmg);
}
else {
$other->AddToHateList($h_ent, $h_hate, $h_dmg, 0, 0, 0);
}
}
}
}
joligario
05-16-2011, 09:58 PM
I've also used signals before. On your mob with the hatelist, he can select the random player, and then send the name or id to one of the other NPCs. Then that other NPC would add that player to his own hatelist.
Astal
05-16-2011, 10:00 PM
What Joligario says is the best solution. Get your npc with the entity list and hate random.
That said here is some quick untested code for manual hate list manipulation...
#hate_clone(npc1, npc2) = npc2 gains npc1's hate list
sub hate_clone
{
my $cloned = shift;
my $other = shift;
my @hatelist1 = $cloned->GetHateList();
foreach $ent (@hatelist)
{
my $h_ent = $ent->GetEnt();
my $h_dmg = $ent->GetDamage();
my $h_hate = $ent->GetHate();
if($h_ent)
{
if($other->CheckAggro($h_ent)) {
$other->SetHate($h_ent, $h_hate, $h_dmg);
}
else {
$other->AddToHateList($h_ent, $h_hate, $h_dmg, 0, 0, 0);
}
}
}
}
what are $cloned and $other?
c0ncrete
05-16-2011, 10:10 PM
$cloned = $npc1 (npc you're cloning hate from)
$other = $npc2 (npc you're cloning hate to)
Astal
05-16-2011, 10:12 PM
ok, what event would i put that in?
I see you define your own sub, i didnt even know you could do that
also does the npc getting the list automatically set a target?
Like would this be the correct usage
Sorry for being dumb, i cant exactly tell whats going on in the code.
Not sure how i can then use that code to get a target in the hatelist on either the npc with the hatelist code or the casting npc.
Would you guys be able to explain your sub better or help me do it an easier way with getentity list and randomhate?
sub EVENT_TIMER {
my $range = 120; #maximum number
my $minimum = 60; #minimum number
my $random_number = int(rand($range)) + $minimum; #generate a number between $minimum and $range
if (($timer eq "CastPlague" ) && (defined($entity_list->GetNPCByNPCTypeID(999426))))
{
hate_clone(999426, 2700253); #target player on hatelist
plugin::CastOnTarget(21480); #Virulent Plague
quest::shout("You cannot defeat our mother!!!");
quest::settimer("CastPlague", $random_number);
}
}
Astal
05-16-2011, 10:30 PM
Sorry im just confused the hell out of :(
It was mostly used as an example of how to manipulate the hate lists. To give an idea of how to do what you want to do that way I still suggest Joli's idea.
Ex:
#find npc of npc type 123456
my $parent_npc = $entity_list->GetMobByNpcTypeID(123456);
if($parent_npc) {
my $random_target = $parent_npc->GetHateRandom();
#do something
}
Astal
05-16-2011, 11:13 PM
It was mostly used as an example of how to manipulate the hate lists. To give an idea of how to do what you want to do that way I still suggest Joli's idea.
Ex:
#find npc of npc type 123456
my $parent_npc = $entity_list->GetMobByNpcTypeID(123456);
if($parent_npc) {
my $random_target = $parent_npc->GetHateRandom();
#do something
}
oh, ok i have that so far, couldnt figure out how to sent the $random_target to the other mob though.
sub EVENT_ATTACK {
$laibach = $entity_list->GetMobByNpcTypeID(999424);
if($laibach) {
$random_hate = $mob->GetHateRandom();
}
}
trevius
05-16-2011, 11:27 PM
Try something like this, where 999424 is the NPCID of your main boss, which I assume is named Laibach. This script would be placed on each of your add NPCs. This assumes that they are attacked as well, to trigger this event, otherwise you can just signal them from your main boss to trigger this same bit of code instead.
sub EVENT_ATTACK {
# Get Laibach if he is up
my $laibach = $entity_list->GetMobByNpcTypeID(999424);
# Make sure you got him before using $laibach as a pointer
if($laibach)
{
# Get a random entry on Laibach's hate list
my $HateTarget = $laibach->GetHateRandom();
# Get the ID of that hate entry for use with CastSpell
my $HateTargetID = $HateTarget->GetID();
# Cast a spell on the random hate target (Courage in this example)
$npc->CastSpell(11, $HateTargetID);
}
}
Astal
05-16-2011, 11:32 PM
Try something like this, where 999424 is the NPCID of your main boss, which I assume is named Laibach. This script would be placed on each of your add NPCs. This assumes that they are attacked as well, to trigger this event, otherwise you can just signal them from your main boss to trigger this same bit of code instead.
sub EVENT_ATTACK {
# Get Laibach if he is up
my $laibach = $entity_list->GetMobByNpcTypeID(999424);
# Make sure you got him before using $laibach as a pointer
if($laibach)
{
# Get a random entry on Laibach's hate list
my $HateTarget = $laibach->GetHateRandom();
# Get the ID of that hate entry for use with CastSpell
my $HateTargetID = $HateTarget->GetID();
# Cast a spell on the random hate target (Courage in this example)
$npc->CastSpell(11, $HateTargetID);
}
}
oh, so i can put that on my other mobs not liabach and it will work the same?
the other mobs are immune to melee, only damaged by spells
trevius
05-16-2011, 11:47 PM
Personally, I like to run everything from 1 NPC so there is less scripts involved, but sometimes that can get a little tricky and it is probably best for you to start off as simple as possible until you are comfortable moving to more complex stuff.
To run it all from the boss, would take a bit more information. But, a simple example would be like this:
sub EVENT_ATTACK {
# Get each of the NPC casters:
my $AddNPC1 = $entity_list->GetMobByNpcTypeID(999425);
my $AddNPC2 = $entity_list->GetMobByNpcTypeID(999426);
my $AddNPC3 = $entity_list->GetMobByNpcTypeID(999427);
my $AddNPC4 = $entity_list->GetMobByNpcTypeID(999428);
# Get a random entry on Laibach's hate list
my $HateTarget = $npc->GetHateRandom();
# Get the ID of that hate entry for use with CastSpell
my $HateTargetID = $HateTarget->GetID();
# Make sure you got him before using $laibach as a pointer
if($AddNPC1)
{
# Cast a spell on the random hate target (Courage in this example)
$AddNPC1->CastSpell(11, $HateTargetID);
}
if($AddNPC2)
{
# Cast a spell on the random hate target (Courage in this example)
$AddNPC2->CastSpell(11, $HateTargetID);
}
if($AddNPC3)
{
# Cast a spell on the random hate target (Courage in this example)
$AddNPC3->CastSpell(11, $HateTargetID);
}
if($AddNPC4)
{
# Cast a spell on the random hate target (Courage in this example)
$AddNPC4->CastSpell(11, $HateTargetID);
}
}
That will be run from your boss and you will need to edit the NPC ID for each of the adds that you have, assuming they each have their own unique NPC Type IDs. This version will make it so that each of your adds all concentrate on the same random hate target instead of each of them choosing a separate random hate target. You can get separate random hate targets for each one if you want easy enough though.
Astal
05-16-2011, 11:50 PM
Personally, I like to run everything from 1 NPC so there is less scripts involved, but sometimes that can get a little tricky and it is probably best for you to start off as simple as possible until you are comfortable moving to more complex stuff.
To run it all from the boss, would take a bit more information. But, a simple example would be like this:
sub EVENT_ATTACK {
# Get each of the NPC casters:
my $AddNPC1 = $entity_list->GetMobByNpcTypeID(999425);
my $AddNPC2 = $entity_list->GetMobByNpcTypeID(999426);
my $AddNPC3 = $entity_list->GetMobByNpcTypeID(999427);
my $AddNPC4 = $entity_list->GetMobByNpcTypeID(999428);
# Get a random entry on Laibach's hate list
my $HateTarget = $npc->GetHateRandom();
# Get the ID of that hate entry for use with CastSpell
my $HateTargetID = $HateTarget->GetID();
# Make sure you got him before using $laibach as a pointer
if($AddNPC1)
{
# Cast a spell on the random hate target (Courage in this example)
$AddNPC1->CastSpell(11, $HateTargetID);
}
if($AddNPC2)
{
# Cast a spell on the random hate target (Courage in this example)
$AddNPC2->CastSpell(11, $HateTargetID);
}
if($AddNPC3)
{
# Cast a spell on the random hate target (Courage in this example)
$AddNPC3->CastSpell(11, $HateTargetID);
}
if($AddNPC4)
{
# Cast a spell on the random hate target (Courage in this example)
$AddNPC4->CastSpell(11, $HateTargetID);
}
}
That will be run from your boss and you will need to edit the NPC ID for each of the adds that you have, assuming they each have their own unique NPC Type IDs. This version will make it so that each of your adds all concentrate on the same random hate target instead of each of them choosing a separate random hate target. You can get separate random hate targets for each one if you want easy enough though.
Ok cool, I can understand that, im sure with a bit of reading i can get em to get random hate targets. (thats what im lookin for)
thanks trev
oh what if they have the same Id? its based off of one mob i made multiple spawns of, just use the one Id then?
Also does that update each time he is attacked or only the first attack?
If its just once, ill have to figure a way to maybe work a timer in, so it selects new random targets every so often
trevius
05-17-2011, 01:37 AM
If they are all the same ID, then you will need to do an NPC List search to find each NPC that matches that ID. Then, you can perform whatever within that same part of the loop.
If you need it to happen multiple times, then the best way is to do it on a timer, as EVENT_ATTACK is not for each round.
Astal
05-19-2011, 04:08 PM
still having some problems everything triggers but they dont cast the spell.
Is it because im getting them by an entitylist?
They are getting my guys ID, i checked that in the one shout (not in this script the one in my editor)
so only thing i can think of is
my $AddNPC1 = $entity_list->GetMobByNpcTypeID(2700253);
since its an entitylist and there is no $entity_list->CastSpell function, or am i reading it wrong?
$AddNPC1->CastSpell(21480, $HateTargetID);
sub EVENT_SAY {
if($text=~/Hail/i) {
$client->Message(315, "Script Working");
}
}
sub EVENT_SPAWN {
}
sub EVENT_HP {
}
sub EVENT_AGGRO {
quest::settimer("Random_Hate", 25); #set timer to get random hate mob
quest::shout("Timer Set");
}
sub EVENT_TIMER {
if ($timer eq "Random_Hate" ) {
quest::shout("Timer Triggered");
my $range = 120; #maximum number
my $minimum = 60; #minimum number
my $random_number = int(rand($range)) + $minimum; #generate a number between $minimum and $range
quest::settimer("Random_Hate", $random_number); #set timer to a random number between 60 and 120
# Get each of the NPC casters:
my $AddNPC1 = $entity_list->GetMobByNpcTypeID(2700253);
my $AddNPC2 = $entity_list->GetMobByNpcTypeID(2700259);
my $AddNPC3 = $entity_list->GetMobByNpcTypeID(2700260);
my $AddNPC4 = $entity_list->GetMobByNpcTypeID(2700266);
# Get a random entry on Laibach's hate list
my $HateTarget = $npc->GetHateRandom();
# Get the ID of that hate entry for use with CastSpell
my $HateTargetID = $HateTarget->GetID();
# Make sure you got him before using $laibach as a pointer
if($AddNPC1)
{
# Cast a spell on the random hate target (Courage in this example)
$AddNPC1->CastSpell(21480, $HateTargetID);
quest::shout("You cannot defeat our mother!!!");
}
if($AddNPC2)
{
# Cast a spell on the random hate target (Courage in this example)
$AddNPC2->CastSpell(21480, $HateTargetID);
quest::shout("You cannot defeat our mother!!!");
}
if($AddNPC3)
{
#Cast a spell on the random hate target (Courage in this example)
$AddNPC3->CastSpell(21480, $HateTargetID);
quest::shout("You cannot defeat our mother!!!");
}
if($AddNPC4)
{
#Cast a spell on the random hate target (Courage in this example)
$AddNPC3->CastSpell(21480, $HateTargetID);
quest::shout("You cannot defeat our mother!!!");
}
}
}
joligario
05-19-2011, 09:00 PM
You are looking at that part wrong. $entity_list->GetMobByNpcTypeID() passes a type Mob. Therefore, you when you call $AddNPC->CastSpell() is actually Mob::CastSpell(spellid,targetid)
Astal
05-19-2011, 09:43 PM
You are looking at that part wrong. $entity_list->GetMobByNpcTypeID() passes a type Mob. Therefore, you when you call $AddNPC->CastSpell() is actually Mob::CastSpell(spellid,targetid)
so is that correct usage then?
joligario
05-19-2011, 10:15 PM
Yes, at a quick glance it looks right.
Astal
05-19-2011, 10:16 PM
Yes, at a quick glance it looks right.
hey i think i hit the max spell limit at 21473 can you confirm this and do you know how to change it?
Im using SoD
joligario
05-20-2011, 05:51 AM
It doesn't seem like an integer problem... not that number. I think that may be a client thing. Are you sure SoD handles that spell? It looks pretty new according to Lucy.
Astal
05-20-2011, 04:22 PM
It doesn't seem like an integer problem... not that number. I think that may be a client thing. Are you sure SoD handles that spell? It looks pretty new according to Lucy.
its a custom spell, i found out the problem spell editor changed the database on me. so it was writing to a non existant one
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.