Sarge-AI/sarge/code/scripts/toggle_base_guards.sqf

52 lines
1.7 KiB
Plaintext
Raw Normal View History

2017-11-12 03:46:01 +00:00
private["_authorizedUID","_authorizedPUID","_attackAllToggle","_isBaseGuard","_flag","_nearestGuards","_friendlyPlayers"];
2017-10-26 01:36:31 +00:00
_flag = _this select 0;
_authorizedUID = _flag getVariable ["ExileTerritoryBuildRights", []];
_authorizedPUID = _authorizedUID select 0;
_isBaseGuard = false;
2017-11-12 03:46:01 +00:00
2017-10-26 01:36:31 +00:00
if (!(isNull _flag)) then {
2017-11-12 03:46:01 +00:00
_nearestGuards = (getPosATL _flag) nearEntities [["AllVehicles","CAManBase"], 110];
2017-10-26 01:36:31 +00:00
} else {
2017-11-12 03:46:01 +00:00
_nearestGuards = (getPosATL player) nearEntities [["AllVehicles","CAManBase"], 110];
2017-10-26 01:36:31 +00:00
};
2017-11-12 03:46:01 +00:00
2017-10-26 01:36:31 +00:00
if (count _nearestGuards > 0) then {
{
2017-11-12 03:46:01 +00:00
if (!(isPlayer _x)) then {
_friendlyPlayers = _x getVariable ["SAR_FLAG_FRIENDLY", []];
// Check group array for player
2017-10-26 01:36:31 +00:00
if (count _friendlyPlayers > 0) then {
{
if (_x in _friendlyPlayers) exitWith {
_isBaseGuard = true; // Guard is part of the base owners guards
};
} foreach _authorizedPUID;
2017-11-12 03:46:01 +00:00
2017-10-26 01:36:31 +00:00
// Toggle his attack mode
if (_isBaseGuard) then {
2017-11-12 03:46:01 +00:00
_attackAllToggle = _x getVariable ["ATTACK_ALL", true];
2017-10-26 01:36:31 +00:00
if (_attackAllToggle) then {
2017-11-12 03:46:01 +00:00
_x setVariable ["ATTACK_ALL", false, true];
cutText ["Guards will only attack those who attack them.", "PLAIN DOWN"];
hintsilent "Guards will only attack those who attack them.";
2017-10-26 01:36:31 +00:00
Breakout "exit";
} else {
2017-11-12 03:46:01 +00:00
_x setVariable ["ATTACK_ALL", true, true];
cutText ["Guards will attack anyone that is not in your group.", "PLAIN DOWN"];
hintsilent "Guards will attack anyone that is not in your group.";
2017-10-26 01:36:31 +00:00
Breakout "exit";
};
};
};
};
} forEach _nearestGuards;
cutText ["No guards were found in the area", "PLAIN DOWN"];
hintsilent "No guards were found in the area";
2017-11-12 03:46:01 +00:00
} else {
cutText ["No guards in the area", "PLAIN DOWN"];
hintsilent "No guards were found in the area";
};