From f0c06beb23b70e960d7297b3c9befa138f0a3324 Mon Sep 17 00:00:00 2001 From: bux578 Date: Tue, 27 Jan 2015 09:01:57 +0100 Subject: [PATCH] fix #95 & add ADDON = bool --- addons/switchunits/XEH_preInit.sqf | 4 + .../functions/fnc_addMapFunction.sqf | 11 ++- .../functions/fnc_handleMapClick.sqf | 10 ++- .../switchunits/functions/fnc_markAiOnMap.sqf | 73 ++++++++++--------- 4 files changed, 56 insertions(+), 42 deletions(-) diff --git a/addons/switchunits/XEH_preInit.sqf b/addons/switchunits/XEH_preInit.sqf index 7443b79565..04e81330cb 100644 --- a/addons/switchunits/XEH_preInit.sqf +++ b/addons/switchunits/XEH_preInit.sqf @@ -1,5 +1,7 @@ #include "script_component.hpp" +ADDON = false; + PREP(addMapFunction); PREP(handleMapClick); PREP(initPlayer); @@ -9,3 +11,5 @@ PREP(module); PREP(nearestPlayers); PREP(switchBack); PREP(switchUnit); + +ADDON = true; diff --git a/addons/switchunits/functions/fnc_addMapFunction.sqf b/addons/switchunits/functions/fnc_addMapFunction.sqf index 2b7c3035c7..1c4e158d80 100644 --- a/addons/switchunits/functions/fnc_addMapFunction.sqf +++ b/addons/switchunits/functions/fnc_addMapFunction.sqf @@ -9,7 +9,7 @@ Parameters: 0: OBJECT - unit - 1: ARRAY - sided + 1: ARRAY - sides Returns: VOID @@ -17,9 +17,14 @@ #include "script_component.hpp" -private ["_unit"]; +private ["_unit", "_sides"]; _unit = _this select 0; +_sides = _this select 1; ["theMapClick", "onMapSingleClick", { - [_this, _pos, _shift, _alt] call FUNC(handleMapClick); + + if (alive ACE_player && {GVAR(OriginalUnit) getVariable ["ACE_CanSwitchUnits", false]}) then { + [_this, _pos, _shift, _alt] call FUNC(handleMapClick); + }; + }, [_unit, _sides]] call BIS_fnc_addStackedEventHandler; diff --git a/addons/switchunits/functions/fnc_handleMapClick.sqf b/addons/switchunits/functions/fnc_handleMapClick.sqf index 1c45d32d31..bce28963da 100644 --- a/addons/switchunits/functions/fnc_handleMapClick.sqf +++ b/addons/switchunits/functions/fnc_handleMapClick.sqf @@ -9,7 +9,7 @@ Parameters: 0: OBJECT - MapClickEventHandlerArgs - 0: OBJECT - unit to switch to + 0: OBJECT - unit // useless 1: ARRAY - sides Returns: @@ -18,9 +18,11 @@ #include "script_component.hpp" -private ["_args", "_currentPlayerUnit", "_sides", "_pos", "_sideNearest"]; +private ["_sides", "_pos", "_sideNearest"]; + +// that's wrong +//_currentPlayerUnit = (_this select 0) select 0; -_currentPlayerUnit = (_this select 0) select 0; _sides = (_this select 0) select 1; _pos = _this select 1; @@ -37,7 +39,7 @@ if (count _sideNearest > 0) then { private ["_switchUnit"]; _switchUnit = _sideNearest select 0; - [_currentPlayerUnit, _switchUnit] call FUNC(switchUnit); + [ACE_player, _switchUnit] call FUNC(switchUnit); openMap false; }; diff --git a/addons/switchunits/functions/fnc_markAiOnMap.sqf b/addons/switchunits/functions/fnc_markAiOnMap.sqf index dcf227f955..e54673c1a5 100644 --- a/addons/switchunits/functions/fnc_markAiOnMap.sqf +++ b/addons/switchunits/functions/fnc_markAiOnMap.sqf @@ -22,45 +22,48 @@ _sidesToShow = _this select 0; _sidesToShow spawn { - private ["_sides", "_allMarkerNames"]; - _sides = _this; - _allMarkerNames = []; + private ["_sides", "_allMarkerNames"]; + _sides = _this; + _allMarkerNames = []; - while { true } do { - sleep 1.5; + while { true } do { + sleep 1.5; - // delete markers - { - deleteMarkerLocal _x; - } forEach _allMarkerNames; + // delete markers + { + deleteMarkerLocal _x; + } forEach _allMarkerNames; - // create markers - { - if (([_x] call FUNC(isValidAi) && (side group _x in _sides)) || (_x getVariable [QGVAR(IsPlayerControlled), false])) then { - private ["_markerName", "_marker", "_markerColor"]; + if (alive ACE_player && {GVAR(OriginalUnit) getVariable ["ACE_CanSwitchUnits", false]}) then { - //_markerName = format ["%1", [_x] call EFUNC(common,getName)]; - _markerName = str _x; + // create markers + { + if (([_x] call FUNC(isValidAi) && (side group _x in _sides)) || (_x getVariable [QGVAR(IsPlayerControlled), false])) then { + private ["_markerName", "_marker", "_markerColor"]; - _marker = createMarkerLocal [_markerName, position _x]; - _markerName setMarkerTypeLocal "mil_triangle"; - _markerName setMarkerShapeLocal "ICON"; - _markerName setMarkerSizeLocal [0.5,0.7]; - _markerName setMarkerDirLocal getDir _x; - - // commy's one liner magic - _markerColor = format ["Color%1", side group _x]; - - if ((_x getVariable [QGVAR(IsPlayerControlled), false])) then { - _markerName setMarkerColorLocal "ColorOrange"; - _markerName setMarkerTextLocal (_x getVariable [QGVAR(PlayerControlledName),""]); - } else { - _markerName setMarkerColorLocal _markerColor; - _markerName setMarkerTextLocal (getText (configFile >> "CfgVehicles" >> typeOf _x >> "displayName")); + //_markerName = format ["%1", [_x] call EFUNC(common,getName)]; + _markerName = str _x; + + _marker = createMarkerLocal [_markerName, position _x]; + _markerName setMarkerTypeLocal "mil_triangle"; + _markerName setMarkerShapeLocal "ICON"; + _markerName setMarkerSizeLocal [0.5,0.7]; + _markerName setMarkerDirLocal getDir _x; + + // commy's one liner magic + _markerColor = format ["Color%1", side group _x]; + + if ((_x getVariable [QGVAR(IsPlayerControlled), false])) then { + _markerName setMarkerColorLocal "ColorOrange"; + _markerName setMarkerTextLocal (_x getVariable [QGVAR(PlayerControlledName), ""]); + } else { + _markerName setMarkerColorLocal _markerColor; + _markerName setMarkerTextLocal (getText (configFile >> "CfgVehicles" >> typeOf _x >> "displayName")); + }; + + _allMarkerNames pushBack _markerName; + }; + } forEach allUnits; }; - - _allMarkerNames pushBack _markerName; - }; - } forEach allUnits; - }; + }; };