PDA

View Full Version : New EVENT_CASTED_ON event


Bulle
04-16-2008, 01:43 PM
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) :

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;

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:

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 :
# a_defective_cleaner
sub EVENT_CASTED_ON
{ if($spell_id == 202)
{ quest::setglobal("DefectiveCleanersBuffed", 1, 5, "F"); }
}

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

Knightly
04-17-2008, 12:57 AM
I don't want this to sound trite or anything, but if it's going into the source the past tense of "cast" is just "cast"

Bulle
04-17-2008, 02:35 AM
Very true.As you can see English is not my native language. Thank you for pointing it out.

trevius
04-17-2008, 04:16 AM
We all know Bulle's native language is C or some other code lol.

Sounds interesting. I am all about having more options! Making unique events is one of the goals I work towards on my server. Nothing spectacular yet, but I am always trying to think up new stuff.

KLS
04-19-2008, 11:26 PM
I actually had this and the other thing you posted in when I first did player quests but took them out. The merit one makes a lot more sense on npcs heh, anyway I'll be putting this in soon enough.

Bulle
04-20-2008, 05:05 PM
This is great news KLS, thanks. I have been using these two events since I have written them and have had no problem yet. I leave it up to you whether to rename the CASTED by CAST or not, I am a bit puzzled about my English there :-? : you can find reference to both words in many places on the web or in EQEmu.