ACE3/addons/common/functions/fnc_addSyncedEventHandler.sqf
2015-05-14 17:12:40 -05:00

34 lines
803 B
Plaintext

/*
* Author: jaynus
*
* Register an event handler for an ACE synced event
*
* Argument:
* 0: Name (String)
* 1: Handler (Code)
* 2: TTL (Number or Code) [Optional]
*
* Return value:
* Boolean of success
*/
//#define DEBUG_MODE_FULL
#include "script_component.hpp"
//IGNORE_PRIVATE_WARNING("_handleSyncedEvent");
PARAMS_2(_name,_handler);
private["_ttl", "_eventId", "_data"];
if( (count _this) > 2) then {
_ttl = _this select 2;
} else {
_ttl = 0;
};
if(HASH_HASKEY(GVAR(syncedEvents),_name)) exitWith {
diag_log text format["[ACE] Error, duplicate synced event creation."];
false
};
_eventId = [_name, FUNC(_handleSyncedEvent)] call FUNC(addEventHandler);
_data = [_handler,[],_ttl,_eventId];
HASH_SET(GVAR(syncedEvents),_name,_data);