Add ace_common_fnc_addPlayerEH

This commit is contained in:
PabstMirror 2024-05-23 19:44:45 -05:00
parent 4b30e095bf
commit 3f9da5f308
4 changed files with 49 additions and 4 deletions

View File

@ -6,4 +6,4 @@ GVAR(cachedCasings) = createHashMap;
GVAR(cachedMagazines) = createHashMap;
GVAR(casings) = [];
["CAManBase", "FiredMan", LINKFUNC(createCasing)] call CBA_fnc_addClassEventHandler;
["CAManBase", "Reloaded", LINKFUNC(createMagazine)] call CBA_fnc_addClassEventHandler;
[QGVAR(reloaded), "Reloaded", LINKFUNC(createMagazine)] call EFUNC(common,addPlayerEH);

View File

@ -19,15 +19,15 @@
params ["_unit", "", "", "", "_oldMagazine"];
TRACE_2("createMagazine",_unit,_oldMagazine);
if (_unit != ACE_player) exitWith {};
if (isNil "_oldMagazine") exitWith {};
_oldMagazine params ["_mag", "_ammo"];
if (_ammo != 0) exitWith {};
private _modelPath = GVAR(cachedMagazines) getOrDefaultCall [_mag, {
switch (true) do {
case (_mag in compatibleMagazines ["arifle_Mk20_GL_F", "EGLM"]): { "A3\Weapons_F\MagazineProxies\mag_40x36_HE_1rnd.p3d" }; // Should cover most 40x36
default { getText (configFile >> "CfgMagazines" >> _mag >> QGVAR(dropModel)) }
// Should cover most 40x36
case (_mag in compatibleMagazines ["arifle_Mk20_GL_F", "EGLM"]): { "A3\Weapons_F\MagazineProxies\mag_40x36_HE_1rnd.p3d" };
default { getText (configFile >> "CfgMagazines" >> _mag >> QGVAR(model)) };
};
}, true];

View File

@ -264,6 +264,7 @@ PREP(_handleRequestAllSyncedEvents);
PREP(addActionEventHandler);
PREP(addActionMenuEventHandler);
PREP(addMapMarkerCreatedEventHandler);
PREP(addPlayerEH);
PREP(removeActionEventHandler);
PREP(removeActionMenuEventHandler);

View File

@ -0,0 +1,44 @@
#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>
*
* Return Value:
* None
*
* Example:
* ["example", "FiredNear", {systemChat str _this}] call ace_common_fnc_addPlayerEH
*
* Public: Yes
*/
params [["_key", "", [""]], ["_type", "", [""]], ["_code", {}, [{}]]];
if (isNil QGVAR(playerEventsHash)) then { // init
GVAR(playerEventsHash) = createHashMap;
["unit", {
params ["_newPlayer", "_oldPlayer"];
TRACE_3("",_newPlayer,_oldPlayer,count GVAR(playerEventsHash));
{
private _var = format [QGVAR(playerEvents_%1), _x];
private _oldEH = _oldPlayer getVariable [_var, -1];
_oldPlayer removeEventHandler [_y#0, _oldEH];
_oldPlayer setVariable [_var, nil];
private _newEH = _newPlayer addEventHandler _y;
_newPlayer setVariable [_var, _newEH];
} forEach GVAR(playerEventsHash);
}, false] call CBA_fnc_addPlayerEventHandler;
};
private _event = [_type, _code];
GVAR(playerEventsHash) set [_key, _event];
if (isNull ACE_player) exitWith {};
private _var = format [QGVAR(playerEvents_%1), _key];
private _newEH = ACE_player addEventHandler _event;
ACE_player setVariable [_var, _newEH];