EQEmulator Forums

EQEmulator Forums (https://www.eqemulator.org/forums/index.php)
-   Development::Server Code Submissions (https://www.eqemulator.org/forums/forumdisplay.php?f=669)
-   -   minor change to NPC::Death() (https://www.eqemulator.org/forums/showthread.php?t=34943)

c0ncrete 02-19-2012 10:27 PM

minor change to NPC::Death()
 
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:Death() 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



All times are GMT -4. The time now is 01:20 AM.

Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.