From 090eda3be0b405d5c9f58ac5473211f5f8a9524e Mon Sep 17 00:00:00 2001 From: Timo Salola Date: Sun, 27 Jul 2014 18:27:35 +0300 Subject: [PATCH] First release --- $PBOPREFIX$ | 1 + README.md | 2 + config.cpp | 16 +++++ fnc_ColorUnit.sqf | 33 ++++++++++ fnc_GetAllTurretPaths.sqf | 79 ++++++++++++++++++++++++ fnc_menu.sqf | 7 +++ init.sqf | 6 ++ showPlayers.sqf | 124 ++++++++++++++++++++++++++++++++++++++ 8 files changed, 268 insertions(+) create mode 100644 $PBOPREFIX$ create mode 100644 README.md create mode 100644 config.cpp create mode 100644 fnc_ColorUnit.sqf create mode 100644 fnc_GetAllTurretPaths.sqf create mode 100644 fnc_menu.sqf create mode 100644 init.sqf create mode 100644 showPlayers.sqf diff --git a/$PBOPREFIX$ b/$PBOPREFIX$ new file mode 100644 index 0000000..7924109 --- /dev/null +++ b/$PBOPREFIX$ @@ -0,0 +1 @@ +CULTTI_ShowPlayers \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..c7f9b34 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# ShowPlayers A2 Addon +Addon will add button into cba FlexiMenu(aka Interaction Menu) that allow players to check who is inside current vehicle in which seat. Team member names are colored with corresponding colors and other than team members are in grayish. In addition addon shows current taken seats/maximium available seats in this vehicle. \ No newline at end of file diff --git a/config.cpp b/config.cpp new file mode 100644 index 0000000..adad686 --- /dev/null +++ b/config.cpp @@ -0,0 +1,16 @@ +class CfgPatches +{ + class Cultti_ShowPlayers + { + units[] = {}; + weapons[] = {}; + requiredVersion = 1.0; + requiredAddons[] = {"Extended_EventHandlers"}; + + }; +}; + +class Extended_PostInit_EventHandlers +{ + CULTTI_ShowPlayers_Post_Init = "CULTTI_ShowPlayers_Post_Init_Var = [] execVM ""\CULTTI_ShowPlayers\init.sqf"""; +}; \ No newline at end of file diff --git a/fnc_ColorUnit.sqf b/fnc_ColorUnit.sqf new file mode 100644 index 0000000..7fa061a --- /dev/null +++ b/fnc_ColorUnit.sqf @@ -0,0 +1,33 @@ +private +[ + "_unit" +]; + +_unit = _this; +_txt = ""; + +if(_unit in (units player)) then { + _team = assignedTeam _unit; + switch(_team) do { + case("MAIN"): { + _txt = format["%1", name _unit]; + }; + case("RED"): { + _txt = format["%1", name _unit]; + }; + case("GREEN"): { + _txt = format["%1", name _unit]; + }; + case("BLUE"): { + _txt = format["%1", name _unit]; + }; + case("YELLOW"): { + _txt = format["%1", name _unit]; + }; + }; +} +else { + _txt = format["%1", name _unit]; +}; + +_txt \ No newline at end of file diff --git a/fnc_GetAllTurretPaths.sqf b/fnc_GetAllTurretPaths.sqf new file mode 100644 index 0000000..033a102 --- /dev/null +++ b/fnc_GetAllTurretPaths.sqf @@ -0,0 +1,79 @@ +/******************************************************************************* +* Project: Mushi +* Module: fnc_GetAllTurretPaths.sqf +* Project version: [1.0.0] 20.03.2014 +* Module version: [1] 20.03.2014 +* Author: RAB, Prodavec, Marbot, DumbkRat, SPESNAZ +* Function: fnc_GetAllTurretPaths +* Comments: --//-- +*******************************************************************************/ + +/* +INPUT: + vehicle : OBJECT + +OUTPUT: + paths_array : ARRAY + +EXAMPLE: + _allPaths = MyTank call fnc_GetAllTurretPaths; +// _allPaths: [[0], [0,0], [0,1]] +*/ + +private +[ + "_result", + "_vehicle", + "_currentNode", + "_depth", + "_currentConfig", + "_cfgTurrets" +]; + +_result = []; + +if ((!isNil "_this") && {(typeName _this) in ["ARRAY", "OBJECT"]}) then +{ + _vehicle = objNull; + _currentNode = []; + _depth = -1; + _currentConfig = objNull; + + switch (typeName _this) do + { + case "ARRAY": + { + if ((count _this) == 5) then + { + _vehicle = _this select 0; + _currentConfig = _this select 1; + _currentNode = _this select 2; + _depth = _this select 3; + _result = _this select 4; + }; + }; + case "OBJECT": + { + _vehicle = _this; + _currentConfig = configFile >> "CfgVehicles" >> (typeOf _vehicle); + _depth = 0; + }; + }; + + if ((!isNil "_vehicle") && (!isNil "_currentNode") && (!isNil "_depth") && (!isNil "_result") && (!isNil "_currentConfig") && {((typeName _vehicle) == "OBJECT") && ((typeName _currentNode) == "ARRAY") && ((typeName _depth) == "SCALAR") && ((typeName _result) == "ARRAY") && ((typeName _currentConfig) == "CONFIG")} && {!isNull _vehicle}) then + { + _cfgTurrets = _currentConfig >> "Turrets"; + + if (isClass _cfgTurrets) then + { + for "_i" from 0 to ((count _cfgTurrets) - 1) step 1 do + { + _currentNode set [_depth, _i]; + _result set [count _result, +_currentNode]; + [_vehicle, _cfgTurrets select _i, _currentNode, _depth + 1, _result] call fnc_GetAllTurretPaths; + }; + }; + }; +}; + +_result; \ No newline at end of file diff --git a/fnc_menu.sqf b/fnc_menu.sqf new file mode 100644 index 0000000..ebc0563 --- /dev/null +++ b/fnc_menu.sqf @@ -0,0 +1,7 @@ +_menu = [ + ["main", "test", "popup"], + [ + ["Show players","[cursorTarget] execVM '\CULTTI_ShowPlayers\showPlayers.sqf'","", "", "", -1, 1, 1] + ] +]; +_menu \ No newline at end of file diff --git a/init.sqf b/init.sqf new file mode 100644 index 0000000..021c2b5 --- /dev/null +++ b/init.sqf @@ -0,0 +1,6 @@ +sleep 5; //wait for start + +waitUntil {!isNil "ace_sys_interaction_key_self"}; //wait for start +waitUntil {!isNil "ace_sys_interaction_key"}; //wait for start + +["AllVehicles", [ace_sys_interaction_key], -20, ["\CULTTI_ShowPlayers\fnc_menu.sqf", "main"]] call CBA_ui_fnc_add; \ No newline at end of file diff --git a/showPlayers.sqf b/showPlayers.sqf new file mode 100644 index 0000000..9b6319f --- /dev/null +++ b/showPlayers.sqf @@ -0,0 +1,124 @@ +private +[ + "_temp", + "_target", + "_cargo", + "_driver", + "_commander", + "_turretPaths", + "_turret", + "_txt" +]; + +_target = _this select 0; + +if( isNull _target or vehicle player != player ) then { + _target = vehicle player; +}; + + +/* +_players = "Players inside vehicle:"; +_txt = ""; +{ + if( _x == player) then { + } + else { + if(_x in (units player)) then { + //_txt = format["%1", name _x]; + _team = assignedTeam _x; + switch(_team) do { + case("MAIN"): { + _txt = format["%1", name _x]; + }; + case("RED"): { + _txt = format["%1", name _x]; + }; + case("GREEN"): { + _txt = format["%1", name _x]; + }; + case("BLUE"): { + _txt = format["%1", name _x]; + }; + case("YELLOW"): { + _txt = format["%1", name _x]; + }; + }; + } + else { + _txt = format["%1", name _x]; + }; + _role = assignedVehicleRole _x select 0; + if(_role != "CARGO") then { + _txt = format["%1(%2)", _txt, _role]; + }; + _players = format["%1
%2", _players, _txt]; + }; +} forEach crew _target; +*/ + +fnc_GetAllTurretPaths = compile preprocessFile "\CULTTI_ShowPlayers\fnc_GetAllTurretPaths.sqf"; +fnc_ColorUnit = compile preprocessFile "\CULTTI_ShowPlayers\fnc_ColorUnit.sqf"; +_temp = ""; +_max = getNumber(configFile >> "CfgVehicles" >> TypeOf _target >> "transportSoldier"); + +if(getNumber(configFile >> "CfgVehicles" >> TypeOf _target >> "hasCommander") == 1) then { + _max = _max + 1; +}; +if(getNumber(configFile >> "CfgVehicles" >> TypeOf _target >> "hasDriver") == 1) then { + _max = _max + 1; +}; + +_txt = "Players:"; + +_cargo = crew _target; +_driver = driver _target; +_commander = commander _target; +_turretPaths = _target call fnc_GetAllTurretPaths; + +_max = _max + count _turretPaths; + +_turret = []; +{ + _temp = _target turretUnit _x; + if( !isNull _temp ) then { + _turret = _turret + [_temp]; + }; +} forEach _turretPaths; +_turret = _turret - [_commander]; + +_cargo = _cargo - [_driver, _commander] - _turret; + +_current = 0; + +if( !isNull _driver ) then { + _current = _current + 1; +}; +if( !isNull _commander ) then { + _current = _current + 1; +}; + +_current = _current + count _turret + count _cargo; + +_txt = format["%1 %2/%3", _txt, _current, _max]; + +if( !isNull _driver ) then { + _txt = format["%1
%2(Driver)", _txt, _driver call fnc_ColorUnit]; +}; + +if( !isNull _commander ) then { + _txt = format["%1
%2(Commander)", _txt, _commander call fnc_ColorUnit]; +}; +if ( !(count _turret == 0)) then { + { + _txt = format["%1
%2(Turret)", _txt, _x call fnc_ColorUnit]; + } forEach _turret; +}; +if( !(count _cargo == 0)) then { + { + _txt = format["%1
%2", _txt, _x call fnc_ColorUnit]; + } forEach _cargo; +}; + + +hintSilent parseText format["%1", _txt]; \ No newline at end of file