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