Jump to content
Sign in to follow this  
tophe

Simple Vehicle Respawn Script [Arma3]

Recommended Posts

Hi, I am having problems with my vehicle re-spawn scripts since the latest main patch and I hope someone here can help me.

All scripts I have tried are either just spawning vehicles when the original is still alive so any left in the original position are destroyed, or they are just not re-spawning.

Had anyone else had these issues since the patch this week?

Share this post


Link to post
Share on other sites

Mariodu62 code:

_getout =_unit addeventhandler [ 
		"getout",
			{
				_this spawn {
					private "_veh";
					_veh = _this select 0;
					if (count crew _veh == 0) then {
					sleep 10;
					_veh setdamage 1;
					};
				};
			}
		];

@Mariodu62 - I was just browsing, looking at some of the different Tophe's vehicle respawn variants. Anyhow, what if a crew person gets right back into the vehicle after he's gotten out (within the 10 seconds) ?

Edited by Iceman77

Share this post


Link to post
Share on other sites

this event is for our mission, and it's for the last respawn. All "free" vehicle are only to go to fight.

if the player gets right back before the sleep time , nothing will happen because the vehicle is not empty.

the new code is :

 if (count crew _veh == 0) then {
 sleep 120;
  if (count crew _veh == 0) then {_veh setdamage 1;};
  };

Maybe kiddy code but its working fine

Share this post


Link to post
Share on other sites
In fact if you want to do like this you must change _haveinit to true...

in this case _haveinit is false because you don't send 6 arguments.

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

Hi Mariodu62, sorry to answer so late, i was really buisy thoses month.

So i follow your orders but no way to put an init in the respawned vehicle. That's what i have now :

_unit = _this select 0;

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

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

_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 = clearweaponcargo this; clearmagazinecargo this; clearitemcargo this;

_haveinit = true;

Someone know how to put an init in the script ?

Thanks so much

Share this post


Link to post
Share on other sites

this is my current init of my unit:

null=[this] execVM "IgiLoad\IgiLoad.sqf";veh = [this, 60, 300, 0, FALSE, FALSE,"null=[this] execVM ""IgiLoad\IgiLoad.sqf"" nul = [this,""C9"",0.5] execVM ""mark_unit.sqf"""] execVM "vehicle.sqf";

the init of the vehicle are not being put on the vehicle on respawn. please help!

Share this post


Link to post
Share on other sites
I see lots of people asking about this script and when will it be fixed. well, it's been fixed for some time actually its just posted in the much earlier pages. the only thing in the script that needed updating was the "setvihicleinit" command stuff. I have always used this excellent script and it works far better then the one BIS has in game. here is a copy of the full script with the update so the init option can be used again.

/*  
=========================================================
 Simple Vehicle Respawn Script v1.7
 by Tophe of Östgöta Ops [OOPS]

 Put this in the vehicles init line:
 veh = [this] execVM "veh_respawn.sqf"


 Options:
 There are some optional settings. The format for these are:
 veh = [this, Delay, Deserted timer, Respawns, Effect, Static] execVM "veh_respawn.sqf"


 Default respawn delay is 30 seconds, to set a custom
 respawn delay time, put that in the init as well. 
 Like this:
 veh = [this, 15] execVM "veh_respawn.sqf"

 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. (0 = disabled)
 Like this:  
 veh = [this, 15, 10] execVM "veh_respawn.sqf"

 By default the number of respawns is infinite. To set a limit
 First set the other values then the number of respawns you want (0 = infinite).
 Like this:
 veh = [this, 15, 10, 5] execVM "veh_respawn.sqf"

 By default the vehicle will respawn to the point where it first
 was when the mission started (static). This can be changed to 
 dynamic. Then the vehicle will respawn to the position where it was destroyed. 
 First set all the other values then set TRUE for dynamic or FALSE for static.
 Like this:
 veh = [this, 15, 10, 5, TRUE] execVM "veh_respawn.sqf"

 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.
 Like this:
 veh = [this, 15, 10, 5, TRUE, "_this setDammage 0.5"] execVM "veh_respawn.sqf"

 Default values of all settings are:
 veh = [this, 30, 120, 0, FALSE] execVM "veh_respawn.sqf"

Contact & Bugreport: harlechin@hotmail.com
=========================================================
Updated for arma 3   -   replaces (setvehicleinit)

NOTES:
(init) and (name)  will only work correctly in MP / these do not work as expected in single player.

when using custom (init) for vehicle to respawn with, note the example above - (this) should now be (_this) otherwise it will error in MP.

explosion effect removed: because in arma 3 it created a missle that flew across map that impacts vehicle to cause exploision.
=========================================================
*/

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};
_dynamic = if (count _this > 4) then {_this select 4} else {false};
_unitinit = if (count _this > 5) then {_this select 5} else {};
_haveinit = if (count _this > 5) 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;


