Jump to content
Sign in to follow this  
tophe

Simple Vehicle Respawn Script [Arma3]

Recommended Posts

Simple Vehicle Respawn Script v1.8 [Arma 3]

by Tophe of Östgöta Ops [OOPS]

SimpleVehicleRespawn.jpg

>> DOWNLOAD TAKEN DOWN WHILE FIXING SCRIPT <<

This script will respawn a vehicle when it is destroyed or left empty in the battlefield.

It will be respawned to the position where it first stood when the mission started.

Works with any vehicle.

Just put this in the vehicles init line:

veh = [this] execVM "vehicle.sqf"

Default settings are:

30 seconds respawn delay after destruction

120 seconds respawn delay after deserting a vehicle (leaving it empty after driving it).

Unlimited respawns

No special effect when respawning

Static respawn.

OPTIONS:

There are some optional settings. The format for these are:

veh = [this, Delay, Deserted timer, Respawns, Effect, Static, "INIT"] execVM "vehicle.sqf"

If you don't use any additional settings the default settings will be used, they look like this:

veh = [this, 30, 120, 0, FALSE, FALSE] execVM "vehicle.sqf"

Respawn Delay:

Default respawn delay is 30 seconds, to set a custom respawn delay time, put that in the init as well.

This one will respawn in 15 seconds:

veh = [this, 15] execVM "vehicle.sqf"

Deserted Vehicle Respawn:

Default respawn time when vehicle is deserted, but not destroyed is 120 seconds.

To set a custom timer for this first put the respawn delay, then the deserted vehicle timer.

The value 0 will disable the timer and the vehicle will not respawn when deserted.

This one will respawn in 15 seconds if destroy, and in 50 seconds if left empty in the field.

veh = [this, 15, 50] execVM "vehicle.sqf"

Respawn limit:

By default the number of respawns is unlimited. To set a limit, first set the other values

then the number of respawns you want (0 = infinite).

veh = [this, 15, 10, 5] execVM "vehicle.sqf"

Effect:

Set this value to TRUE to add a special explosion effect to the wreck when respawning.

Default value is FALSE, which will simply have the wreck disappear.

veh = [this, 15, 10, 5, TRUE] execVM "vehicle.sqf"

Dynamic Respawn:

By default the vehicle will respawn to the point where it first was when the mission started (static). This can be changed to dynamic.

Set it to TRUE to get the vehicle to respawn to the position where it was destroyed. FALSE makes it use the default static setting.

veh = [this, 15, 10, 5, FALSE, TRUE] execVM "vehicle.sqf"

INIT field:

If you you want to set the INIT field of the respawned vehicle, first set all other

values, then set init commands. Those must be inside quotations.

veh = [this, 15, 10, 5, TRUE, FALSE, "this setDammage 0.5"] execVM "vehicle.sqf"

if you need to use quotations in your init, use double. like this:

veh = [this, 15, 10, 5, TRUE, FALSE, "hey = [this] execVM ""loadout.sqf"""] execVM "vehicle.sqf"

Also, remember that you need to put your init outside the vehicles script as well if you want

it to run initially:

hey = [this] execVM "loadout.sqf"; veh = [this, 15, 10, 5, TRUE, FALSE, "hey = [this] execVM ""loadout.sqf"""] execVM "vehicle.sqf"

Change log:

v1.8

* Updated for Arma 3

v1.7

* Added function to disable deserted vehicle respawn.

v1.6

* Fixed serious bug introduced in v1.5, where respawn timer was disabled.

* The script will no longer try to reset the name of vehicles originally unnamed.

* Added check if deserted vehicle is destroyed.

v1.5

* Option to set the INIT of the respawned vehicle.

* Vehicle now respawns with original name.

v1.4

* Fixed some bad code that ended up in error codes. Script should be less heavy now. (thanks Xeno!)

* Fixed bug where a vehicle that moved by an explosion would trigger the deserted timer.

v1.3:

* Support added for vehicles placed on hangars (with setPosASL).

* Added optional respawn limit.

* Added optional respawn effect (explosion).

* Better damage checking. Now the vehicles shouldn't respawn when units are in them.

v1.2:

* Script now fully support any vehicle, including bícycles.

* Fixed positioning for vehicles close to other objects.

* Improved stability. The script runs much better with large amounts of vehicles.

v1.1:

* Rewrote most of the the script.

* Added respawn for vehicles left empty in the field. The delay can be set.

* Added dynamic respawn option. The vehicles can now be spawned where it was destroyed.

v1.0

* First release.

Future plans:

The dynamic setting is experimental. Works fine on land, but might cause trouble if a vehicle

crashes into water. This will be fixed in a future version.

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

Edited by Tophe

