R4IDER 10 Posted April 28, 2014 Hi, So something that I thought would be pretty simple is changing a team leader from one guy to another. Like most things in ARMA using SelectLeader works perfectly in the editor but in the multiplayer it doesn't. Like it says at the bottom of the wiki page a few seconds later it will revert to the old leader. I have been trying to get setLeader to work but because I have named all of the playable units p1,p2,p3 etc I am unable to get this to work because SetLeader reports that it only accepts a team leader and not an object. I am simply using _UnitLeader = leader player; to select the team leader and then _UnitLeader setLeader player; to try and set a new leader. I have been trying to work out a way of making this work for a few hours now so any help would be appreciated. Thanks. Share this post Link to post Share on other sites
Harzach 2517 Posted April 28, 2014 What is your code exactly, and how are you calling it? Using "player" in MP is problematic at best, and is likely where your issue lies. Share this post Link to post Share on other sites
R4IDER 10 Posted April 28, 2014 What is your code exactly, and how are you calling it? Using "player" in MP is problematic at best, and is likely where your issue lies. if (_code == "TakeCommand") then { _UnitLeader = leader player; // This gets the current leader of the players group. _UnitLeader setLeader player; }; Not really much to it tbh. Maybe it should be player SetLeader player; Share this post Link to post Share on other sites
brians200 51 Posted April 28, 2014 The reason it is not working is because of locality. If you read the note at the bottom, it says, SnowSky: In Multiplayer the command has to be executed on the client which the group is actually local, otherwhise the effect would stay only for shorter then 1 second. P.S.: remember, Teamleader is not equivalent to the client on which the group is local! What this means is that the Team Leader of the group is not necessarily the owner of it. Sometimes it is the server that owns it and sometimes it is other players in the group. So how to do you go about figuring out who owns the group? Well this is simple enough. You will need to use the following 4 commands. https://community.bistudio.com/wiki/local https://community.bistudio.com/wiki/BIS_fnc_MP https://community.bistudio.com/wiki/group https://community.bistudio.com/wiki/selectLeader Here is what you need to accomplish: 1. Use BIS_fnc_MP and call your script with the group of the newLeader. [[group _newLeader, _newLeader], "ScriptName" , true, false] spawn BIS_fnc_MP; //_newLeader is the handle of the player that you want to be the leader. //The true parameter indicates to run it on all clients //The false parameter indicates that it doesn't need to be persistent, ie JIP don't need to call it when they join. 2. Then at the top of your script, use the local command to see if the current player is the owner. if(! local (_this select 0)) exitwith {}; // if the current player isn't the owner we will exit // _this select 0 is the group you passed in in step 1 3. Run your SelectLeader Code with "_this select 1". This is your _newLeader you passed in. Hope this helps Share this post Link to post Share on other sites
R4IDER 10 Posted April 29, 2014 Thanks for your help brians200. This is what I've got so far. TakeCommand = { if (!local (_this select 0)) ExitWith {}; _CurrentLeader = _this select 0; _NewLeader = _this select 1; _CurrentLeader selectLeader _NewLeader; }; if (_code == "TakeCommand") then { _newLeader = player; [[group _newLeader, _newLeader], "TakeCommand" , true, false] spawn BIS_fnc_MP; }; An error comes back which states that it expected an object, I expect I have made some stupid error. Share this post Link to post Share on other sites
R4IDER 10 Posted April 29, 2014 I have managed to get this working. TakeCommand = { _CurrentLeader = _this select 0; _NewLeader = _this select 1; { _CurrentLeader selectLeader _NewLeader; } forEach units _CurrentLeader; }; if (_code == "TakeCommand") then { [[group player, player], "TakeCommand" , true, false] spawn BIS_fnc_MP; }; Share this post Link to post Share on other sites
dlegion 98 Posted April 28, 2018 hello guys, i have the same problem, i need to give every player in the group an action to allow them take leadership of the group (to command AI). [group player, player] remoteExec ["selectLeader", 0, true]; the above line seems to not work correctly...sometimes it works, but most of the times dont see the icons of AI soldiers in group. i'm not familiar with this locality concept...maybe thats the problem, can someone explain it a bit ? thanks! Share this post Link to post Share on other sites
Grumpy Old Man 3546 Posted April 28, 2018 13 minutes ago, dlegion said: hello guys, i have the same problem, i need to give every player in the group an action to allow them take leadership of the group (to command AI). [group player, player] remoteExec ["selectLeader", 0, true]; the above line seems to not work correctly...sometimes it works, but most of the times dont see the icons of AI soldiers in group. i'm not familiar with this locality concept...maybe thats the problem, can someone explain it a bit ? thanks! Using 0 executes the command on every client, you don't want that. Try this: [group player, player] remoteExec ["selectLeader", (groupOwner group player), true]; Make sure you call this from the server. So the command will only be executed wherever the group is local. MP can be quite finicky, player might even not be local to his own client in some weird cases. Cheers 1 Share this post Link to post Share on other sites
dlegion 98 Posted April 28, 2018 thanks man! you're great as always ! Share this post Link to post Share on other sites
dlegion 98 Posted April 28, 2018 1 hour ago, Grumpy Old Man said: Make sure you call this from the server. actually i was calling it from an action in script OnPlayerRespawn.sqf player addAction ["Take squad command", "DDscripts\Dleader.sqf",[],1,false,false]; so, how can i make it call from server? ...and using "player" calling it from server will stillwork ? thanks man ! Share this post Link to post Share on other sites
Grumpy Old Man 3546 Posted April 28, 2018 1 hour ago, dlegion said: actually i was calling it from an action in script OnPlayerRespawn.sqf player addAction ["Take squad command", "DDscripts\Dleader.sqf",[],1,false,false]; so, how can i make it call from server? ...and using "player" calling it from server will stillwork ? thanks man ! Actually scratch that, doesn't need to be called from server. Just tested this on dedicated: _group = group player; _newLeader = player; [_group,_newLeader] remoteExec ["selectLeader",groupOwner _group]; Made me the leader of the group permanently, without being the leader before. Addaction: player addAction ["Take Squad Command",{ _group = group player; _newLeader = player; [_group,_newLeader] remoteExec ["selectLeader",groupOwner _group]; }]; That'll do it. Cheers 1 1 Share this post Link to post Share on other sites
dlegion 98 Posted April 28, 2018 it works perfectly, thanks man, i just wish i can give you more kudos! huge thanks ! 1 Share this post Link to post Share on other sites