ACE3/addons/common/functions/fnc_switchToGroupSide.sqf
Dedmen Miller e2ac18a05d [WIP] Fix script errors reporting wrong line numbers (#6407)
* advanced_ballistics

* advanced_fatigue

* advanced_throwing

* ai

* aircraft

* arsenal

* atragmx

* attach

* backpacks

* ballistics

* captives

* cargo

* chemlights

* common

* concertina_wire

* cookoff

* dagr

* disarming

* disposable

* dogtags

* dragging

* explosives

* fastroping

* fcs

* finger

* frag

* gestures

* gforces

* goggles

* grenades

* gunbag

* hearing

* hitreactions

* huntir

* interact_menu

* interaction

* inventory

* kestrel4500

* laser

* laserpointer

* logistics_uavbattery

* logistics_wirecutter

* magazinerepack

* map

* map_gestures

* maptools

* markers

* medical

* medical_ai

* medical_blood

* medical_menu

* microdagr

* minedetector

* missileguidance

* missionmodules

* mk6mortar

* modules

* movement

* nametags

* nightvision

* nlaw

* optics

* optionsmenu

* overheating

* overpressure

* parachute

* pylons

* quickmount

* rangecard

* rearm

* recoil

* refuel

* reload

* reloadlaunchers

* repair

* respawn

* safemode

* sandbag

* scopes

* slideshow

* spectator

* spottingscope

* switchunits

* tacticalladder

* tagging

* trenches

* tripod

* ui

* vector

* vehiclelock

* vehicles

* viewdistance

* weaponselect

* weather

* winddeflection

* yardage450

* zeus

* arsenal defines.hpp

* optionals

* DEBUG_MODE_FULL 1

* DEBUG_MODE_FULL 2

* Manual fixes

* Add SQF Validator check for #include after block comment

* explosives fnc_openTimerUI

* fix uniqueItems
2018-09-17 14:19:29 -05:00

73 lines
2.2 KiB
Plaintext

#include "script_component.hpp"
/*
* Author: Glowbal
* Stack group switches. Will always trace back to original group.
*
* Arguments:
* 0: Unit <OBJECT>
* 1: switch <BOOLEAN>
* 2: id <STRING>
* 3: side <SIDE>
*
* Return Value:
* None
*
* Example:
* [bob, true, "id", SIDE] call ace_common_fnc_switchToGroupSide
*
* Public: Yes
*/
params [["_unit", objNull], ["_switch", false], ["_id", ""], ["_side", sideUnknown]];
private _previousGroupsList = _unit getVariable [QGVAR(previousGroupSwitchTo), []];
if (_switch) then {
// go forward
private _previousGroup = group _unit;
private _originalSide = side group _unit;
if (count units _previousGroup == 1 && _originalSide == _side) exitWith {
[format ["Current group has only 1 member and is of same side as switch. Not switching unit %1", _id]] call FUNC(debug);
};
private _newGroup = createGroup _side;
[_unit] joinSilent _newGroup;
_previousGroupsList pushBack [_previousGroup, _originalSide, _id, true];
_unit setVariable [QGVAR(previousGroupSwitchTo), _previousGroupsList, true];
} else {
// go one back
{
if (_id == (_x select 2)) exitWith {
_x set [ 3, false];
_previousGroupsList set [_forEachIndex, _x];
[format["found group with ID: %1", _id]] call FUNC(debug);
};
} forEach _previousGroupsList;
reverse _previousGroupsList;
{
if (_x select 3) exitWith {}; // stop at first id set to true
if !(_x select 3) then {
private _currentGroup = group _unit;
if (!isNull (_x select 0)) then {
[_unit] joinSilent (_x select 0);
} else {
private _newGroup = createGroup (_x select 1);
[_unit] joinSilent _newGroup;
};
if (count units _currentGroup == 0) then {
deleteGroup _currentGroup;
};
_previousGroupsList set [_forEachIndex, objNull];
};
} forEach _previousGroupsList;
_previousGroupsList = _previousGroupsList - [objNull];
reverse _previousGroupsList; // we have to reverse again, to ensure the list is in the right order.
_unit setVariable [QGVAR(previousGroupSwitchTo), _previousGroupsList, true];
};