====== PAGE INFO ALREADY TRANSFERRED TO THE NEW WIKI - Variable Based Events ======
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:\\
{{:building:scripts:events:variable_based_20190311-000047.png?400}} \\
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:\\
{{:building:scripts:events:variable_based_20190311-001248.png?400}}\\
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 [[https://nwn.sinfar.net/res_nss_edit.php?name=pc_ev_useitem|pc_ev_useitem]] so you can still get the item with GetEventParamObject(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.