This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Arma 3 Vehicle Respawn

By: a guest on May 4th, 2013  |  syntax: None  |  size: 6.04 KB  |  views: 779  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /*  
  2. ==================================================================================================================
  3.   Simple Vehicle Respawn Script v1.81 for Arma 3
  4.   by Tophe of Östgöta Ops [OOPS]
  5.  
  6.   Put this in the vehicles init line:
  7.   veh = [this] execVM "vehicle.sqf"
  8.  
  9.  
  10.   Options:
  11.   There are some optional settings. The format for these are:
  12.   veh = [object, Delay, Deserted timer, Respawns, Effect, Dynamic] execVM "vehicle.sqf"
  13.  
  14.   Default respawn delay is 30 seconds, to set a custom respawn delay time, put that in the init as well.
  15.   Like this:
  16.   veh = [this, 15] execVM "vehicle.sqf"
  17.  
  18.   Default respawn time when vehicle is deserted, but not destroyed is 120 seconds. To set a custom timer for this
  19.   first set respawn delay, then the deserted vehicle timer. (0 = disabled)
  20.   Like this:  
  21.   veh = [this, 15, 10] execVM "vehicle.sqf"
  22.  
  23.   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).
  24.   Like this:
  25.   veh = [this, 15, 10, 5] execVM "vehicle.sqf"
  26.  
  27.   Set this value to TRUE to add a special explosion effect to the wreck when respawning.
  28.   Default value is FALSE, which will simply have the wreck disappear.
  29.   Like this:
  30.   veh = [this, 15, 10, 5, TRUE] execVM "vehicle.sqf"
  31.  
  32.   By default the vehicle will respawn to the point where it first was when the mission started (static).
  33.   This can be changed to dynamic. Then the vehicle will respawn to the position where it was destroyed.
  34.   First set all preceding values then set TRUE for dynamic or FALSE for static.
  35.   Like this:
  36.   veh = [this, 15, 10, 5, TRUE, TRUE] execVM "vehicle.sqf"
  37.  
  38.   If you you want to set the INIT field of the respawned vehicle, first set all other values, then set init commands.
  39.   Those must be inside quotations.
  40.   Like this:
  41.   veh = [this, 15, 10, 5, TRUE, FALSE, "this setDammage 0.5"] execVM "vehicle.sqf"
  42.  
  43.   Default values of all settings are:
  44.   veh = [this, 30, 120, 0, FALSE, FALSE] execVM "vehicle.sqf"
  45.  
  46.        
  47. Contact & Bugreport: cwadensten@gmail.com
  48. ================================================================================================================== */
  49.  
  50.  
  51. if (!isServer) exitWith {};
  52.  
  53. // Define variables
  54. _unit = _this select 0;
  55. _delay = if (count _this > 1) then {_this select 1} else {30};
  56. _deserted = if (count _this > 2) then {_this select 2} else {120};
  57. _respawns = if (count _this > 3) then {_this select 3} else {0};
  58. _explode = if (count _this > 4) then {_this select 4} else {false};
  59. _dynamic = if (count _this > 5) then {_this select 5} else {false};
  60. _unitinit = if (count _this > 6) then {_this select 6} else {};
  61. _haveinit = if (count _this > 6) then {true} else {false};
  62.  
  63. _hasname = false;
  64. _unitname = vehicleVarName _unit;
  65. if (isNil _unitname) then {_hasname = false;} else {_hasname = true;};
  66. _noend = true;
  67. _run = true;
  68. _rounds = 0;
  69.  
  70. if (_delay < 0) then {_delay = 0};
  71. if (_deserted < 0) then {_deserted = 0};
  72. if (_respawns <= 0) then {_respawns= 0; _noend = true;};
  73. if (_respawns > 0) then {_noend = false};
  74.  
  75. _dir = getDir _unit;
  76. _position = getPosASL _unit;
  77. _type = typeOf _unit;
  78. _dead = false;
  79. _nodelay = false;
  80.  
  81. /////////////////////////////////////
  82. // Added by naong
  83. if (isNil "FNC_setVehicleInit") then {
  84.     FNC_setVehicleInit = {
  85.         private ["_netID","_unit","_unitinit"];
  86.        
  87.         _netID = _this select 0;
  88.         _unit = objectFromNetID _netID;
  89.         _unitinit = _this select 1;
  90.        
  91.         _unit call compile format ["%1",_unitinit];
  92.     };
  93. };
  94. if (isNil "FNC_setVehicleVarName") then {
  95.     FNC_setVehicleVarName = {
  96.         private ["_netID","_unit","_unitname"];
  97.        
  98.         _netID = _this select 0;
  99.         _unit = objectFromNetID _netID;
  100.         _unitname = _this select 1;
  101.        
  102.         _unit setVehicleVarName _unitname;
  103.         _unit call compile format ["%1=_This; PublicVariable ""%1""",_unitname];
  104.     };
  105. };
  106. /////////////////////////////////////
  107.  
  108. // Start monitoring the vehicle
  109. while {_run} do
  110. {    
  111.     sleep (2 + random 10);
  112.       if ((getDammage _unit > 0.8) and ({alive _x} count crew _unit == 0)) then {_dead = true};
  113.  
  114.     // Check if the vehicle is deserted.
  115.     if (_deserted > 0) then
  116.     {
  117.         if ((getPosASL _unit distance _position > 10) and ({alive _x} count crew _unit == 0) and (getDammage _unit < 0.8)) then
  118.         {
  119.             _timeout = time + _deserted;
  120.             sleep 0.1;
  121.              waitUntil {_timeout < time or !alive _unit or {alive _x} count crew _unit > 0};
  122.             if ({alive _x} count crew _unit > 0) then {_dead = false};
  123.             if ({alive _x} count crew _unit == 0) then {_dead = true; _nodelay =true};
  124.             if !(alive _unit) then {_dead = true; _nodelay = false};
  125.         };
  126.     };
  127.  
  128.     // Respawn vehicle
  129.       if (_dead) then
  130.     {    
  131.         if (_nodelay) then {sleep 0.1; _nodelay = false;} else {sleep _delay;};
  132.         if (_dynamic) then {_position = getPosASL _unit; _dir = getDir _unit;};
  133.         if (_explode) then {_effect = "M_AT" createVehicle getPosASL _unit; _effect setPosASL getPosASL _unit;};
  134.         sleep 0.1;
  135.  
  136.         deleteVehicle _unit;
  137.         sleep 2;
  138.         _unit = _type createVehicle _position;
  139.         _unit setPosASL _position;
  140.         _unit setDir _dir;
  141.        
  142.         // Modified by naong
  143.         if (_haveinit) then {
  144.             //_unit setVehicleInit format ["%1;", _unitinit];
  145.             //processInitCommands;
  146.            
  147.             [[netID _unit, _unitinit], "FNC_setVehicleInit", true, true] spawn BIS_fnc_MP;
  148.         };
  149.         if (_hasname) then {
  150.             //_unit setVehicleInit format ["%1 = this; this setVehicleVarName ""%1""",_unitname];
  151.             //processInitCommands;
  152.            
  153.             [[netID _unit, _unitname], "FNC_setVehicleVarName", true, true] spawn BIS_fnc_MP;
  154.         };
  155.         _dead = false;
  156.         ////////////////////
  157.        
  158.         // Check respawn amount
  159.         if !(_noend) then {_rounds = _rounds + 1};
  160.         if ((_rounds == _respawns) and !(_noend)) then {_run = false;};
  161.     };
  162. };
clone this paste RAW Paste Data