Share this post


Link to post
Share on other sites

I'm fairly new to making my own missions so I apologize if this is a noob mistake but I downloaded the script, put it in the missions folder and set the init field for a helicopter but it won't let me get in as pilot but will let me access the gear. I'm also using a crate filling script that is working fine so I figure I'm not doing something right. This is what I've done, step by step.

1) Created a player

2) Created an empty helicopter

3) Set the init field to read: veh = [this] execVM "vehicle.sqf"

4) Created a weapons crate

5) Applied the init field for that script

6) Save and hit preview

Any idea's?

Share this post


Link to post
Share on other sites
I'm fairly new to making my own missions so I apologize if this is a noob mistake but I downloaded the script, put it in the missions folder and set the init field for a helicopter but it won't let me get in as pilot but will let me access the gear. I'm also using a crate filling script that is working fine so I figure I'm not doing something right. This is what I've done, step by step.

1) Created a player

2) Created an empty helicopter

3) Set the init field to read: veh = [this] execVM "vehicle.sqf"

4) Created a weapons crate

5) Applied the init field for that script

6) Save and hit preview

Any idea's?

Set the heli to empty and as non playable. Select non playable option first to open the empty option.

I almost forgot. Great script Tophe thank you.:bounce3::bounce3:

Edited by xx-LSD-xx

Share this post


Link to post
Share on other sites
Set the heli to empty and as non playable. Select non playable option first to open the empty option.

That's how I have it now.

---------- Post added at 20:21 ---------- Previous post was at 20:11 ----------

Ok, I think I got it. I went in and changed them to not being in formation and set it to "unlocked" instead of "default" and now I can hop in.

Thanks for the help guys.

Share this post


Link to post
Share on other sites

@HughMadBro

You have it like this?

Side = Empty?

Faction = Blank?

Class = Air?

Unit = Ah9?

Special = None or Formation?

Control = Non playable?

Vehicle lock = default?

Name = Whatever I have ch1?

I just did that to check and it works for me.

Share this post


Link to post
Share on other sites

That's exactly how I had it (except for the name, I'm not that experienced enough to even know why I should name things) and I couldn't enter it. I changed formation to none and vehicle lock to unlocked and now I can get in. Not sure why but it works now .

Share this post


Link to post
Share on other sites

Hey guys, currently working on "ARMEX3", practically the ARMA 3 version of ARMEX. Not many vehicles, tried using this script, it just says that script is missing, to make sure I am installing it right, can you explain it to me?

Share this post


Link to post
Share on other sites

Thanks for the update :) Used 1.7 for a few days, was working aswel(as far i could see).

Share this post


Link to post
Share on other sites
Thanks for the update :) Used 1.7 for a few days, was working aswel(as far i could see).

Yeah, works for the most part, but some options call for stuff with new classnames A3. So that's fixed now.

Hey guys, currently working on "ARMEX3", practically the ARMA 3 version of ARMEX. Not many vehicles, tried using this script, it just says that script is missing, to make sure I am installing it right, can you explain it to me?

Make sure you put it in the root folder of your mission. If you don't know how to do that, search the forum for some mission editing and scripting tutorials.

Share this post


Link to post
Share on other sites

Hey, guys. I'm pretty lame in scripts. But I'm making Machinimas and as you can see - Arma 3 is the best place for that.

So I need somekind of the timer for the first spawn for 2 cars. I searched some forums and google and didn't find it...may be I really bad in searching...but...anyway.

I hope for your help.

Have a nice day.

Ivan Seelnon.

Share this post


Link to post
Share on other sites

I'm sorry about asking this newbish question, but I have been looking all over for a simple scripting tutorial. I've been trying to install your vehicle respawn script, and I have no clue where to put it. I'm not sure if what you meant by 'root mission folder' was this: C:\Users\Username\Documents\Arma 3 Alpha - Other Profiles\Username\missions\MissionName

I've been trying to get this problem solved all day, can you explain to me where exactly to put it and i will be good to go. Thanks for your help.

Share this post


Link to post
Share on other sites

For general mission editing/ scripting questions - not specifically about this script - please start a new thread or search the forums.

  • More people will be able to help help you.
  • More people will be able to benefit from the answers of your questions.
  • This thread will be kept relevant to what it is actually about.

Share this post


Link to post
Share on other sites

Ah nice one Tophe - that was next on my list to reproduce your last A2 version - thanks dude -

Share this post


Link to post
Share on other sites

There's a silly error in version 1.8. If you have effects turned on there will be a hint that says "dude" when the vehicle respawns. It's a debug artifact. I just submitted 1.81 - but for those of you that knows a bit about scripting - just remove the hint from the code.

Share this post


