From bd22390736d51176f679761b41634cee89d1f7c5 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Tue, 30 Aug 2016 12:42:21 -0500 Subject: [PATCH 1/2] playerEH - Optional call function if player defined Adds optional param to call event handler function if player is already defined --- addons/events/fnc_addPlayerEventHandler.sqf | 27 ++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/addons/events/fnc_addPlayerEventHandler.sqf b/addons/events/fnc_addPlayerEventHandler.sqf index abce170ad..7423806f7 100644 --- a/addons/events/fnc_addPlayerEventHandler.sqf +++ b/addons/events/fnc_addPlayerEventHandler.sqf @@ -17,6 +17,7 @@ Description: Parameters: _type - Event handler type. _function - Function to add to event. + _autoCall - Call function immediately if player is defined already Returns: _id - The ID of the event handler. @@ -34,33 +35,57 @@ SCRIPT(addPlayerEventHandler); if (!hasInterface) exitWith {-1}; -params [["_type", "", [""]], ["_function", {}, [{}]]]; +params [["_type", "", [""]], ["_function", {}, [{}]], ["_autoCall", false, [false]]]; _type = toLower _type; private _id = switch (_type) do { case ("unit"): { + if (_autoCall && {!isNull (missionNamespace getVariable [QGVAR(oldUnit), objNull])}) then { + [GVAR(oldUnit), objNull] call _function; + }; [QGVAR(unitEvent), _function] call CBA_fnc_addEventHandler // return id }; case ("weapon"): { + if (_autoCall && {!isNull (missionNamespace getVariable [QGVAR(oldUnit), objNull])}) then { + [GVAR(oldUnit), currentWeapon GVAR(oldUnit)] call _function; + }; [QGVAR(weaponEvent), _function] call CBA_fnc_addEventHandler // return id }; case ("loadout"): { + if (_autoCall && {!isNull (missionNamespace getVariable [QGVAR(oldUnit), objNull])}) then { + [GVAR(oldUnit), getUnitLoadout GVAR(oldUnit)] call _function; + }; [QGVAR(loadoutEvent), _function] call CBA_fnc_addEventHandler // return id }; case ("vehicle"): { + if (_autoCall && {!isNull (missionNamespace getVariable [QGVAR(oldUnit), objNull])}) then { + [GVAR(oldUnit), vehicle GVAR(oldUnit)] call _function; + }; [QGVAR(vehicleEvent), _function] call CBA_fnc_addEventHandler // return id }; case ("turret"): { + if (_autoCall && {!isNull (missionNamespace getVariable [QGVAR(oldUnit), objNull])}) then { + [GVAR(oldUnit), GVAR(oldUnit) call CBA_fnc_turretPath] call _function; + }; [QGVAR(turretEvent), _function] call CBA_fnc_addEventHandler // return id }; case ("visionmode"): { + if (_autoCall && {!isNull (missionNamespace getVariable [QGVAR(oldUnit), objNull])}) then { + [GVAR(oldUnit), currentVisionMode GVAR(oldUnit)] call _function; + }; [QGVAR(visionModeEvent), _function] call CBA_fnc_addEventHandler // return id }; case ("cameraview"): { + if (_autoCall && {!isNull (missionNamespace getVariable [QGVAR(oldUnit), objNull])}) then { + [GVAR(oldUnit), cameraView] call _function; + }; [QGVAR(cameraViewEvent), _function] call CBA_fnc_addEventHandler // return id }; case ("visiblemap"): { + if (_autoCall && {!isNull (missionNamespace getVariable [QGVAR(oldUnit), objNull])}) then { + [GVAR(oldUnit), visibleMap] call _function; + }; [QGVAR(visibleMapEvent), _function] call CBA_fnc_addEventHandler // return id }; default {-1}; From 388ed6cf9d15d8847fbaed0fbb12781e1ac0b183 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Wed, 31 Aug 2016 12:08:39 -0500 Subject: [PATCH 2/2] Rename var to _applyRetroactively --- addons/events/fnc_addPlayerEventHandler.sqf | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/addons/events/fnc_addPlayerEventHandler.sqf b/addons/events/fnc_addPlayerEventHandler.sqf index 7423806f7..51bb69786 100644 --- a/addons/events/fnc_addPlayerEventHandler.sqf +++ b/addons/events/fnc_addPlayerEventHandler.sqf @@ -17,7 +17,7 @@ Description: Parameters: _type - Event handler type. _function - Function to add to event. - _autoCall - Call function immediately if player is defined already + _applyRetroactively - Call function immediately if player is defined already (optional, default: false) Returns: _id - The ID of the event handler. @@ -35,55 +35,55 @@ SCRIPT(addPlayerEventHandler); if (!hasInterface) exitWith {-1}; -params [["_type", "", [""]], ["_function", {}, [{}]], ["_autoCall", false, [false]]]; +params [["_type", "", [""]], ["_function", {}, [{}]], ["_applyRetroactively", false, [false]]]; _type = toLower _type; private _id = switch (_type) do { case ("unit"): { - if (_autoCall && {!isNull (missionNamespace getVariable [QGVAR(oldUnit), objNull])}) then { + if (_applyRetroactively && {!isNull (missionNamespace getVariable [QGVAR(oldUnit), objNull])}) then { [GVAR(oldUnit), objNull] call _function; }; [QGVAR(unitEvent), _function] call CBA_fnc_addEventHandler // return id }; case ("weapon"): { - if (_autoCall && {!isNull (missionNamespace getVariable [QGVAR(oldUnit), objNull])}) then { + if (_applyRetroactively && {!isNull (missionNamespace getVariable [QGVAR(oldUnit), objNull])}) then { [GVAR(oldUnit), currentWeapon GVAR(oldUnit)] call _function; }; [QGVAR(weaponEvent), _function] call CBA_fnc_addEventHandler // return id }; case ("loadout"): { - if (_autoCall && {!isNull (missionNamespace getVariable [QGVAR(oldUnit), objNull])}) then { + if (_applyRetroactively && {!isNull (missionNamespace getVariable [QGVAR(oldUnit), objNull])}) then { [GVAR(oldUnit), getUnitLoadout GVAR(oldUnit)] call _function; }; [QGVAR(loadoutEvent), _function] call CBA_fnc_addEventHandler // return id }; case ("vehicle"): { - if (_autoCall && {!isNull (missionNamespace getVariable [QGVAR(oldUnit), objNull])}) then { + if (_applyRetroactively && {!isNull (missionNamespace getVariable [QGVAR(oldUnit), objNull])}) then { [GVAR(oldUnit), vehicle GVAR(oldUnit)] call _function; }; [QGVAR(vehicleEvent), _function] call CBA_fnc_addEventHandler // return id }; case ("turret"): { - if (_autoCall && {!isNull (missionNamespace getVariable [QGVAR(oldUnit), objNull])}) then { + if (_applyRetroactively && {!isNull (missionNamespace getVariable [QGVAR(oldUnit), objNull])}) then { [GVAR(oldUnit), GVAR(oldUnit) call CBA_fnc_turretPath] call _function; }; [QGVAR(turretEvent), _function] call CBA_fnc_addEventHandler // return id }; case ("visionmode"): { - if (_autoCall && {!isNull (missionNamespace getVariable [QGVAR(oldUnit), objNull])}) then { + if (_applyRetroactively && {!isNull (missionNamespace getVariable [QGVAR(oldUnit), objNull])}) then { [GVAR(oldUnit), currentVisionMode GVAR(oldUnit)] call _function; }; [QGVAR(visionModeEvent), _function] call CBA_fnc_addEventHandler // return id }; case ("cameraview"): { - if (_autoCall && {!isNull (missionNamespace getVariable [QGVAR(oldUnit), objNull])}) then { + if (_applyRetroactively && {!isNull (missionNamespace getVariable [QGVAR(oldUnit), objNull])}) then { [GVAR(oldUnit), cameraView] call _function; }; [QGVAR(cameraViewEvent), _function] call CBA_fnc_addEventHandler // return id }; case ("visiblemap"): { - if (_autoCall && {!isNull (missionNamespace getVariable [QGVAR(oldUnit), objNull])}) then { + if (_applyRetroactively && {!isNull (missionNamespace getVariable [QGVAR(oldUnit), objNull])}) then { [GVAR(oldUnit), visibleMap] call _function; }; [QGVAR(visibleMapEvent), _function] call CBA_fnc_addEventHandler // return id