PHP Code:
/*
QTS = Quick Team Switch system. Single Player only.
Adds actions for available units, so they can be switched quickly. The switched unit becomes leader, which makes precise team management easier.
Usage:
1. You need to make the variable: ITF_QTS_script = "qts.sqf";
(the script is called many times, so it is imperative to store its name in this variable.)
2. Then you can init it by []execVM ITF_QTS_script;
3. Management is automatic after that until player is alive.
+. You can run []execVM ITF_QTS_script anytime during a mission, script reinitializes, but doesn't make any harm, it only checks available units.
Author: Zaphat
*/
//the filename should be here, with path relative to mission.
ITF_QTS_script = "qts.sqf";
//the style of the action
ITF_QTS_textStyle = "shadow='1' shadowColor='#99000000' color='#99ffffff'";
//if true, selected player will become leader for easier management.
ITF_QTS_leader = true;
//leave this as is. (you can use it for different actiongroups)
ITF_QTS_actionIndex = 0;
//----------------------------CODE-----------------------------------
//vehicle watcher loop
if (isnil "IFT_QTS_started") then
{
[] spawn
{
while {alive player} do
{
waitUntil {sleep 1; player != vehicle player || !alive player};
[] execVM ITF_QTS_script;
waitUntil {sleep 1; player == vehicle player || !alive player};
[] execVM ITF_QTS_script;
};
};
IFT_QTS_started = true;
};
//function1
if (isnil ("fn_unitAddAction")) then
{
fn_unitAddAction=
{
/*
[
_index,
_unit,
[_text,"shadow='1' shadowColor='#99000000' color='#99ffffff'"],
[_u,ITF_QTS_script],
[10,false,false],
""
] call fn_unitAddAction;
ITF_VAR_unitActions = [[index 0 actions],[index 1 actions]];
*/
private ["_index", "_unit", "_text", "_u", "_script", "_settings", "_condition", "_units", "_textProperty", "_textText", "_scriptArgs", "_scriptFile", "_setPriority", "_setShowWindow", "_setHideOnUse", "_id", "_sameIndex", "_allActions"];
//init of function
_index = _this select 0;
_unit = _this select 1;
_text = _this select 2;
_script = _this select 3;
_settings = _this select 4;
_condition = "";
if (typeName _unit == "ARRAY") then {_units = _unit} else {_units = [_unit]};
if (typeName _text == "ARRAY") then
{
_textProperty = _text select 1;
_textText = _text select 0;
}
else
{
_textProperty = "";
_textText = _text;
};
_scriptArgs = _script select 0;
_scriptFile = _script select 1;
_setPriority = _settings select 0;
_setShowWindow = _settings select 1;
_setHideOnUse = _settings select 2;
if (count _this > 5) then {_condition = _this select 5};
{
_unit = _x;
//add action
_id = _unit addAction
[
("<t " + _textProperty +">" + _textText +"</t>"),
_scriptFile,
_scriptArgs,
_setPriority,
_setShowWindow,
_setHideOnUse,
"",
_condition
];
//get actions already in the list
/*
1. null
2a. [[1,2,3]]
2b.
*/
_sameIndex = [];
_allActions = _unit getVariable "ITF_VAR_unitActions";
if (isnil "_allActions") then {_allActions = []};
if (count _allActions > _index) then
{
_sameIndex = _allActions select _index;
if (isnil "_sameIndex") then {_sameIndex = []};
};
//insert new action
_sameIndex = _sameIndex + [_id];
//rebuild allActions
_allActions set [_index, _sameIndex];
//readd_unitTo
_unit setVariable ["ITF_VAR_unitActions",_allActions];
} foreach _units;
};
};
//function2
if(isnil ("fn_unitRemoveAction")) then
{
fn_unitRemoveAction=
{
/*
[
_index,
_unit
] call fn_unitRemoveAction;
ITF_VAR_unitActions = [[index 0 actions],[index 1 actions]];
*/
private ["_index", "_unit", "_units", "_u", "_allActions", "_sameIndex"];
_index = _this select 0;
_unit = _this select 1;
_units = [];
if (typeName _unit == "ARRAY") then {_units = _unit} else {_units = [_unit]};
{
_u = _x;
//get actions already in the list
_allActions = _u getVariable "ITF_VAR_unitActions";
//player sidechat str _allActions;
if (count _allActions > _index) then
{
//remove actions from indexed pos
_sameIndex = _allActions select _index;
{
_u removeAction _x;
}foreach _sameIndex;
//rebuild allActions
_allActions set [_index, []];
//readd_unitTo
_x setVariable ["ITF_VAR_unitActions",_allActions];
};
} foreach _units;
};
};
//SCRIPT
private ["_unitTo", "_unitFrom", "_units", "_cnt", "_unitActions", "_u", "_ua", "_sp", "_un"];
_unitTo = "";
_unitFrom = "";
_units = units group player;
//init
if (count _this < 3) then
{
//init call
_unitTo = vehicle player;
_unitFrom = vehicle player;
}
else
{
//switch call
_unitTo = _this select 3;
_unitFrom = _this select 1;
};
if (alive _unitTo && canMove _unitTo) then
{
//remove actions
[ITF_QTS_actionIndex,_unitFrom] call fn_unitRemoveAction;
//add actions according to available units
_cnt = 1;
_unitActions = [];
{
if (_unitTo != vehicle _x) then
{
//extract unit's number
_u = vehicle (_units select (_cnt-1));
_ua = toArray (str _u);
_sp = _ua find 58;
_un = toString[_ua select _sp + 1, _ua select _sp + 2];
//addAction
[
ITF_QTS_actionIndex,
_unitTo,
["Unit " + _un,ITF_QTS_textStyle],
[_u,ITF_QTS_script],
[10,false,false],
"_target == vehicle player"
] call fn_unitAddAction;
};
_cnt = _cnt + 1;
} foreach units group player;
//after actionhandling, spawn to selected unit
selectPlayer _unitTo;
if (_unitFrom != vehicle player) then {doStop _unitFrom};
if (ITF_QTS_leader) then{group player selectLeader player};
}
else
{
//unit is not available, recursively init script, so actionlist becomes up-to-date
[] execVM ITF_QTS_script;
};