Jump to content
Sign in to follow this  
tophe

Simple Vehicle Respawn Script [Arma3]

Recommended Posts

The same functionality has been added in game as a module now, tried that?

I cant make it respawn when I get killed. Anything I should keep in mind or do you have a tutorial?

Share this post


Link to post
Share on other sites

Are you synching the VehicleRespawn module with an empty vehicle?

Share this post


Link to post
Share on other sites

I just tried that module for the first time on a dedicated server with somebody else, and it was sometimes respawning the same vehicle twice at once. Has anybody else had this happen? Also I read there was a problem with vehicles not spawning on the exact position they were originally but they had fixed it, but that still happens.

Share this post


Link to post
Share on other sites
I just tried that module for the first time on a dedicated server with somebody else, and it was sometimes respawning the same vehicle twice at once. Has anybody else had this happen? Also I read there was a problem with vehicles not spawning on the exact position they were originally but they had fixed it, but that still happens.

That probably means you've placed 2 of the same vehicle in the same place on editor by accident. Check on the editor to see if this is what is happening.

Share this post


Link to post
Share on other sites

I have a small problem. If the UAV -for instance MQ4A Greyhawk (NATO) is respawned by a script that you cant connnect to it. (Missing Side and Faction ?). Does anyone know how to fix this problem.

Edited by Cpl.Hicks

Share this post


Link to post
Share on other sites

The problem with UAVs resolved. There was no crew. You can use the UAV after spawn.

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;
//--------------------edited by [JSO]Hicks-----------------------
_grupa = group _unit;
_hasgroup = false;
If (str(_grupa) == "<NULL-group>") then {_hasgroup = false;} else {_hasgroup = true;};
//-------------------end editing by Hicks------------------------
_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;

// Kronzky's code
KRON_StrToArray = {
   private["_in","_i","_arr","_out"];
   _in=_this select 0;
   _arr = toArray(_in);
   _out=[];
   for "_i" from 0 to (count _arr)-1 do {
       _out=_out+[toString([_arr select _i])];
   };
   _out
};

KRON_StrLen = {
   private["_in","_arr","_len"];
   _in=_this select 0;
   _arr=[_in] call KRON_StrToArray;
   _len=count (_arr);
   _len
};

KRON_Replace = {
   private["_str","_old","_new","_out","_tmp","_jm","_la","_lo","_ln","_i"];
   _str=_this select 0;
   _arr=toArray(_str);
   _la=count _arr;
   _old=_this select 1;
   _new=_this select 2;
   _na=[_new] call KRON_StrToArray;
   _lo=[_old] call KRON_StrLen;
   _ln=[_new] call KRON_StrLen;
   _out="";
   for "_i" from 0 to (count _arr)-1 do {
       _tmp="";
       if (_i <= _la-_lo) then {
           for "_j" from _i to (_i+_lo-1) do {
               _tmp=_tmp + toString([_arr select _j]);
           };
       };
       if (_tmp==_old) then {
           _out=_out+_new;
           _i=_i+_lo-1;
       } else {
           _out=_out+toString([_arr select _i]);
       };
   };
   _out
};
// End of Kronzky's code

// 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;
       //--------edited by Hicks----Add crew ---------- ---------------
       if (_hasgroup) then {createVehicleCrew _unit};
       //-------------------end editing by Hicks------------------------
       _unit setPosASL _position;
       _unit setDir _dir;                
       if (_haveinit) then {
           //_unit setVehicleInit format ["%1;", _unitinit];
           //processInitCommands;
           // Modified by BearBison
           private ["_IDunit", "_sCommand"];
           _IDunit = format["(objectFromNetID '%1')", netID _unit];
           _sCommand=[format["%1",_unitinit],"this",format["%1",_IDunit]] call KRON_Replace;
           // End of code modified by BearBison
           // Modified by naong and AgentRev
           [call compile format["[{%1}]",_sCommand], "BIS_fnc_spawn", true, true] spawn BIS_fnc_MP;
       };
       if (_hasname) then {
           //_unit setVehicleInit format ["%1 = this; this setVehicleVarName ""%1""",_unitname];
           //processInitCommands;
           private "_sCommand";
           _sCommand = format["[{(objectFromNetID '%1') setVehicleVarName '%2';}]", netID _unit, _unitname];
           [call compile format["%1",_sCommand],"BIS_fnc_spawn", true, true] spawn BIS_fnc_MP;
           _unit call compile format ["%1=_This; PublicVariable '%1'",_unitname];
       };
       // End of code modified by naong
       _dead = false;

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

Share this post


Link to post
Share on other sites

It would be epic if you could fix yours script, as the game module right now is crap. It does not respawn the vehicles at the start position, it won't work for uav's or planes and sometimes it respawn the vehicles even 2 time.

EDIT:

Cpl.Hicks I love you my friend!!! It works like a charm and even with UAV's, thank you so much!

Edited by Bobylein

Share this post


Link to post
Share on other sites

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

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

Share this post


Link to post
Share on other sites

Hi guys,

just a simple question regarding vehicles respawns. I´m using one marker per vehicule (respawn_vehicle_west). If i want the vehicule repawn to a defined place , what should i do ?

In advance thanks ;)

Share this post


Link to post
Share on other sites
Is this being updated?

Will be eventually, but I don't have time at the moment I'm afraid. But soon enough :-)

Share this post


Link to post
Share on other sites

Hi Tophe !

I know you don't have time, but just one question. How to set the init of the vehicles in the script ?

I want to put this : "clearweaponcargo this; clearmagazinecargo this; clearitemcargo this;"

So i opened the script and put it here :

if (!isServer) exitWith {};

// Define variables

_unit = _this select 0;

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

_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 = if (count _this > 6) then {_this select 6} else {clearweaponcargo this; clearmagazinecargo this; clearitemcargo this};

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

But it does not work :confused: What i'm doing bad ? I tried with differents syntax but no way to make it work.

Thanks a lot, and thanks for the script !

Share this post


Link to post
Share on other sites
Hi Tophe !

I know you don't have time, but just one question. How to set the init of the vehicles in the script ?

I want to put this : "clearweaponcargo this; clearmagazinecargo this; clearitemcargo this;"

So i opened the script and put it here :

But it does not work :confused: What i'm doing bad ? I tried with differents syntax but no way to make it work.

Thanks a lot, and thanks for the script !

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

Share this post


Link to post
Share on other sites

Hey, this looks like what I'm looking for to put into my mission. When do you think the working version could be posted? I would love to see it up. Also, does your Arma 2 version work with basic respawns with init?

Share this post


Link to post
Share on other sites

Tophe,

I am still learning here. I'm using this script in my mission and it works wonderfully but I have a problem. I have another script that creates a vehicle after a task is complete and I want it to have it place your respawn on these created vehicles. The vehicle is created fine but I can't get your stuff inserted on the init. I have tried several things now and had no luck at all. Would you mind taking a look at it? I just don't know the correct syntax to get your script to be injected into the init of the created vehicle. It's driving me a bit nuts to be honest.

Thanks in advance for your help!

{
// [captures needed, friendly name, class name, position, direction, respawn delay]
_capturesNeeded = _x select 0;
_friendlyName = _x select 1;
_className = _x select 2;
_position = _x select 3;
_direction = _x select 4;
_respawnDelay = _x select 5;

if (DOM_CaptureCount >= _capturesNeeded && DOM_LastReward < _capturesNeeded) then {
	DOM_LastReward = _capturesNeeded;
	["scripts\domination\routed\reward_notification.sqf", _capturesNeeded, _friendlyName] execVM "scripts\action_router_no_jip.sqf";

	_vehicle = _className createVehicle _position;
	_vehicle setDir _direction;

};
} forEach DOM_Rewards;

Share this post


Link to post
Share on other sites

Maybe give something like this a try?

{
   // [captures needed, friendly name, class name, position, direction, respawn delay]
   _capturesNeeded = _x select 0;
   _friendlyName = _x select 1;
   _className = _x select 2;
   _position = _x select 3;
   _direction = _x select 4;
   _respawnDelay = _x select 5;

   if (DOM_CaptureCount >= _capturesNeeded && DOM_LastReward < _capturesNeeded) then {
       DOM_LastReward = _capturesNeeded;
       ["scripts\domination\routed\reward_notification.sqf", _capturesNeeded, _friendlyName] execVM "scripts\action_router_no_jip.sqf";

       _vehicle = _className createVehicle _position;
       _vehicle setDir _direction;
       [color=#ff0000]veh = [_vehicle, 15, 50] execVM "vehicle.sqf";[/color]

   };
} forEach DOM_Rewards;


Share this post


Link to post
Share on other sites

Thanks but that's one of the first things I tried. Doing it that way causes the vehicle to fail to spawn entirely. Any other ideas? I feel like this may be a time for bis_fnc_mp but that has so far been a dead end as well.

edit: I just tried your suggestion again and this time the vehicle spawned, I had apparently misplaced a ] the last time.

