Jump to content
Sign in to follow this  
Clayman

How to get crew back in vehicle... "dynamically"

Recommended Posts

Hi. I'm working on a little something and I'm kinda stuck at one point. Normally it shouldn't be that much of a problem, but dunno, maybe I'm too tired to think... I just don't know where to start.

So, this is the situation:

I have a (kind of) dynamically created group which has one or more vehicles. At some point the units leave the vehicles and later they should board them again. But this is the tricky part. It could be possible that one or more of the vehicles have been destroyed or that some of the units in the group have been killed. So what I'm looking for is a way to get all remaining units to board all remaining vehicles (including gunner / commander etc. positions).

Like I said, it can't be that hard, but I need someone to point me in the right direction. Thanks. :)

Share this post


Link to post
Share on other sites

Thanks Demonized. I'll look into that.

However I was hoping for a solution without using waypoints. Any other ideas are welcome.

Share this post


Link to post
Share on other sites

Well first you would have to decide how the script will choose who goes in what.

Probably just keep a variable that has the role of each soldier (driver, gunner, commander, some random guy). Then for each vehicle check for each position if original crewman is alive, and if not, replace him with one of the random guys (and remove the random guy from the list of random guys). If a vehicle is destroy, add its crew to the list of random guys.

Assuming you know how to get dude X in vehicle slot Y, all you need in addition is to know some array commands and to check if vehicles are usable and if soldiers are alive.

Share this post


Link to post
Share on other sites

look in my spoiler sig, there is a workaround for assignAsTurret, wich includes how to dynamically mount a vehicle.

use that or parts of that, and leave out the cargo part until all vehicles are "crewed", then use cargo part for rest of group.

---------- Post added at 12:12 AM ---------- Previous post was Yesterday at 11:42 PM ----------

this is a rough draft untested and unoptimized on how to achieve this dynamically.

it does not take into account extra turrets.

folow steps below and whenever you need to get your guys to mount back into their still functioning vehicles do this, change the name ofc.

someGlobalVariable_set_to_true_so_we_know_its_time_to_enter_vehicles_again = true;

place in leader init, or run with leadername instead of this.

do it after all units are placed inside the vehicles, script will first off gather all vehicles used by group, so make sure group is in vehicles before you run the script.

place in leader init, or run with leadername instead of this.

_null = this execVM "scriptname.sqf";

save this as scriptname.sqf

_vehicles = [];
// find and add in all the different vehicles used.
{
_veh = vehicle _x;
if (_veh != _x AND !(_veh in _vehicles)) then {_vehicles = _vehicles + [_veh]};
} foreach units group _this;

someGlobalVariable_set_to_true_so_we_know_its_time_to_enter_vehicles_again = false;
waitUntil {someGlobalVariable_set_to_true_so_we_know_its_time_to_enter_vehicles_again};

// first add a driver to all of the able vehicles.
{
_veh = _x;
if (canMove _veh) then {
	{
		_unit = _x;
		if (isNull (assignedVehicle _unit) AND isNull (assignedDriver _veh)) then {
			_unit assignAsDriver _veh;
			[_unit] orderGetin true;
		};
	} foreach units group _this;
};
} foreach _vehicles;

// second add a gunner to all of the able vehicles.
{
_veh = _x;
if (canMove _veh) then {
	{
		_unit = _x;
		if (isNull (assignedVehicle _unit) AND isNull (assignedGunner _veh)) then {
			_unit assignAsGunner _veh;
			[_unit] orderGetin true;
		};
	} foreach units group _this;
};
} foreach _vehicles;

// third add a gunner to all of the able vehicles.
{
_veh = _x;
if (canMove _veh) then {
	{
		_unit = _x;
		if (isNull (assignedVehicle _unit) AND isNull (assignedCommander _veh)) then {
			_unit assignAsCommander _veh;
			[_unit] orderGetin true;
		};
	} foreach units group _this;
};
} foreach _vehicles;

// last add in cargo rest of group.
{
_veh = _x;
if (canMove _veh) then {
	_freeCargo = _veh emptyPositions "Cargo";
	{
		_unit = _x;
		if (isNull (assignedVehicle _unit) AND _freeCargo != 0) then {
			_freeCargo = _freeCargo - 1;
			_unit assignAsCargo _veh;
			[_unit] orderGetin true;
		};
	} foreach units group _this;
};
} foreach _vehicles;

Edited by Demonized

Share this post


Link to post
Share on other sites

Thanks a lot to both of you. :)

I'm gonna get some sleep now and take a closer look tomorrow. But I'm sure I can come up with something now.

Edit: Wow, Demonized. That looks really good. Much more than I had expected. :D

Going to try it out and report back. Thanks again.

Edited by Clayman

