Jump to content
benw

MP Dedicated Server, moveInCargo

Recommended Posts

Hi guys, i'm trying to make a script that teleport all group units of player into a chopper. I haven't test it with other players yet, but i tested it in the KK MP sandbox, Howerver something really makes me confused that when i use

forEach playableUnits

, i am able to teleport all AI playable units into the chopper.

if(isDedicated)exitWith{};
{
  _x assignAsCargo BENWinsertHeli;_x moveInCargo BENWinsertHeli;
}forEach playableUnits;

But when i use
forEach units player

, nothing happens except only myself is sitting in the chopper. What is the cause of this?

I checked the wiki, it said Arguments of moveInCargo have to be local to the client the command is executed on. what is this mean?

Is this mean this command cannot be used in MP?

and why forEach playableUnits works, but forEach units player doesn't work?

Also, i used if(isDedicated)exitWith{}; is it correct to place this if(isDedicated)exitWith{}; in order to make all group units of player moveInCargo of the chopper?:confused::confused:

Added:

1.When i used foreach playableunits, it seems only 1 of the connected players and all grouped AI uints got teleported into the chopper, while other players stays in the original position. Even i used the console to manually move other player into the chopper, still didn't work, and no error message shown.

2. Other players obviously can see all objects that created by script dynamically

3. I'm guessing that i need to create an addaction on all the players, so that they can have the moveInCargo scripts that is local to them? and let them choose the MoveInCargo? command?

==================================================================================================================

Problem solved, solution below:

I have solved the issue, now i can get all players moveInCargo in the chopper.

I think other new mission editors like me will also encounter the same problem, so i should write these down:

1. In the BIS wiki, it stated that the moveInCargo command has to be "executed locally".

2. While the sqf file in the Server Side has stored this moveInCargo command only for the server itself (In other words, it stored in the server mission file).

3. Now what you need to do is to find some commands that accept the "Server Side execution" and also has "Local Effect", I guess addPublicVariableEventHandler is the most reliable way, so just use addPublicVariableEventHandler.

4. and then, i just broadcast something to trigger the connected player execute some codes in his pc locally:

moveIn=true; // can be anything, just for trigger your connected players to execute local commands
publicVariable "moveIn";
"moveIn" addPublicVariableEventHandler {
	{
		_x moveInAny BENWInsertHeli;
		_x additem "NVGoggles";
		_x assignitem "NVGoggles";
	} forEach units player;
};
// Maybe forEach units player is a surplus now, because now every connected client actually execute the code locally, have no time to test it

.And, that's it, problem solved!:yay:

Edited by benw

Share this post


Link to post
Share on other sites

Hi Benw,

Use forEach units group player; as this will guarantee the parameter for units is of type group which will return an array of all the players in the group. Units player; will return just the group, hence why your problem occurs.

The reason playableUnits works is because the command returns an array of all playable units regardless if its AI or a player, whereas units player; doesn't.

Best,

NorybiaK

Share this post


Link to post
Share on other sites

Problem solved, solution below:

I have solved the issue, now i can get all players moveInCargo in the chopper.

I think other new mission editors like me will also encounter the same problem, so i should write these down:

1. In the BIS wiki, it stated that the moveInCargo command has to be "executed locally".

2. While the sqf file in the Server Side has stored this moveInCargo command only for the server itself (In other words, it stored in the server mission file).

3. Now what you need to do is to find some commands that accept the "Server Side execution" and also has "Local Effect", I guess addPublicVariableEventHandler is the most reliable way, so just use addPublicVariableEventHandler.

4. and then, i just broadcast something, to trigger the connected player execute some codes in his pc locally:

moveIn=true; // can be anything, just for broadcast the code for your connected players

publicVariable "moveIn";

"moveIn" addPublicVariableEventHandler {

{

_x moveInAny BENWInsertHeli;

_x additem "NVGoggles";

_x assignitem "NVGoggles";

} forEach units player;

}

[/php]

. And, that's it, problem solved!:yay:

Edited by benw

Share this post


Link to post
Share on other sites

I am curious about the method you used to test the script. You mentioned using KK's MP sandbox, but was it through the editor or dedicated server? Also, are you trying to execute the script on the server or client? You mentioned that you are the only one in the chopper, did you move into it or were you already in it?

Share this post


Link to post
Share on other sites

hi, norybiak .

I tested the script in 3 environments, 1. editor, 2. KK's MP sandbox, 3. real dedicated server with 1 other player (i'm running DS and game client at the same time)

i'm not sure what you mean by trying to execute the script on the server or client, because i think all the scripts are stored in server mission files, I want to use moveInCargo. When i tested the script, only me got teleported into the chopper with moveInCargo command with the real DS environment.

Edited by benw

Share this post


Link to post
Share on other sites

The mission file is downloaded by every client that connects the server. Every client has a copy of the mission, and runs the scripts within the .pbo based on what is scripted. Using control statements such as if(isDedicated)exitWith{}; allow the possibility for some scripts to run on the server or client only. Some of the missions you've probably played, such as Altis Life, separate the server scripts from the client scripts completely by removing any script designed to run on the server from the mission file that each client downloads. The server is capable of running scripts outside the mission file, either as an addon or as a plain folder in the root directory of the game. Some reasons why this is beneficial:

1) decrease the mission file size each client downloads

2) prevent secret scripts from being extracted from the .pbo, as they are not present

My point in all this is to find out if your script is running as the server or client, because I just tested:

{
_x assignAsCargo test; 
_x moveInCargo test;
}forEach units player; 

as a local script in a dedicated environment on my own machine. Each AI within my group moved into the helicopter I named test.

Edited by norybiak

Share this post


Link to post
Share on other sites

I have read somewhere that every unit is, for a short time, local to the server on mission start.

It was suggested to use this in a units init:

if (isServer) then {p1 moveInDriver heli1;}

This seems to work too.

Share this post


Link to post
Share on other sites

This was very helpful!! Thanks for the advice! I used the eventhandlers for moving my players into a helicopter and for deploying them with parachutes. Even with your solution it took me quite a few hours to figure it out :)

Share this post


Link to post
Share on other sites

Hey I know that it's a bit late... But I bump this up with a workin and tested solution for anyone interested:
 

//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;
};

execute the code globally (eg from init) but call the function only locally it handles locality on its own. Tested in MP on a dedi.
First parameter needs to be an array, second the target vehicle eg:
[[player1, player2,etc ], plane] call MRH_fnc_MoveInCargo;
or
[allplayers,plane] call MRH_fnc_MoveInCargo;

  • Like 1

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

×