diff --git a/addons/common/XEH_preInit.sqf b/addons/common/XEH_preInit.sqf index 57713d2611..4e94e554e7 100644 --- a/addons/common/XEH_preInit.sqf +++ b/addons/common/XEH_preInit.sqf @@ -138,13 +138,16 @@ PREP(addCuratorUnloadEventhandler); PREP(fixCrateContent); //ACE events global variables -GVAR(netEvents) = [[],[]]; +GVAR(events) = [[],[]]; PREP(globalEvent); PREP(_handleNetEvent); -PREP(addNetEventHandler); +PREP(addEventHandler); PREP(targetEvent); PREP(serverEvent); +PREP(localEvent); +PREP(removeEventHandler); +PREP(removeAlLEventHandlers); // Loop to update the ACE_player variable diff --git a/addons/common/functions/fnc__handleNetEvent.sqf b/addons/common/functions/fnc__handleNetEvent.sqf index 37a8ce8e6e..40d5d84e5e 100644 --- a/addons/common/functions/fnc__handleNetEvent.sqf +++ b/addons/common/functions/fnc__handleNetEvent.sqf @@ -12,10 +12,10 @@ if(_eventType == "ACEg") then { _eventName = _event select 0; _eventArgs = _event select 1; - _eventNames = GVAR(netEvents) select 0; + _eventNames = GVAR(events) select 0; _eventIndex = _eventNames find _eventName; if(_eventIndex != -1) then { - _events = (GVAR(netEvents) select 1) select _eventIndex; + _events = (GVAR(events) select 1) select _eventIndex; { if(!isNil "_x") then { _eventArgs call CALLSTACK_NAMED(_x, format[ARR_3("Net Event %1 ID: %2",_eventName,_forEachIndex)]); diff --git a/addons/common/functions/fnc_addNetEventHandler.sqf b/addons/common/functions/fnc_addEventHandler.sqf similarity index 84% rename from addons/common/functions/fnc_addNetEventHandler.sqf rename to addons/common/functions/fnc_addEventHandler.sqf index 1a6160e93c..b21221b294 100644 --- a/addons/common/functions/fnc_addNetEventHandler.sqf +++ b/addons/common/functions/fnc_addEventHandler.sqf @@ -1,14 +1,14 @@ /* * Author: Nou * - * Add a network event handler. + * Add a event handler. * * Argument: * 0: Event name (string) * 1: Event code (code) * * Return value: - * Event handler ID number (for use with fnc_removeNetEventHandler) + * Event handler ID number (for use with fnc_removeEventHandler) */ #include "script_component.hpp" private ["_eventName", "_eventCode", "_eventNames", "_eventFunctions", "_eventNameCount", "_eventIndex", "_eventFunctionCount"]; diff --git a/addons/common/functions/fnc_localEvent.sqf b/addons/common/functions/fnc_localEvent.sqf new file mode 100644 index 0000000000..85cc63a3b6 --- /dev/null +++ b/addons/common/functions/fnc_localEvent.sqf @@ -0,0 +1,27 @@ +/* + * Author: Nou + * + * Execute a local event on this client only. + * + * Argument: + * 0: Event name (string) + * 1: Event args (any) + * + * Return value: + * Nothing + */ +#include "script_component.hpp" + +_eventName = _this select 0; +_eventArgs = _this select 1; + +_eventNames = GVAR(events) select 0; +_eventIndex = _eventNames find _eventName; +if(_eventIndex != -1) then { + _events = (GVAR(events) select 1) select _eventIndex; + { + if(!isNil "_x") then { + _eventArgs call CALLSTACK_NAMED(_x, format[ARR_3("Local Event %1 ID: %2",_eventName,_forEachIndex)]); + }; + } forEach _events; +}; \ No newline at end of file diff --git a/addons/common/functions/fnc_removeAllEventHandlers.sqf b/addons/common/functions/fnc_removeAllEventHandlers.sqf new file mode 100644 index 0000000000..e3c5f49715 --- /dev/null +++ b/addons/common/functions/fnc_removeAllEventHandlers.sqf @@ -0,0 +1,21 @@ +/* + * Author: Nou + * + * Remove all events of a certain event type. + * + * Argument: + * 0: Event name (string) + * + * Return value: + * Nothing + */ +#include "script_component.hpp" +private ["_eventName", "_eventNames", "_eventFunctions", "_eventIndex"]; +_eventName = _this select 0; + +_eventNames = GVAR(netEvents) select 0; +_eventFunctions = []; +_eventIndex = _eventNames find _eventName; +if(_eventIndex != -1) then { + (GVAR(netEvents) select 1) set[_eventIndex, []]; +}; \ No newline at end of file diff --git a/addons/common/functions/fnc_removeEventHandler.sqf b/addons/common/functions/fnc_removeEventHandler.sqf new file mode 100644 index 0000000000..156b762872 --- /dev/null +++ b/addons/common/functions/fnc_removeEventHandler.sqf @@ -0,0 +1,24 @@ +/* + * Author: Nou + * + * Remove an event handler. + * + * Argument: + * 0: Event name (string) + * 1: Event code (number) + * + * Return value: + * Nothing + */ +#include "script_component.hpp" +private ["_eventName", "_eventNames", "_eventFunctions", "_eventIndex", "_eventCodeIndex"]; +_eventName = _this select 0; +_eventCodeIndex = _this select 1; + +_eventNames = GVAR(netEvents) select 0; +_eventFunctions = []; +_eventIndex = _eventNames find _eventName; +if(_eventIndex != -1) then { + _eventFunctions = (GVAR(netEvents) select 1) select _eventIndex; + _eventFunctions set[_eventCodeIndex, nil]; +}; \ No newline at end of file