ACE3/addons/common/functions/fnc_addEventHandler.sqf

33 lines
794 B
Plaintext
Raw Normal View History

/*
* Author: Nou
2015-09-18 06:47:14 +00:00
* Add an event handler.
*
2015-09-18 06:47:14 +00:00
* Arguments:
* 0: Event name <STRING>
* 1: Event code <CODE>
*
2015-09-18 06:47:14 +00:00
* Return Value:
* Event handler ID number (for use with fnc_removeEventHandler) <NUMBER>
*
2015-09-18 06:47:14 +00:00
* Public: Yes
*/
#include "script_component.hpp"
2015-05-14 18:02:42 +00:00
2015-09-18 06:47:14 +00:00
params ["_eventName", "_eventCode"];
2015-05-14 18:02:42 +00:00
GVAR(events) params ["_eventNames"];
private _eventFunctions = [];
private _eventIndex = _eventNames find _eventName;
2015-09-18 06:47:14 +00:00
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;
} else {
private _eventNameCount = count _eventNames;
2015-09-18 06:47:14 +00:00
_eventNames set [_eventNameCount, _eventName];
(GVAR(events) select 1) set [_eventNameCount, _eventFunctions];
};
2015-09-18 06:47:14 +00:00
_eventFunctions pushBack _eventCode // Return event function count