vehicle.sqf 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. ==================================================================================================================
  3. Simple Vehicle Respawn Script v1.81 for Arma 3
  4. by Tophe of Östgöta Ops [OOPS] and tweaked for I&A 3 by Rarek [AW]
  5. Edited for Star Wars Opposistion by 501st Legion
  6. Put this in the vehicles init line:
  7. veh = [this] execVM "vehicle.sqf"
  8. Options:
  9. There are some optional settings. The format for these are:
  10. veh = [object, Delay, Deserted timer, Respawns, Effect, Dynamic] execVM "vehicle.sqf"
  11. Default respawn delay is 30 seconds, to set a custom respawn delay time, put that in the init as well.
  12. Like this:
  13. veh = [this, 15] execVM "vehicle.sqf"
  14. Default respawn time when vehicle is deserted, but not destroyed is 120 seconds. To set a custom timer for this
  15. first set respawn delay, then the deserted vehicle timer. (0 = disabled)
  16. Like this:
  17. veh = [this, 15, 10] execVM "vehicle.sqf"
  18. 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).
  19. Like this:
  20. veh = [this, 15, 10, 5] execVM "vehicle.sqf"
  21. Set this value to TRUE to add a special explosion effect to the wreck when respawning.
  22. Default value is FALSE, which will simply have the wreck disappear.
  23. Like this:
  24. veh = [this, 15, 10, 5, TRUE] execVM "vehicle.sqf"
  25. By default the vehicle will respawn to the point where it first was when the mission started (static).
  26. This can be changed to dynamic. Then the vehicle will respawn to the position where it was destroyed.
  27. First set all preceding values then set TRUE for dynamic or FALSE for static.
  28. Like this:
  29. veh = [this, 15, 10, 5, TRUE, TRUE] execVM "vehicle.sqf"
  30. If you you want to set the INIT field of the respawned vehicle, first set all other values, then set init commands.
  31. Those must be inside quotations.
  32. Like this:
  33. veh = [this, 15, 10, 5, TRUE, FALSE, "this setDammage 0.5"] execVM "vehicle.sqf"
  34. Default values of all settings are:
  35. veh = [this, 30, 120, 0, FALSE, FALSE] execVM "vehicle.sqf"
  36. Contact & Bugreport: cwadensten@gmail.com
  37. ================================================================================================================== */
  38. if (!isServer) exitWith {};
  39. // Define variables
  40. _unit = [_this,0,objNull,[objNull]] call BIS_fnc_param;
  41. _delay = [_this,1,30,[0]] call BIS_fnc_param;
  42. _deserted = [_this,2,120,[0]] call BIS_fnc_param;
  43. _respawns = [_this,3,0,[0]] call BIS_fnc_param;
  44. _explode = [_this,4,false,[true]] call BIS_fnc_param;
  45. _dynamic = [_this,5,false,[true]] call BIS_fnc_param;
  46. _unitinit = [_this,6];
  47. _haveinit = if (count _this > 6) then { true } else { false };
  48. _hasname = false;
  49. _unitname = vehicleVarName _unit;
  50. if (isNil _unitname) then {_hasname = false;} else {_hasname = true;};
  51. _noend = true;
  52. _run = true;
  53. _rounds = 0;
  54. if (_delay < 0) then {_delay = 0};
  55. if (_deserted < 0) then {_deserted = 0};
  56. if (_respawns <= 0) then {_respawns= 0; _noend = true;};
  57. if (_respawns > 0) then {_noend = false};
  58. _dir = getDir _unit;
  59. _position = getPosASL _unit;
  60. _type = typeOf _unit;
  61. _dead = false;
  62. _nodelay = false;
  63. // Start monitoring the vehicle
  64. while {_run} do
  65. {
  66. sleep (2 + random 10);
  67. if ((getDammage _unit > 0.8) and ({alive _x} count crew _unit == 0)) then {_dead = true};
  68. // Check if the vehicle is deserted.
  69. if (_deserted > 0) then
  70. {
  71. if ((getPosASL _unit distance _position > 10) and ({alive _x} count crew _unit == 0) and (getDammage _unit < 0.8)) then
  72. {
  73. _timeout = time + _deserted;
  74. sleep 0.1;
  75. waitUntil {_timeout < time or !alive _unit or {alive _x} count crew _unit > 0};
  76. if ({alive _x} count crew _unit > 0) then {_dead = false};
  77. if ({alive _x} count crew _unit == 0) then {_dead = true; _nodelay =true};
  78. if !(alive _unit) then {_dead = true; _nodelay = false};
  79. };
  80. };
  81. // Respawn vehicle
  82. if (_dead) then
  83. {
  84. if (_nodelay) then {sleep 0.1; _nodelay = false;} else {sleep _delay;};
  85. if (_dynamic) then {_position = getPosASL _unit; _dir = getDir _unit;};
  86. if (_explode) then {_effect = "M_AT" createVehicle getPosASL _unit; _effect setPosASL getPosASL _unit;};
  87. sleep 0.1;
  88. deleteVehicle _unit;
  89. sleep 2;
  90. _unit = _type createVehicle _position;
  91. _unit setPosASL _position;
  92. _unit setDir _dir;
  93. if (["B_UAV", _type] call BIS_fnc_inString) then { createVehicleCrew _unit; };
  94. if (_haveinit) then
  95. {
  96. _unit call compile format ["%1=_This; PublicVariable '%1'",_unitinit];
  97. };
  98. if (_hasname) then
  99. {
  100. _unit setVehicleVarName _unitname;
  101. _unit call compile format ["%1=_This; PublicVariable '%1'",_unitname];
  102. };
  103. _dead = false;
  104. // Check respawn amount
  105. if !(_noend) then {_rounds = _rounds + 1};
  106. if ((_rounds == _respawns) and !(_noend)) then {_run = false;};
  107. };
  108. };