ACE3/addons/common/functions/fnc_addEventHandler.sqf

32 lines
939 B
Plaintext
Raw Normal View History

/*
* Author: Nou
*
* Add a event handler.
*
* Argument:
* 0: Event name (string)
* 1: Event code (code)
*
* Return value:
* Event handler ID number (for use with fnc_removeEventHandler)
*/
#include "script_component.hpp"
private ["_eventName", "_eventCode", "_eventNames", "_eventFunctions", "_eventNameCount", "_eventIndex", "_eventFunctionCount"];
_eventName = _this select 0;
_eventCode = _this select 1;
2015-01-14 20:55:44 +00:00
_eventNames = GVAR(events) select 0;
_eventFunctions = [];
_eventIndex = _eventNames find _eventName;
if(_eventIndex != -1) then {
2015-01-14 20:55:44 +00:00
_eventFunctions = (GVAR(events) select 1) select _eventIndex;
} else {
_eventNameCount = count _eventNames;
_eventNames set[_eventNameCount, _eventName];
2015-01-14 20:55:44 +00:00
(GVAR(events) select 1) set[_eventNameCount, _eventFunctions];
};
_eventFunctionCount = count _eventFunctions;
_eventFunctions set[_eventFunctionCount, _eventCode];
_eventFunctionCount;