ACE3/addons/spectator/functions/fnc_updateUnits.sqf

73 lines
1.9 KiB
Plaintext
Raw Normal View History

2015-07-16 10:15:33 +00:00
/*
* Author: SilentSpike
2015-07-17 15:02:38 +00:00
* Adds units to spectator whitelist/blacklist and refreshes the filter units
2015-07-16 10:15:33 +00:00
*
* Arguments:
2015-07-17 17:40:49 +00:00
* 0: Units to add to the whitelist <ARRAY>
2015-07-17 15:02:38 +00:00
* 1: Use blacklist <BOOL> <OPTIONAL>
2015-07-16 10:15:33 +00:00
*
* Return Value:
* None <NIL>
*
* Example:
* [allUnits,true] call ace_spectator_fnc_updateUnits
*
* Public: Yes
*/
2015-07-15 13:58:38 +00:00
#include "script_component.hpp"
2015-07-17 15:02:38 +00:00
params [["_newUnits",[],[[]]],["_blacklist",false,[false]]];
2015-07-15 13:58:38 +00:00
2015-07-19 11:09:57 +00:00
// Function only matters on player clients
2015-07-17 17:40:49 +00:00
if !(hasInterface) exitWith {};
2015-07-19 11:09:57 +00:00
// If adding to a list we can exit here, since it won't show up until the UI refreshes anyway
if !(_newUnits isEqualTo []) exitWith {
2015-07-17 15:02:38 +00:00
if (_blacklist) then {
2015-07-16 10:15:33 +00:00
GVAR(unitWhitelist) = GVAR(unitWhitelist) - _newUnits;
GVAR(unitBlacklist) append _newUnits;
2015-07-17 15:02:38 +00:00
} else {
GVAR(unitBlacklist) = GVAR(unitBlacklist) - _newUnits;
GVAR(unitWhitelist) append _newUnits;
2015-07-15 13:58:38 +00:00
};
2015-07-16 10:15:33 +00:00
};
2015-07-15 13:58:38 +00:00
2015-07-19 11:09:57 +00:00
private ["_playerSide","_sides","_filteredUnits"];
2015-07-17 17:40:49 +00:00
2015-07-19 11:09:57 +00:00
// Unit setting filter
2015-07-17 15:02:38 +00:00
_newUnits = [[],allPlayers,allUnits] select GVAR(filterUnits);
2015-07-15 13:58:38 +00:00
2015-07-19 11:09:57 +00:00
// Side setting filter
2015-07-17 17:40:49 +00:00
_playerSide = side group player;
if (GVAR(filterSides) == 0) then {
_sides = [_playerSide];
} else {
2015-07-17 23:40:20 +00:00
_sides = [west,east,resistance,civilian];
if (GVAR(filterSides) == 1) then {
{
if ((_x getFriend _playerSide) < 0.6) then {
_sides = _sides - [_x];
};
} forEach _sides;
};
2015-07-17 17:40:49 +00:00
};
// Filter units and append to list
2015-07-19 11:09:57 +00:00
_filteredUnits = [];
2015-07-17 15:02:38 +00:00
{
if (
(alive _x) &&
{(_x isKindOf "CAManBase")} &&
2015-07-17 17:40:49 +00:00
{(side _x) in _sides} && // Side filter
2015-07-18 16:13:27 +00:00
{simulationEnabled _x} &&
2015-07-17 15:02:38 +00:00
{!(_x getVariable [QGVAR(isSpectator), false])} // Who watches the watchmen?
) then {
2015-07-19 11:09:57 +00:00
_filteredUnits pushBack _x;
2015-07-17 15:02:38 +00:00
};
} forEach (_newUnits - GVAR(unitBlacklist));
2015-07-19 11:09:57 +00:00
_filteredUnits append GVAR(unitWhitelist);
2015-07-17 01:30:00 +00:00
2015-07-19 11:09:57 +00:00
// Replace previous list entirely (removes any no longer valid)
GVAR(unitList) = _filteredUnits arrayIntersect _filteredUnits;