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:
@ -5,7 +5,7 @@ class Extended_PreInit_EventHandlers {
|
|||||||
};
|
};
|
||||||
|
|
||||||
class Extended_PostInit_EventHandlers {
|
class Extended_PostInit_EventHandlers {
|
||||||
class ADDON {
|
class ADDON {
|
||||||
postInit = QUOTE(call COMPILE_FILE(XEH_postInit) );
|
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: bux578
|
||||||
|
* Adds a mapClick Eventhandler
|
||||||
Author(s):
|
*
|
||||||
bux578
|
* Arguments:
|
||||||
|
* 0: unit <OBJECT>
|
||||||
Description:
|
* 1: sides <ARRAY<OBJECT>>
|
||||||
Adds a mapClick Eventhandler
|
*
|
||||||
|
* Return Value:
|
||||||
Parameters:
|
* None
|
||||||
0: OBJECT - unit
|
*
|
||||||
1: ARRAY<OBJECT> - sides
|
* Example:
|
||||||
|
* [_unit, _sides] call FUNC(addMapFunction)
|
||||||
Returns:
|
*
|
||||||
VOID
|
* Public: No
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "script_component.hpp"
|
#include "script_component.hpp"
|
||||||
|
|
||||||
|
@ -1,45 +1,41 @@
|
|||||||
/*
|
/*
|
||||||
Name: ACE_SwitchUnits_fnc_handleMapClick
|
* Author: bux578
|
||||||
|
* Switches to a unit close to a clicked map position
|
||||||
Author(s):
|
*
|
||||||
bux578
|
* Arguments:
|
||||||
|
* 0: unit <OBJECT>
|
||||||
Description:
|
* 1: sides <ARRAY<OBJECT>>
|
||||||
Finds the clicked unit
|
*
|
||||||
|
* Return Value:
|
||||||
Parameters:
|
* None
|
||||||
0: OBJECT - MapClickEventHandlerArgs
|
*
|
||||||
0: OBJECT - unit // useless
|
* Example:
|
||||||
1: ARRAY<OBJECT> - sides
|
* [_unit, _sides] call FUNC(handleMapClick)
|
||||||
|
*
|
||||||
Returns:
|
* Public: No
|
||||||
VOID
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
#include "script_component.hpp"
|
#include "script_component.hpp"
|
||||||
|
|
||||||
private ["_sides", "_pos", "_sideNearest"];
|
private ["_sides", "_pos", "_sideNearest"];
|
||||||
|
|
||||||
// that's wrong
|
|
||||||
//_currentPlayerUnit = (_this select 0) select 0;
|
|
||||||
|
|
||||||
_sides = (_this select 0) select 1;
|
_sides = (_this select 0) select 1;
|
||||||
_pos = _this select 1;
|
_pos = _this select 1;
|
||||||
|
|
||||||
_sideNearest = [];
|
_sideNearest = [];
|
||||||
|
|
||||||
{
|
{
|
||||||
if ([_x] call FUNC(isValidAi) && (side group _x in _sides)) then {
|
if ([_x] call FUNC(isValidAi) && (side group _x in _sides)) then {
|
||||||
_sideNearest pushBack _x;
|
_sideNearest pushBack _x;
|
||||||
};
|
};
|
||||||
} forEach (nearestObjects [_pos, ["Man"], 20]);
|
} forEach (nearestObjects [_pos, ["Man"], 20]);
|
||||||
|
|
||||||
|
|
||||||
if (count _sideNearest > 0) then {
|
if (count _sideNearest > 0) then {
|
||||||
private ["_switchUnit"];
|
private ["_switchUnit"];
|
||||||
|
|
||||||
_switchUnit = _sideNearest select 0;
|
_switchUnit = _sideNearest select 0;
|
||||||
[ACE_player, _switchUnit] call FUNC(switchUnit);
|
[ACE_player, _switchUnit] call FUNC(switchUnit);
|
||||||
|
|
||||||
openMap false;
|
openMap false;
|
||||||
};
|
};
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
/*
|
/*
|
||||||
Name: ACE_SwitchUnits_fnc_initPlayer
|
* Author: bux578
|
||||||
|
* Initializes the player
|
||||||
Author(s):
|
*
|
||||||
bux578
|
* Arguments:
|
||||||
|
* 0: player <OBJECT>
|
||||||
Description:
|
* 1: sides <ARRAY<OBJECT>>
|
||||||
Initializes the player
|
*
|
||||||
|
* Return Value:
|
||||||
Parameters:
|
* None
|
||||||
0: OBJECT - player
|
*
|
||||||
1: ARRAY<OBJECT> - Array containing selected sides
|
* Example:
|
||||||
|
* [_player, _sides] call FUNC(initPlayer)
|
||||||
Returns:
|
*
|
||||||
VOID
|
* Public: No
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "script_component.hpp"
|
#include "script_component.hpp"
|
||||||
|
|
||||||
@ -24,27 +24,28 @@ _sides = _this select 1;
|
|||||||
|
|
||||||
if (vehicle _playerUnit == _playerUnit) then {
|
if (vehicle _playerUnit == _playerUnit) then {
|
||||||
|
|
||||||
[_sides] call FUNC(markAiOnMap);
|
[_sides] call FUNC(markAiOnMap);
|
||||||
|
|
||||||
_playerUnit setVariable [QGVAR(IsPlayerUnit), true];
|
_playerUnit setVariable [QGVAR(IsPlayerUnit), true];
|
||||||
_playerUnit allowDamage false;
|
_playerUnit allowDamage false;
|
||||||
|
|
||||||
GVAR(OriginalUnit) = _playerUnit;
|
GVAR(OriginalUnit) = _playerUnit;
|
||||||
GVAR(OriginalName) = [_playerUnit] call EFUNC(common,getName);
|
//GVAR(OriginalName) = [_playerUnit] call EFUNC(common,getName);
|
||||||
GVAR(OriginalGroup) = group _playerUnit;
|
GVAR(OriginalName) = name _playerUnit;
|
||||||
|
GVAR(OriginalGroup) = group _playerUnit;
|
||||||
|
|
||||||
// remove all starting gear of a player
|
// remove all starting gear of a player
|
||||||
removeAllWeapons _playerUnit;
|
removeAllWeapons _playerUnit;
|
||||||
removeGoggles _playerUnit;
|
removeGoggles _playerUnit;
|
||||||
removeHeadgear _playerUnit;
|
removeHeadgear _playerUnit;
|
||||||
removeVest _playerUnit;
|
removeVest _playerUnit;
|
||||||
removeAllAssignedItems _playerUnit;
|
removeAllAssignedItems _playerUnit;
|
||||||
clearAllItemsFromBackpack _playerUnit;
|
clearAllItemsFromBackpack _playerUnit;
|
||||||
removeBackpack _playerUnit;
|
removeBackpack _playerUnit;
|
||||||
_playerUnit linkItem "ItemMap";
|
_playerUnit linkItem "ItemMap";
|
||||||
removeUniform _playerUnit;
|
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: bux578
|
||||||
|
* Checks if AI is a valid target for switching.
|
||||||
Author(s):
|
*
|
||||||
bux578
|
* Arguments:
|
||||||
|
* 0: unit <OBJECT>
|
||||||
Description:
|
*
|
||||||
Checks if AI is a valid target for switching
|
* Return Value:
|
||||||
|
* Boolean
|
||||||
Parameters:
|
*
|
||||||
0: OBJECT - unit
|
* Example:
|
||||||
|
* [_unit] call FUNC(isValidAi)
|
||||||
Returns:
|
*
|
||||||
VOID
|
* Public: Yes
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "script_component.hpp"
|
#include "script_component.hpp"
|
||||||
|
|
||||||
private ["_unit"];
|
private "_unit";
|
||||||
|
|
||||||
_unit = _this select 0;
|
_unit = _this select 0;
|
||||||
|
|
||||||
|
@ -1,69 +1,71 @@
|
|||||||
/*
|
/*
|
||||||
Name: ACE_SwitchUnits_fnc_markAiOnMap
|
* Author: bux578
|
||||||
|
* Creates markers for AI units for given sides.
|
||||||
Author(s):
|
* Marks players in a different colour.
|
||||||
bux578
|
*
|
||||||
|
* Arguments:
|
||||||
Description:
|
* 0: side <OBJECT>
|
||||||
Creates markers for AI units for given sides
|
*
|
||||||
Marks players in a different color
|
* Return Value:
|
||||||
|
* None
|
||||||
Parameters:
|
*
|
||||||
0: OBJECT - side
|
* Example:
|
||||||
|
* [[west, east]] call FUNC(markAiOnMap)
|
||||||
Returns:
|
*
|
||||||
VOID
|
* Public: No
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "script_component.hpp"
|
#include "script_component.hpp"
|
||||||
|
|
||||||
private ["_sidesToShow"];
|
private "_sidesToShow";
|
||||||
_sidesToShow = _this select 0;
|
_sidesToShow = _this select 0;
|
||||||
|
|
||||||
_sidesToShow spawn {
|
GVAR(AllMarkerNames) = [];
|
||||||
|
|
||||||
private ["_sides", "_allMarkerNames"];
|
DFUNC(pfhMarkAiOnMap) = {
|
||||||
_sides = _this;
|
private ["_args", "_sides"];
|
||||||
_allMarkerNames = [];
|
_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;
|
if (([_x] call FUNC(isValidAi) && (side group _x in _sides)) || (_x getVariable [QGVAR(IsPlayerControlled), false])) then {
|
||||||
} forEach _allMarkerNames;
|
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
|
_marker = createMarkerLocal [_markerName, position _x];
|
||||||
{
|
_markerName setMarkerTypeLocal "mil_triangle";
|
||||||
if (([_x] call FUNC(isValidAi) && (side group _x in _sides)) || (_x getVariable [QGVAR(IsPlayerControlled), false])) then {
|
_markerName setMarkerShapeLocal "ICON";
|
||||||
private ["_markerName", "_marker", "_markerColor"];
|
_markerName setMarkerSizeLocal [0.5,0.7];
|
||||||
|
_markerName setMarkerDirLocal getDir _x;
|
||||||
|
|
||||||
//_markerName = format ["%1", [_x] call EFUNC(common,getName)];
|
// commy's one liner magic
|
||||||
_markerName = str _x;
|
_markerColor = format ["Color%1", side group _x];
|
||||||
|
|
||||||
_marker = createMarkerLocal [_markerName, position _x];
|
if ((_x getVariable [QGVAR(IsPlayerControlled), false])) then {
|
||||||
_markerName setMarkerTypeLocal "mil_triangle";
|
_markerName setMarkerColorLocal "ColorOrange";
|
||||||
_markerName setMarkerShapeLocal "ICON";
|
_markerName setMarkerTextLocal (_x getVariable [QGVAR(PlayerControlledName), ""]);
|
||||||
_markerName setMarkerSizeLocal [0.5,0.7];
|
} else {
|
||||||
_markerName setMarkerDirLocal getDir _x;
|
_markerName setMarkerColorLocal _markerColor;
|
||||||
|
_markerName setMarkerTextLocal (getText (configFile >> "CfgVehicles" >> typeOf _x >> "displayName"));
|
||||||
// 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;
|
|
||||||
};
|
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: bux578
|
||||||
|
* Initializes the SwitchUnits module
|
||||||
Author(s):
|
*
|
||||||
bux578
|
* Arguments:
|
||||||
|
* 0: module logic <OBJECT>
|
||||||
Description:
|
* 1: list of affected units <ARRAY<OBJECT>>
|
||||||
Initializes the SwitchUnits module
|
* 2: isActivated <BOOLEAN>
|
||||||
|
*
|
||||||
Parameters:
|
* Return Value:
|
||||||
0: OBJECT - module logic
|
* None
|
||||||
1: ARRAY<OBJECT> - list of affected units
|
*
|
||||||
2: BOOLEAN - isActivated
|
* Example:
|
||||||
|
* None
|
||||||
Returns:
|
*
|
||||||
BOOLEAN (Good practice to include one)
|
* Public: No
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "script_component.hpp"
|
#include "script_component.hpp"
|
||||||
|
|
||||||
@ -27,8 +27,6 @@ if !(_activated) exitWith {};
|
|||||||
|
|
||||||
GVAR(Module) = true;
|
GVAR(Module) = true;
|
||||||
|
|
||||||
[QGVAR(EnableSwitchUnits), true] call EFUNC(common,setParameter);
|
|
||||||
|
|
||||||
[_logic, QGVAR(SwitchToWest), "SwitchToWest"] call EFUNC(common,readSettingFromModule);
|
[_logic, QGVAR(SwitchToWest), "SwitchToWest"] call EFUNC(common,readSettingFromModule);
|
||||||
[_logic, QGVAR(SwitchToEast), "SwitchToEast"] call EFUNC(common,readSettingFromModule);
|
[_logic, QGVAR(SwitchToEast), "SwitchToEast"] call EFUNC(common,readSettingFromModule);
|
||||||
[_logic, QGVAR(SwitchToIndependent), "SwitchToIndependent"] 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(EnableSafeZone), "EnableSafeZone"] call EFUNC(common,readSettingFromModule);
|
||||||
[_logic, QGVAR(SafeZoneRadius), "SafeZoneRadius"] 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.";
|
diag_log text "[ACE]: SwitchUnits Module Initialized.";
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
/*
|
/*
|
||||||
Name: ACE_SwitchUnits_fnc_nearestPlayers
|
* Author: bux578
|
||||||
|
* Returns an array of alive players in a given radius around a given location
|
||||||
Author(s):
|
*
|
||||||
bux578
|
* Arguments:
|
||||||
|
* 0: Center position <POSTION>
|
||||||
Description:
|
* 1: Radius <NUMBER>
|
||||||
Returns an array of alive players in a given radius around a given location
|
*
|
||||||
|
* Return Value:
|
||||||
Parameters:
|
* Player units <ARRAY<OBJECT>>
|
||||||
0: POSTION - Center position
|
*
|
||||||
1: NUMBER - Radius
|
* Example:
|
||||||
|
* [_pos, 100] call FUNC(nearestPlayers)
|
||||||
Returns:
|
*
|
||||||
ARRAY<OBJECT> - Player units
|
* Public: Yes
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "script_component.hpp"
|
#include "script_component.hpp"
|
||||||
|
|
||||||
|
@ -1,31 +1,41 @@
|
|||||||
/*
|
/*
|
||||||
Name: ACE_SwitchUnits_fnc_switchBack
|
* Author: bux578
|
||||||
|
* Switches back to the original player unit
|
||||||
Author(s):
|
*
|
||||||
bux578
|
* Arguments:
|
||||||
|
* 0: Original player unit <OBJECT>
|
||||||
Description:
|
* 1: Respawned unit <OBJECT>
|
||||||
Switches back to the original player unit
|
*
|
||||||
This method needs to be "spawn"ed
|
* Return Value:
|
||||||
|
* None
|
||||||
Parameters:
|
*
|
||||||
0: OBJECT - original player unit
|
* Example:
|
||||||
1: OBJECT - respawned unit
|
* [_origPlayer, _respPlayer] call FUNC(switchBack)
|
||||||
|
*
|
||||||
Returns:
|
* Public: Yes
|
||||||
VOID
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
#include "script_component.hpp"
|
#include "script_component.hpp"
|
||||||
|
|
||||||
private ["_originalPlayerUnit", "_currentUnit"];
|
private ["_origPlayerUnit"];
|
||||||
_originalPlayerUnit = _this select 0;
|
|
||||||
_currentUnit = _this select 1;
|
|
||||||
|
|
||||||
[_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: bux578
|
||||||
|
* Switches to the new given player unit
|
||||||
Author(s):
|
*
|
||||||
bux578
|
* Arguments:
|
||||||
|
* 0: current unit <OBJECT>
|
||||||
Description:
|
* 1: the unit to switch to <OBJECT>
|
||||||
Selects the new given player unit
|
*
|
||||||
|
* Return Value:
|
||||||
Parameters:
|
* None
|
||||||
0: OBJECT - the unit to switch to
|
*
|
||||||
|
* Example:
|
||||||
Returns:
|
* [_unit] call FUNC(switchUnit)
|
||||||
VOID
|
*
|
||||||
*/
|
* Public: Yes
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "script_component.hpp"
|
#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
|
// 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);
|
_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);
|
_nearestEnemyPlayers = [_allNearestPlayers, {((side GVAR(OriginalGroup)) getFriend (side _this) < 0.6) && !(_this getVariable [QGVAR(IsPlayerControlled), false])}] call EFUNC(common,filter);
|
||||||
|
|
||||||
if (count _nearestEnemyPlayers > 0) exitWith {
|
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;
|
||||||
|
Reference in New Issue
Block a user