Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions addons/common/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
{
Expand Down
15 changes: 15 additions & 0 deletions addons/common/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
};
24 changes: 24 additions & 0 deletions addons/common/fnc_onTeamColorChanged.sqf
Original file line number Diff line number Diff line change
@@ -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];
};
27 changes: 27 additions & 0 deletions addons/common/fnc_synchTeamColors.sqf
Original file line number Diff line number Diff line change
@@ -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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why a globalEvent and not a targetEvent? Is this color necessary to be synced on all clients?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, in case another player joins the squad he needs to know the assigned colors as well.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't that mean you want to sync them up upon joining the team instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's possible too, but would require extension of the PFH (unless there's a CBA event for it? there's no doc for default events and I didn't see any either) and it would ofc have a delay. Without that delay it would be great for triggering a CBA event though.

Either options aren't perfect in my opinion. Choose your poison...

};
true
} count units player;
};