I was recently looking for a way to use Perl to remove a particular item from an NPC's corpse that was added to its inventory from within the same script. I had intended to use $corpse->RemoveItem($slotID) in the EVENT_DEATH sub, and found that there is currently no way to do this, as slotIDs are apparently not assigned to the items until the corpse is in the process of being looted. I have since solved the problem by moving the call to parse EVENT_DEATH in NPC
eath() to a bit earlier in the function. This allows me to use $npc->RemoveItem($itemID) in EVENT_DEATH, as it is now parsed just prior to corpse creation.
Code:
Index: attack.cpp
===================================================================
--- attack.cpp (revision 2103)
+++ attack.cpp (working copy)
@@ -2174,7 +2174,18 @@
//do faction hits even if we are a merchant, so long as a player killed us
if(give_exp_client)
hate_list.DoFactionHits(GetNPCFactionID());
-
+
+ // Parse quests even if we're killed by an NPC
+ if(killerMob) {
+ Mob *oos = killerMob->GetOwnerOrSelf();
+ parse->EventNPC(EVENT_DEATH, this, oos, "", 0);
+ if(oos->IsNPC())
+ {
+ parse->EventNPC(EVENT_NPC_SLAY, oos->CastToNPC(), this, "", 0);
+ killerMob->TrySpellOnKill();
+ }
+ }
+
if (!HasOwner() && class_ != MERCHANT && class_ != ADVENTUREMERCHANT && !GetSwarmInfo()
&& MerchantType == 0 && killer && (killer->IsClient() || (killer->HasOwner() && killer->GetUltimateOwner()->IsClient()) ||
(killer->IsNPC() && killer->CastToNPC()->GetSwarmInfo() && killer->CastToNPC()->GetSwarmInfo()->GetOwner() && killer->CastToNPC()->GetSwarmInfo()->GetOwner()->IsClient()))) {
@@ -2264,17 +2275,6 @@
}
}
- // Parse quests even if we're killed by an NPC
- if(killerMob) {
- Mob *oos = killerMob->GetOwnerOrSelf();
- parse->EventNPC(EVENT_DEATH, this, oos, "", 0);
- if(oos->IsNPC())
- {
- parse->EventNPC(EVENT_NPC_SLAY, oos->CastToNPC(), this, "", 0);
- killerMob->TrySpellOnKill();
- }
- }
-
this->WipeHateList();
p_depop = true;
if(killerMob && killerMob->GetTarget() == this) //we can kill things without having them targeted