View Single Post
  #1  
Old 04-16-2008, 01:43 PM
Bulle
Hill Giant
 
Join Date: Jan 2008
Posts: 102
Default New EVENT_CASTED_ON event

I have implemented this event to be able to create quests like "go heal this NPC", "go buff this NPC", potentially it could be used to implement a special spell or proc harming an NPC (if the spell is cast on this specific NPC, then some harm is done). This event is received by an NPC each time a spell is cast on him, and it is passed the identity of the caster (usually a PC) and the ID of the casted spell in variable "$spell_id".
Note that it is triggered before any resist or invulnerability is checked. The spell hits the NPC, that is it.

BE CAREFUL : it means an event is fired each tme a spell is cast on an NPC. I have no idea how much CPU overload this can cause. If this proves useless for "Live".like servers and a performance-hog may be this post should be moved to the "Custom" section.

Here is how it is implemented (as an SVN diff from version 1102) :

Code:
Index: hero-emulator/zone/event_codes.h
===================================================================
--- hero-emulator/zone/event_codes.h    (revision 135)
+++ hero-emulator/zone/event_codes.h    (working copy)
@@ -23,6 +23,7 @@
        EVENT_ZONE,                     //pc only
        EVENT_LEVEL_UP,         //pc only
        EVENT_KILLED_MERIT,     //received by an NPC once for every PC having merit (would receive XP if mob were not green) to kill the NPC -
basically all the group
+       EVENT_CASTED_ON,        //received by an NPC when a spell is cast on him (whether it sticks, is invuln'd etc or not, when the spell hit
s)

        _LargestEventID
 } QuestEventID;
Code:
Index: hero-emulator/zone/embparser.cpp
===================================================================
--- hero-emulator/zone/embparser.cpp    (revision 135)
+++ hero-emulator/zone/embparser.cpp    (working copy)
@@ -57,7 +57,8 @@
        "EVENT_LOOT",
        "EVENT_ZONE",
        "EVENT_LEVEL_UP",
-       "EVENT_KILLED_MERIT"
+       "EVENT_KILLED_MERIT",
+       "EVENT_CASTED_ON"
 };

 PerlembParser::PerlembParser(void) : Parser()
@@ -494,6 +495,11 @@
                        break;
                }

+               case EVENT_CASTED_ON:{
+                       ExportVar(packagename.c_str(), "spell_id", data);
+                       break;
+               }
+
                //nothing special about these events
                case EVENT_DEATH:
                case EVENT_SPAWN:
Code:
Index: hero-emulator/zone/spells.cpp
===================================================================
--- hero-emulator/zone/spells.cpp       (revision 132)
+++ hero-emulator/zone/spells.cpp       (working copy)
@@ -2259,6 +2259,13 @@
 // end of action packet


+       /* Send the EVENT_CASTED_ON event */
+       if(spelltar->IsNPC())
+       {       char temp1[100];
+               sprintf(temp1, "%d", spell_id);
+               parse->Event(EVENT_CASTED_ON, spelltar->GetNPCTypeID(), temp1, spelltar->CastToNPC(), this);
+       }
+
        // solar: now check if the spell is allowed to land

        // invuln mobs can't be affected by any spells, good or bad
Finally an example on how to use it :
Code:
# a_defective_cleaner
sub EVENT_CASTED_ON
{ if($spell_id == 202)
  { quest::setglobal("DefectiveCleanersBuffed", 1, 5, "F"); }
}

sub EVENT_ITEM
{ plugin::return_items(\%itemcount);
}
Reply With Quote