Jump to content
Mr H.

MoveinCargo on a remote player (Dedicated server)

Recommended Posts

I'm trying to teleport all players in a vehicle at some point in the mission (in MP, on a dedicated server)

{_x moveInCargo xplane} forEach allplayers;
 

won't work but I think that's normal because 'player' can't be passed to another machine in MP
but what's stranger is that this:

[[],{player moveInCargo xplane}] RemoteExec ["Spawn",0,true]; won't work either, it only moves one player inside the plane

I've even tried this

{[[],{player moveInCargo xplane}] RemoteExec ["Spawn",_x,true];} forEach allPlayers;

with the same result.
Ive tried giving variable names to playable units
eg.
allPlayersSpecial = [p1,p2,p3, etc.];
{_x moveInCargo xplane} forEach allPlayerSpecials;
same results

[[],"introscript\intro.sqf"] RemoteExec ["ExecVM",0,true];
where intro.sqf contains a bunch of stuff and the line
player moveInCargo xplane
==> the other stuff will run fine for all other players,  but they won't be moved inside the plane...
Any ideas, solutions?

Share this post


Link to post
Share on other sites

For anyone stumbling into this I have found a working solution:
 

//eg [allplayers,plane] call MRH_fnc_MoveInCargo;
MRH_fnc_MoveInCargo = {

	Params ["_groupOfplayers", "_vehicle"];
	{	
		//this scope will be remote executed for all given players
		[[_vehicle,_x],{	
			Params ["_vehicle","_entityToMove"];
			if (isPlayer _entityToMove) then {_entityToMove = player};//might not be necessary
			//innermost scope create trigger localy
			//step 0 generate a random contion variable
			
			
			//step 1 pass the variables to the player
			_trg = createTrigger ["EmptyDetector", [0,0,0],false];
			
			_trg setVariable ["MRH_MoveInCargoVeh",_vehicle];
			_trg setVariable ["MRH_MoveInCargoEntity",_entityToMove];
			//step 2 create the trigger, get the variables from player
				
				_trg setTriggerActivation ["NONE", "PRESENT", false];
				_trg triggerAttachVehicle [player];
				_trg setTriggerStatements ["true", 
				"
				
				_veh = thisTrigger getVariable 'MRH_MoveInCargoVeh';
				_entityToMove = thisTrigger getVariable 'MRH_MoveInCargoEntity';
				_entityToMove moveInCargo _veh;
				deleteVehicle thisTrigger;

				"
				, ""];
			
		}] RemoteExec ["Call",_x,true];
	} forEach _groupOfplayers;
};

 

Share this post


Link to post
Share on other sites

That's a whole lotta "stuff" just to pass local commands to remote units. The below should do the trick, executed on only one machine. Don't think you actually need the assignAsCargo, I just like working with AI!

{
	[_x, xplane] remoteExecCall ["assignAsCargo", local _x, true];
	[_x, xplane] remoteExecCall ["moveInCargo", local _x, true];
} forEach allPlayers;

This will execute the command only where the player is local, for each player. 

 

Another approach, and what I think you were more interested in with "passing player":

//On all machines
fnc_moveInCargo = {
	player assignAsCargo xplane;
	player moveInCargo xplane;
};

//On only one machine
[] remoteExec ["fnc_moveInCargo", 0, true];

The latter is probably more efficient in the long run, but requires the function be defined on all machines at some point. 

 

I suppose you could also remoteExec the "call" command with your argument being the code, including use of player, but... eh. 

Share this post


Link to post
Share on other sites

Don't remoteExec from inside a forEach loop,

Alternatively to the suggestions from @KC Grimes you could try this:

 

[_yourVehicle, {player moveInCargo _this}] remoteExec ["call", [0,-2] select isDedicated];

 

 

Cheers

Share this post


Link to post
Share on other sites
2 minutes ago, Grumpy Old Man said:

Don't remoteExec from inside a forEach loop,

Alternatively to the suggestions from @KC Grimes you could try this:

 


[_yourVehicle, {player moveInCargo _this}] remoteExec ["call", [0,-2] select isDedicated];

 

 

Cheers

 

Agreed, just easy to read. 

 

Thumbs up for your remoteExec target. Was wondering how to go about handling that. 

  • Like 1

Share this post


Link to post
Share on other sites

kcgrims I had tried your solution with local _x, and it didn't work. It seems to me that moveIncargo si bugged with remote exec on dedi servers, my solution is a workaround.

+ it is my understanding that this:
[[],{player moveInCargo xplane}] RemoteExec ["Spawn",0,true];
will run the code on everymachine so if the player is local where the code executes (everywhere because of the 0) the player will be moved inside the vehicle. You wouldn't need allplayers then ==> That didn't work
also the wiki for remote exec states:
"String - the function will be executed only where object or group defined by the variable with passed name is local"
so local _x is not necessary in your code and I tried it and it didn't work.
I agree that both your solutions are simpler and more elegant, problem is they don't work because... arma.

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

×