Skip to content

Commit

Permalink
rewrite checkActivateConditions
Browse files Browse the repository at this point in the history
  • Loading branch information
Madin authored and Madin committed May 11, 2024
1 parent 3ceba4b commit 99fcf59
Showing 1 changed file with 36 additions and 44 deletions.
80 changes: 36 additions & 44 deletions addons/main/functions/fn_checkActivateConditions.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -17,56 +17,48 @@ params [
];

if (_logic isEqualTo objNull) exitWith {
diag_log text "[MAI_fnc_checkActivateConditions] logic is objNull, exit script"
diag_log text "[MAI - checkActiveConditions] logic is objNull, exit script";
false
};

private _forceActivate = _logic getVariable [QGVAR(forceActivate), false];
private _activationTriggers = _logic getVariable [QGVAR(activationTriggers),[]];
private _activateCondition = _logic getVariable [QGVAR(activateCondition), {true}];
private _activation = _logic getVariable [QGVAR(activation), 1000];
// check if player is in minimal distance
private _activationDistance = _logic getVariable [QGVAR(activationDistance), 0];
private _includeAir = _logic getVariable [QGVAR(includeAir), false];
private _activateByDistance = true;

private _activated = false;
if (_forceActivate) then {
if (!(_activationTriggers isEqualTo []) && (_activationTriggers select {!triggerActivated _x}) isEqualTo []) exitWith {_activated = true};
if (call _activateCondition) exitWith {_activated = true};
private _activateByDistance = true;
if (_activation > 0) then {
private _nearUnits = _logic nearEntities ["AllVehicles", _activation];
if (_includeAir) then {
_activateByDistance = ((_nearUnits findIf {isPlayer _x}) != -1);
} else {
_activateByDistance = ((_nearUnits findIf {isPlayer _x && {!(_x isKindOf "Air")}}) != -1);
};
};
if (_activateByDistance) exitWith {_activated = true};
} else {
if !((_activationTriggers select {!triggerActivated _x}) isEqualTo []) exitWith {_activated = false};
if !(call _activateCondition) exitWith {_activated = false};
private _activateByDistance = true;
if (_activation > 0) then {
private _nearUnits = _logic nearEntities ["AllVehicles", _activation];
if (_includeAir) then {
_activateByDistance = ((_nearUnits findIf {isPlayer _x}) != -1);
} else {
_activateByDistance = ((_nearUnits findIf {isPlayer _x && {!(_x isKindOf "Air")}}) != -1);
};
if (_activationDistance > 0) then {
private _nearUnits = _logic nearEntities ["AllVehicles", _activationDistance];
if (_includeAir) then {
_activateByDistance = ((_nearUnits findIf {isPlayer _x}) != -1);
} else {
_activateByDistance = ((_nearUnits findIf {isPlayer _x && {!(_x isKindOf "Air")}}) != -1);
};
if !(_activateByDistance) exitWith {_activated = false};
_activated = true;
};
if !(_activateByDistance) exitWith {false};

if (_activated) then {
private _deleteTrigger = _logic getVariable [QGVAR(deleteTrigger), false];
if (_deleteTrigger) then {
[
{
{deleteVehicle _x} forEach _this;
},
_activationTriggers,
5
] call CBA_fnc_waitAndExecute;
};
// check synchronized triggers
private _activationTriggers = _logic getVariable [QGVAR(activationTriggers),[]];
if !((_activationTriggers select {!triggerActivated _x}) isEqualTo []) exitWith {false};

// check custom activation code
private _activateCondition = _logic getVariable [QGVAR(activateCondition), {true}];
if !(call _activateCondition) exitWith {false};

// ????
// private _forceActivate = _logic getVariable [QGVAR(forceActivate), false];

// all checks done, activate script

// check if delete triggers after activation
private _deleteTrigger = _logic getVariable [QGVAR(deleteTrigger), false];
if (_deleteTrigger) then {
[
{
{deleteVehicle _x} forEach _this;
},
_activationTriggers,
5
] call CBA_fnc_waitAndExecute;
};

_activated
true

0 comments on commit 99fcf59

Please sign in to comment.