Link to post
Share on other sites

On top of respawning vehicles, is it possible to respawn vehicles with items,clothing and weapons in them?

Share this post


Link to post
Share on other sites

Sure, just add the loadout to the init parameter. And don't forget to add it outside the respawn script call, otherwise it will only apply after the vehicle has been respawned.

Share this post


Link to post
Share on other sites

tophe i changed code to spawn a unit instead of vehicle but when unit spawns it should retain its name which will then respawn unit into the helis driver seat any suggestions?

Share this post


Link to post
Share on other sites

Then you're looking for something else than this script. This script will give the vehicle it's old name. But you'll probably need to fiddle with the moveInDriver command. Look into that.

Share this post


Link to post
Share on other sites

right im very close to making it so ai spawns and enters the heli, but some strange reason the ai spawns as if hes sitting in heli but it pops him out and he slides down front of chopper. I'm guessing i need to change or add summit to the vehicle spawn script which by the way is amazing.

in the ai pilots init feild ive put assignasdriver and then moveindriver any thoughts.

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;

// 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_AT" createUnit  getPosASL _unit; 
		_effect setPosASL getPosASL _unit; 
		hint "dude";
	};
	sleep 0.1;

	deleteUnit _unit;
	sleep 2;
	_unit = _type createUnit  _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;
	};
};
};

Edited by curtcooll

Share this post


Link to post
Share on other sites
Sure, just add the loadout to the init parameter. And don't forget to add it outside the respawn script call, otherwise it will only apply after the vehicle has been respawned.

Ok so I came up with this code

//vehicleloadout.sqf//

_numbag = 2;
_numammo = 16;
_numweapon = 2;
_vcl = vehicle;


if(_vcl iskindof "car" && iskindof "HnunterGMG") then

{

_this addWeaponCargo ["arifle_MX_F", _numWeapon];

_this addMagazineCargo ["30Rnd_65x39_caseless_green", _numAmmo];

_this addBackpackCargo ["B_AssaultPack_Base", _numBag];

};

Now I know the "HunterGMG" is wrong. I probably should put the class name but I do not have that yet. Im using that to give mission makers the ability to give specific items in specific vehicles.

So this is what would go in the vehicle init.


veh = [this, 15, 10, 5, TRUE, FALSE, "veh = [this] execVM ""vehicleloadout.sqf"""] execVM "vehicle.sqf"

Can someone over look this. I have not actually tested this but Im sure there are some syntax errors.

Thanks.

Edited by BloodxGusher

Share this post


Link to post
Share on other sites
Ok so I came up with this code

//vehicleloadout.sqf//

_numbag = 2;
_numammo = 16;
_numweapon = 2;
_vcl = vehicle;


if(_vcl iskindof "car" && iskindof "HnunterGMG") then

{

_this addWeaponCargo ["arifle_MX_F", _numWeapon];

_this addMagazineCargo ["30Rnd_65x39_caseless_green", _numAmmo];

_this addBackpackCargo ["B_AssaultPack_Base", _numBag];

};

Now I know the "HunterGMG" is wrong. I probably should put the class name but I do not have that yet. Im using that to give mission makers the ability to give specific items in specific vehicles.

So this is what would go in the vehicle init.


veh = [this, 15, 10, 5, TRUE, FALSE, "veh = [this] execVM ""vehicleloadout.sqf"""] execVM "vehicle.sqf"

Can someone over look this. I have not actually tested this but Im sure there are some syntax errors.

Thanks.

Yes, that looks just about right!

---------- Post added at 07:39 AM ---------- Previous post was at 06:23 AM ----------

Or rather.. choose another handle for the loadout script than "veh". Like this:

veh = [this, 15, 10, 5, TRUE, FALSE, "dude = [this] execVM ""vehicleloadout.sqf"""] execVM "vehicle.sqf"

Share this post


Link to post
Share on other sites

Yes, that looks just about right!

---------- Post added at 07:39 AM ---------- Previous post was at 06:23 AM ----------

Or rather.. choose another handle for the loadout script than "veh". Like this:

Code:
veh = [this, 15, 10, 5, TRUE, FALSE, "dude = [this] execVM ""vehicleloadout.sqf"""] execVM "vehicle.sqf"

Ya that seems to not be firing for me. I think I need the classname of the Hunter. I will attain that and report back.

Share this post


Link to post
Share on other sites

Yes. You need the correct classnames. Make sure you get the loadout script working before you try to run it from the respawn script.

Share this post


Link to post
Share on other sites

So, i looked through your code, and tried to write a similair script (for learning purpose :) ). It's working, though sometimes the vehicles spawns like 2 m from where they were actually standing. Do you have this problem, Tophe?

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  

×