Jump to content
🛡️FORUMS ARE IN READ-ONLY MODE Read more... ×
Sign in to follow this  
perineum

How to have players respawn inside a vehicle?

Recommended Posts

I am trying to make a race map with the go-kart addon and I want it so a player respawns inside another go-kart if they die. I am a complete noob at mission editing but I figured this would be easy to figure out on my own. It isn't. Can someone help?

Share this post


Link to post
Share on other sites

http://community.bistudio.com/wiki/Description.ext#Respawn...

info on respawn taken from link:

in description.ext in your mission folder

Respawn...

respawn = RespawnType;

respawnDelay = DelayInSeconds;

respawnVehicleDelay = DelayInSeconds;

respawnDialog = 0; // Show the scoreboard and respawn countdown timer for a player if he is killed with respawnType 3. Default is 1 (true).

RespawnType Description

0 or "NONE" No respawn

1 or "BIRD" Respawn as a seagull

2 or "INSTANT" Respawn just where you died.

3 or "BASE" Respawn in base. Requires a marker named:

* respawn_west

* respawn_east

* respawn_guerrila

* respawn_civilian

Add markers named with the prefix 'respawn_west' with any suffix (eg: respawn_westABC, respawn_west1, respawn_west_2, etc) for multiple random respawn points. Similarly for east, guerrila and civilian.

Vehicle respawn in base requires a marker named:

* respawn_vehicle_west

* respawn_vehicle_east

* respawn_vehicle_guerrila

* respawn_vehicle_civilian

4 or "GROUP" Respawn in your group (if there's no AI left, you'll become a seagull).

5 or "SIDE" Respawn into an AI unit on your side (if there's no AI left, you'll become a seagull) - implemented in ArmA 1.08: with this respawn type, team switch is also available to any AI controlled playable units.

this probably only works for MP missions.

Share this post


Link to post
Share on other sites

This will of course only work in multiplayer, single player does not have respawns and some tricky scripting is needed in order to make some kind of "respawn" in SP.

If the mission has no playable AI, then once you set respawn to base, just add an init.sqf file to your mission folder and in it write:

