From b8fb1cb86ddf4263efab499162aef7c60a446aa2 Mon Sep 17 00:00:00 2001 From: bux578 Date: Mon, 9 Feb 2015 19:06:28 +0100 Subject: [PATCH 1/6] SwitchUnits: remove PFH and code cleanup --- addons/switchunits/CfgEventHandlers.hpp | 3 ++- addons/switchunits/XEH_clientInit.sqf | 4 ++++ addons/switchunits/config.cpp | 8 ++++---- .../switchunits/functions/fnc_markAiOnMap.sqf | 3 --- addons/switchunits/functions/fnc_module.sqf | 17 +++++++++++++++-- addons/switchunits/script_component.hpp | 4 ++-- addons/switchunits/stringtable.xml | 1 - 7 files changed, 27 insertions(+), 13 deletions(-) diff --git a/addons/switchunits/CfgEventHandlers.hpp b/addons/switchunits/CfgEventHandlers.hpp index 38f9883743..ccebe8bc6f 100644 --- a/addons/switchunits/CfgEventHandlers.hpp +++ b/addons/switchunits/CfgEventHandlers.hpp @@ -3,9 +3,10 @@ class Extended_PreInit_EventHandlers { init = QUOTE( call COMPILE_FILE(XEH_preInit) ); }; }; - +/* class Extended_PostInit_EventHandlers { class ADDON { clientInit = QUOTE( call COMPILE_FILE(XEH_clientInit) ); }; }; +*/ diff --git a/addons/switchunits/XEH_clientInit.sqf b/addons/switchunits/XEH_clientInit.sqf index 3075d67941..24e0b4d3b6 100644 --- a/addons/switchunits/XEH_clientInit.sqf +++ b/addons/switchunits/XEH_clientInit.sqf @@ -16,6 +16,8 @@ #include "script_component.hpp" +/* + DFUNC(pfhClientInit) = { if (GVAR(EnableSwitchUnits)) exitWith { @@ -37,3 +39,5 @@ DFUNC(pfhClientInit) = { }; [FUNC(pfhClientInit), 0.5, []] call cba_fnc_addPerFrameHandler; + +*/ diff --git a/addons/switchunits/config.cpp b/addons/switchunits/config.cpp index 09d3e05594..c400be855c 100644 --- a/addons/switchunits/config.cpp +++ b/addons/switchunits/config.cpp @@ -16,10 +16,6 @@ class CfgPatches { #include "CfgVehicles.hpp" class ACE_Settings { - class GVAR(SafeZoneRadius) { - value = 100; - typeName = "SCALAR"; - }; class GVAR(EnableSwitchUnits) { value = 0; typeName = "BOOL"; @@ -44,4 +40,8 @@ class ACE_Settings { value = 1; typeName = "BOOL"; }; + class GVAR(SafeZoneRadius) { + value = 100; + typeName = "SCALAR"; + }; }; diff --git a/addons/switchunits/functions/fnc_markAiOnMap.sqf b/addons/switchunits/functions/fnc_markAiOnMap.sqf index ed94c31b0b..d51c1b888e 100644 --- a/addons/switchunits/functions/fnc_markAiOnMap.sqf +++ b/addons/switchunits/functions/fnc_markAiOnMap.sqf @@ -40,9 +40,6 @@ DFUNC(pfhMarkAiOnMap) = { if (([_x] call FUNC(isValidAi) && (side group _x in _sides)) || (_x getVariable [QGVAR(IsPlayerControlled), false])) then { private ["_markerName", "_marker", "_markerColor"]; - hint format ["marker. %1", time]; - - //_markerName = format ["%1", [_x] call EFUNC(common,getName)]; _markerName = str _x; _marker = createMarkerLocal [_markerName, position _x]; diff --git a/addons/switchunits/functions/fnc_module.sqf b/addons/switchunits/functions/fnc_module.sqf index e622a65338..74c8bd8d10 100644 --- a/addons/switchunits/functions/fnc_module.sqf +++ b/addons/switchunits/functions/fnc_module.sqf @@ -20,8 +20,7 @@ if !(isServer) exitWith {}; -_logic = _this select 0; -_activated = _this select 2; +EXPLODE_3_PVT(_this,_logic,_units,_activated); if !(_activated) exitWith {}; @@ -38,3 +37,17 @@ GVAR(Module) = true; [QGVAR(EnableSwitchUnits), true, false, true] call EFUNC(common,setSetting); diag_log text "[ACE]: SwitchUnits Module Initialized."; + +if (GVAR(EnableSwitchUnits)) then { + private ["_sides"]; + _sides = []; + + if(GVAR(SwitchToWest)) then {_sides pushBack west;}; + if(GVAR(SwitchToEast)) then {_sides pushBack east;}; + if(GVAR(SwitchToIndependent)) then {_sides pushBack independent;}; + if(GVAR(SwitchToCivilian)) then {_sides pushBack civilian;}; + + if (player getVariable ["ACE_CanSwitchUnits", false]) then { + [player, _sides] call FUNC(initPlayer); + }; +}; diff --git a/addons/switchunits/script_component.hpp b/addons/switchunits/script_component.hpp index 989c1c2e0c..4e76fb1495 100644 --- a/addons/switchunits/script_component.hpp +++ b/addons/switchunits/script_component.hpp @@ -2,11 +2,11 @@ #include "\z\ace\addons\main\script_mod.hpp" #ifdef DEBUG_ENABLED_SWITCHUNITS - #define DEBUG_MODE_FULL + #define DEBUG_MODE_FULL #endif #ifdef DEBUG_SETTINGS_SWITCHUNITS - #define DEBUG_SETTINGS DEBUG_SETTINGS_SwitchUnits + #define DEBUG_SETTINGS DEBUG_SETTINGS_SwitchUnits #endif #include "\z\ace\addons\main\script_macros.hpp" diff --git a/addons/switchunits/stringtable.xml b/addons/switchunits/stringtable.xml index b12e8dc17d..842bf89127 100644 --- a/addons/switchunits/stringtable.xml +++ b/addons/switchunits/stringtable.xml @@ -1,5 +1,4 @@  - From 58b557bd9977c4649b963c26a4e3f0473ece33c6 Mon Sep 17 00:00:00 2001 From: bux578 Date: Mon, 9 Feb 2015 19:07:58 +0100 Subject: [PATCH 2/6] remove file and comments --- addons/switchunits/CfgEventHandlers.hpp | 7 ---- addons/switchunits/XEH_clientInit.sqf | 43 ------------------------- 2 files changed, 50 deletions(-) delete mode 100644 addons/switchunits/XEH_clientInit.sqf diff --git a/addons/switchunits/CfgEventHandlers.hpp b/addons/switchunits/CfgEventHandlers.hpp index ccebe8bc6f..4ac5671c57 100644 --- a/addons/switchunits/CfgEventHandlers.hpp +++ b/addons/switchunits/CfgEventHandlers.hpp @@ -3,10 +3,3 @@ class Extended_PreInit_EventHandlers { init = QUOTE( call COMPILE_FILE(XEH_preInit) ); }; }; -/* -class Extended_PostInit_EventHandlers { - class ADDON { - clientInit = QUOTE( call COMPILE_FILE(XEH_clientInit) ); - }; -}; -*/ diff --git a/addons/switchunits/XEH_clientInit.sqf b/addons/switchunits/XEH_clientInit.sqf deleted file mode 100644 index 24e0b4d3b6..0000000000 --- a/addons/switchunits/XEH_clientInit.sqf +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Author: bux578 - * Initializes the SwitchUnits pbo. - * - * Arguments: - * None - * - * Return Value: - * None - * - * Example: - * None - * - * Public: No - */ - -#include "script_component.hpp" - -/* - -DFUNC(pfhClientInit) = { - - if (GVAR(EnableSwitchUnits)) exitWith { - - private ["_sides"]; - _sides = []; - - if(GVAR(SwitchToWest)) then {_sides pushBack west;}; - if(GVAR(SwitchToEast)) then {_sides pushBack east;}; - if(GVAR(SwitchToIndependent)) then {_sides pushBack independent;}; - if(GVAR(SwitchToCivilian)) then {_sides pushBack civilian;}; - - if (player getVariable ["ACE_CanSwitchUnits", false]) then { - [player, _sides] call FUNC(initPlayer); - }; - - [(_this select 1)] call cba_fnc_removePerFrameHandler; - }; -}; - -[FUNC(pfhClientInit), 0.5, []] call cba_fnc_addPerFrameHandler; - -*/ From e14d49393a42e0b7fd81e3da24fc3fbb7a49c31c Mon Sep 17 00:00:00 2001 From: bux578 Date: Tue, 10 Feb 2015 18:40:06 +0100 Subject: [PATCH 3/6] Revert "remove file and comments" This reverts commit 58b557bd9977c4649b963c26a4e3f0473ece33c6. --- addons/switchunits/CfgEventHandlers.hpp | 7 ++++ addons/switchunits/XEH_clientInit.sqf | 43 +++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 addons/switchunits/XEH_clientInit.sqf diff --git a/addons/switchunits/CfgEventHandlers.hpp b/addons/switchunits/CfgEventHandlers.hpp index 4ac5671c57..ccebe8bc6f 100644 --- a/addons/switchunits/CfgEventHandlers.hpp +++ b/addons/switchunits/CfgEventHandlers.hpp @@ -3,3 +3,10 @@ class Extended_PreInit_EventHandlers { init = QUOTE( call COMPILE_FILE(XEH_preInit) ); }; }; +/* +class Extended_PostInit_EventHandlers { + class ADDON { + clientInit = QUOTE( call COMPILE_FILE(XEH_clientInit) ); + }; +}; +*/ diff --git a/addons/switchunits/XEH_clientInit.sqf b/addons/switchunits/XEH_clientInit.sqf new file mode 100644 index 0000000000..24e0b4d3b6 --- /dev/null +++ b/addons/switchunits/XEH_clientInit.sqf @@ -0,0 +1,43 @@ +/* + * Author: bux578 + * Initializes the SwitchUnits pbo. + * + * Arguments: + * None + * + * Return Value: + * None + * + * Example: + * None + * + * Public: No + */ + +#include "script_component.hpp" + +/* + +DFUNC(pfhClientInit) = { + + if (GVAR(EnableSwitchUnits)) exitWith { + + private ["_sides"]; + _sides = []; + + if(GVAR(SwitchToWest)) then {_sides pushBack west;}; + if(GVAR(SwitchToEast)) then {_sides pushBack east;}; + if(GVAR(SwitchToIndependent)) then {_sides pushBack independent;}; + if(GVAR(SwitchToCivilian)) then {_sides pushBack civilian;}; + + if (player getVariable ["ACE_CanSwitchUnits", false]) then { + [player, _sides] call FUNC(initPlayer); + }; + + [(_this select 1)] call cba_fnc_removePerFrameHandler; + }; +}; + +[FUNC(pfhClientInit), 0.5, []] call cba_fnc_addPerFrameHandler; + +*/ From 40e422f95aded77f5981762e8571f5bc521c7b48 Mon Sep 17 00:00:00 2001 From: bux578 Date: Tue, 10 Feb 2015 18:57:23 +0100 Subject: [PATCH 4/6] added PM's solution --- addons/switchunits/CfgEventHandlers.hpp | 4 +-- addons/switchunits/XEH_clientInit.sqf | 31 +++++------------ addons/switchunits/XEH_preInit.sqf | 1 + addons/switchunits/functions/fnc_module.sqf | 14 -------- .../functions/fnc_startSwitchUnits.sqf | 33 +++++++++++++++++++ 5 files changed, 44 insertions(+), 39 deletions(-) create mode 100644 addons/switchunits/functions/fnc_startSwitchUnits.sqf diff --git a/addons/switchunits/CfgEventHandlers.hpp b/addons/switchunits/CfgEventHandlers.hpp index ccebe8bc6f..689e06c529 100644 --- a/addons/switchunits/CfgEventHandlers.hpp +++ b/addons/switchunits/CfgEventHandlers.hpp @@ -3,10 +3,10 @@ class Extended_PreInit_EventHandlers { init = QUOTE( call COMPILE_FILE(XEH_preInit) ); }; }; -/* + class Extended_PostInit_EventHandlers { class ADDON { clientInit = QUOTE( call COMPILE_FILE(XEH_clientInit) ); }; }; -*/ + diff --git a/addons/switchunits/XEH_clientInit.sqf b/addons/switchunits/XEH_clientInit.sqf index 24e0b4d3b6..06f60d71f2 100644 --- a/addons/switchunits/XEH_clientInit.sqf +++ b/addons/switchunits/XEH_clientInit.sqf @@ -16,28 +16,13 @@ #include "script_component.hpp" -/* - -DFUNC(pfhClientInit) = { - - if (GVAR(EnableSwitchUnits)) exitWith { - - private ["_sides"]; - _sides = []; - - if(GVAR(SwitchToWest)) then {_sides pushBack west;}; - if(GVAR(SwitchToEast)) then {_sides pushBack east;}; - if(GVAR(SwitchToIndependent)) then {_sides pushBack independent;}; - if(GVAR(SwitchToCivilian)) then {_sides pushBack civilian;}; - - if (player getVariable ["ACE_CanSwitchUnits", false]) then { - [player, _sides] call FUNC(initPlayer); +if (missionNamespace getVariable [QGVAR(EnableSwitchUnits), false]) then { + [player] call FUNC(startSwitchUnits); +} else { + ["SettingChanged", { + PARAMS_2(_name,_value); + if ((_name == QGVAR(EnableSwitchUnits)) && {_value}) then { + [player] call FUNC(startSwitchUnits); }; - - [(_this select 1)] call cba_fnc_removePerFrameHandler; - }; + }] call FUNC(addEventhandler); }; - -[FUNC(pfhClientInit), 0.5, []] call cba_fnc_addPerFrameHandler; - -*/ diff --git a/addons/switchunits/XEH_preInit.sqf b/addons/switchunits/XEH_preInit.sqf index 04e81330cb..c120608357 100644 --- a/addons/switchunits/XEH_preInit.sqf +++ b/addons/switchunits/XEH_preInit.sqf @@ -9,6 +9,7 @@ PREP(isValidAi); PREP(markAiOnMap); PREP(module); PREP(nearestPlayers); +PREP(startSwitchUnits); PREP(switchBack); PREP(switchUnit); diff --git a/addons/switchunits/functions/fnc_module.sqf b/addons/switchunits/functions/fnc_module.sqf index 74c8bd8d10..9563dea71f 100644 --- a/addons/switchunits/functions/fnc_module.sqf +++ b/addons/switchunits/functions/fnc_module.sqf @@ -37,17 +37,3 @@ GVAR(Module) = true; [QGVAR(EnableSwitchUnits), true, false, true] call EFUNC(common,setSetting); diag_log text "[ACE]: SwitchUnits Module Initialized."; - -if (GVAR(EnableSwitchUnits)) then { - private ["_sides"]; - _sides = []; - - if(GVAR(SwitchToWest)) then {_sides pushBack west;}; - if(GVAR(SwitchToEast)) then {_sides pushBack east;}; - if(GVAR(SwitchToIndependent)) then {_sides pushBack independent;}; - if(GVAR(SwitchToCivilian)) then {_sides pushBack civilian;}; - - if (player getVariable ["ACE_CanSwitchUnits", false]) then { - [player, _sides] call FUNC(initPlayer); - }; -}; diff --git a/addons/switchunits/functions/fnc_startSwitchUnits.sqf b/addons/switchunits/functions/fnc_startSwitchUnits.sqf new file mode 100644 index 0000000000..ee301a8fea --- /dev/null +++ b/addons/switchunits/functions/fnc_startSwitchUnits.sqf @@ -0,0 +1,33 @@ +/* + * Author: bux578 + * Starts the SwitchUnits functionality + * + * Arguments: + * 0: player + * + * Return Value: + * None + * + * Example: + * [_player] call FUNC(startSwitchUnits) + * + * Public: No + */ + +#include "script_component.hpp" + +EXPLODE_1_PVT[_this,_player]; + +if (GVAR(EnableSwitchUnits)) then { + private ["_sides"]; + _sides = []; + + if(GVAR(SwitchToWest)) then {_sides pushBack west;}; + if(GVAR(SwitchToEast)) then {_sides pushBack east;}; + if(GVAR(SwitchToIndependent)) then {_sides pushBack independent;}; + if(GVAR(SwitchToCivilian)) then {_sides pushBack civilian;}; + + if (_player getVariable ["ACE_CanSwitchUnits", false]) then { + [_player, _sides] call FUNC(initPlayer); + }; +}; From 5ef729ee801644a3409c82456af67bb7b71bf59c Mon Sep 17 00:00:00 2001 From: bux578 Date: Tue, 10 Feb 2015 19:11:58 +0100 Subject: [PATCH 5/6] small fix --- addons/switchunits/functions/fnc_startSwitchUnits.sqf | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/switchunits/functions/fnc_startSwitchUnits.sqf b/addons/switchunits/functions/fnc_startSwitchUnits.sqf index ee301a8fea..ef344475b9 100644 --- a/addons/switchunits/functions/fnc_startSwitchUnits.sqf +++ b/addons/switchunits/functions/fnc_startSwitchUnits.sqf @@ -16,7 +16,10 @@ #include "script_component.hpp" -EXPLODE_1_PVT[_this,_player]; + +private "_player"; +_player = _this select 0; + if (GVAR(EnableSwitchUnits)) then { private ["_sides"]; From 29459e23c9c84726de197d621d15d892d4af4292 Mon Sep 17 00:00:00 2001 From: bux578 Date: Sun, 1 Mar 2015 13:43:39 +0100 Subject: [PATCH 6/6] fix events --- addons/switchunits/XEH_clientInit.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/switchunits/XEH_clientInit.sqf b/addons/switchunits/XEH_clientInit.sqf index 06f60d71f2..6a908071c9 100644 --- a/addons/switchunits/XEH_clientInit.sqf +++ b/addons/switchunits/XEH_clientInit.sqf @@ -24,5 +24,5 @@ if (missionNamespace getVariable [QGVAR(EnableSwitchUnits), false]) then { if ((_name == QGVAR(EnableSwitchUnits)) && {_value}) then { [player] call FUNC(startSwitchUnits); }; - }] call FUNC(addEventhandler); + }] call EFUNC(common,addEventhandler); };