Those events will run only run for a specific object so they are optimal and should be your preferred way to register an event.
Registering / Unregistering a variable Event
As you can guess, it is using local variables, for example:
Will cause the myerf_useitem script to be called when the item on which the variable is set is used.
You can also register multiple script to the same event:
With the variables above, all scripts (myerf_useitem, myerf_useitem2, myerf_useitem3 and myerf_useitem4) will run when the item is used.
You can register / unregister a variable event dynamically with the following functions:
void RegisterVariableEvent(object oObject, string sEvent, string sScript, int bNoByPass=FALSE);
void UnregisterVariableEvent(object oObject, string sEvent, string sScript);
Accessing the Parameters
- The registered scripts will run in the same context as the calling script so for example:
EVENT_USE
is called by pc_ev_useitem so you can still get the item withGetEventParamObject(0)
. - A variable event can also have its own parameters, they can be accessed with the following functions:
array GetCurrentVariableEventParams();
- You can get the object on which the variable event was registered (it may not be the caller) and the currently running variable event (in case that you decide to register the same script to many events) with the following functions:
object GetCurrentVariableEventTarget(); string GetCurrentVariableEvent();
Creating / Running a Variable Based Event
You can trigger a variable event on an object by calling one of those functions:
int RunVariableEvent(object oObject, string sEvent);
int RunVariableEventWithParams(object oObject, string sEvent, array aParams);
They will return TRUE if the BypassVariableEvent()
was calling during the execution of one of the registered scripts.
List of events
More information here for now (to be merged here most likely): Event System
pc_ev_useitem -> item:EVENT_USE
self : user
p0: item
p1: target object
p2: target position
p3: sub type
pc_ev_examine -> player:EVENT_EXAMINE
self: player
p0: target object
pc_ev_attack -> attacker:EVENT_ATTACK
self: attacker
p0: target object
p1: attack type
pc_ev_trap -> target:EVENT_TRAP
self: trapper
p0: type
p1: target object
p2: target position
pc_ev_firetrap -> target:EVENT_FIRETRAP
self: trigger
p0: type
p1: target
pc_ev_useskill -> user:EVENT_USESKILL, user:EVENT_USESKILL_%skill%
self: user
p0: skill
p1: target
p2: target position
p3: item
pc_ev_usefeat -> user:EVENT_USEFEAT, user:EVENT_USEFEAT_%feat%
self: user
p0: feat
p1: target
p2: target position
pc_ev_togglemode -> user:EVENT_TOGGLEMODE, user:EVENT_TOGGLEMODE_%mode%
self: user
p0: mode
pc_ev_castspell -> caster:EVENT_CASTING, caster:EVENT_CASTING_%spell%
self: caster
p0: target
p1: target position
p2: spell
p3: meta magic
p4: class
p5: is instant
ilr_canequip -> item:EVENT_CAN_EQUIP
self: equip by
p0: item
pc_ev_setlike setter:EVENT_SETLIKE
self: setter
p0: type
p1: target
pc_ev_party
self: setter
p0: type
p1: target
pc_ev_pickpocket
self: attacker
p0: target object
EVENT_EQUIP
object oItem = GetPCItemLastEquipped();
object oPC = GetPCItemLastEquippedBy();
EVENT_UNEQUIP
object oItem = GetPCItemLastUnequipped();
object oPC = GetPCItemLastUnequippedBy();
EVENT_ACQUIRE
todo
EVENT_ATTACKROLL
todo