Unfortunately it did not get the init line so the respawn script is not running.

Edited by Sarlac

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.

Share this post


Link to post
Share on other sites

Thanks Nimrod, but this is the newest version

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

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


 Options:
 There are some optional settings. The format for these are:
 veh = [object, Delay, Deserted timer, Respawns, Effect, Dynamic] execVM "vehicle.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 "vehicle.sqf"

 Default respawn time when vehicle is deserted, but not destroyed is 120 seconds. To set a custom timer for this 
 first set respawn delay, then the deserted vehicle timer. (0 = disabled) 
 Like this:  
 veh = [this, 15, 10] execVM "vehicle.sqf"

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

 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.
 Like this:
 veh = [this, 15, 10, 5, TRUE] execVM "vehicle.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 preceding values then set TRUE for dynamic or FALSE for static.
 Like this:
 veh = [this, 15, 10, 5, TRUE, TRUE] execVM "vehicle.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, FALSE, "this setDammage 0.5"] execVM "vehicle.sqf"

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


Contact & Bugreport: cwadensten@gmail.com
================================================================================================================== */

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;

// Kronzky's code
KRON_StrToArray = {
   private["_in","_i","_arr","_out"];
   _in=_this select 0;
   _arr = toArray(_in);
   _out=[];
   for "_i" from 0 to (count _arr)-1 do {
       _out=_out+[toString([_arr select _i])];
   };
   _out
};

KRON_StrLen = {
   private["_in","_arr","_len"];
   _in=_this select 0;
   _arr=[_in] call KRON_StrToArray;
   _len=count (_arr);
   _len
};

KRON_Replace = {
   private["_str","_old","_new","_out","_tmp","_jm","_la","_lo","_ln","_i"];
   _str=_this select 0;
   _arr=toArray(_str);
   _la=count _arr;
   _old=_this select 1;
   _new=_this select 2;
   _na=[_new] call KRON_StrToArray;
   _lo=[_old] call KRON_StrLen;
   _ln=[_new] call KRON_StrLen;
   _out="";
   for "_i" from 0 to (count _arr)-1 do {
       _tmp="";
       if (_i <= _la-_lo) then {
           for "_j" from _i to (_i+_lo-1) do {
               _tmp=_tmp + toString([_arr select _j]);
           };
       };
       if (_tmp==_old) then {
           _out=_out+_new;
           _i=_i+_lo-1;
       } else {
           _out=_out+toString([_arr select _i]);
       };
   };
   _out
};
// End of Kronzky's code

// 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;
       if (_haveinit) then {
           //_unit setVehicleInit format ["%1;", _unitinit];
           //processInitCommands;
           // Modified by BearBison
           private ["_IDunit", "_sCommand"];
           _IDunit = format["(objectFromNetID '%1')", netID _unit];
           _sCommand=[format["%1",_unitinit],"this",format["%1",_IDunit]] call KRON_Replace;
           // End of code modified by BearBison
           // Modified by naong and AgentRev
           [call compile format["[{%1}]",_sCommand], "BIS_fnc_spawn", true, true] spawn BIS_fnc_MP;
       };
       if (_hasname) then {
           //_unit setVehicleInit format ["%1 = this; this setVehicleVarName ""%1""",_unitname];
           //processInitCommands;
           private "_sCommand";
           _sCommand = format["[{(objectFromNetID '%1') setVehicleVarName '%2';}]", netID _unit, _unitname];
           [call compile format["%1",_sCommand],"BIS_fnc_spawn", true, true] spawn BIS_fnc_MP;
           _unit call compile format ["%1=_This; PublicVariable '%1'",_unitname];
       };
       // End of code modified by naong
       _dead = false;

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

Share this post


Link to post
Share on other sites

yep, I saw that 1 but with the way the other is done it cuts out a lot of lines and still has same effect. but ,either 1 works. that's all that matters :)

Share this post


Link to post
Share on other sites

Agreed!

btw did you read my previous post? I'm desperate here...

Share this post


Link to post
Share on other sites
Agreed!

btw did you read my previous post? I'm desperate here...

I just did. what iceman posted should have worked. im using it that way in 2 scripts that create vehicles then runs the respawn script on them.

heres just a snipit of the code I use -

_veh = createVehicle [_car, getPos _road, [], 12, "CAN_COLLIDE"];

_veh setDir floor (random 360);
_VarName = _vehName;
_veh SetVehicleVarName _VarName;

              // name the vehicle global
