mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Add ace_common_fnc_addPlayerEH
This commit is contained in:
parent
4b30e095bf
commit
3f9da5f308
@ -6,4 +6,4 @@ GVAR(cachedCasings) = createHashMap;
|
|||||||
GVAR(cachedMagazines) = createHashMap;
|
GVAR(cachedMagazines) = createHashMap;
|
||||||
GVAR(casings) = [];
|
GVAR(casings) = [];
|
||||||
["CAManBase", "FiredMan", LINKFUNC(createCasing)] call CBA_fnc_addClassEventHandler;
|
["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);
|
||||||
|
@ -19,15 +19,15 @@
|
|||||||
params ["_unit", "", "", "", "_oldMagazine"];
|
params ["_unit", "", "", "", "_oldMagazine"];
|
||||||
TRACE_2("createMagazine",_unit,_oldMagazine);
|
TRACE_2("createMagazine",_unit,_oldMagazine);
|
||||||
|
|
||||||
if (_unit != ACE_player) exitWith {};
|
|
||||||
if (isNil "_oldMagazine") exitWith {};
|
if (isNil "_oldMagazine") exitWith {};
|
||||||
_oldMagazine params ["_mag", "_ammo"];
|
_oldMagazine params ["_mag", "_ammo"];
|
||||||
if (_ammo != 0) exitWith {};
|
if (_ammo != 0) exitWith {};
|
||||||
|
|
||||||
private _modelPath = GVAR(cachedMagazines) getOrDefaultCall [_mag, {
|
private _modelPath = GVAR(cachedMagazines) getOrDefaultCall [_mag, {
|
||||||
switch (true) do {
|
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
|
// Should cover most 40x36
|
||||||
default { getText (configFile >> "CfgMagazines" >> _mag >> QGVAR(dropModel)) }
|
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];
|
}, true];
|
||||||
|
|
||||||
|
@ -264,6 +264,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);
|
||||||
|
44
addons/common/functions/fnc_addPlayerEH.sqf
Normal file
44
addons/common/functions/fnc_addPlayerEH.sqf
Normal 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];
|
Loading…
Reference in New Issue
Block a user