More event handler changes! Added removeEventHandler and removeAllEventHandler, changed name from addNetEventHandler to addEventHandler, and added a localEvent function.

This commit is contained in:
Nou 2015-01-14 12:44:32 -08:00
parent ccc3b9d076
commit 9a37538d50
6 changed files with 81 additions and 6 deletions

View File

@ -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

View File

@ -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)]);

View File

@ -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"];

View File

@ -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;
};

View File

@ -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, []];
};

View File

@ -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];
};