Jump to content
jassida

Retain leadership of AI in multiplayer co-op using team switch

Recommended Posts

Hi.

I'd like to create/edit multiplayer missions so that I always retain control of the AI.

An example would be to team switch to an AT soldier to knock out a vehicle myself but so that I instantly become squad leader again and my old "body" doesn't begin ordering the troops around.

I know how to make the mission a team switch mission but I don't know how to script the retention of leader status on teamswitch, especially in multiplayer.

Can anyone help me? This will only be the second script I will have ever tried (and I haven't got the first one working yet :p)

Thanks very much.

Share this post


Link to post
Share on other sites
selectLeader should still work. You just need to ensure that the command is executed on the machine where the group is local. If you are currently the leader of the group, then the group will be local to your machine. Use selectLeader to change the group leader to the AI you wish to switch to, then team switch to that AI.

Share this post


Link to post
Share on other sites

Thanks a lot.

Do I run the command from the console when pressing escape?

Share this post


Link to post
Share on other sites

You could do it that way. It's important that you change the leader first, though, before team switching. If you team switch first, locality of the group may shift to the server as the group would become AI-controlled, and then selectLeader might not work when executed from your machine. I haven't tested this, though, so I'm not 100% sure.

Share this post


Link to post
Share on other sites

Ok thanks, what is the best way to do it then, a script?

Share this post


Link to post
Share on other sites

There's rarely ever a single best way to do something, but the script approach would be simple enough. When called, the following little script will make the unit at which you are pointing the group leader and then give you control of that unit, provided that you are pointing at a unit in your group.

_target = cursorTarget player;
_group = group player;
_playerVarName = vehicleVarName player;

if (isNil _target) exitWith {hint "No target in sight!"};
if (!_target in (units _group)) exitWith {hint "Target is not part of your group!"};

_group selectLeader _target;
selectPlayer _target;
_target setVehicleVarName _playerVarName;
hint "You have occupied a new body!";

  • This script should only be called locally on your machine during a mission.
  • Your original unit needs to be named in the editor for the vehicleVarName stuff to work.

  • Like 1

Share this post


Link to post
Share on other sites

In your init.sqf:

onTeamSwitch "group player selectLeader player";

Does this not work in multiplayer?

Share this post


Link to post
Share on other sites

Thanks guys.

I might not get time to try this for a few days but I'll give it a whirl and let you know how I get on.

Share this post


Link to post
Share on other sites
In your init.sqf:

onTeamSwitch "group player selectLeader player";

Does this not work in multiplayer?

I didn't know about the onTeamSwitch command. I would definitely try that first!

Share this post


Link to post
Share on other sites
In your init.sqf:

onTeamSwitch "group player selectLeader player";

Does this not work in multiplayer?

Dont think that works in MP, but i hope i am wrong.

If that does not work, try a simple loop in unit init.

_null = this spawn {
if (!local _this) exitWith {};
while {true} do {
	waitUntil {sleep 0.5; alive player AND player != leader (group player)};
	(group player) selectLeader player;
};
};

will run until mission end, and when player is alive and not a teamleader, he will be teamleader.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×