mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Merge branch 'PFH_SwitchUnits' of github.com:KoffeinFlummi/ACE3 into PFH_SwitchUnits
Conflicts: addons/switchunits/functions/fnc_module.sqf
This commit is contained in:
commit
bedf059af5
@ -5,7 +5,7 @@ class Extended_PreInit_EventHandlers {
|
||||
};
|
||||
|
||||
class Extended_PostInit_EventHandlers {
|
||||
class ADDON {
|
||||
postInit = QUOTE(call COMPILE_FILE(XEH_postInit) );
|
||||
};
|
||||
class ADDON {
|
||||
clientInit = QUOTE( call COMPILE_FILE(XEH_clientInit) );
|
||||
};
|
||||
};
|
||||
|
39
addons/switchunits/XEH_clientInit.sqf
Normal file
39
addons/switchunits/XEH_clientInit.sqf
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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;
|
@ -1,27 +0,0 @@
|
||||
/*
|
||||
Author(s):
|
||||
bux578
|
||||
*/
|
||||
|
||||
#include "script_component.hpp"
|
||||
|
||||
//0 spawn {
|
||||
|
||||
private ["_sides"];
|
||||
|
||||
//waitUntil {sleep 0.5; AGM_SwitchUnits_EnableSwitchUnits};
|
||||
|
||||
//_side = [west, east, independent, civilian] select AGM_SwitchUnits_SwitchUnitsAllowedForSide;
|
||||
|
||||
_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);
|
||||
};
|
||||
|
||||
//};
|
@ -1,19 +1,19 @@
|
||||
/*
|
||||
Name: ACE_SwitchUnits_fnc_addMapFunction
|
||||
|
||||
Author(s):
|
||||
bux578
|
||||
|
||||
Description:
|
||||
Adds a mapClick Eventhandler
|
||||
|
||||
Parameters:
|
||||
0: OBJECT - unit
|
||||
1: ARRAY<OBJECT> - sides
|
||||
|
||||
Returns:
|
||||
VOID
|
||||
*/
|
||||
* Author: bux578
|
||||
* Adds a mapClick Eventhandler
|
||||
*
|
||||
* Arguments:
|
||||
* 0: unit <OBJECT>
|
||||
* 1: sides <ARRAY<OBJECT>>
|
||||
*
|
||||
* Return Value:
|
||||
* None
|
||||
*
|
||||
* Example:
|
||||
* [_unit, _sides] call FUNC(addMapFunction)
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
|
||||
#include "script_component.hpp"
|
||||
|
||||
|
@ -1,45 +1,41 @@
|
||||
/*
|
||||
Name: ACE_SwitchUnits_fnc_handleMapClick
|
||||
|
||||
Author(s):
|
||||
bux578
|
||||
|
||||
Description:
|
||||
Finds the clicked unit
|
||||
|
||||
Parameters:
|
||||
0: OBJECT - MapClickEventHandlerArgs
|
||||
0: OBJECT - unit // useless
|
||||
1: ARRAY<OBJECT> - sides
|
||||
|
||||
Returns:
|
||||
VOID
|
||||
*/
|
||||
* Author: bux578
|
||||
* Switches to a unit close to a clicked map position
|
||||
*
|
||||
* Arguments:
|
||||
* 0: unit <OBJECT>
|
||||
* 1: sides <ARRAY<OBJECT>>
|
||||
*
|
||||
* Return Value:
|
||||
* None
|
||||
*
|
||||
* Example:
|
||||
* [_unit, _sides] call FUNC(handleMapClick)
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
|
||||
#include "script_component.hpp"
|
||||
|
||||
private ["_sides", "_pos", "_sideNearest"];
|
||||
|
||||
// that's wrong
|
||||
//_currentPlayerUnit = (_this select 0) select 0;
|
||||
|
||||
_sides = (_this select 0) select 1;
|
||||
_pos = _this select 1;
|
||||
|
||||
_sideNearest = [];
|
||||
|
||||
{
|
||||
if ([_x] call FUNC(isValidAi) && (side group _x in _sides)) then {
|
||||
_sideNearest pushBack _x;
|
||||
};
|
||||
if ([_x] call FUNC(isValidAi) && (side group _x in _sides)) then {
|
||||
_sideNearest pushBack _x;
|
||||
};
|
||||
} forEach (nearestObjects [_pos, ["Man"], 20]);
|
||||
|
||||
|
||||
if (count _sideNearest > 0) then {
|
||||
private ["_switchUnit"];
|
||||
|
||||
_switchUnit = _sideNearest select 0;
|
||||
[ACE_player, _switchUnit] call FUNC(switchUnit);
|
||||
|
||||
openMap false;
|
||||
private ["_switchUnit"];
|
||||
|
||||
_switchUnit = _sideNearest select 0;
|
||||
[ACE_player, _switchUnit] call FUNC(switchUnit);
|
||||
|
||||
openMap false;
|
||||
};
|
||||
|
@ -1,19 +1,19 @@
|
||||
/*
|
||||
Name: ACE_SwitchUnits_fnc_initPlayer
|
||||
|
||||
Author(s):
|
||||
bux578
|
||||
|
||||
Description:
|
||||
Initializes the player
|
||||
|
||||
Parameters:
|
||||
0: OBJECT - player
|
||||
1: ARRAY<OBJECT> - Array containing selected sides
|
||||
|
||||
Returns:
|
||||
VOID
|
||||
*/
|
||||
* Author: bux578
|
||||
* Initializes the player
|
||||
*
|
||||
* Arguments:
|
||||
* 0: player <OBJECT>
|
||||
* 1: sides <ARRAY<OBJECT>>
|
||||
*
|
||||
* Return Value:
|
||||
* None
|
||||
*
|
||||
* Example:
|
||||
* [_player, _sides] call FUNC(initPlayer)
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
|
||||
#include "script_component.hpp"
|
||||
|
||||
@ -24,27 +24,28 @@ _sides = _this select 1;
|
||||
|
||||
if (vehicle _playerUnit == _playerUnit) then {
|
||||
|
||||
[_sides] call FUNC(markAiOnMap);
|
||||
[_sides] call FUNC(markAiOnMap);
|
||||
|
||||
_playerUnit setVariable [QGVAR(IsPlayerUnit), true];
|
||||
_playerUnit allowDamage false;
|
||||
_playerUnit setVariable [QGVAR(IsPlayerUnit), true];
|
||||
_playerUnit allowDamage false;
|
||||
|
||||
GVAR(OriginalUnit) = _playerUnit;
|
||||
GVAR(OriginalName) = [_playerUnit] call EFUNC(common,getName);
|
||||
GVAR(OriginalGroup) = group _playerUnit;
|
||||
GVAR(OriginalUnit) = _playerUnit;
|
||||
//GVAR(OriginalName) = [_playerUnit] call EFUNC(common,getName);
|
||||
GVAR(OriginalName) = name _playerUnit;
|
||||
GVAR(OriginalGroup) = group _playerUnit;
|
||||
|
||||
// remove all starting gear of a player
|
||||
removeAllWeapons _playerUnit;
|
||||
removeGoggles _playerUnit;
|
||||
removeHeadgear _playerUnit;
|
||||
removeVest _playerUnit;
|
||||
removeAllAssignedItems _playerUnit;
|
||||
clearAllItemsFromBackpack _playerUnit;
|
||||
removeBackpack _playerUnit;
|
||||
_playerUnit linkItem "ItemMap";
|
||||
removeUniform _playerUnit;
|
||||
// remove all starting gear of a player
|
||||
removeAllWeapons _playerUnit;
|
||||
removeGoggles _playerUnit;
|
||||
removeHeadgear _playerUnit;
|
||||
removeVest _playerUnit;
|
||||
removeAllAssignedItems _playerUnit;
|
||||
clearAllItemsFromBackpack _playerUnit;
|
||||
removeBackpack _playerUnit;
|
||||
_playerUnit linkItem "ItemMap";
|
||||
removeUniform _playerUnit;
|
||||
|
||||
[_playerUnit, "ACE_SwitchUnits", true] call EFUNC(common,setForceWalkStatus);
|
||||
[_playerUnit, "ACE_SwitchUnits", true] call EFUNC(common,setForceWalkStatus);
|
||||
|
||||
[_playerUnit, _sides] call FUNC(addMapFunction);
|
||||
[_playerUnit, _sides] call FUNC(addMapFunction);
|
||||
};
|
||||
|
@ -1,22 +1,22 @@
|
||||
/*
|
||||
Name: ACE_SwitchUnits_fnc_isValidAi
|
||||
|
||||
Author(s):
|
||||
bux578
|
||||
|
||||
Description:
|
||||
Checks if AI is a valid target for switching
|
||||
|
||||
Parameters:
|
||||
0: OBJECT - unit
|
||||
|
||||
Returns:
|
||||
VOID
|
||||
*/
|
||||
* Author: bux578
|
||||
* Checks if AI is a valid target for switching.
|
||||
*
|
||||
* Arguments:
|
||||
* 0: unit <OBJECT>
|
||||
*
|
||||
* Return Value:
|
||||
* Boolean
|
||||
*
|
||||
* Example:
|
||||
* [_unit] call FUNC(isValidAi)
|
||||
*
|
||||
* Public: Yes
|
||||
*/
|
||||
|
||||
#include "script_component.hpp"
|
||||
|
||||
private ["_unit"];
|
||||
private "_unit";
|
||||
|
||||
_unit = _this select 0;
|
||||
|
||||
|
@ -1,69 +1,71 @@
|
||||
/*
|
||||
Name: ACE_SwitchUnits_fnc_markAiOnMap
|
||||
|
||||
Author(s):
|
||||
bux578
|
||||
|
||||
Description:
|
||||
Creates markers for AI units for given sides
|
||||
Marks players in a different color
|
||||
|
||||
Parameters:
|
||||
0: OBJECT - side
|
||||
|
||||
Returns:
|
||||
VOID
|
||||
*/
|
||||
* Author: bux578
|
||||
* Creates markers for AI units for given sides.
|
||||
* Marks players in a different colour.
|
||||
*
|
||||
* Arguments:
|
||||
* 0: side <OBJECT>
|
||||
*
|
||||
* Return Value:
|
||||
* None
|
||||
*
|
||||
* Example:
|
||||
* [[west, east]] call FUNC(markAiOnMap)
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
|
||||
#include "script_component.hpp"
|
||||
|
||||
private ["_sidesToShow"];
|
||||
private "_sidesToShow";
|
||||
_sidesToShow = _this select 0;
|
||||
|
||||
_sidesToShow spawn {
|
||||
GVAR(AllMarkerNames) = [];
|
||||
|
||||
private ["_sides", "_allMarkerNames"];
|
||||
_sides = _this;
|
||||
_allMarkerNames = [];
|
||||
DFUNC(pfhMarkAiOnMap) = {
|
||||
private ["_args", "_sides"];
|
||||
_args = _this select 0;
|
||||
_sides = _args select 0;
|
||||
|
||||
while { true } do {
|
||||
sleep 1.5;
|
||||
|
||||
// delete markers
|
||||
{
|
||||
deleteMarkerLocal _x;
|
||||
} forEach GVAR(AllMarkerNames);
|
||||
|
||||
// delete markers
|
||||
if (alive ACE_player && {GVAR(OriginalUnit) getVariable ["ACE_CanSwitchUnits", false]}) then {
|
||||
|
||||
// create markers
|
||||
{
|
||||
deleteMarkerLocal _x;
|
||||
} forEach _allMarkerNames;
|
||||
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];
|
||||
|
||||
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;
|
||||
|
||||
//_markerName = format ["%1", [_x] call EFUNC(common,getName)];
|
||||
_markerName = str _x;
|
||||
// commy's one liner magic
|
||||
_markerColor = format ["Color%1", side group _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;
|
||||
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"));
|
||||
};
|
||||
} forEach allUnits;
|
||||
};
|
||||
|
||||
GVAR(AllMarkerNames) pushBack _markerName;
|
||||
};
|
||||
} forEach allUnits;
|
||||
};
|
||||
};
|
||||
|
||||
[FUNC(pfhMarkAiOnMap), 1.5, [_sidesToShow]] call CBA_fnc_addPerFrameHandler;
|
||||
|
@ -1,20 +1,20 @@
|
||||
/*
|
||||
Name: ACE_SwitchUnits_fnc_module
|
||||
|
||||
Author(s):
|
||||
bux578
|
||||
|
||||
Description:
|
||||
Initializes the SwitchUnits module
|
||||
|
||||
Parameters:
|
||||
0: OBJECT - module logic
|
||||
1: ARRAY<OBJECT> - list of affected units
|
||||
2: BOOLEAN - isActivated
|
||||
|
||||
Returns:
|
||||
BOOLEAN (Good practice to include one)
|
||||
*/
|
||||
* Author: bux578
|
||||
* Initializes the SwitchUnits module
|
||||
*
|
||||
* Arguments:
|
||||
* 0: module logic <OBJECT>
|
||||
* 1: list of affected units <ARRAY<OBJECT>>
|
||||
* 2: isActivated <BOOLEAN>
|
||||
*
|
||||
* Return Value:
|
||||
* None
|
||||
*
|
||||
* Example:
|
||||
* None
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
|
||||
#include "script_component.hpp"
|
||||
|
||||
@ -27,8 +27,6 @@ if !(_activated) exitWith {};
|
||||
|
||||
GVAR(Module) = true;
|
||||
|
||||
[QGVAR(EnableSwitchUnits), true] call EFUNC(common,setParameter);
|
||||
|
||||
[_logic, QGVAR(SwitchToWest), "SwitchToWest"] call EFUNC(common,readSettingFromModule);
|
||||
[_logic, QGVAR(SwitchToEast), "SwitchToEast"] call EFUNC(common,readSettingFromModule);
|
||||
[_logic, QGVAR(SwitchToIndependent), "SwitchToIndependent"] call EFUNC(common,readSettingFromModule);
|
||||
@ -37,4 +35,6 @@ GVAR(Module) = true;
|
||||
[_logic, QGVAR(EnableSafeZone), "EnableSafeZone"] call EFUNC(common,readSettingFromModule);
|
||||
[_logic, QGVAR(SafeZoneRadius), "SafeZoneRadius"] call EFUNC(common,readSettingFromModule);
|
||||
|
||||
[QGVAR(EnableSwitchUnits), true, false, true] call EFUNC(common,setSetting);
|
||||
|
||||
diag_log text "[ACE]: SwitchUnits Module Initialized.";
|
||||
|
@ -1,19 +1,19 @@
|
||||
/*
|
||||
Name: ACE_SwitchUnits_fnc_nearestPlayers
|
||||
|
||||
Author(s):
|
||||
bux578
|
||||
|
||||
Description:
|
||||
Returns an array of alive players in a given radius around a given location
|
||||
|
||||
Parameters:
|
||||
0: POSTION - Center position
|
||||
1: NUMBER - Radius
|
||||
|
||||
Returns:
|
||||
ARRAY<OBJECT> - Player units
|
||||
*/
|
||||
* Author: bux578
|
||||
* Returns an array of alive players in a given radius around a given location
|
||||
*
|
||||
* Arguments:
|
||||
* 0: Center position <POSTION>
|
||||
* 1: Radius <NUMBER>
|
||||
*
|
||||
* Return Value:
|
||||
* Player units <ARRAY<OBJECT>>
|
||||
*
|
||||
* Example:
|
||||
* [_pos, 100] call FUNC(nearestPlayers)
|
||||
*
|
||||
* Public: Yes
|
||||
*/
|
||||
|
||||
#include "script_component.hpp"
|
||||
|
||||
|
@ -1,31 +1,41 @@
|
||||
/*
|
||||
Name: ACE_SwitchUnits_fnc_switchBack
|
||||
|
||||
Author(s):
|
||||
bux578
|
||||
|
||||
Description:
|
||||
Switches back to the original player unit
|
||||
This method needs to be "spawn"ed
|
||||
|
||||
Parameters:
|
||||
0: OBJECT - original player unit
|
||||
1: OBJECT - respawned unit
|
||||
|
||||
Returns:
|
||||
VOID
|
||||
*/
|
||||
* Author: bux578
|
||||
* Switches back to the original player unit
|
||||
*
|
||||
* Arguments:
|
||||
* 0: Original player unit <OBJECT>
|
||||
* 1: Respawned unit <OBJECT>
|
||||
*
|
||||
* Return Value:
|
||||
* None
|
||||
*
|
||||
* Example:
|
||||
* [_origPlayer, _respPlayer] call FUNC(switchBack)
|
||||
*
|
||||
* Public: Yes
|
||||
*/
|
||||
|
||||
#include "script_component.hpp"
|
||||
|
||||
private ["_originalPlayerUnit", "_currentUnit"];
|
||||
_originalPlayerUnit = _this select 0;
|
||||
_currentUnit = _this select 1;
|
||||
private ["_origPlayerUnit"];
|
||||
|
||||
[_originalPlayerUnit] joinSilent GVAR(OriginalGroup);
|
||||
_origPlayerUnit = _this select 0;
|
||||
[_origPlayerUnit] joinSilent GVAR(OriginalGroup);
|
||||
|
||||
waitUntil {local _originalPlayerUnit};
|
||||
DFUNC(pfhSwitchBack) = {
|
||||
|
||||
private ["_args", "_originalPlayerUnit", "_currentUnit"];
|
||||
|
||||
_args = _this select 0;
|
||||
|
||||
_originalPlayerUnit = _args select 0;
|
||||
_currentUnit = _args select 1;
|
||||
|
||||
selectPlayer _originalPlayerUnit;
|
||||
if (local _originalPlayerUnit) exitWith {
|
||||
selectPlayer _originalPlayerUnit;
|
||||
deleteVehicle _currentUnit;
|
||||
[(_this select 1)] call cba_fnc_removePerFrameHandler;
|
||||
};
|
||||
};
|
||||
|
||||
deleteVehicle _currentUnit;
|
||||
[FUNC(pfhSwitchBack), 0.2, _this] call CBA_fnc_addPerFrameHandler;
|
||||
|
@ -1,81 +1,98 @@
|
||||
/*
|
||||
Name: ACE_SwitchUnits_fnc_switchUnit
|
||||
|
||||
Author(s):
|
||||
bux578
|
||||
|
||||
Description:
|
||||
Selects the new given player unit
|
||||
|
||||
Parameters:
|
||||
0: OBJECT - the unit to switch to
|
||||
|
||||
Returns:
|
||||
VOID
|
||||
*/
|
||||
* Author: bux578
|
||||
* Switches to the new given player unit
|
||||
*
|
||||
* Arguments:
|
||||
* 0: current unit <OBJECT>
|
||||
* 1: the unit to switch to <OBJECT>
|
||||
*
|
||||
* Return Value:
|
||||
* None
|
||||
*
|
||||
* Example:
|
||||
* [_unit] call FUNC(switchUnit)
|
||||
*
|
||||
* Public: Yes
|
||||
*/
|
||||
|
||||
|
||||
#include "script_component.hpp"
|
||||
|
||||
private ["_newUnit"];
|
||||
private ["_unit", "_allNearestPlayers", "_oldUnit", "_leave"];
|
||||
|
||||
_newUnit = _this select 1;
|
||||
_unit = _this select 1;
|
||||
|
||||
// don't switch to original player units
|
||||
if (!([_newUnit] call FUNC(isValidAi))) exitWith {};
|
||||
if (!([_unit] call FUNC(isValidAi))) exitWith {};
|
||||
|
||||
// exit var
|
||||
_leave = false;
|
||||
|
||||
if (GVAR(EnableSafeZone)) then {
|
||||
|
||||
_newUnit spawn {
|
||||
private ["_unit", "_allNearestPlayers", "_oldUnit", "_respawnEhId", "_oldOwner", "_leave"];
|
||||
|
||||
_unit = _this;
|
||||
|
||||
_leave = false;
|
||||
|
||||
if (GVAR(EnableSafeZone)) then {
|
||||
|
||||
_allNearestPlayers = [position _unit, GVAR(SafeZoneRadius)] call FUNC(nearestPlayers);
|
||||
_nearestEnemyPlayers = [_allNearestPlayers, {((side GVAR(OriginalGroup)) getFriend (side _this) < 0.6) && !(_this getVariable [QGVAR(IsPlayerControlled), false])}] call EFUNC(common,filter);
|
||||
|
||||
if (count _nearestEnemyPlayers > 0) exitWith {
|
||||
_leave = true;
|
||||
_leave = true;
|
||||
};
|
||||
};
|
||||
|
||||
// exitWith doesn't exit past the "if(EnableSafeZone)" block
|
||||
if (_leave) exitWith {
|
||||
[localize "STR_ACE_SwitchUnits_TooCloseToEnemy"] call EFUNC(common,displayTextStructured);
|
||||
};
|
||||
|
||||
// should switch locality
|
||||
// This doesn't work anymore, because one's now able to switch to units from a different side
|
||||
//[_unit] joinSilent group player;
|
||||
[[_unit, player], QUOTE({(_this select 0) setVariable [ARR_3(QUOTE(QGVAR(OriginalOwner)), owner (_this select 0), true)]; (_this select 0) setOwner owner (_this select 1)}), 1] call EFUNC(common,execRemoteFnc);
|
||||
|
||||
_oldUnit = player;
|
||||
waitUntil {sleep 0.2; local _unit};
|
||||
|
||||
_oldUnit setVariable [QGVAR(IsPlayerControlled), false, true];
|
||||
_oldUnit setVariable [QGVAR(PlayerControlledName), "", true];
|
||||
|
||||
_respawnEhId = _unit getVariable [QGVAR(RespawnEhId), -1];
|
||||
if (_respawnEhId != -1) then {
|
||||
_oldUnit removeEventHandler ["Respawn", _respawnEhId];
|
||||
};
|
||||
|
||||
selectPlayer _unit;
|
||||
|
||||
_unit setVariable [QGVAR(IsPlayerControlled), true, true];
|
||||
_unit setVariable [QGVAR(PlayerControlledName), GVAR(OriginalName), true];
|
||||
|
||||
_respawnEhId = _unit addEventHandler ["Respawn", {
|
||||
[GVAR(OriginalUnit), _this select 0] spawn FUNC(switchBack);
|
||||
}];
|
||||
_unit setVariable [QGVAR(RespawnEhId), _respawnEhId, true];
|
||||
|
||||
// set owner back to original owner
|
||||
_oldOwner = _oldUnit getVariable[QGVAR(OriginalOwner), -1];
|
||||
if (_oldOwner > -1) then {
|
||||
[[_oldUnit, _oldOwner], QUOTE({(_this select 0) setOwner (_this select 1)}), 1] call EFUNC(common,execRemoteFnc);
|
||||
};
|
||||
|
||||
[localize "STR_ACE_SwitchUnits_SwitchedUnit"] call EFUNC(common,displayTextStructured);
|
||||
|
||||
};
|
||||
|
||||
// exitWith doesn't exit past the "if(EnableSafeZone)" block
|
||||
if (_leave) exitWith {
|
||||
[localize "STR_ACE_SwitchUnits_TooCloseToEnemy"] call EFUNC(common,displayTextStructured);
|
||||
};
|
||||
|
||||
// should switch locality
|
||||
// This doesn't work anymore, because one's now able to switch to units from a different side
|
||||
//[_unit] joinSilent group player;
|
||||
[[_unit, player], QUOTE({(_this select 0) setVariable [ARR_3(QUOTE(QGVAR(OriginalOwner)), owner (_this select 0), true)]; (_this select 0) setOwner owner (_this select 1)}), 1] call EFUNC(common,execRemoteFnc);
|
||||
|
||||
_oldUnit = player;
|
||||
|
||||
|
||||
DFUNC(pfhSwitchUnit) = {
|
||||
|
||||
private ["_args", "_unit", "_oldUnit", "_respawnEhId", "_oldOwner"];
|
||||
_args = _this select 0;
|
||||
|
||||
_unit = _args select 0;
|
||||
_oldUnit = _args select 1;
|
||||
|
||||
|
||||
|
||||
if (local _unit) exitWith {
|
||||
|
||||
_oldUnit setVariable [QGVAR(IsPlayerControlled), false, true];
|
||||
_oldUnit setVariable [QGVAR(PlayerControlledName), "", true];
|
||||
|
||||
_respawnEhId = _unit getVariable [QGVAR(RespawnEhId), -1];
|
||||
if (_respawnEhId != -1) then {
|
||||
_oldUnit removeEventHandler ["Respawn", _respawnEhId];
|
||||
};
|
||||
|
||||
selectPlayer _unit;
|
||||
|
||||
_unit setVariable [QGVAR(IsPlayerControlled), true, true];
|
||||
_unit setVariable [QGVAR(PlayerControlledName), GVAR(OriginalName), true];
|
||||
|
||||
_respawnEhId = _unit addEventHandler ["Respawn", {
|
||||
[GVAR(OriginalUnit), _this select 0] call FUNC(switchBack);
|
||||
}];
|
||||
_unit setVariable [QGVAR(RespawnEhId), _respawnEhId, true];
|
||||
|
||||
// set owner back to original owner
|
||||
_oldOwner = _oldUnit getVariable[QGVAR(OriginalOwner), -1];
|
||||
if (_oldOwner > -1) then {
|
||||
[[_oldUnit, _oldOwner], QUOTE({(_this select 0) setOwner (_this select 1)}), 1] call EFUNC(common,execRemoteFnc);
|
||||
};
|
||||
|
||||
[localize "STR_ACE_SwitchUnits_SwitchedUnit"] call EFUNC(common,displayTextStructured);
|
||||
|
||||
[(_this select 1)] call cba_fnc_removePerFrameHandler;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
[FUNC(pfhSwitchUnit), 0.2, [_unit, _oldUnit]] call cba_fnc_addPerFrameHandler;
|
||||
|
Loading…
Reference in New Issue
Block a user