ACE3/addons/common/functions/fnc_closeDialogIfTargetMoves.sqf

50 lines
1.4 KiB
Plaintext
Raw Normal View History

/*
* Author: commy2
*
* Closes the current dialog if the target moves, changes vehicle etc.
*
* Arguments:
* 0: Target unit
* 1: Ignore the unit being dead? (Optional, default: No)
*
* Return Value:
* None
*/
2015-01-13 19:56:02 +00:00
#include "script_component.hpp"
_this spawn {
2015-05-14 18:06:06 +00:00
PARAMS_2(_target,_ignoreDead);
2015-05-14 22:12:40 +00:00
private["_inVehicle", "_position", "_vehiclePlayer", "_vehicleTarget"];
2015-05-14 18:06:06 +00:00
if (isNil "_ignoreDead") then {_ignoreDead = false};
2015-05-14 18:06:06 +00:00
_vehicleTarget = vehicle _target;
_vehiclePlayer = vehicle ACE_player;
_inVehicle = _target != _vehicleTarget;
2015-05-14 18:06:06 +00:00
_position = getPosASL _target;
2015-05-14 18:06:06 +00:00
_fnc_check = {
// either unit changed vehicles
if (_vehiclePlayer != vehicle ACE_player) exitWith {True};
if (_vehicleTarget != vehicle _target) exitWith {True};
2015-05-14 18:06:06 +00:00
// target died
if (!alive _target && {!_ignoreDead}) exitWith {True};
2015-05-14 18:06:06 +00:00
// player fell unconscious
if (ACE_player getVariable ["ACE_isUnconscious", False]) exitWith {True};
2015-05-14 18:06:06 +00:00
// target moved (outside of vehicle)
(!_inVehicle && {getPosASL _target distanceSqr _position > 1})
};
2015-05-14 18:06:06 +00:00
waitUntil {
if (call _fnc_check) then {
closeDialog 0;
call EFUNC(interaction,hideMenu);
};
(isNil QEGVAR(interaction,MainButton) && !dialog) || {!isNull (uiNamespace getVariable [QGVAR(dlgDisableMouse), displayNull])} //Exit loop if DisableMouse dialog open
};
};