mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Common - Add addPlayerEH
for adding EHs to ace_player (#10056)
* Common - Add `addPlayerEH` for adding EHs to ace_player * Update fnc_addPlayerEH.sqf * convert ui to use new func
This commit is contained in:
parent
130348d3a5
commit
97bc371f5c
@ -265,6 +265,7 @@ PREP(_handleRequestAllSyncedEvents);
|
|||||||
PREP(addActionEventHandler);
|
PREP(addActionEventHandler);
|
||||||
PREP(addActionMenuEventHandler);
|
PREP(addActionMenuEventHandler);
|
||||||
PREP(addMapMarkerCreatedEventHandler);
|
PREP(addMapMarkerCreatedEventHandler);
|
||||||
|
PREP(addPlayerEH);
|
||||||
|
|
||||||
PREP(removeActionEventHandler);
|
PREP(removeActionEventHandler);
|
||||||
PREP(removeActionMenuEventHandler);
|
PREP(removeActionMenuEventHandler);
|
||||||
|
61
addons/common/functions/fnc_addPlayerEH.sqf
Normal file
61
addons/common/functions/fnc_addPlayerEH.sqf
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
#include "..\script_component.hpp"
|
||||||
|
/*
|
||||||
|
* Author: PabstMirror
|
||||||
|
* Adds event handler just to ACE_player
|
||||||
|
*
|
||||||
|
* Arguments:
|
||||||
|
* 0: Key <STRING>
|
||||||
|
* 1: Event Type <STRING>
|
||||||
|
* 2: Event Code <CODE>
|
||||||
|
* 3: Ignore Virtual Units (spectators, virtual zeus, uav RC) <BOOL> (default: false)
|
||||||
|
*
|
||||||
|
* Return Value:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
* ["example", "FiredNear", {systemChat str _this}] call ace_common_fnc_addPlayerEH
|
||||||
|
*
|
||||||
|
* Public: Yes
|
||||||
|
*/
|
||||||
|
params [["_key", "", [""]], ["_type", "", [""]], ["_code", {}, [{}]], ["_ignoreVirtual", false, [false]]];
|
||||||
|
TRACE_3("addPlayerEH",_key,_type,_ignoreVirtual);
|
||||||
|
|
||||||
|
if (isNil QGVAR(playerEventsHash)) then { // first-run init
|
||||||
|
GVAR(playerEventsHash) = createHashMap;
|
||||||
|
["unit", {
|
||||||
|
params ["_newPlayer", "_oldPlayer"];
|
||||||
|
// uav check only applies to direct controlling UAVs from zeus, no effect on normal UAV operation
|
||||||
|
private _isVirutal = (unitIsUAV _newPlayer) || {getNumber (configOf _newPlayer >> "isPlayableLogic") == 1};
|
||||||
|
|
||||||
|
TRACE_4("",_newPlayer,_oldPlayer,_isVirutal,count GVAR(playerEventsHash));
|
||||||
|
{
|
||||||
|
_y params ["_type", "_code", "_ignoreVirtual"];
|
||||||
|
|
||||||
|
private _oldEH = _oldPlayer getVariable [_x, -1];
|
||||||
|
if (_oldEH != -1) then {
|
||||||
|
_oldPlayer removeEventHandler [_type, _oldEH];
|
||||||
|
_oldPlayer setVariable [_x, nil];
|
||||||
|
};
|
||||||
|
|
||||||
|
_oldEH = _newPlayer getVariable [_x, -1];
|
||||||
|
if (_oldEH != -1) then { continue }; // if respawned then var and EH already exists
|
||||||
|
if (_ignoreVirtual && _isVirutal) then { continue };
|
||||||
|
|
||||||
|
private _newEH = _newPlayer addEventHandler [_type, _code];
|
||||||
|
_newPlayer setVariable [_x, _newEH];
|
||||||
|
} forEach GVAR(playerEventsHash);
|
||||||
|
}, false] call CBA_fnc_addPlayerEventHandler;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
_key = format [QGVAR(playerEvents_%1), toLower _key];
|
||||||
|
if (_key in GVAR(playerEventsHash)) exitWith { ERROR_1("bad key %1",_this); };
|
||||||
|
|
||||||
|
GVAR(playerEventsHash) set [_key, [_type, _code, _ignoreVirtual]];
|
||||||
|
|
||||||
|
if (isNull ACE_player) exitWith {};
|
||||||
|
if (_ignoreVirtual && {(unitIsUAV ACE_player) || {getNumber (configOf ACE_player >> "isPlayableLogic") == 1}}) exitWith {};
|
||||||
|
|
||||||
|
// Add event now
|
||||||
|
private _newEH = ACE_player addEventHandler [_type, _code];
|
||||||
|
ACE_player setVariable [_key, _newEH];
|
@ -1,5 +1,4 @@
|
|||||||
PREP(compileConfigUI);
|
PREP(compileConfigUI);
|
||||||
PREP(handlePlayerChanged);
|
|
||||||
PREP(handleSpeedIndicator);
|
PREP(handleSpeedIndicator);
|
||||||
PREP(moduleInit);
|
PREP(moduleInit);
|
||||||
PREP(onAnimChanged);
|
PREP(onAnimChanged);
|
||||||
|
@ -48,4 +48,4 @@ GVAR(elementsSet) = call CBA_fnc_createNamespace;
|
|||||||
}] call CBA_fnc_addEventHandler;
|
}] call CBA_fnc_addEventHandler;
|
||||||
}] call CBA_fnc_addEventHandler;
|
}] call CBA_fnc_addEventHandler;
|
||||||
|
|
||||||
["unit", LINKFUNC(handlePlayerChanged), true] call CBA_fnc_addPlayerEventHandler;
|
[QUOTE(ADDON), "AnimChanged", LINKFUNC(onAnimChanged)] call EFUNC(common,addPlayerEH);
|
||||||
|
@ -1,32 +0,0 @@
|
|||||||
#include "..\script_component.hpp"
|
|
||||||
/*
|
|
||||||
* Author: veteran29
|
|
||||||
* Handles switching units.
|
|
||||||
*
|
|
||||||
* Arguments:
|
|
||||||
* 0: New Unit <OBJECT>
|
|
||||||
* 1: Old Unit <OBJECT>
|
|
||||||
*
|
|
||||||
* Return Value:
|
|
||||||
* None
|
|
||||||
*
|
|
||||||
* Example:
|
|
||||||
* [newbob, oldbob] call ace_ui_fnc_handlePlayerChanged
|
|
||||||
*
|
|
||||||
* Public: No
|
|
||||||
*/
|
|
||||||
params ["_newUnit", "_oldUnit"];
|
|
||||||
TRACE_2("unit changed",_newUnit,_oldUnit);
|
|
||||||
|
|
||||||
if (!isNull _oldUnit) then {
|
|
||||||
_oldUnit removeEventHandler ["AnimChanged", _oldUnit getVariable [QGVAR(animHandler), -1]];
|
|
||||||
_oldUnit setVariable [QGVAR(animHandler), nil];
|
|
||||||
TRACE_1("remove old",_oldUnit getVariable QGVAR(animHandler));
|
|
||||||
};
|
|
||||||
|
|
||||||
// Don't add a new EH if the unit respawned
|
|
||||||
if (_newUnit getVariable [QGVAR(animHandler), -1] == -1) then {
|
|
||||||
private _animHandler = _newUnit addEventHandler ["AnimChanged", LINKFUNC(onAnimChanged)];
|
|
||||||
TRACE_1("add new",_animHandler);
|
|
||||||
_newUnit setVariable [QGVAR(animHandler), _animHandler];
|
|
||||||
};
|
|
Loading…
Reference in New Issue
Block a user