Jump to content
felipechapmanfromm

how do I find nearest vehicle then assign as cargo for that vehicle

Recommended Posts

I have tried using GETIN NEAREST in a waypoint, but I had problems with it.

This is my code atm

nObj = nearestObject[casPos, ['sarheli0','sarheli1','sarheli2']];
casSpawn assignAsCargo nObj;
[casSpawn] orderGetIn true;

I know this code is wrong, also in the type for nearestobject can I put global variables into it

Share this post


Link to post
Share on other sites
nObj = nearestObjects[casPos, ["sarheli0","sarheli1","sarheli"]];

casSpawn assignAsCargo nObj select 0;

[casSpawn] orderGetIn true;

In the future remember that nearestObject returns a single type, doesn't support arrays. nearestObjects returns an array so use that, should work. wiki.

Also for future reference its recommended to add a radius to nObj's nearestObjects, so that the engine doesn't have to scan a 15km and lag everyone for no reason if the vehicles are far away.

  • Like 1

Share this post


Link to post
Share on other sites

So I have modified my code but now how have an undiffined variable in expression _veh, when it is defined

_nObj = nearestObjects[casPos, ["sarheli0","sarheli1","sarheli2"],100];
_veh = _nObj select 0;
casSpawn assignAsCargo _veh;
[casSpawn] orderGetIn true;
hint _veh;

heres my code.

 

Thanks

Share this post


Link to post
Share on other sites

I guess sarheli0,sarheli1,sarheli2 and casSpawn are defined objects (and not classes of helos). You can't use them as is in nearestObjects.

So:

_nObj = [sarheli0,sarheli1,sarheli2] apply {[casSpawn distance2D _x,_x]};

_nObj sort true;

_veh = _nObj select 0 select 1;

casSpawn assignAsCargo _veh;

[casSpawn] orderGetIn true;

  • Like 1

Share this post


Link to post
Share on other sites

nearestObjects takes class names or config parents.

There are no vehicles with a  "sarheli0"/"sarheli1"/"sarheli2" classname, nearestObjects won't find anything.

_nObj will therefore be an empty array, and _veh will be undefined.

 

Use something like:

_nObj = nearestObjects [casPos,["Helicopter"],100];

 

If you want to find the nearest vehicle from sarheli0/sarheli1/sarheli2 do:

 

_helis = [sarheli0,sarheli1,sarheli2];
_helisSorted = [_helis,[],{casPos distance _x}] call BIS_fnc_sortBy;
_veh = _helisSorted select 0;

 

  • Like 1

Share this post


Link to post
Share on other sites

Hi there again,

Your code works but when I do

casSpawn assignAsCargo _veh;
[casSpawn] orderGetIn true;

The AI move in front of the Heli and does not get in,

so I used moveInCargo, That works but there is not animation, How do I use assignAsCargo properly / get it to work.

 

Cheers.

Share this post


Link to post
Share on other sites

Not sure if you are trying to get passengers into a heli or a pilot/gunner. Use moveInDriver/moveInGunner/moveInCommander for pilot/gunner/command, seems like ur plane doesn't have passenger seats. (If it does, then post some more details like planes name etc)

Share this post


Link to post
Share on other sites

Hi, the heli is a helenic eurocopter, it has passenger seats, I am trying to get the AI to get in passenger seat, as I said before it works with moveInCargo, but there is no animation.

 

Cheers!

Share this post


Link to post
Share on other sites
9 hours ago, felipechapmanfromm said:

Hi there again,

Your code works but when I do


casSpawn assignAsCargo _veh;
[casSpawn] orderGetIn true;

The AI move in front of the Heli and does not get in,

so I used moveInCargo, That works but there is not animation, How do I use assignAsCargo properly / get it to work.

 

Cheers.

 

Use assignAsCargoIndex instead.

You can check all places in your helo, filling it with named units, then, in console watch: yourHelo getCargoIndex unit1, ... If you want to see the place, preview and switch unit.

 

This works on Huron. For example:

{_x assignAsCargoIndex [myHelo, _forEachIndex *2]; [_x] orderGetIn true} forEach units myGrp

will assign even seats (_forEachIndex * 2) inside the huron. Make sure the index exists.

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

×