Jump to content
Sign in to follow this  
pcc

eject dead crews from vehicles

Recommended Posts

I'm trying to eject dead crews from their vehicles.

Here's what I have so far but its not working.

while {true} do {

crew = _this select 0;

if (crew not alive) then
{
	unassignVehicle (_x);
	(_x) action ["eject", vehicle _x];
	//sleep 1;
}
       foreach units crew;

};

What am I doing wrong?

Share this post


Link to post
Share on other sites
while {true} do {

[color="Red"][b]_vehicle[/b][/color] = _this select 0; [i]- this is vehicle with assigned script (this)[/i]

[indent][color="Red"][b]_crew = crew _vehicle;[/b][/color][/indent]


if [b][color="Red"](!(alive _crew))[/color][/b] then
{
	unassignVehicle (_x);
	[color="Red"][b](_x) setPos (getPos (vehicle _x));[/b][/color]
	//sleep 1;
}
       foreach [color="Red"][b]_crew[/b][/color];
[b]sleep 1;[/b]
};

Edited by DAP

Share this post


Link to post
Share on other sites

You got the sctructure all wrong.

_veh = TAG_someVehicle;

while {true} do 
{	
{
	_x action ["eject", vehicle _x]; //Will this work with dead units?
} foreach (crew _veh);

sleep 1;
};

_neo_

Share this post


Link to post
Share on other sites

@twirly

I saved it in eject.sqf and put [] execVM "eject.sqf";

in the init.sqf.

@DAP

_vehicle = _this select 0; - this is vehicle with assigned script (this)

How do I assign it to all vehicles spawned in the game?

Share this post


Link to post
Share on other sites

What DAP is doing would require you to execute eject.sqf through the vehicle init, not init.sqf. _this would represent the vehicle who's init its in.

Basically, if you're going to use DAPs method, just exec eject.sqf through every vehicle's init.

Share this post


Link to post
Share on other sites

I'm using this for warfare and vehicles are spawned by factories, so I can't put it in the vehicle's init.

How can I make it work with init.sqf?

Share this post


Link to post
Share on other sites

It seems the eject action doesn't work on dead units....so DAP is correct with using setpos instead of eject.

Don't know much about Warfare.... but somehow you have to find where the vehicle is created in the code and modify it. Run the script with:-

nul = [[b]_vehicle_created_by_warfare[/b]] execVM "eject.sqf";

eject.sqf:-

private ["_veh","_run","_crew"];

_veh = _this select 0;
_run = true;

while {_run} do {
_crew = crew _veh;
if ({alive _x} count (crew _veh) == 0) then {
	{_x setpos getpos _veh} foreach crew _veh;
	_run =false;
};
sleep 1;
};

The above code runs until everyone in the vehicle is dead and then exits....this (below) will run as long as the vehicle is alive.

eject.sqf:-

private ["_veh","_crew"];

_veh = _this select 0;

while {alive _veh} do {
_crew = crew _veh;
if ({alive _x} count (crew _veh) == 0) then {
	{_x setpos getpos _veh} foreach crew _veh;
};
sleep 1;
};

Edited by twirly

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  

×