diff --git a/addons/switchunits/CfgEventHandlers.hpp b/addons/switchunits/CfgEventHandlers.hpp index 38f9883743..689e06c529 100644 --- a/addons/switchunits/CfgEventHandlers.hpp +++ b/addons/switchunits/CfgEventHandlers.hpp @@ -9,3 +9,4 @@ class Extended_PostInit_EventHandlers { clientInit = QUOTE( call COMPILE_FILE(XEH_clientInit) ); }; }; + diff --git a/addons/switchunits/XEH_clientInit.sqf b/addons/switchunits/XEH_clientInit.sqf index 3075d67941..6a908071c9 100644 --- a/addons/switchunits/XEH_clientInit.sqf +++ b/addons/switchunits/XEH_clientInit.sqf @@ -16,24 +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 EFUNC(common,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/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..9563dea71f 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 {}; diff --git a/addons/switchunits/functions/fnc_startSwitchUnits.sqf b/addons/switchunits/functions/fnc_startSwitchUnits.sqf new file mode 100644 index 0000000000..ef344475b9 --- /dev/null +++ b/addons/switchunits/functions/fnc_startSwitchUnits.sqf @@ -0,0 +1,36 @@ +/* + * Author: bux578 + * Starts the SwitchUnits functionality + * + * Arguments: + * 0: player <OBJECT> + * + * Return Value: + * None + * + * Example: + * [_player] call FUNC(startSwitchUnits) + * + * Public: No + */ + +#include "script_component.hpp" + + +private "_player"; +_player = _this select 0; + + +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 @@ <?xml version="1.0" encoding="utf-8"?> -<!-- Edited with tabler - 2014-12-20 --> <Project name="ACE"> <Package name="SwitchUnits"> <Key ID="STR_ACE_SwitchUnits_SwitchedUnit">