Share this post


Link to post
Share on other sites
Edit: Wow, Demonized. That looks really good. Much more than I had expected. :D

Going to try it out and report back. Thanks again.

I dunno, his variable names aren't quite as detailed as I'd like.

Share this post


Link to post
Share on other sites
I dunno, his variable names aren't quite as detailed as I'd like.

I know he should really think about commenting his code so we can figure it out.

Lmao :) jk Demonized, good work

Share this post


Link to post
Share on other sites

just a word of warning, i tested script and it works fine, but when used on a vehicle with crew placed in editor, (the one with crew already inside) a getout wp will still list the units assigned to the vehicle they started the mission in after a getout wp.

even if using unassign vehicle ordergetin false, it still lists the unit as assigned to the vehicle.

so then the script does nothing as it sees someone already occupying the positions.

when script is used on a group that has been scripted in to the vehicles via assignAsDriver, etc commands the script works perfectly.

im running Arma2 CO patch 1.59. all patches updated (A2 1.10 etc).

i also have installed the latest beta but not started the game with it.

i also have the latest Take On Helicopters installed, but again ofc not running the game with it.

maybe someone else can check if this is the case on your version:

to test do this:

1st test:

place a vehicle, for example a stryker m2.

place 2 wps, 1st is a getout waypoint.

2nd is a move wp with this in on act of wp:

_null = (group this) spawn {
{
	diag_log "---------------------------------------------";
	diag_log "---------------------------------------------";
	diag_log format["assigned vehicle is %1",(assignedVehicle _x)];
	diag_log "---------------- unit info ------------------";
	diag_log format["is this driver %1",(assignedDriver testcar)];
	diag_log format["is this gunner %1",(assignedGunner testcar)];
	diag_log format["is this commander %1",(assignedCommander testcar)];
	diag_log format["is this cargo %1",(assignedCargo testcar)];
} foreach units _this;
       player sidechat "finnished check rpt file";
};

2nd test:

do the same as above, but instead of getout wp make it a normal MOVE wp and in on act of that wp (1) place this:

_null = (group this) spawn {
{
	[_x] orderGetIn false;
	unAssignVehicle _x;
} foreach units _this;
};

and in 2nd wp place same as in 1st test.

open your -rpt file after and see what the results were: i got this:

test1

"---------------------------------------------"
"---------------------------------------------"
"assigned vehicle is 20dd7000# 438925: m1126_icv_m2.p3d"
"---------------- unit info ------------------"
"is this driver B 1-1-C:2"
"is this gunner B 1-1-C:1"
"is this commander B 1-1-C:1"
"is this cargo []"
"---------------------------------------------"
"---------------------------------------------"
"assigned vehicle is 20dd7000# 438925: m1126_icv_m2.p3d"
"---------------- unit info ------------------"
"is this driver B 1-1-C:2"
"is this gunner B 1-1-C:1"
"is this commander B 1-1-C:1"
"is this cargo []"

test2

"---------------------------------------------"
"---------------------------------------------"
"assigned vehicle is 1e13c400# 438925: m1126_icv_m2.p3d"
"---------------- unit info ------------------"
"is this driver B 1-1-C:1"
"is this gunner B 1-1-C:2"
"is this commander B 1-1-C:2"
"is this cargo []"
"---------------------------------------------"
"---------------------------------------------"
"assigned vehicle is 1e13c400# 438925: m1126_icv_m2.p3d"
"---------------- unit info ------------------"
"is this driver B 1-1-C:1"
"is this gunner B 1-1-C:2"
"is this commander B 1-1-C:2"
"is this cargo []"

when i tested same above on a group mounted into vehicles via the script commands assignAs... movein... and then exited the vehicles with ordergetin and unassignVehicle the results was this:

"---------------------------------------------"
"---------------------------------------------"
"assigned vehicle is <NULL-object>"
"---------------- unit info ------------------"
"is this driver 0xc9ac6c"
"is this gunner 0xc9ac6c"
"is this commander 0xc9ac6c"
"is this cargo array"
"---------------------------------------------"
"---------------------------------------------"
"assigned vehicle is <NULL-object>"
"---------------- unit info ------------------"
"is this driver 0xc9ac6c"
"is this gunner 0xc9ac6c"
"is this commander 0xc9ac6c"
"is this cargo array"
"---------------------------------------------"
"---------------------------------------------"
"assigned vehicle is <NULL-object>"
"---------------- unit info ------------------"
"is this driver 0xc9ac6c"
"is this gunner 0xc9ac6c"
"is this commander 0xc9ac6c"
"is this cargo array"
"---------------------------------------------"
"---------------------------------------------"
"assigned vehicle is <NULL-object>"
"---------------- unit info ------------------"
"is this driver 0xc9ac6c"
"is this gunner 0xc9ac6c"
"is this commander 0xc9ac6c"
"is this cargo array"
"---------------------------------------------"
"---------------------------------------------"
"assigned vehicle is <NULL-object>"
"---------------- unit info ------------------"
"is this driver 0xc9ac6c"
"is this gunner 0xc9ac6c"
"is this commander 0xc9ac6c"
"is this cargo array"
"---------------------------------------------"
"---------------------------------------------"
"assigned vehicle is <NULL-object>"
"---------------- unit info ------------------"
"is this driver 0xc9ac6c"
"is this gunner 0xc9ac6c"
"is this commander 0xc9ac6c"
"is this cargo array"
"---------------------------------------------"
"---------------------------------------------"
"assigned vehicle is <NULL-object>"
"---------------- unit info ------------------"
"is this driver 0xc9ac6c"
"is this gunner 0xc9ac6c"
"is this commander 0xc9ac6c"
"is this cargo array"
"---------------------------------------------"
"---------------------------------------------"
"assigned vehicle is <NULL-object>"
"---------------- unit info ------------------"
"is this driver 0xc9ac6c"
"is this gunner 0xc9ac6c"
"is this commander 0xc9ac6c"
"is this cargo array"
"---------------------------------------------"
"---------------------------------------------"
"assigned vehicle is <NULL-object>"
"---------------- unit info ------------------"
"is this driver 0xc9ac6c"
"is this gunner 0xc9ac6c"
"is this commander 0xc9ac6c"
"is this cargo array"
"---------------------------------------------"
"---------------------------------------------"
"assigned vehicle is <NULL-object>"
"---------------- unit info ------------------"
"is this driver 0xc9ac6c"
"is this gunner 0xc9ac6c"
"is this commander 0xc9ac6c"
"is this cargo array"
"---------------------------------------------"
"---------------------------------------------"
"assigned vehicle is <NULL-object>"
"---------------- unit info ------------------"
"is this driver 0xc9ac6c"
"is this gunner 0xc9ac6c"
"is this commander 0xc9ac6c"
"is this cargo array"
"---------------------------------------------"
"---------------------------------------------"
"assigned vehicle is <NULL-object>"
"---------------- unit info ------------------"
"is this driver 0xc9ac6c"
"is this gunner 0xc9ac6c"
"is this commander 0xc9ac6c"
"is this cargo array"
"---------------------------------------------"
"---------------------------------------------"
"assigned vehicle is <NULL-object>"
"---------------- unit info ------------------"
"is this driver 0xc9ac6c"
"is this gunner 0xc9ac6c"
"is this commander 0xc9ac6c"
"is this cargo array"
"---------------------------------------------"
"---------------------------------------------"
"assigned vehicle is <NULL-object>"
"---------------- unit info ------------------"
"is this driver 0xc9ac6c"
"is this gunner 0xc9ac6c"
"is this commander 0xc9ac6c"
"is this cargo array"
"---------------------------------------------"
"---------------------------------------------"
"assigned vehicle is <NULL-object>"
"---------------- unit info ------------------"
"is this driver 0xc9ac6c"
"is this gunner 0xc9ac6c"
"is this commander 0xc9ac6c"
"is this cargo array"
"---------------------------------------------"
"---------------------------------------------"
"assigned vehicle is <NULL-object>"
"---------------- unit info ------------------"
"is this driver 0xc9ac6c"
"is this gunner 0xc9ac6c"
"is this commander 0xc9ac6c"
"is this cargo array"
"---------------------------------------------"
"---------------------------------------------"
"assigned vehicle is <NULL-object>"
"---------------- unit info ------------------"
"is this driver 0xc9ac6c"
"is this gunner 0xc9ac6c"
"is this commander 0xc9ac6c"
"is this cargo array"

i have no idea what 0xc9ac6c is, but it checks out in the isNull check in the scripts, so i dont care atm, but as you see the rest is correct with obj null.

Share this post


Link to post
Share on other sites

First I wanted to say that I got it working. Had to make a few little changes to your script to fit it into my existing ones. But so far everything works just fine.

So, once again, thank you very much, Demonized.

maybe someone else can check if this is the case on your version:

I've done a few tests, and I can pretty much confirm your observations.

.rpt:

test1 (crew'd vehicle, get out / move wp's)

"---------------------------------------------"
"---------------------------------------------"
"assigned vehicle is testcar"
"---------------- unit info ------------------"
"is this driver testcard"
"is this gunner testcarg"
"is this commander testcarg"
"is this cargo []"
"---------------------------------------------"
"---------------------------------------------"
"assigned vehicle is testcar"
"---------------- unit info ------------------"
"is this driver testcard"
"is this gunner testcarg"
"is this commander testcarg"
"is this cargo []"
"is this cargo array"

