Jump to content
Sign in to follow this  
Valfunction

Moving Units Into and Out of Vehicles

Recommended Posts

I am trying to create a script where I can load/unload "captured" units into vehicles and then unload them when I want to. I don't want them to join my group.

So far I have a script for putting them in a vehicle

getin.sqf

_thisunit = _this select 0;

detach _thisunit;
_thisunit switchMove "";

_thisunit removeAction move2;
_thisunit removeAction getin1;

_thisunit enableAI "MOVE";

_thisunit moveInCargo (nearestObject [_thisunit, "LandVehicle"]);

Question is how do I get them out?

I have tried the following which is not ideal as it removes all civilians from vehicles but the guys get out and then run back and board the vehicle again:

getout.sqf

{
  if ((side _x) == civilian) then
  {
      doGetout _x;
  };
} forEach allUnits;

Does anyone have any ideas or a better way to do this?

Share this post


Link to post
Share on other sites

You maybe could have them get in instead of magically moving them into the cargo. Unless ofcourse you don't care for how it looks.

Share this post


Link to post
Share on other sites

If you have a goup of civs set up

 newgrp = group this

Then you can get them out and into another vehicle by using

{_x assignAsCargo newcar;[_x] orderGetIn true; } foreach units newgrp

Share this post


Link to post
Share on other sites

The group idea looks like a good start.

Only problem is this loading script will need to work multiple times and needs to work on ANY civy on the map for ANY vehicle on the map. I have tried the action "getInCargo" way which at least plays the animation of them moving to the vehicle.

And how how do I get them out again though? I'm thinking of the moveOut command along with disableAI "move" to get them out and make sure they don't get back in.

Share this post


Link to post
Share on other sites

This should be a little more useful. Civs don't need to be grouped for this.

save as in_out_veh.sqf

// null=[veh] execvm "in_out_veh.sqf"

_unitsarray = [];// temp array to store exiting crew
_veh = _this select 0;// current vehicle


// eject from vehicle
{
  if ((side _x) == civilian) then
  {
   _unitsarray = _unitsarray +[_x];// create array of civ crew
   _x leavevehicle _veh;// force out civ crew and keep them out
  };
} forEach crew _veh;// all crew of vehicle inc cargo


// find next vehicle
_newveharray = nearestobjects [_veh,["landvehicle"],50];//find vehicles within 50 meters
_newveh = _newveharray select 1;// select next vehicle;


// move into new vehicle
{
 _x assignAsCargo _newveh;// assign to new vehicle

   [_x] orderGetIn true; // order them to get in new vehicle

} foreach _unitsArray;// units in temp array  

Any time you want them out the current vehicle and into another just use the vehicles name.

null=[vehiclesname] execvm "in_out_veh.sqf"

If no vehicle is found within 50meters they get out and remain on foot.

Edited by F2k Sel

Share this post


Link to post
Share on other sites

That is a really clever bit of script. Only a couple of problems:

The vehicle can be any vehicle on the map and I don't know which one the player will use so I can't use a specific vehicle name.

Also the moving in and out needs to be able to be done on the fly by the player so addActions would have to be used.

I've managed to get it done so far using this:

getin.sqf

_veh = nearestObject [_thisunit, "Landvehicle"];
_thisunit = _this select 0;

if ((_thisunit distance _veh) < 10) then {     //so it only runs when close to vehicles
detach _thisunit;
_thisunit switchMove "";

_thisunit removeAction move2;
_thisunit removeAction getin1;

_thisunit disableAI "MOVE";

_thisunit action ["getInCargo", (nearestObject [_thisunit, "Landvehicle"])];

getout1 = (nearestObject [_thisunit, "Landvehicle"]) addAction ["Get out", "getout.sqf"];
};

getout.sqf

{
  if ((side _x) == civilian) then
  {
moveOut _x;
_x switchMove "ActsPsitMstpSnonWunaDnon_sceneNikitinDisloyalty_Sykes";
_x addAction ["Move", "test.sqf"];
_x removeAction putdown1;
  };
} forEach (crew cursorTarget);

(nearestObject [player, "Landvehicle"]) removeAction getout1;

The disableAI "move" stops them getting back into the vehicle. I didn't know about cursorTarget before so that came in handy being able to order units out of whatever vehicle the player is looking at.

Edited by Valfunction

Share this post


Link to post
Share on other sites

Still using the script I posted above this will get the units out of the vehicle, no need to name the vehicles or civs.

null=[] execvm "cursor.sqf"

save as cursor.sqf

while {alive player} do {

 _target = cursortarget;
if (_target iskindof  "landvehicle") then {
	{ if ((side _x) == civilian) then {
	    _act = _target addaction ["Exit Vehicle", "in_out_veh.sqf"];
	 waituntil  {_target != cursortarget};
	   _target removeaction _act; 
};

	} foreach crew _target;
};

sleep 0.5;		
};

Why not just have the civs join your group so you could just order them in or out of any vehicle you choose?

Edited by F2k Sel

Share this post


Link to post
Share on other sites

I see how it works now. Was reading it wrong.

The reason for them not to join the group is so that anyone can use these actions in MP rather than just the squad leader ordering the civy around.

Share this post


Link to post
Share on other sites
[/php]

Then you can get them out and into another vehicle by using

{_x assignAsCargo newcar;[_x] orderGetIn true; } foreach units newgrp

Greetings, I am looking for something similar with ai infantry

Chopper: hindWaypoints

AI leader: waypointsTeam

BTR-60: btr2

I have this in the ai leaders init:

waypointsTeam = group this; {_x assignAsCargo hindWaypoints; _x moveInCargo hindWaypoints} forEach units waypointsTeam;

As soon as they disembark the chopper, they run to the GET IN waypoint set next to btr2.

I want them to GET IN the BTR and drive off into SEEK AND DESTROY waypoint set elsewhere on the map.....

...........so, where would I put this additional code?:

{_x assignAsCargo newcar;[_x] orderGetIn true; } foreach units newgrp

Lastly, when the AI disembark the chopper, they seem to always get stuck at the chopper landing gear.........anyway to fix this? It looks so damn silly.........:butbut:

Thank you for your help

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  

×