diff --git a/addons/common/CfgFunctions.hpp b/addons/common/CfgFunctions.hpp index 9c6198441..c3c4df283 100644 --- a/addons/common/CfgFunctions.hpp +++ b/addons/common/CfgFunctions.hpp @@ -339,6 +339,12 @@ class CfgFunctions description = "Creates a ""random"" number 0-9 based on an object's velocity"; file = "\x\cba\addons\common\fnc_objectRandom.sqf"; }; + // CBA_fnc_onTeamColorChanged + class onTeamColorChanged + { + description = "Assigns the units team color if it changed on another machine."; + file = "\x\cba\addons\common\fnc_onTeamColorChanged.sqf"; + }; // CBA_fnc_parseYAML class parseYAML { @@ -441,6 +447,12 @@ class CfgFunctions description = "Switch player to another unit."; file = "\x\cba\addons\common\fnc_switchPlayer.sqf"; }; + // CBA_fnc_synchTeamColors + class synchTeamColors + { + description = "Synchs the team colors every second."; + file = "\x\cba\addons\common\fnc_synchTeamColors.sqf"; + }; // CBA_fnc_systemChat class systemChat { diff --git a/addons/common/XEH_postInit.sqf b/addons/common/XEH_postInit.sqf index 5fafc334b..cf6f4f616 100644 --- a/addons/common/XEH_postInit.sqf +++ b/addons/common/XEH_postInit.sqf @@ -118,3 +118,18 @@ if !(isDedicated) then { activateAddons _addons; }; */ + +["CBA_teamColorChanged", CBA_fnc_onTeamColorChanged] call CBA_fnc_addEventHandler; +if (hasInterface) then { + [CBA_fnc_synchTeamColors, 1, []] call CBA_fnc_addPerFrameHandler; + if (didJIP) then { + private "_team"; + { + _team = _x getVariable [QGVAR(synchedTeam), ""]; + if (_team != "") then { + _x assignTeam _team; + }; + true + } count allUnits; + }; +}; diff --git a/addons/common/fnc_onTeamColorChanged.sqf b/addons/common/fnc_onTeamColorChanged.sqf new file mode 100644 index 000000000..29094f452 --- /dev/null +++ b/addons/common/fnc_onTeamColorChanged.sqf @@ -0,0 +1,24 @@ +/* ---------------------------------------------------------------------------- +Internal Function: CBA_fnc_onTeamColorChanged + +Description: + Assigns the units team color if it changed on the squad leaders machine. + +Parameters: + _unit - unit [OBJECT] + _team - team the unit got assigned to [STRING] + +Returns: + Nothing + +Author: + BaerMitUmlaut +---------------------------------------------------------------------------- */ + +#include "script_component.hpp" +params ["_unit", "_team"]; + +_unit assignTeam _team; +if (local (leader _unit)) then { + _unit setVariable [QGVAR(synchedTeam), _team, true]; +}; diff --git a/addons/common/fnc_synchTeamColors.sqf b/addons/common/fnc_synchTeamColors.sqf new file mode 100644 index 000000000..4d93f650e --- /dev/null +++ b/addons/common/fnc_synchTeamColors.sqf @@ -0,0 +1,27 @@ +/* ---------------------------------------------------------------------------- +Internal Function: CBA_fnc_synchTeamColors + +Description: + Synchs the team colors. Does not need to be called manually. + +Parameters: + None + +Returns: + Nothing + +Author: + BaerMitUmlaut +---------------------------------------------------------------------------- */ + +#include "script_component.hpp" + +if (leader player == player) then { + { + if ((assignedTeam _x) != (_x getVariable [QGVAR(synchedTeam), "MAIN"])) then { + //Local team != currently synched team, so we need to synchronize them again + ["CBA_teamColorChanged", [_x, assignedTeam _x]] call CBA_fnc_globalEvent; + }; + true + } count units player; +};