forked from acemod/ACE3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Common - Add
addPlayerEH
for adding EHs to ace_player (acemod#10056)
* Common - Add `addPlayerEH` for adding EHs to ace_player * Update fnc_addPlayerEH.sqf * convert ui to use new func
- Loading branch information
1 parent
560d4dd
commit 8f67914
Showing
5 changed files
with
63 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.