Added team color synchronization #185

Merged
merged 7 commits into from Oct 30, 2015

Projects

None yet

4 participants

@BaerMitUmlaut
Contributor

This synchronizes fireteam colors across the network. Other addons can either call the "CBA_teamColorChanged" event or indirectly trigger that event by remote calling assignTeam on the squad leaders machine.

See issue #94.

@PabstMirror
Contributor

In my opinion, checking each frame might be overkill, 1-3 seconds should be fine.

Why not have the group leader call setVariable. I think if there is network traffic delays, the client could raise that event multiple times before it gets the updated variable back from the server. (really only an issue if checking each frame)

This doesn't throw script error, so nothing probably needs to be done, just an oddity to be aware of.
When zeusing into a unit, assignedTeam player can return nil:

{
    _assignedTeam = assignedTeam _x;
    diag_log text format ["%1's team is [%2](%3)", _x, _assignedTeam, (isNil "_assignedTeam")];
    if (_assignedTeam != "MAIN") then {diag_log text "A";} else {diag_log text "B";};
    true
} count units player;
//Returns `zee's team is [<null>](true)` //Note neither A or B run

Debug:

[player, ace_player] = [zee,pp_2]
assignedTeam zee = nil
assignedTeam pp_2 = "RED"
@BaerMitUmlaut
Contributor

Why not have the group leader call setVariable

Because then if I call the event through another addon the setVariable would never be called with the third parameter being true, thus it wouldn't be JIP safe. Unless I missed something?

@PabstMirror
Contributor

Start Local MP Server
Change group member's team to "RED"
Event will fire each frame forever on all machines besides the server.
The variable will never be set because remoteEvent doesn't happen locally and all other machines will fail the isServer check.

What I am thinking of is changing remote to globalEvent
And then in the event do:
if (local (leader _unit)) then {
Which should be the group leader who triggered the event.

@BaerMitUmlaut
Contributor

Fixed. I also set the PFH to run every second instead of every frame, but I could increase the delay further. ACE3 synchs them every 5 seconds, however I think that is a bit too much. It's not a very demanding function.

@Glowbal Glowbal commented on the diff Oct 20, 2015
addons/common/fnc_synchTeamColors.sqf
+ 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;
@Glowbal
Glowbal Oct 20, 2015 Contributor

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

@BaerMitUmlaut
BaerMitUmlaut Oct 20, 2015 Contributor

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

@Glowbal
Glowbal Oct 20, 2015 Contributor

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

@BaerMitUmlaut
BaerMitUmlaut Oct 20, 2015 Contributor

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...

@Glowbal Glowbal commented on an outdated diff Oct 20, 2015
addons/common/fnc_synchTeamColors.sqf
@@ -0,0 +1,27 @@
+/* ----------------------------------------------------------------------------
+Internal Function: CBA_fnc_synchTeamColors
+
+Description:
+ Synchs the team colors every second. Does not need to be called manually.
@Glowbal
Glowbal Oct 20, 2015 Contributor

There is no time delay in this function, but rather in the PFH calling this function. I'd remove the every second part from the description.

@Glowbal Glowbal commented on an outdated diff Oct 20, 2015
addons/common/fnc_onTeamColorChanged.sqf
@@ -0,0 +1,24 @@
+/* ----------------------------------------------------------------------------
+Internal Function: CBA_fnc_onTeamColorChanged
+
+Description:
+ Assigns the units team color if it changed on another machine.
@Glowbal
Glowbal Oct 20, 2015 Contributor

Only if it changed on the leaders machine?

@Killswitch00 Killswitch00 merged commit 354f1b1 into CBATeam:master Oct 30, 2015
@PabstMirror PabstMirror added this to the 2.2 milestone Nov 24, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment