Jump to content
Sign in to follow this  
tophe

Simple Vehicle Respawn Script [Arma3]

Recommended Posts

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?

Nice to hear! You probably need to setPos the vehicle at the position after creating it. createVehicle is usually not that accurate.

Share this post


Link to post
Share on other sites
Nice to hear! You probably need to setPos the vehicle at the position after creating it. createVehicle is usually not that accurate.

Thank you! It seems to work :)

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.

So I got my hands on the classname for teh hunter and my code now looks like this.


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


if(_vcl iskindof "B_Hunter_F") then

{

_this addWeaponCargo ["arifle_MX_F", _numWeapon];

_this addMagazineCargo ["30Rnd_65x39_caseless_green", _numAmmo];

_this addBackpackCargo ["B_AssaultPack_Base", _numBag];

};

This is not firing at all.

Could it be the pre-loaded items that come with all vehicles in game?

Could it be the something in the init field not spelled correctly? Here is the code i have there

veh = [this, 180, 900, FALSE, FALSE, "veh = [this] execVM ""vehicleloadout.sqf"""] execVM "vehicle.sqf"

If someone could review this for me that would be great.

Share this post


Link to post
Share on other sites
So I got my hands on the classname for teh hunter and my code now looks like this.


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


if(_vcl iskindof "B_Hunter_F") then

{

_this addWeaponCargo ["arifle_MX_F", _numWeapon];

_this addMagazineCargo ["30Rnd_65x39_caseless_green", _numAmmo];

_this addBackpackCargo ["B_AssaultPack_Base", _numBag];

};

This is not firing at all.

Could it be the pre-loaded items that come with all vehicles in game?

Could it be the something in the init field not spelled correctly? Here is the code i have there

veh = [this, 180, 900, FALSE, FALSE, "veh = [this] execVM ""vehicleloadout.sqf"""] execVM "vehicle.sqf"

If someone could review this for me that would be great.

As I mentioned in an earlier answer - don't use the same handle for the two scripts... It might mess stuff up (I think).

So use dude = [this] execVM "vehicleloadout.sqf" or something instead.

Have you made sure that your loadou tscript works without the respawn script? By just running this: dude = [this] execVM "vehicleloadout.sqf" in the init field?

Also maybe try and clean up the code a bit like this:

_numbag = 2;
_numammo = 16;
_numweapon = 2;
[b][i]_vcl = _this select 0;[/i][/b]


if(_vcl iskindof "B_Hunter_F") then

{

[b][i]_vcl [/i][/b]addWeaponCargo ["arifle_MX_F", _numWeapon];

[b][i]_vcl [/i][/b]addMagazineCargo ["30Rnd_65x39_caseless_green", _numAmmo];

[b][i]_vcl [/i][/b]addBackpackCargo ["B_AssaultPack_Base", _numBag];

};

Edited by Tophe

Share this post


Link to post
Share on other sites
As I mentioned in an earlier answer - don't use the same handle for the two scripts... It might mess stuff up (I think).

So use dude = [this] execVM "vehicleloadout.sqf" or something instead.

Have you made sure that your loadou tscript works without the respawn script? By just running this: dude = [this] execVM "vehicleloadout.sqf" in the init field?

Also maybe try and clean up the code a bit like this:

_numbag = 2;
_numammo = 16;
_numweapon = 2;
[b][i]_vcl = _this select 0;[/i][/b]


if(_vcl iskindof "B_Hunter_F") then

{

[b][i]_vcl [/i][/b]addWeaponCargo ["arifle_MX_F", _numWeapon];

[b][i]_vcl [/i][/b]addMagazineCargo ["30Rnd_65x39_caseless_green", _numAmmo];

[b][i]_vcl [/i][/b]addBackpackCargo ["B_AssaultPack_Base", _numBag];

};

Ah ok. Ya I tried "dude" earlier but also was not firing. would I have to actually change the name of the vehicle to dude?

I am retesting all of this now so I will update in a sec.

Share this post


Link to post
Share on other sites

No. It's just the handle for the instance of the script. You rarely use it.

But have you tried getting your loadout script to work without the respawn script?

Share this post


Link to post
Share on other sites
No. It's just the handle for the instance of the script. You rarely use it.

But have you tried getting your loadout script to work without the respawn script?

No I haven't.

i removed what ever other lines of code I had in my vehicles init field and use the line you suggested.

dude = [this] execVM "vehicleloadout.sqf"

with no luck on that.

Share this post


Link to post
Share on other sites

Ok, then I suggest you work on your loadout script first. Perhaps start a new thread about it so more people can help - then get back here if you get problems related to the vehicle respawn script.

Share this post


Link to post
Share on other sites

does this re spawn work for putting in AI units back in the manned faction vehicles as im having issue with empty vehicles being shown as enemy vehicles.

Share this post