missionNameSpace setVariable [_vehName, _veh];
publicVariable _vehName;
             // run respawn script
[_veh] execVM "VIR_vehicle_chk.sqf";

the syntax on my respawn is different just because I hardcoded everything for the particular mission.

Share this post


Link to post
Share on other sites

here is mine,

Mix beetween this one and bis module respawn.

notification, deserted delay, deserted distance, keep vehicle name and destroy vehicle when deserted after last respawn.

Not yet tested send code.

/*

Parameter(s):
	0: OBJECT - vehicle
	1:
		NUMBER - respawn delay in seconds (default is 0)
		BOOL - true to remove vehicle respawn (further params are ignored), false to check if the vehicle is marked for respawn
	2: NUMBER - how long until the vehicle is automatically respawned after its crew leaves it (default is -1, i.e., disabled)
	3: NUMBER - Distance for checking if vehicle is deserted (default is 5, i.e., 5 m)
	4: NUMBER - 0 to not show notification when the vehicle is respawned (default is 2, i.e., show notification)
	5: NUMBER - number of time the vehicle can be respawned (default is -1, i.e., unlimited)
	6: CODE - code executed upon respawn. Passed arguments are [<newVehicle>,<oldVehicle>]. 
	7: BOOL - type of old vehicle deletion (false = delete, true = delete with an explosion effect, default is -1, i.e., disabled)
	8: POSITION - type of respawn position:
		0 = where it started
		1 = where it was destroyed
		2 = on vehicle's side respawn marker (e.g., "respawn_vehicle_west") //todo
		3 = on BLUFOR respawn marker	//todo
		4 = on OPFOR respawn marker		//todo
		5 = on Independent respawn marker	//todo
		6 = on Civilian respawn marker		//todo
		7 = on side respawn marker of unit which destroyed the vehicle	//todo

*/

if (!isServer) exitWith {};

private ["_respawnName","_showNotification","_side","_param","_lift","_unit","_delay","_deserted","_respawnsCount","_explode","_dynamic","_unitinit","_haveinit","_hasname","_grupa","_hasgroup","_unitname","_run","_dir","_position","_type","_dead","_nodelay"];

// Define variables
_param = _this;
_unit = _this select 0;
_delay = [_this,1,getnumber (missionconfigfile >> "respawnVehicleDelay"),[0]] call bis_fnc_param;
_deserted = [_this,2,-1,[0]] call bis_fnc_param;
_desertedDistance =	[_this,3,5,[0]] call bis_fnc_param;
_showNotification = [_this,4,2,[0]] call bis_fnc_param;
_respawnsCount = [_this,5,-1,[0]] call bis_fnc_param;
_unitinit = if (count _this > 6) then {_this select 6} else {};
_haveinit = if (count _this > 6) then {true} else {false};
_explode = [_this,7,false,[false]] call bis_fnc_param;
_dynamic = [_this,8,0,[0]] call bis_fnc_param;

_hasname = false;

_lift = _unit getvariable ["BTC_canbe_lift",0];

_respawnName = "";
_side = _unit call bis_fnc_objectSide;

//--------------------edited by [JSO]Hicks-----------------------
_grupa = group _unit;
_hasgroup = false;
If (str(_grupa) == "<NULL-group>") then {_hasgroup = false;} else {_hasgroup = true;};
//-------------------end editing by Hicks------------------------
_unitname = vehicleVarName _unit;
if (isNil '_unitname') then {_hasname = false;} else {_hasname = true;};

_run = (_respawnsCount != 0);

_dir = getDir _unit;
_position = getPosASL _unit;
_type = typeOf _unit;
_dead = false;
_nodelay = false;

// Kronzky's code
KRON_StrToArray = {
   private["_in","_i","_arr","_out"];
   _in=_this select 0;
   _arr = toArray(_in);
   _out=[];
   for "_i" from 0 to (count _arr)-1 do {
       _out=_out+[toString([_arr select _i])];
   };
   _out
};

KRON_StrLen = {
   private["_in","_arr","_len"];
   _in=_this select 0;
   _arr=[_in] call KRON_StrToArray;
   _len=count (_arr);
   _len
};