if (!isDedicated) then
{
player addEventHandler ["KILLED", "execVM 'respawn.sqf'];
};

And then create a file called respawn.sqf, and in it write:

waitUntil {alive player};
player moveInDriver respawnCart;

Where respawnCart is the name in the editor of the cart to which you want him to respawn. Of course if you want him to respawn into a different cart every time you will have to instead set a value for respawnCart to the relevant one. Since I don't know your mission I don't know how you want to choose which cart the player will respawn into.

Also, if you want him to respawn in cargo rather than in driver, use moveInCargo instead of moveInDriver.

Share this post


Link to post
Share on other sites

Wow, thanks guys. I didn't know it was in the description.ext.

Share this post


Link to post
Share on other sites

hi,

i am a newbie to posting so here goes...

1. i am creating a multiplayer tank level - where i need, when killed player (me - commander) and all crew (computer generated - driver, gunner, loader) to respawn in tank. (i am hoping to do this for may be 5 or 6 players)

the closest i have got to this is by using an init.sqf :-

if (!isDedicated) then

{

player addEventHandler ["KILLED", "execVM 'respawn.sqf'];

};

with a respawn.sqf:-

waitUntil {alive player};

player moveInDriver tank; - tank being the name of vehicle

this works in as much as the crew and tank will respawn with one of the crew in as driver - i then have to get in tank as commander and order other two crew in as both gunners.

im not sure why the computr generated player is put in as driver and not me the actual player and have tried to use......

waitUntil {alive player};

player moveInDriver tank;

player moveIngunner tank;

player moveInturret tank;

as my respawn.sqf.

this still only put driver in tank on respawn leaving me and crew outside tank as before.

i am wondering how i refere to crew to order them into tank in correct positions.

my editor is full of different attempts i have made to try and resolve this problem.

can someone help me or point me to an example i can adjust or alter to overcome this problem.

thanks in advance for any help given.

Edited by musky
double post

Share this post


Link to post
Share on other sites

Don't you also need to make the tank and crew respawn?

If you have no intention to have playable crew, just AI, then just delete the crew memeber and spawn new ones.

If they're playble this actually might be easier - When player respawns to a new tank, do:

// respawn tank first and do tank = ... so tank points at the correct tank. Of course save the old tank in another variable so that you can delete it at the end of the script
player moveInCommander tank;
_aiCrew = (units group player) - [player];
(_aiCrew select 0) moveInGunner tank;
(_aiCrew select 1) moveInDriver tank;
(_aiCrew select 2) moveInTurret [tank, [1]]; //not sure if this is the correct turret path for loader, you'll have to check. Might be [0,1] instead of [1]!
{
_x setDammage 0;

//add this line only if you're using ACE:
_x call ace_sys_wounds_fnc_RemoveUncon

} forEach _aiCrew;

// probably delete old tank here

Share this post


Link to post
Share on other sites

Thanks for your reply Galzohar,

Yes i need to make the tank respawn but now you have mentioned it i'm not sure if i need the crew to respawn?? may be this would stop them jumping out as the tank get damaged leaving me to fight it out alone??. the idea is once spawned as commander i want to be able to move to gunners seat but still have control of tank movement whilst in as gunner fireing as i go - with machine guns manned by computer generated players and computer generated driver.

i have tried resolving this for so long now until my brain n eyes went pop. so to have your help is nothing short of the most exciting thing thats happened this year!

thanks loads n loads for your time and skill:D:bounce3::yay:

Share this post


Link to post
Share on other sites

Put your player as a higher rank than the crew, then he'll remain leader even after respawn. If after that they still jump out, try assignAndGunner and the related commands, in addition to the moveInGunner and the related commands.

Share this post


Link to post
Share on other sites

Galzohar, can i be so bold as to ask for an example? (if you have time of course)

I spent hours last night trying to work the code you kindly wrote.

The only thing i could get was a respawn with a driver in tank and me and rest of crew outside of tank?

Thanks for all your help:)

Share this post


Link to post
Share on other sites

Higher rank is done in the editor, double click the unit and give it a higher rank.

After (_aiCrew select 0) moveInGunner tank;

add (_aiCrew select 0) assignAsGunner tank; if you have problems with the gunner bailing.

Again it's a bit hard to see what's going on there:

How do you spawn the tank? How did you put the driver in there and why did the same thing not work for your player and the rest of your crew?

Is your crew playable (and thus respawning) or are they non-playable and you use a script to spawn them? First would make it easier by not needing to spawn them but make it harder to move them into the tank, as they (and you) might be dead waiting for respawn while the script tries to move them (and you) in. Second would make moving everyone into the tank easier, but you'd have to delete old crew and spawn new crew every time you respawn.

Share this post


Link to post
Share on other sites

Sorry Galzohar...i'm a numpty:(...here goes...

I have tried both ways....like this...

Both End up spawning tank with diver in and rest of crew outside of vehicle leaving me to get in as commander and order both gunners in tank...which they do and then i can move in as gunner and controle tank whilst fireing.

with players...

1 mee...(playable) init... mee moveincommander tank; nul = [Grp1, 0, 0, "respawn_vehicle_west"] execVM "Script.sqs"

2 crew...(non playable) init... this moveindriver tank

3 crew...(non playable) init... this MoveInTurret [tank,[0]]

4 crew...(non playable) init... this MoveInTurret [tank,[0,1]]

tank...(empty) init... tank setVehicleVarName "tank"; tank = [tank, 0, 0, 0, TRUE, FALSE, "this setDammage 0"] execVM "vehicle.sqf"

vehicle.sqf...

if (!isServer) exitWith {};

// Define variables

_unit = _this select 0;

_delay = if (count _this > 1) then {_this select 1} else {30};

_deserted = if (count _this > 2) then {_this select 2} else {120};

_respawns = if (count _this > 3) then {_this select 3} else {0};

_explode = if (count _this > 4) then {_this select 4} else {false};

_dynamic = if (count _this > 5) then {_this select 5} else {false};

_unitinit = if (count _this > 6) then {_this select 6} else {};

_haveinit = if (count _this > 6) then {true} else {false};

_hasname = false;

_unitname = vehicleVarName _unit;

if (isNil _unitname) then {_hasname = false;} else {_hasname = true;};

_noend = true;

_run = true;

_rounds = 0;

if (_delay < 0) then {_delay = 0};

if (_deserted < 0) then {_deserted = 0};

if (_respawns <= 0) then {_respawns= 0; _noend = true;};

if (_respawns > 0) then {_noend = false};

_dir = getDir _unit;

_position = getPosASL _unit;

_type = typeOf _unit;

_dead = false;

_nodelay = false;

// Start monitoring the vehicle

while {_run} do

{

sleep (2 + random 10);

if ((getDammage _unit > 0.8) and ({alive _x} count crew _unit == 0)) then {_dead = true};

// Check if the vehicle is deserted.

if (_deserted > 0) then

{

if ((getPosASL _unit distance _position > 10) and ({alive _x} count crew _unit == 0) and (getDammage _unit < 0.8)) then

{

_timeout = time + _deserted;

sleep 0.1;

waitUntil {_timeout < time or !alive _unit or {alive _x} count crew _unit > 0};

if ({alive _x} count crew _unit > 0) then {_dead = false};

if ({alive _x} count crew _unit == 0) then {_dead = true; _nodelay =true};

if !(alive _unit) then {_dead = true; _nodelay = false};

};

};

// Respawn vehicle

if (_dead) then

{

if (_nodelay) then {sleep 0.1; _nodelay = false;} else {sleep _delay;};

if (_dynamic) then {_position = getPosASL _unit; _dir = getDir _unit;};

if (_explode) then {_effect = "M_TOW_AT" createVehicle getPosASL _unit; _effect setPosASL getPosASL _unit;};

sleep 0.1;

deleteVehicle _unit;

sleep 2;

_unit = _type createVehicle _position;

_unit setPosASL _position;

_unit setDir _dir;

if (_haveinit) then

{_unit setVehicleInit format ["%1;", _unitinit];

processInitCommands;};

if (_hasname) then

{_unit setVehicleInit format ["%1 = this; this setVehicleVarName ""%1""",_unitname];

processInitCommands;};

_dead = false;

// Check respawn amount

if !(_noend) then {_rounds = _rounds + 1};

if ((_rounds == _respawns) and !(_noend)) then {_run = false;};

};

};

marker...respawn_vehicle_west

Game Lodgic...server

description.ext...

respawn = 3;

respawnDelay = 5;

respawnVehicle = 3;

respawnVehicleDelay = 0;

respawnDialog = 1;

init.sqf...

if (!isDedicated) then

{

player addEventHandler ["KILLED", "execVM 'Script.sqs'];

};

Script.sqs...

waitUntil {alive player};

player moveInCommander tank;

_aiCrew = (units group player) - [player];

(_aiCrew select 0) moveInGunner tank;

(_aiCrew select 1) moveInDriver tank;

(_aiCrew select 2) moveInTurret [tank, [0,1]]; //not sure if this is the correct turret path for loader, you'll have to check. Might be [0,1] instead of [1]!

{

_x setDammage 0;

} forEach _aiCrew;

// probably delete old tank here

without players....

tank... playable as commander, driver,gunner init... tank setVehicleVarName "tank"; tank = [tank, 0, 0, 0, TRUE, FALSE, "this setDammage 0"]

marker...respawn_vehicle_west

Gamelodgic...server

description.ext...

respawn = 3;

respawnDelay = 0;

respawnVehicle = 3;

respawnVehicleDelay = 0;

respawnDialog = 1;

init.sqf...

_Object="M1A2_US_TUSK_MG_EP1" CreateVehicle (GetPos Player);

_VarName="tank";

_Object SetVehicleVarName _VarName;

player moveInCommander tank;

_aiCrew = (units group player) - [player];

(_aiCrew select 0) assignAsGunner tank;

(_aiCrew select 0) moveInGunner tank;

(_aiCrew select 1) assignAsDriver tank;

(_aiCrew select 1) moveInDriver tank;

(_aiCrew select 2) assignAsGunner [tank, [1]];

(_aiCrew select 2) moveInTurret [tank, [0,1]]; //not sure if this is the correct turret path for loader, you'll have to check. Might be [0,1] instead of [1]!

{

_x setDammage 0;

} forEach _aiCrew;

if (!isDedicated) then

{

player addEventHandler ["KILLED", "execVM 'Script.sqs']

};

Script.sqs....

// respawn tank first and do tank = ... so tank points at the correct tank. Of course save the old tank in another variable so that you can delete it at the end of the script

player moveInCommander tank;

_aiCrew = (units group player) - [player];

(_aiCrew select 0) assignAsGunner tank;

(_aiCrew select 0) moveInGunner tank;

(_aiCrew select 1) assignAsDriver tank;

(_aiCrew select 1) moveInDriver tank;

//(_aiCrew select 2) assignAsGunner [tank, [1]];

(_aiCrew select 2) moveInTurret [tank, [0,1]]; //not sure if this is the correct turret path for loader, you'll have to check. Might be [0,1] instead of [1]!

{

_x setDammage 0;

} forEach _aiCrew;

// probably delete old tank here

Hope this helps... Thanks in advance:)

Share this post


Link to post
Share on other sites

Wait, why are you initializing the vehicle with this setDammage 0? New vehicles normally don't spawn with any damage.

Also, it's probably not a good idea to just use random sleep delays the way you're doing it, nor is using getDammage (since it would be incompatible with ACE armor system). Just treat "abandoned" and "destroyed" the same and your life will be easier.

Don't use the game's vehicle respawn (I never even checked how it works), just spawn it yourself. Remove the vehicle-respawn-related lines from description.ext...

Better vehicle respawn script you can use for reference:


#define MAX_SPAWN_DAMAGE 0.001
private ["_vehicle", "_delay", "_initSQF", "_startpos", "_startdir", "_type", "_startTime", "_damageEnabled"];
if (!isServer) exitWith{}; // here you may want to do a different check, probably only run the script on the machine of the player that owns the tank

_vehicle = _this select 0;
_delay = _this select 1;

_maxLevel = 5;
//_levelIndex = 1;
//if (!(_vehicle isKindOf "LandVehicle")) then
//{
//	_levelIndex = 2;
//};
//if (!isNil "paramsArray") then
//{
//	_maxLevel = paramsArray select _levelIndex;
//};

_level = 0;
if (count _this > 2) then
{
_level = _this select 2;
};

if (_level>_maxLevel) exitWith {deleteVehicle _vehicle;};

_initSQF = "";
if (count _this > 3) then
{
_initSQF = _this select 3;
[_vehicle] execVM _initSQF;
};
_startpos = getposASL _vehicle;
_startdir = getdir _vehicle;
_type = typeof _vehicle;
_startTime = - _Delay;
_damageEnabled=0;

waitUntil {!(({alive _x} count (crew _vehicle)) == 0) || ((getDammage _vehicle)>MAX_SPAWN_DAMAGE)};


while {true} do
{
if (!(({alive _x} count (crew _vehicle)) == 0) || (_damageEnabled==1)) then {
	_damageEnabled=1;
	waitUntil {(({alive _x} count (crew _vehicle)) == 0)};	
	_startTime=time;
	waitUntil {(time > (_startTime + _delay)) || !(({alive _x} count (crew _vehicle)) == 0)};
};

if (time > (_startTime + _delay) || (_damageEnabled==0)) then
{
	deletevehicle _vehicle;
	sleep 0.5;
	_vehicle = _type createvehicle _startpos;
	_vehicle setposASL _startpos;
	_vehicle setdir _startdir;
	_damageEnabled=0;
	if (_initSQF!="") then
	{
		[_vehicle] execVM _initSQF;
	};

	waitUntil {!(({alive _x} count (crew _vehicle)) == 0) || ((getDammage _vehicle)>MAX_SPAWN_DAMAGE)};
};
};

Now to that script you can add the lines I gave for moving crew in, in the appropriate place (after spawning the vehicle). Of course you still have to actually respawn the crew first! I don't see you doing it anywhere. I usually don't spawn AI group members so not sure what's the best way to do it, but anything that will spawn AI and make them join your group will work. Make sure you also delete old crew first!

Of course the script will have to run on the machine that belongs to the player who is supposed to own the tank. How you want to determine that is up to you...

Share this post


Link to post
Share on other sites

Thank you Galzohar woohoo,:yay:

I managed to get it working like this...

In editor...

tank...(empty)...named "tank". init...tank setVehicleVarName "tank"; nul = [tank, 0, 0, 0, TRUE, FALSE] execVM "vehicle.sqf"

man..."crewman"...(playable)...(all 4 not named)

man..."crewman"...(playable)

man..."crewman"...(playable)

man..."crewman"...(playable)...all joined as group - (nothing in init lines).

marker...named (respawn_west).

Game logic...named (server).

In mission folder...

description.ext...

respawn = 3;

respawnDelay = 5;

respawnDialog = 1;

vehicle.sqf...

//Simple Vehicle Respawn Script v1.7

//by Tophe of Östgöta Ops [OOPS]

if (!isServer) exitWith {};

// Define variables

_unit = _this select 0;

_delay = if (count _this > 1) then {_this select 1} else {30};

_deserted = if (count _this > 2) then {_this select 2} else {120};

_respawns = if (count _this > 3) then {_this select 3} else {0};

_explode = if (count _this > 4) then {_this select 4} else {false};

_dynamic = if (count _this > 5) then {_this select 5} else {false};

_unitinit = if (count _this > 6) then {_this select 6} else {};

_haveinit = if (count _this > 6) then {true} else {false};

_hasname = false;

_unitname = vehicleVarName _unit;

if (isNil _unitname) then {_hasname = false;} else {_hasname = true;};

_noend = true;

_run = true;

_rounds = 0;

if (_delay < 0) then {_delay = 0};

if (_deserted < 0) then {_deserted = 0};

if (_respawns <= 0) then {_respawns= 0; _noend = true;};

if (_respawns > 0) then {_noend = false};

_dir = getDir _unit;

_position = getPosASL _unit;

_type = typeOf _unit;

_dead = false;

_nodelay = false;

// Start monitoring the vehicle

while {_run} do

{

sleep (2 + random 10);

if ((getDammage _unit > 0.8) and ({alive _x} count crew _unit == 0)) then {_dead = true};

// Check if the vehicle is deserted.

if (_deserted > 0) then

{

if ((getPosASL _unit distance _position > 10) and ({alive _x} count crew _unit == 0) and (getDammage _unit < 0.8)) then

{

_timeout = time + _deserted;

sleep 0.1;

waitUntil {_timeout < time or !alive _unit or {alive _x} count crew _unit > 0};

if ({alive _x} count crew _unit > 0) then {_dead = false};

if ({alive _x} count crew _unit == 0) then {_dead = true; _nodelay =true};

if !(alive _unit) then {_dead = true; _nodelay = false};

};

};

// Respawn vehicle

if (_dead) then

{

if (_nodelay) then {sleep 0.1; _nodelay = false;} else {sleep _delay;};

if (_dynamic) then {_position = getPosASL _unit; _dir = getDir _unit;};

if (_explode) then {_effect = "M_TOW_AT" createVehicle getPosASL _unit; _effect setPosASL getPosASL _unit;};

sleep 0.1;

deleteVehicle _unit;

sleep 2;

_unit = _type createVehicle _position;

_unit setPosASL _position;

_unit setDir _dir;

if (_haveinit) then

{_unit setVehicleInit format ["%1;", _unitinit];

processInitCommands;};

if (_hasname) then

{_unit setVehicleInit format ["%1 = this; this setVehicleVarName ""%1""",_unitname];

processInitCommands;};

_dead = false;

// Check respawn amount

if !(_noend) then {_rounds = _rounds + 1};

if ((_rounds == _respawns) and !(_noend)) then {_run = false;};

};

// Script by Galzohar -

player moveInCommander tank;

_aiCrew = (units group player) - [player];

(_aiCrew select 0) assignAsGunner tank;

(_aiCrew select 0) moveInGunner tank;

(_aiCrew select 1) assignAsDriver tank;

(_aiCrew select 1) moveInDriver tank;

(_aiCrew select 2) moveInTurret [tank, [0,1]]; //not sure if this is the correct turret path for loader, you'll have to check. Might be [0,1] instead of [1]!

{

_x setDammage 0;

} forEach _aiCrew;

};

not sure how to use respawn script you posted for reference??

tried it and nothing happened?? can you point me in the right direction

There is one other question.... if you would be so kind....

How do i use this say for five or six players?

I have seen this question of mine come up time and time again here and on other sites and have posted elsewhere without a single reply...you were the first person to help me...Thanks... and after searching (for over a month) and dowloading loads of stuff i never found what i wanted. So if you dont mind i will post this for other people to use on different sites with reference to you

for your part of the script?

You are most helpful...thank you for your time and effort.....musky:D

Share this post


Link to post
Share on other sites

The problem with the simple vehicle respawn script is that, well, the way it decides whether it's time to respawn the vehicle or not is quite funky. I really wouldn't use something like that in a mission that is supposed to be good. You really need to decide on your own conditions for respawn and use those with the waitUntil command.

To be honest with the time I spent trying to help you I could've just made it for you, but I don't actually know exactly what you're trying to do, since you didn't really lay down the rules you want to take place in a very clear manner.

In any case, you don't need to give me credit for a few lines that move and assign units to crew positions, those things are supposed to be common knowledge ;)

Edited by galzohar

Share this post


Link to post
Share on other sites
This will of course only work in multiplayer, single player does not have respawns and some tricky scripting is needed in order to make some kind of "respawn" in SP.

If the mission has no playable AI, then once you set respawn to base, just add an init.sqf file to your mission folder and in it write:

if (!isDedicated) then
{
player addEventHandler ["KILLED", "execVM 'respawn.sqf'];
};

And then create a file called respawn.sqf, and in it write:

waitUntil {alive player};
player moveInDriver respawnCart;

Where respawnCart is the name in the editor of the cart to which you want him to respawn. Of course if you want him to respawn into a different cart every time you will have to instead set a value for respawnCart to the relevant one. Since I don't know your mission I don't know how you want to choose which cart the player will respawn into.

Also, if you want him to respawn in cargo rather than in driver, use moveInCargo instead of moveInDriver.

I did not work, I want to do is when a player die, respawn inside the vehicle as driver

How can I do this?

Besides that if the vehicles are destroyed also appear again with the player inside, is possible?

players only.

Share this post


Link to post
Share on other sites
Sign in to follow this  

×