Link to post
Share on other sites
does this re spawn work for putting in AI units back in the manned faction vehicles as im having issue with empty vehicles being shown as enemy vehicles.

No, this script will not respawn AI units.The AI units are not part of the vehicle - you would need to spawn them separately and move them into the vechicle.

Share this post


Link to post
Share on other sites

ok so there no way for me to spawn a faction vehicle without ai already in there thats issue im having cant use empty vehicle coz it classes it as a enemy showing up with red dot instead of green.

thanks

Edited by curtcooll

Share this post


Link to post
Share on other sites

What ^.

Anyway wonderful script. I used the old script from A2 in my A3 mish and it seemed to work just as well with the old one. But I am glad you decided to optimize it further for A3. :)

Share this post


Link to post
Share on other sites

Anyone able to get AI units to rep sawn with the vehicle instead of spawning empty vehicle.

Share this post


Link to post
Share on other sites
Anyone able to get AI units to rep sawn with the vehicle instead of spawning empty vehicle.

As mentioned above - this script doesn't do that. You will have to create AI units and move them into the vehicle.

You can not just have them respawn with the vehicle - they are not part of the vehicle. It is not certain that they are dead just because the vehicle is damaged or left in the field.

Share this post


Link to post
Share on other sites

Is it possible to use this script but have the vehicle respawn at a marker on map rather than where it was originally placed or destroyed?

Share this post


Link to post
Share on other sites

Absolutely... But you'd have to edit it a bit. Just edit the script to get it to Setpos the vehicle at the getmarkerpos of the marker you want.

Share this post


Link to post
Share on other sites
Absolutely... But you'd have to edit it a bit. Just edit the script to get it to Setpos the vehicle at the getmarkerpos of the marker you want.

I am very much a novice when it comes to scripting. I can manage usually to figure out simple things, but I am at a loss as to what exactly needs to be changed and added. All attempts so far have made the script not respawn anything at all rather than respawning at my marker "vw1" upon testing.

Any help with getting this to function would be much appreciated, as it goes well beyond my knowledge.

Update: I seemed to have figured it out.

After fiddling around with the _position = setPosASL _unit; section I managed to get the vehicle to respawn at the marker, but it kept disappearing (underground I assume). I had to change setPosASL to setPosATL for _unit setPosASL _position;.

_position = setPosASL _unit

_unit setPosASL _position

Changed to

_position = getMarkerPos "vw1";

_unit setPosATL _position;

Only issue I have now is when I move said marker "vw1" with a trigger

"vw1" setMarkerPos getMarkerPos "vw2";

The marker moves but vehicle still spawns at original marker position. I am not sure if I need to change more of your script to fix this or if I am just missing something else.

Edited by oOAzraelOo

Share this post


Link to post
Share on other sites
Script broken by latest update. :butbut: ArmA3 now no longer supports setVehicleInit, clearVehicleInit, processInitCommands

See Development-branch-changelog

Discussion Help-on-script-after-removal-of-processInitCommands

Thanks for the heads up! I will look into it when I have time! If anyone else solves this with my script - please let me know here and I'll put that in the next release (with appropriate credit of course!)

Share this post


Link to post
Share on other sites

--- UPDATE ---

Given the post below, I've removed my suggestion so as not to cause confusion.

Edited by Beerkan

Share this post


Link to post
Share on other sites

OK come across this on Armoholic and it works NOT my code it is was made BY "Naong "

/////////////////////////////////////
//  Simple Vehicle Respawn Script v1.81 for Arma 3
//  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;

/////////////////////////////////////
// Added by naong
if (isNil "FNC_setVehicleInit") then {
FNC_setVehicleInit = {
	private ["_netID","_unit","_unitinit"];

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

	_unit call compile format ["%1",_unitinit];
};
};
if (isNil "FNC_setVehicleVarName") then {
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;};
	if (_explode) then {_effect = "M_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;

	// Modified by naong
	if (_haveinit) then {
		//_unit setVehicleInit format ["%1;", _unitinit];
		//processInitCommands;

		[[netID _unit, _unitinit], "FNC_setVehicleInit", true, true] spawn BIS_fnc_MP;
	};
	if (_hasname) then {
		//_unit setVehicleInit format ["%1 = this; this setVehicleVarName ""%1""",_unitname];
		//processInitCommands;

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

Edited by psvialli
error in code

Share this post


Link to post
Share on other sites

Can confirm psvialli's script works. Good job, mate.

Share this post


Link to post
Share on other sites

I copy the coding from psvialli post, and found that it had issue with _unitinit in relationship to setvehicleinit function. I tried to get a screenshot of it, but no luck, it just kept taking screenshots of my window screen and not Arma 3.

Share this post


Link to post
Share on other sites

Basically, you need to make sure you are not using the last parameter with the disabled code posted above:

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

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  

×