Jump to content
Sign in to follow this  
Knobhead

Script to move AI into a vehicle not working in multiplayer

Recommended Posts

http://pastebin.com/y48xd039

This is a script I have that moves an ai character into the passenger space of the nearest out of three vehicles (hunters1, hunters2, hunters3) and while it works just fine in preview or when hosting myself it does not work on a dedicated server.

Why is this?

Share this post


Link to post
Share on other sites

This is getting insanely frustrating

is no one able to help with this?

Share this post


Link to post
Share on other sites

Not the cleanest example but this works, tested on dedicated..

_distance = 10e4;
_results = [];
_hunters = [hunters1, hunters2, hunters3];
{
_howFar = hostage1 distance _x;
_results set [count _results, _howFar];
_distance = _distance min _howFar;
} forEach _hunters;
_nearest = _hunters select (_results find _distance);
[[[units (group hostage1),_nearest],{
{
	_x assignAsCargo (_this select 1);
	[_x] orderGetIn true;
} forEach (_this select 0);
}],"BIS_fnc_spawn",hostage1,false] call BIS_fnc_MP;

TestMission pbo

Commented code...

//A large number to test against
_distance = 10e4;
//Empty array for holding distances to each hunter
_results = [];
//Array of named vehicles
_hunters = [hunters1, hunters2, hunters3];
{
//Get the distance from a hunter to hostage1
   _howFar = hostage1 distance _x;
   //Store the distance _howFar in _results
   _results set [count _results, _howFar];
   //_distance equals the smallest value between _distance and _howFar
   _distance = _distance min _howFar;

   //Check each hunter
} forEach _hunters;

//_nearest equals the hunter at the same index in _hunters as _distance is in _results
_nearest = _hunters select (_results find _distance);

//Send an array of the units in hostage1's group and the _nearest hunter
[[[units (group hostage1),_nearest],{

//For each member of the group of hostage1
//assign them as cargo of the _nearest hunter
//and order them to get in
   {
       _x assignAsCargo (_this select 1);
       [_x] orderGetIn true;
   } forEach (_this select 0);

   //Send the above code to be run on the machine where hostage1 is local
}],"BIS_fnc_spawn",hostage1,false] call BIS_fnc_MP; 

Although assignAsCargo is global (WIKI?), unless it was used locally on the hostages (at the same locality as the orderGetIn command is used) sending orderGetIn via BIS_fnc_MP on its own still did not seem to work, so i ended up sending the whole forEach loop. Could be tidied up further by creating a function to call rather than sending the whole code block.

Edited by Larrow

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
Sign in to follow this  

×