fnc_setVehicleInit = {
       private ["_netID","_unit","_unitinit"];

       _netID = _this select 0;
       _unit = objectFromNetID _netID;
       _unitinit = _this select 1;

       _unit call compile format ["%1",_unitinit];
};


fnc_setVehicleVarName = {
       private ["_netID","_unit","_unitname"];

       _netID = _this select 0;
       _unit = objectFromNetID _netID;
       _unitname = _this select 1;

       _unit setVehicleVarName _unitname;
       _unit call compile format ["%1=_This; PublicVariable ""%1""",_unitname];
};


// 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;};
	sleep 0.1;

	deleteVehicle _unit;
	sleep 2;
	_unit = _type createVehicle _position;
	_unit setPosASL _position;
	_unit setDir _dir;

	if (_haveinit) then {[[netID _unit, _unitinit], "fnc_setVehicleInit", true, true] spawn BIS_fnc_MP;};

	if (_hasname) then {[[netID _unit, _unitname], "fnc_setVehicleVarName", true, true] spawn BIS_fnc_MP;};

	_dead = false;

	// Check respawn amount
	if !(_noend) then {_rounds = _rounds + 1};
	if ((_rounds == _respawns) and !(_noend)) then {_run = false;};
};
};

and thank you very much Tophe for this great script of yours.

For anyone wondering what the current build of this script is for Arma 3, the above quoted is it, it works beautifully and is exactly what i needed. Thanks Tophe for the original script and thanks Nimrod for reposting the updated one!

However, i couldnt get one thing to work after countless tweaking and trying different things, i couldnt get my custom loadout to respawn with the vehicle, or more precisely, i couldnt get the respawned vehicle to use the custom loadout (secondary sqf file, the primary sqf being the respawn script). Custom loadout shows up at the begining of the mission but subsequent respawns are just the default loadout.

Still learning about scripting so i'm assuming my syntax might be off or i'm missing something here, any help would be greatly appreciated!

Here is my current code:

Vehicle init:

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

Respawn sqf (vehicle.sqf):

/*

=========================================================

Simple Vehicle Respawn Script v1.7

by Tophe of Östgöta Ops [OOPS]

Put this in the vehicles init line:

veh = [this] execVM "veh_respawn.sqf"

Options:

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

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

Default respawn delay is 30 seconds, to set a custom

respawn delay time, put that in the init as well.

Like this:

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

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. (0 = disabled)

Like this:

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

By default the number of respawns is infinite. To set a limit

First set the other values then the number of respawns you want (0 = infinite).

Like this:

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

By default the vehicle will respawn to the point where it first

was when the mission started (static). This can be changed to

dynamic. Then the vehicle will respawn to the position where it was destroyed.

First set all the other values then set TRUE for dynamic or FALSE for static.

Like this:

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

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.

Like this:

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

Default values of all settings are:

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

Contact & Bugreport: harlechin@hotmail.com

=========================================================

Updated for arma 3 - replaces (setvehicleinit)

NOTES:

(init) and (name) will only work correctly in MP / these do not work as expected in single player.

when using custom (init) for vehicle to respawn with, note the example above - (this) should now be (_this) otherwise it will error in MP.

explosion effect removed: because in arma 3 it created a missle that flew across map that impacts vehicle to cause exploision.

=========================================================

*/

if (!isServer) exitWith {};

nul = [_this] execVM "loadout.sqf";

// 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};

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

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

_haveinit = if (count _this > 5) 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;

fnc_setVehicleInit = {

private ["_netID","_unit","_unitinit"];

_netID = _this select 0;

_unit = objectFromNetID _netID;

_unitinit = _this select 1;

_unit call compile format ["%1",_unitinit];

};

fnc_setVehicleVarName = {

private ["_netID","_unit","_unitname"];

_netID = _this select 0;

_unit = objectFromNetID _netID;

_unitname = _this select 1;

_unit setVehicleVarName _unitname;

_unit call compile format ["%1=_This; PublicVariable ""%1""",_unitname];

};

