diff --git a/A3A/addons/core/functions/Base/fn_airspaceControl.sqf b/A3A/addons/core/functions/Base/fn_airspaceControl.sqf index a3c3ee0fe7..f661502398 100644 --- a/A3A/addons/core/functions/Base/fn_airspaceControl.sqf +++ b/A3A/addons/core/functions/Base/fn_airspaceControl.sqf @@ -1,27 +1,25 @@ -#define CIV_HELI 0 -#define MIL_HELI 1 -#define JET 2 - -params ["_vehicle"]; -#include "..\..\script_component.hpp" -FIX_LINE_NUMBERS() /* Handles the airspace control of any player aircraft, breaking undercover and calling support - Execution on: Any + Execution on: Client Scope: Internal Params: - _vehicle: OBJECT : The vehicles that should be checked against enemy positions + _player: OBJECT : Player who boarded the vehicle + _vehicle: OBJECT : The vehicle that should be checked against enemy positions Returns: Nothing */ -//If vehicle already has an airspace control script, exit here -if(_vehicle getVariable ["airspaceControl", false]) exitWith {}; +#define CIV_HELI 0 +#define MIL_HELI 1 +#define JET 2 -_vehicle setVariable ["airspaceControl", true, true]; +#include "..\..\script_component.hpp" +FIX_LINE_NUMBERS() + +params ["_player", "_vehicle"]; //Select the kind of aircraft private _airType = -1; @@ -72,13 +70,13 @@ private _fn_sendSupport = private _markerSide = sidesX getVariable [_marker, sideUnknown]; //Reveal vehicle to all groups of the side so they can take actions - { +/* { if(side _x == _markerSide) then { _x reveal [_vehicle, 4]; // TODO: doesn't actually work, needs remoteExec }; } forEach allGroups; - +*/ //Take actions against the aircraft // Let support system decide whether it's worth reacting to private _revealValue = [getMarkerPos _marker, _markerSide] call A3A_fnc_calculateSupportCallReveal; @@ -137,9 +135,13 @@ private _fn_getMarkersInRange = }; -//While not in garage and alive and crewed we check what the aircraft is doing -while {!(isNull _vehicle) && {alive _vehicle && {count (crew _vehicle) != 0}}} do +while {_player in crew _vehicle && alive _vehicle} do { + sleep 1; + + // Only run the checks for the vehicle's commander + if (_player != effectiveCommander _vehicle) then { continue }; + //Check undercover status _vehicleIsUndercover = captive ((crew _vehicle) select 0); _vehPos = getPosASL _vehicle; @@ -230,7 +232,6 @@ while {!(isNull _vehicle) && {alive _vehicle && {count (crew _vehicle) != 0}}} d }; }; }; - sleep 1; }; -_vehicle setVariable ["airspaceControl", nil, true]; +Debug_2("Exiting airspace control for player %1, vehicle %2", _player, typeof _vehicle); diff --git a/A3A/addons/core/functions/CREATE/fn_AIVEHinit.sqf b/A3A/addons/core/functions/CREATE/fn_AIVEHinit.sqf index bf124653c1..e14d2a3607 100644 --- a/A3A/addons/core/functions/CREATE/fn_AIVEHinit.sqf +++ b/A3A/addons/core/functions/CREATE/fn_AIVEHinit.sqf @@ -203,19 +203,6 @@ if (_side != teamPlayer) then }]; }; -if(_veh isKindOf "Air") then -{ - //Start airspace control script if rebel player enters - _veh addEventHandler ["GetIn", { - params ["_veh", "_role", "_unit"]; - if((side (group _unit) == teamPlayer) && {isPlayer _unit}) then - { - // TODO: check this isn't spammed - [_veh] spawn A3A_fnc_airspaceControl; - }; - }]; -}; - // Handler for refunding vehicles after cleanup if (A3A_vehicleResourceCosts getOrDefault [typeof _veh, 0] > 0) then { diff --git a/A3A/addons/core/functions/init/fn_initClient.sqf b/A3A/addons/core/functions/init/fn_initClient.sqf index cce6ca86f3..ff3f8f3e2d 100644 --- a/A3A/addons/core/functions/init/fn_initClient.sqf +++ b/A3A/addons/core/functions/init/fn_initClient.sqf @@ -267,9 +267,7 @@ player addEventHandler ["WeaponDisassembled", { }]; player addEventHandler ["GetInMan", { - private ["_unit","_veh"]; - _unit = _this select 0; - _veh = _this select 2; + params ["_unit", "_role", "_veh", "_turret"]; _exit = false; if !([player] call A3A_fnc_isMember) then { if (!isNil {_veh getVariable "A3A_locked"}) then { @@ -287,9 +285,21 @@ player addEventHandler ["GetInMan", { [] spawn A3A_fnc_goUndercover; }; }; + if (_veh isKindOf "Air") then { + Debug_2("Installing airspace control for player %1, vehicle %2", _unit, typeof _veh); + private _handle = [_unit, _veh] spawn A3A_fnc_airspaceControl; + _unit setVariable ["airspaceControlHandle", _handle]; + }; }; }]; +player addEventHandler ["GetOutMan", { + params ["_unit", "_role", "_veh", "_turret"]; + Debug_2("Terminating airspace control for player %1, vehicle %2", _unit, typeof _veh); + private _handle = _unit getVariable ["airspaceControlHandle", scriptNull]; + if (!isNull _handle) then { terminate _handle }; +}]; + // Prevent players getting shot by their own AIs. EH is respawn-persistent player addEventHandler ["HandleRating", {0}];