Those events are tie to a script name/ResRef they will run whenever the script that they are registered to is called. It is good to change the behaviour or a specific script by bypassing it or when the caller doesn't matter, but if you want to do something only when something happen to a specific object, you should use the PAGE INFO ALREADY TRANSFERRED TO THE NEW WIKI - Variable Based Events system.
This is done with the 2 following functions:
void RegisterEvent(string sEvent, string sScript); void UnregisterEvent(string sEvent, string sScript);
For example, the following line:
RegisterEvent("pc_ev_death", "myerf_ev_pcdeath")
… will cause the myerf_ev_pcdeath script to be called before and every time that the pc_ev_death is about to be executed.
The parameters can be accessed the same way as the original script and the caller will be the same.
If in the middle of a script you want to notify everyone interested by what is happening, you can use the ExecuteScript function, but better, you can use the RunEvent(ReturnType) functions, which will create a script based event that can be registered, have parameters and a return value:
int RunEvent(string sScript, object oTarget, array aParams); int RunEventInt(string sScript, object oTarget, array aParams); object RunEventObject(string sScript, object oTarget, array aParams); string RunEventString(string sScript, object oTarget, array aParams); float RunEventFloat(string sScript, object oTarget, array aParams); effect RunEventEffect(string sScript, object oTarget, array aParams); array RunEventArray(string sScript, object oTarget, array aParams); dictionary RunEventDictionary(string sScript, object oTarget, array aParams); vector RunEventVector(string sScript, object oTarget, array aParams); location RunEventLocation(string sScript, object oTarget, array aParams);