test2 (crew'd vehicle, move / move wp's + unassignVehicle / orderGetIn)

"---------------------------------------------"
"---------------------------------------------"
"assigned vehicle is testcar"
"---------------- unit info ------------------"
"is this driver testcarg"
"is this gunner testcard"
"is this commander testcard"
"is this cargo []"
"---------------------------------------------"
"---------------------------------------------"
"assigned vehicle is testcar"
"---------------- unit info ------------------"
"is this driver testcarg"
"is this gunner testcard"
"is this commander testcard"
"is this cargo []"

test3 (empty vehicle + assignAs / moveIn, get out / move wp's)

"---------------------------------------------"
"---------------------------------------------"
"assigned vehicle is testcar"
"---------------- unit info ------------------"
"is this driver 0xc9ac6c"
"is this gunner 0xc9ac6c"
"is this commander 0xc9ac6c"
"is this cargo array"
"---------------------------------------------"
"---------------------------------------------"
"assigned vehicle is testcar"
"---------------- unit info ------------------"
"is this driver 0xc9ac6c"
"is this gunner 0xc9ac6c"
"is this commander 0xc9ac6c"
"is this cargo array"

test4 (empty vehicle + assignAs / moveIn, move / move wp's + unassignVehicle / orderGetIn)

"---------------------------------------------"
"---------------------------------------------"
"assigned vehicle is <NULL-object>"
"---------------- unit info ------------------"
"is this driver 0xc9ac6c"
"is this gunner 0xc9ac6c"
"is this commander 0xc9ac6c"
"is this cargo array"
"---------------------------------------------"
"---------------------------------------------"
"assigned vehicle is <NULL-object>"
"---------------- unit info ------------------"
"is this driver 0xc9ac6c"
"is this gunner 0xc9ac6c"
"is this commander 0xc9ac6c"
"is this cargo array"

The only way I could get the script working was with empty vehicles and assignAs/moveIn the crew, and with both move waypoints and the unassignVehicle/orderGetIn false. In all other tests the script simply did nothing.

What worked pretty good however was the leaveVehicle command. This way the script works fine also with crew'd vehicles.

Edited by Clayman

Share this post


Link to post
Share on other sites

@Clayman, nice find on the leaveVehicle command, i did not know it was existing.

Share this post


Link to post
Share on other sites

Have you tried simply using addVehicle? A Get In WP not attached to anything will cause the group to populate any vehicles assigned to them. They should man all available crew positions in all assigned vehicles before they start boarding cargo positions.

Share this post


Link to post
Share on other sites

:D Big Dawg KS

well that would make things very much easier, if the description of the command is accurate, also what if there are several vehicles with guns etc, will all guns and driver positions be filled and rest in cargo for all vehicles or will AI just consider one vehicle to be enough based on units in group etc?

edit: yes it does, group will divide out between driver gunner etc and then fill up cargo slots in the vehicles alive, dont even have to check if vehicle can move or is destroyed as AI handles that automatically.

you have to name vehicles ofc.

edit2: word of warning, turret positions will not be included in leaveVehicle command.

edit, these commands seems to be bugged or im using them wrong.

having a move wp with leaveVehicle command and then move to a wp on foot with addVehicle command works, just not for turrets, getout wp makes turrets also leave vehicle.

the addvehicle command on move on foot wp on act will make them remount.

there seems to be issues so test more with this command is needed.

addVehicle on a empty named placed vehicle does nothing.

Edited by Demonized

Share this post


Link to post
Share on other sites
:D Big Dawg KS

well that would make things very much easier, if the description of the command is accurate, also what if there are several vehicles with guns etc, will all guns and driver positions be filled and rest in cargo for all vehicles or will AI just consider one vehicle to be enough based on units in group etc?

My observations:

  1. Units will try to fill all crew positions of one vehicle
  2. If they cannot fill all crew positions of a vehicle, they fill in this order: 1-driver, 2-gunner (I'm guessing all turrets in the order they are defined), 3-commander
  3. If they fill those positions with units left over, they will start to crew the next vehicle
  4. If all crew positions are filled in all vehicles, only then do they try to fill all cargo positions of the first vehicle
  5. If units are still left over, they fill in cargo of the next vehicle, and so on
  6. If all vehicles are filled to 100% capacity and there are still units left, those poor bastards have to go on foot

Of course if you start assigning roles to individual units they will respect those first. If they have units on foot I don't think they will man any positions that open up until you give them another get in order. Although sometimes, if the group has to travel a long distance to their next WP, the AI leader will automatically issue a get in order.

Edited by Big Dawg KS

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  

×