// 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;};

sleep 0.1;

deleteVehicle _unit;

sleep 2;

_unit = _type createVehicle _position;

_unit setPosASL _position;

_unit setDir _dir;

if (_haveinit) then {[[netID _unit, _unitinit], "fnc_setVehicleInit", true, true] spawn BIS_fnc_MP;};

if (_hasname) then {[[netID _unit, _unitname], "fnc_setVehicleVarName", true, true] spawn BIS_fnc_MP;};

_dead = false;

// Check respawn amount

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

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

};

};

As you might have noticed i even put an extra line in the vehicle.sqf (respawn script) to try and get it to load the custom loadout with no luck. Thanks in advance for any help you might be able to offer on this!

Zulu

Share this post


Link to post
Share on other sites
this is my current init of my unit:

null=[this] execVM "IgiLoad\IgiLoad.sqf";veh = [this, 60, 300, 0, FALSE, FALSE,"null=[this] execVM ""IgiLoad\IgiLoad.sqf"" nul = [this,""C9"",0.5] execVM ""mark_unit.sqf"""] execVM "vehicle.sqf";

the init of the vehicle are not being put on the vehicle on respawn. please help!

This is exactly the same issue as i'm having.

Share this post


Link to post
Share on other sites

I have put the script in the mission folder but when i try to start it as a multiplayer mission it says "can´t find vehicle.sqf". The strange thing is it worked before but i tried to implement EOS (Enemy Occupation System) and failed. So i deleted all EOS files. But all Respawn files are still in the folder and i have no idea where the issue is. :(

Share this post


Link to post
Share on other sites

Quick Question: I have tried virtually everything

veh = [this, 2, 120, 5, FALSE, FALSE,"this addMagazine ""2000Rnd_65x39_Belt_Tracer_Green"";this addWeapon ""LMG_Minigun"";"] execVM "vehicle.sqf"

Anyone know how I would make this work?

Share this post


Link to post
Share on other sites

try using instead _unit

veh = [this, 2, 120, 5, FALSE, FALSE,"_unit addMagazine ""2000Rnd_65x39_Belt_Tracer_Green"";_unit addWeapon ""LMG_Minigun"";"] execVM "vehicle.sqf"

or maybe

veh = [this, 2, 120, 5, FALSE, FALSE,"(_this select 0) addMagazine ""2000Rnd_65x39_Belt_Tracer_Green"";(_this select 0) addWeapon ""LMG_Minigun"";"] execVM "vehicle.sqf"

or

veh = [this, 2, 120, 5, FALSE, FALSE,"_this addMagazine ""2000Rnd_65x39_Belt_Tracer_Green"";_this addWeapon ""LMG_Minigun"";"] execVM "vehicle.sqf"

Share this post


Link to post
Share on other sites

Thanks for the quick response.

Tried all three. None work. T_T

Went so far as to duplicate vehicle.sqf,

Rewrite

_haveinit = {true};

_unitinit = {"this addMagazine ""2000Rnd_65x39_Belt_Tracer_Green"";this addWeapon ""LMG_Minigun"";"};

Nothing.

Tried

[{_unit addMagazine "2000Rnd_65x39_Belt_Tracer_Green";_unit addWeapon "LMG_Minigun";}, "BIS_fnc_spawn", true, true] spawn BIS_fnc_MP;

[{"this addMagazine ""2000Rnd_65x39_Belt_Tracer_Green"";this addWeapon ""LMG_Minigun"";"}, "BIS_fnc_spawn", true, true] spawn BIS_fnc_MP;

I am, as always with any form of arma 3 modding, frustrated, and recognize that the hours wasted trying to understand this god forsaken scripting system created by satan's anus is not ever worth the effort.

Edited by noguns

Share this post


Link to post
Share on other sites

The up-to-date version of Tophe's Simple Vehicle Respawn Script is v1.81. However, this script has been temporarily withdrawn.

See Here Simple Vehicle Respawn Script by Tophe of Östgöta Ops v1.81

Note the comment. This script does no longer work in Arma 3! At some point the author will release an updated version.

Try this one instead.

Light-Vehicle-Respawn-Script By iceman77

See the "Not so light" version of the script that supports a vehicle init.

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  

×