Log in

View Full Version : Trivial random loot help


N0ctrnl
06-05-2016, 06:53 PM
I use a variation of the following to add a random item to an NPC when it spawns (from global_npc.pl):


sub EVENT_SPAWN {
$roll = int(rand(100)) + 1;

if($roll >= 90) {
my $itemid=(132522);

$npc->AddItem($itemid);
}
}

What I would like to do is to remove the item if a player is too many levels over the NPC when they loot the corpse. Is there a way to key off of that? I know there's a $corpse->RemoveItem(); I could use, but what would I trigger on? It looks like EVENT_LOOT is only when an item is plucked.

Any help is appreciated :) Just can't come up with a good way to do this so far.

N0ctrnl
06-06-2016, 05:53 PM
This is what I went with. It's not perfect, but it's good enough for my uses.


sub EVENT_DEATH {
if ($ulevel > ($mlevel + 15)) {
$npc->RemoveItem(132522);
}
}

DanCanDo
06-06-2016, 06:38 PM
Nice, this is something to help with a different idea I wanted to experiment with.
What I want to have happen, is when a certain lower level mob is killed, there
would be a mob spawn from EVENT_DEATH, but the spawned mob would be at a
level closer to the toon that killed the PH.
In a nutshell, for example, if a level 15 kills the PH, the mob that spawns would
be 15-20'ish. But if a level 40 toon kills the PH, it would spawn a level 40-45'ish
mob.

N0ctrnl
06-06-2016, 07:01 PM
What I had hoped to do was remove the drop if a higher level even got on the hatelist - which would be the right way do to it - but that's above my skill level to figure out. Assuming it's even possible :)

Shin Noir
06-06-2016, 07:11 PM
What I had hoped to do was remove the drop if a higher level even got on the hatelist - which would be the right way do to it - but that's above my skill level to figure out. Assuming it's even possible :)

It's possible.
You could verify it by adding this code: (found in http://wiki.eqemulator.org/p?Ultimate_Perl_Reference)

my @hatelist = $npc->GetHateList();
foreach $ent (@hatelist) {
my $h_ent = $ent->GetEnt(); # do not forget GetEnt() or the script halts!
my $h_dmg = $ent->GetDamage();
my $h_hate = $ent->GetHate();
if($h_ent) {
my $h_ent_name = $h_ent->GetCleanName();
quest::say("$h_ent_name is on my hate list with $h_hate hate and $h_dmg damage.");
}
}

$npc may not be set, so may need to get the entity and cast it over, but if the hate list isn't wiped out before DEATH event is triggered, the above code lets you iterate it's hate list.

Then, just change the code logic to get each entity's level and remove loot if a higher level is there.

DanCanDo
06-06-2016, 07:13 PM
I can't remember for the life of me, but way back on eqlive, I seem to remember some kind of named that dropped something for a specific class and if the wrong class killed the named, the item would not drop ? I'm not 100% positive on that. (memory fizzles a lot).

NatedogEZ
06-06-2016, 08:11 PM
This should work for you...


sub EVENT_HATE_LIST {
if ($hate_state == 1 && $client && $client->GetLevel() > ($mlevel + 15) && $npc->GetEntityVariable("removed") != 1) {
$npc->RemoveItem(132522);
$npc->SetEntityVariable("removed", 1); #so it stops trying to remove the item when more people aggro it
}
}

c0ncrete
06-07-2016, 05:12 PM
This should work for you...


sub EVENT_HATE_LIST {
if ($hate_state == 1 && $client && $client->GetLevel() > ($mlevel + 15) && $npc->GetEntityVariable("removed") != 1) {
$npc->RemoveItem(132522);
$npc->SetEntityVariable("removed", 1); #so it stops trying to remove the item when more people aggro it
}
}


simple and elegant

N0ctrnl
06-07-2016, 05:26 PM
That is exactly what I was trying to get to. Thanks Natedog :)