Home   Help Search Login Register  

Author Topic: High Command as client and respawning  (Read 1684 times)

0 Members and 1 Guest are viewing this topic.

Offline laggy

  • Members
  • *
  • "Behold a pale horse"
High Command as client and respawning
« on: 10 Jul 2011, 14:17:28 »
Hi all,

I want the high command commander to pass on his ability to the next group leader after his death. One has to create new module logics and synchronize them and units by scripting. This following solution works well in SP and playing as hosting MP server. At least if the subordinate groups are AI.

HCtransfer.sqf
Code: [Select]
HCunits = HCunits + [player];
publicVariable "HCunits";

_newHCcom = HCcomGroupLogic createUnit ["HighCommand",position player,[],0,"NONE"];
_newHCsub = HCsubGroupLogic createUnit ["HighCommandSubordinate",position player,[],0,"NONE"];

_newHCcom synchronizeObjectsAdd [player];
_newHCcom synchronizeObjectsAdd [_newHCsub];

_newHCsub synchronizeObjectsAdd [leader sg1];
_newHCsub synchronizeObjectsAdd [leader sg2];
_newHCsub synchronizeObjectsAdd [leader sg3];
_newHCsub synchronizeObjectsAdd [leader sg4];
_newHCsub synchronizeObjectsAdd [leader sg5];
_newHCsub synchronizeObjectsAdd [leader sg6];
_newHCsub synchronizeObjectsAdd [leader sg7];
_newHCsub synchronizeObjectsAdd [leader sg8];
_newHCsub synchronizeObjectsAdd [leader sg9];
_newHCsub synchronizeObjectsAdd [leader sg10];

However, as a client this doesn't work. Once the original commander is dead, no one can take his job. The command module is dead for that player for the rest of the mission. Looked at the wiki regarding "synchronizeObjectsAdd". There is however no info on if this command is global or local, how it works really.

What I see as the potential issue, is that the player has to be synced with units and objects that are local to the server or other players.

Does anyone know how this works?

Laggy
« Last Edit: 10 Jul 2011, 14:19:12 by laggy »
And I looked and beheld a pale horse and his name that sat on him was Death and Hell followed with him.

Offline Zipper5

  • BIS Team
  • ****
Re: High Command as client and respawning
« Reply #1 on: 10 Jul 2011, 16:19:05 »
A simple loop with a check may work:
Code: [Select]
_leader = leader _group;

while {count units _group > 0} do {
_newHCcom synchronizeObjectsAdd [_leader];
waitUntil {leader _group != _leader};
_leader = leader _group;
};
Obviously replacing the variables as you see fit. I'm not 100% sure that's what you're after but in theory that should constantly update who the commander is after the last one dies so long as there is someone in his group to take over.

Also, you don't need that huge amount of subordinate adds at the end of your script. Just use this line:
Code: [Select]
_newHCsub synchronizeObjectsAdd [leader sg1,leader sg2,leader sg3,leader sg4,leader sg5,leader sg6,leader sg7,leader sg8,leader sg9,leader sg10];Or even:
Code: [Select]
{_newHCsub synchronizeObjectsAdd [leader _x]} forEach [sg1,sg2,sg3,sg4,sg5,sg6,sg7,sg8,sg9,sg10]
« Last Edit: 10 Jul 2011, 16:26:06 by Zipper5 »

Offline laggy

  • Members
  • *
  • "Behold a pale horse"
Re: High Command as client and respawning
« Reply #2 on: 10 Jul 2011, 18:49:45 »
Thanks for the input.

I finally got it to work... My HC group is called "badguygroup"

init.sqf
Code: [Select]
if (isServer) then {HCunits = []; publicvariable "HCunits"};

global trigger1 (repeatedly)
con: player == leader badguygroup AND ! (player in HCunits)
on act: transferCommand = true; publicVariable "transferCommand"

global trigger2 (repeatedly)
con: transferCommand
on act: transferCommand = false; [] exec "HCtransfer.sqs"

HCtransfer.sqs (yeah, yeah!)
Code: [Select]
? ! isServer : exit;

HCunits = HCunits + [leader badguygroup];
publicVariable "HCunits";

_newHCcom = HCcomGroupLogic createUnit ["HighCommand",position leader badguygroup,[],0,"NONE"];
_newHCsub = HCsubGroupLogic createUnit ["HighCommandSubordinate",position leader badguygroup,[],0,"NONE"];

_newHCcom synchronizeObjectsAdd [leader badguygroup];
_newHCcom synchronizeObjectsAdd [_newHCsub];

_newHCsub synchronizeObjectsAdd [leader sg1];
_newHCsub synchronizeObjectsAdd [leader sg2];
_newHCsub synchronizeObjectsAdd [leader sg3];
_newHCsub synchronizeObjectsAdd [leader sg4];
_newHCsub synchronizeObjectsAdd [leader sg5];
_newHCsub synchronizeObjectsAdd [leader sg6];
_newHCsub synchronizeObjectsAdd [leader sg7];
_newHCsub synchronizeObjectsAdd [leader sg8];
_newHCsub synchronizeObjectsAdd [leader sg9];
_newHCsub synchronizeObjectsAdd [leader sg10];

exit

Running it on the server was the key it seems... not surprising.

Will tidy it up later... but this works as a client respawning "side", with no bugs found yet.

Cheerio!

Laggy
And I looked and beheld a pale horse and his name that sat on him was Death and Hell followed with him.