mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Code cleanup of Switchunits module
This commit is contained in:
parent
016f45f0e8
commit
a330e7b0c5
@ -10,19 +10,18 @@
|
||||
* None
|
||||
*
|
||||
* Example:
|
||||
* [_unit, _sides] call FUNC(addMapFunction)
|
||||
* [_unit, _sides] call ace_switchunits_fnc_addMapFunction
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
|
||||
#include "script_component.hpp"
|
||||
|
||||
PARAMS_2(_unit,_sides);
|
||||
params ["_unit", "_sides"];
|
||||
|
||||
["theMapClick", "onMapSingleClick", {
|
||||
// IGNORE_PRIVATE_WARNING(_pos,_shift,_alt)
|
||||
if (alive ACE_player && {GVAR(OriginalUnit) getVariable ["ACE_CanSwitchUnits", false]}) then {
|
||||
[_this, _pos, _shift, _alt] call FUNC(handleMapClick);
|
||||
};
|
||||
|
||||
|
||||
}, [_unit, _sides]] call BIS_fnc_addStackedEventHandler;
|
||||
|
@ -3,24 +3,25 @@
|
||||
* Switches to a unit close to a clicked map position
|
||||
*
|
||||
* Arguments:
|
||||
* 0: unit <OBJECT>
|
||||
* 1: sides <ARRAY<OBJECT>>
|
||||
* 0: Faction
|
||||
* 0: unit <OBJECT>
|
||||
* 1: sides <ARRAY>
|
||||
* 1: Map Position <ARRAY>
|
||||
*
|
||||
* Return Value:
|
||||
* None
|
||||
*
|
||||
* Example:
|
||||
* [unit, _sides] call FUNC(handleMapClick)
|
||||
* [[unit, _sides], [20, 30]] call ace_switchunits_fnc_handleMapClick
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
|
||||
#include "script_component.hpp"
|
||||
|
||||
private ["_sides", "_pos", "_sideNearest"];
|
||||
private ["_sideNearest"];
|
||||
|
||||
_sides = (_this select 0) select 1;
|
||||
_pos = _this select 1;
|
||||
params ["_faction", "_pos"];
|
||||
_faction params ["", "_sides"];
|
||||
|
||||
_sideNearest = [];
|
||||
|
||||
@ -28,7 +29,8 @@ _sideNearest = [];
|
||||
if ([_x] call FUNC(isValidAi) && (side group _x in _sides)) then {
|
||||
_sideNearest pushBack _x;
|
||||
};
|
||||
} forEach (nearestObjects [_pos, ["Man"], 15]);
|
||||
nil
|
||||
} count (nearestObjects [_pos, ["Man"], 15]);
|
||||
|
||||
if (count _sideNearest > 0) then {
|
||||
[_sideNearest select 0] call FUNC(switchUnit);
|
||||
|
@ -10,24 +10,21 @@
|
||||
* None
|
||||
*
|
||||
* Example:
|
||||
* [player, [west]] call FUNC(initPlayer)
|
||||
* [player, [west]] call ace_switchunits_fnc_initPlayer
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
|
||||
#include "script_component.hpp"
|
||||
|
||||
PARAMS_2(_playerUnit,_sides);
|
||||
params ["_playerUnit", "_sides"];
|
||||
|
||||
if (vehicle _playerUnit == _playerUnit) then {
|
||||
|
||||
[_sides] call FUNC(markAiOnMap);
|
||||
|
||||
_playerUnit setVariable [QGVAR(IsPlayerUnit), true];
|
||||
_playerUnit allowDamage false;
|
||||
|
||||
GVAR(OriginalUnit) = _playerUnit;
|
||||
//GVAR(OriginalName) = [_playerUnit] call EFUNC(common,getName);
|
||||
GVAR(OriginalName) = name _playerUnit;
|
||||
GVAR(OriginalGroup) = group _playerUnit;
|
||||
|
||||
|
@ -6,22 +6,19 @@
|
||||
* 0: unit <OBJECT>
|
||||
*
|
||||
* Return Value:
|
||||
* Boolean
|
||||
* Valid AI <BOOL>
|
||||
*
|
||||
* Example:
|
||||
* [_unit] call FUNC(isValidAi)
|
||||
* [_unit] call ace_switchunits_fnc_isValidAi
|
||||
*
|
||||
* Public: Yes
|
||||
*/
|
||||
|
||||
#include "script_component.hpp"
|
||||
|
||||
private "_unit";
|
||||
|
||||
_unit = _this select 0;
|
||||
params ["_unit"];
|
||||
|
||||
!([_unit] call EFUNC(common,isPlayer)
|
||||
|| {_unit in playableUnits}
|
||||
|| {vehicle _unit != _unit}
|
||||
|| {_unit getVariable [QGVAR(IsPlayerUnit), false]}
|
||||
|| {_unit getVariable [QGVAR(IsPlayerControlled), false]})
|
||||
|| {vehicle _unit != _unit}
|
||||
|| {_unit getVariable [QGVAR(IsPlayerUnit), false]}
|
||||
|| {_unit getVariable [QGVAR(IsPlayerControlled), false]}) // return
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Author: bux578
|
||||
* Creates markers for AI units for given sides.
|
||||
* Marks players in a different colour.
|
||||
* Marks players in a different colour.
|
||||
*
|
||||
* Arguments:
|
||||
* 0: side <OBJECT>
|
||||
@ -10,28 +10,24 @@
|
||||
* None
|
||||
*
|
||||
* Example:
|
||||
* [[west, east]] call FUNC(markAiOnMap)
|
||||
* [[west, east]] call ace_switchunits_fnc_markAiOnMap
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
|
||||
#include "script_component.hpp"
|
||||
|
||||
private "_sidesToShow";
|
||||
_sidesToShow = _this select 0;
|
||||
params ["_sidesToShow"];
|
||||
|
||||
GVAR(AllMarkerNames) = [];
|
||||
|
||||
DFUNC(pfhMarkAiOnMap) = {
|
||||
private ["_args", "_sides"];
|
||||
_args = _this select 0;
|
||||
_sides = _args select 0;
|
||||
|
||||
_fnc_pfhMarkAiOnMap = {
|
||||
params ["_args"];
|
||||
_args params ["_sides"];
|
||||
|
||||
// delete markers
|
||||
{
|
||||
deleteMarkerLocal _x;
|
||||
} forEach GVAR(AllMarkerNames);
|
||||
deleteMarkerLocal _x;
|
||||
} count GVAR(AllMarkerNames);
|
||||
|
||||
// reset the array
|
||||
GVAR(AllMarkerNames) = [];
|
||||
@ -48,7 +44,7 @@ DFUNC(pfhMarkAiOnMap) = {
|
||||
_marker = createMarkerLocal [_markerName, position _x];
|
||||
_markerName setMarkerTypeLocal "mil_triangle";
|
||||
_markerName setMarkerShapeLocal "ICON";
|
||||
_markerName setMarkerSizeLocal [0.5,0.7];
|
||||
_markerName setMarkerSizeLocal [0.5, 0.7];
|
||||
_markerName setMarkerDirLocal getDir _x;
|
||||
|
||||
// commy's one liner magic
|
||||
@ -63,9 +59,10 @@ DFUNC(pfhMarkAiOnMap) = {
|
||||
};
|
||||
|
||||
GVAR(AllMarkerNames) pushBack _markerName;
|
||||
nil
|
||||
};
|
||||
} forEach allUnits;
|
||||
} count allUnits;
|
||||
};
|
||||
};
|
||||
|
||||
[FUNC(pfhMarkAiOnMap), 1.5, [_sidesToShow]] call CBA_fnc_addPerFrameHandler;
|
||||
[_fnc_pfhMarkAiOnMap, 1.5, [_sidesToShow]] call CBA_fnc_addPerFrameHandler;
|
||||
|
@ -15,12 +15,11 @@
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
|
||||
#include "script_component.hpp"
|
||||
|
||||
if !(isServer) exitWith {};
|
||||
|
||||
EXPLODE_3_PVT(_this,_logic,_units,_activated);
|
||||
params ["_logic", "_units", "_activated"];
|
||||
|
||||
if !(_activated) exitWith {};
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
* Player units <ARRAY<OBJECT>>
|
||||
*
|
||||
* Example:
|
||||
* [[300,300,0], 100] call FUNC(nearestPlayers)
|
||||
* [[300,300,0], 100] call ace_switchunits_fnc_nearestPlayers
|
||||
*
|
||||
* Public: Yes
|
||||
*/
|
||||
@ -18,10 +18,7 @@
|
||||
|
||||
private ["_nearestPlayers"];
|
||||
|
||||
PARAMS_2(_position,_radius);
|
||||
|
||||
_position = _this select 0;
|
||||
_radius = _this select 1;
|
||||
params ["_position", "_radius"];
|
||||
|
||||
_nearestPlayers = [];
|
||||
|
||||
|
@ -9,14 +9,14 @@
|
||||
* None
|
||||
*
|
||||
* Example:
|
||||
* [_player] call FUNC(startSwitchUnits)
|
||||
* [_player] call ace_switchunits_fnc_startSwitchUnits
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
|
||||
#include "script_component.hpp"
|
||||
|
||||
PARAMS_1(_player);
|
||||
params ["_player"];
|
||||
|
||||
if (GVAR(EnableSwitchUnits)) then {
|
||||
private "_sides";
|
||||
|
@ -10,20 +10,19 @@
|
||||
* None
|
||||
*
|
||||
* Example:
|
||||
* [_originalPlayerUnit, _currentUnit] call FUNC(switchBack)
|
||||
* [_originalPlayerUnit, _currentUnit] call ace_switchunits_fnc_switchBack
|
||||
*
|
||||
* Public: Yes
|
||||
*/
|
||||
|
||||
#include "script_component.hpp"
|
||||
|
||||
PARAMS_1(_originalPlayerUnit);
|
||||
params ["_originalPlayerUnit"];
|
||||
|
||||
[_originalPlayerUnit] joinSilent GVAR(OriginalGroup);
|
||||
|
||||
DFUNC(pfhSwitchBack) = {
|
||||
PARAMS_2(_args,_pfID);
|
||||
EXPLODE_2_PVT(_args,_originalPlayerUnit,_currentUnit);
|
||||
_fnc_pfhSwitchBack = {
|
||||
params ["_args", "_pfhId"];
|
||||
_args params ["_originalPlayerUnit", "_currentUnit"];
|
||||
|
||||
if (local _originalPlayerUnit) exitWith {
|
||||
selectPlayer _originalPlayerUnit;
|
||||
@ -33,8 +32,8 @@ DFUNC(pfhSwitchBack) = {
|
||||
_layer = "BIS_fnc_respawnCounter" call bis_fnc_rscLayer;
|
||||
_layer cuttext ["","plain"];
|
||||
|
||||
[(_this select 1)] call cba_fnc_removePerFrameHandler;
|
||||
[_pfhId] call cba_fnc_removePerFrameHandler;
|
||||
};
|
||||
};
|
||||
|
||||
[FUNC(pfhSwitchBack), 0.2, _this] call CBA_fnc_addPerFrameHandler;
|
||||
[_fnc_pfhSwitchBack, 0.2, _this] call CBA_fnc_addPerFrameHandler;
|
||||
|
@ -3,24 +3,21 @@
|
||||
* Switches to the new given player unit
|
||||
*
|
||||
* Arguments:
|
||||
* 0: current unit <OBJECT>
|
||||
* 1: the unit to switch to <OBJECT>
|
||||
* 0: the unit to switch to <OBJECT>
|
||||
*
|
||||
* Return Value:
|
||||
* None
|
||||
*
|
||||
* Example:
|
||||
* [_unit] call FUNC(switchUnit)
|
||||
* [_unit] call ace_switchunits_fnc_switchUnit
|
||||
*
|
||||
* Public: Yes
|
||||
*/
|
||||
|
||||
|
||||
#include "script_component.hpp"
|
||||
|
||||
private ["_nearestEnemyPlayers", "_allNearestPlayers", "_oldUnit", "_leave"];
|
||||
|
||||
PARAMS_1(_unit);
|
||||
params ["_unit"];
|
||||
|
||||
// don't switch to original player units
|
||||
if (!([_unit] call FUNC(isValidAi))) exitWith {};
|
||||
@ -29,14 +26,12 @@ if (!([_unit] call FUNC(isValidAi))) exitWith {};
|
||||
_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;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
// exitWith doesn't exit past the "if(EnableSafeZone)" block
|
||||
@ -49,21 +44,12 @@ if (_leave) exitWith {
|
||||
//[_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;
|
||||
|
||||
|
||||
_fnc_pfhSwitchUnit = {
|
||||
private ["_respawnEhId", "_oldOwner"];
|
||||
params ["_args", "_pfhId"];
|
||||
_args params ["_unit", "_oldUnit"];
|
||||
|
||||
if (local _unit) exitWith {
|
||||
|
||||
_oldUnit setVariable [QGVAR(IsPlayerControlled), false, true];
|
||||
_oldUnit setVariable [QGVAR(PlayerControlledName), "", true];
|
||||
|
||||
@ -90,9 +76,8 @@ DFUNC(pfhSwitchUnit) = {
|
||||
|
||||
[localize LSTRING(SwitchedUnit)] call EFUNC(common,displayTextStructured);
|
||||
|
||||
[(_this select 1)] call cba_fnc_removePerFrameHandler;
|
||||
|
||||
[_pfhId] call cba_fnc_removePerFrameHandler;
|
||||
};
|
||||
};
|
||||
|
||||
[FUNC(pfhSwitchUnit), 0.2, [_unit, _oldUnit]] call CBA_fnc_addPerFrameHandler;
|
||||
[_fnc_pfhSwitchUnit, 0.2, [_unit, player]] call CBA_fnc_addPerFrameHandler;
|
||||
|
Loading…
Reference in New Issue
Block a user