Jump to content

Photo
- - - - -

Simple Vehicle Respawn Script [Arma3]


  • Please log in to reply
187 replies to this topic

#1 Tophe

Tophe

    Master Gunnery Sergeant

  • Members
  • 1041 posts

Posted 06 March 2013 - 08:25 PM

Simple Vehicle Respawn Script v1.8 [Arma 3]
by Tophe of Östgöta Ops [OOPS]

Posted Image

>> 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, 13 July 2013 - 02:13 PM.


#2 chrizzo

chrizzo

    Private First Class

  • Members
  • 39 posts

Posted 06 March 2013 - 08:37 PM

thanks :)

#3 HughMadBro

HughMadBro

    Rookie

  • Members
  • 6 posts

Posted 07 March 2013 - 07:59 PM

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?

#4 xx-LSD-xx

xx-LSD-xx

    Sergeant

  • Members
  • 144 posts

Posted 07 March 2013 - 08:09 PM

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, 07 March 2013 - 08:12 PM.


#5 HughMadBro

HughMadBro

    Rookie

  • Members
  • 6 posts

Posted 07 March 2013 - 08:21 PM

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.

#6 xx-LSD-xx

xx-LSD-xx

    Sergeant

  • Members
  • 144 posts

Posted 07 March 2013 - 08:25 PM

@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.

#7 HughMadBro

HughMadBro

    Rookie

  • Members
  • 6 posts

Posted 07 March 2013 - 08:37 PM

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 .

#8 Xotodazo

Xotodazo

    Private First Class

  • Members
  • 26 posts

Posted 08 March 2013 - 09:09 AM

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?

#9 m0nkm0nk

m0nkm0nk

    Sergeant

  • Members
  • 104 posts

Posted 08 March 2013 - 09:38 AM

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

#10 Tophe

Tophe

    Master Gunnery Sergeant

  • Members
  • 1041 posts

Posted 08 March 2013 - 12:36 PM

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.

#11 seelnon

seelnon

    Newbie

  • Members
  • 1 posts

Posted 08 March 2013 - 02:09 PM

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.

#12 LieutenantLZ

LieutenantLZ

    Rookie

  • Members
  • 5 posts

Posted 11 March 2013 - 02:50 AM

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.

#13 Tophe

Tophe

    Master Gunnery Sergeant

  • Members
  • 1041 posts

Posted 11 March 2013 - 02:17 PM

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.


#14 Mikie boy

Mikie boy

    Master Sergeant

  • Members
  • 660 posts

Posted 11 March 2013 - 03:55 PM

Ah nice one Tophe - that was next on my list to reproduce your last A2 version - thanks dude -
[FOCK] Mikie J -
Giving bad advice since 2009 :)

Looking for New Players/scripters at Fockersteam
http://fockers.moonfruit.com/
Email: fockersteam@hotmail.co.uk

A3
3 Chapters of Scripting Tutotials -http://www.armaholic...=20465#comments MORE TO FOLLOW
TvTCache Hunt - [FOCK]ers Cache Hunt TvT-x [ALPHA]
Fock Recruit/Group Management - http://www.armaholic...ge.php?id=19041

Currently NOT ACTIVE- Awaiting completion of MSc Computer Science - will return soon....

#15 Tophe

Tophe

    Master Gunnery Sergeant

  • Members
  • 1041 posts

Posted 12 March 2013 - 07:24 PM

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.

#16 BloodxGusher

BloodxGusher

    Staff Sergeant

  • Members
  • 201 posts

Posted 12 March 2013 - 10:27 PM

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

#17 Tophe

Tophe

    Master Gunnery Sergeant

  • Members
  • 1041 posts

Posted 12 March 2013 - 10:59 PM

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.

#18 curtcooll

curtcooll

    Sergeant

  • Members
  • 141 posts

Posted 12 March 2013 - 11:19 PM

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?

#19 Tophe

Tophe

    Master Gunnery Sergeant

  • Members
  • 1041 posts

Posted 12 March 2013 - 11:23 PM

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.

#20 curtcooll

curtcooll

    Sergeant

  • Members
  • 141 posts

Posted 12 March 2013 - 11:27 PM

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, 13 March 2013 - 12:05 AM.