KRON_Replace = {
   private["_str","_old","_new","_out","_tmp","_jm","_la","_lo","_ln","_i"];
   _str=_this select 0;
   _arr=toArray(_str);
   _la=count _arr;
   _old=_this select 1;
   _new=_this select 2;
   _na=[_new] call KRON_StrToArray;
   _lo=[_old] call KRON_StrLen;
   _ln=[_new] call KRON_StrLen;
   _out="";
   for "_i" from 0 to (count _arr)-1 do {
       _tmp="";
       if (_i <= _la-_lo) then {
           for "_j" from _i to (_i+_lo-1) do {
               _tmp=_tmp + toString([_arr select _j]);
           };
       };
       if (_tmp==_old) then {
           _out=_out+_new;
           _i=_i+_lo-1;
       } else {
           _out=_out+toString([_arr select _i]);
       };
   };
   _out
};
// End of Kronzky's code

// Start monitoring the vehicle
while {_run} do 
{    
   sleep (2 + random 10);

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

   // Respawn vehicle
   if (_dead) then 
   {   
	// Check respawn amount if vehicle is destroy
	if (_respawnsCount > 0 and !Alive _unit) then {_respawnsCount= _respawnsCount -1;_param set [3,_respawnsCount];};

       if (_nodelay) then {sleep 0.1;} else {sleep (_delay max 0.1);};
       switch _dynamic do {
		case 1 : {_position = getPosASL _unit; _dir = getDir _unit;};
		default {};
	};
       if (_explode) then {_effect = createvehicle ["M_AT",position _unit,[],0,"none"];_effect setvelocity [0,0,-1];};
       sleep 0.1;

	// delete vehicle
       deleteVehicle _unit;
	sleep 2;

       // _unit = _type createVehicle _position;
	 _unit = createVehicle [_type, (_position findEmptyPosition[ 2 , 100 , _type ]),[], 0, "NONE"];
	 _unit setvariable ["BTC_canbe_lift",_lift,true];
	 _unit setvehiclevarname _unitname;
	 _unit setDir _dir;  
	 _unit setVelocity [0, 0, -1];

       //--------edited by Hicks----Add crew ---------- ---------------
       if (_hasgroup) then {createVehicleCrew _unit};
       //-------------------end editing by Hicks------------------------

       if (_haveinit) then {
           private ["_IDunit", "_sCommand"];
           _IDunit = format["(objectFromNetID '%1')", netID _unit];
           _sCommand=[format["%1",_unitinit],"this",format["%1",_IDunit]] call KRON_Replace;
           // End of code modified by BearBison
           // Modified by naong and AgentRev
           [call compile format["[{%1}]",_sCommand], "BIS_fnc_spawn", true, true] spawn BIS_fnc_MP;
       };
       if (_hasname) then {
           private "_sCommand";
		_sCommand = format["[{(objectFromNetID '%1') setVehicleVarName '%2';}]", netID _unit, _unitname];
           [call compile format["%1",_sCommand],"BIS_fnc_spawn", true, true] spawn BIS_fnc_MP;
           _unit call compile format ["%1=_This; PublicVariable '%1'",_unitname];
       };

	_param set [0,_unit];
       // End of code modified by naong
	_run = false;

	//--- Show notification
	if (_showNotification > 0) then {
		private ["_cfgVeh","_displayName","_picture"];
		_cfgVeh = configfile >> "cfgvehicles" >> _type;
		_displayName = gettext (_cfgVeh >> "displayName");
		_picture = (gettext (_cfgVeh >> "picture")) call bis_fnc_textureVehicleIcon;
		if (_respawnName == "") then {_respawnName = format [localize "str_a3_bis_fnc_respawnmenuposition_grid",mapgridposition (position _unit)];}; 
		[["RespawnVehicle",[_displayName,_respawnName,_picture]],"BIS_fnc_showNotification",_side] call bis_fnc_mp;
	};
   }
else
{
	// Check if the vehicle is deserted.
	if (_deserted > 0) then
	{
		if ((getPosASL _unit distance _position > 10) and getPosATL _unit select 2 < 5 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 && {_x distance _unit < _desertedDistance} count (playableunits + switchableunits) == 0) then {_dead = true; _nodelay =true}; 
			if !(alive _unit) then {_dead = true; _nodelay = false}; 
		};
	};
};
};
if (_respawnsCount != 0) then {
_param execVM "server\vehicles\Tee_Respawn_Vehicle.sqf";
}
else
{
_getout =_unit addeventhandler [ 
		"getout",
			{
				_this spawn {
					private "_veh";
					_veh = _this select 0;
					if (count crew _veh == 0) then {
					sleep 10;
					_veh setdamage 1;
					};
				};
			}
		];
_unit spawn {waituntil {!Alive _this}; sleep 120; deletevehicle _this;};
};

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  

×