-
Notifications
You must be signed in to change notification settings - Fork 9
/
vehRespawn.sqf
84 lines (69 loc) · 2.59 KB
/
vehRespawn.sqf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* ---------------------------------------------------------------------------------------------------
File: vehRespawn.sqf
Author: Iceman77
Description:
Respawn destroyed and abandoned vehicles
Parameter(s):
_this select 0: vehicle
_this select 1: abandoned delay in minute(s) - Required
_this select 2: destroyed delay in minute(s) - Required
_this select 3: Function to call for the newly spawned vehicle (for custom armaments etc) - Optional
How to use - Vehicle Init Line:
_nul = [this, 2, 1, {[_this] call TAG_FNC_TankInit}] execVM "vehRespawn.sqf"; << 2 minute abandoned delay, 1 minute destroyed delay, call the function that disables the TI
_nul = [this, 2, 1, {}] execVM "vehrespawn.sqf"; << 2 minute abandoned delay, 1 minute destroyed delay, NO function called for the newly respawned vehicle (standard way)
---------------------------------------------------------------------------------------------------- */
private ["_veh","_abandonDelay","_deadDelay","_vehInit","_dir","_vehPos","_vehtype","_vehName"];
_veh = _this select 0;
_abandonDelay = (_this select 1) * 60;
_deadDelay = (_this select 2) * 180;
_vehInit = _this select 3;
_dir = getDir _veh;
_vehPos = getPos _veh;
_vehtype = typeOf _veh;
_vehName = vehicleVarName _veh;
if (isServer) then {
uiSleep (random 1);
While {True} Do {
uiSleep 1;
if ((alive _veh) && {canMove _veh} && {{alive _x} count crew _veh isEqualTo 0}) then {
_abandoned = true;
for "_i" from 0 to _abandonDelay step 1 do {
if (({alive _x} count (crew _veh) > 0) || (!alive _veh) || (!canMove _veh)) exitWith {_abandoned = false;};
sleep 1;
};
if (_abandoned && {_veh distance2D _vehPos > 10}) then {
deleteVehicle _veh;
sleep 1;
_veh = createVehicle [_vehtype, _vehPos, [], 0, "CAN_COLLIDE"];
_veh setDir _dir;
_veh setPos [_vehPos # 0, _vehPos # 1, 0];
if !(_vehName isEqualTo "") then {
missionNamespace setVariable [_vehName, _veh];
publicVariable _vehName;
};
_veh call _vehInit;
_veh setdamage 0;
};
};
if ((!alive _veh) || (!canMove _veh)) then {
_dead = true;
for "_i" from 0 to _deadDelay step 1 do {
if (({alive _x} count (crew _veh) > 0) || (canMove _veh)) exitWith {_dead = false;};
sleep 1;
};
if (_dead) then {
deleteVehicle _veh;
uiSleep 1;
_veh = createVehicle [_vehtype, _vehPos, [], 0, "CAN_COLLIDE"];
_veh setDir _dir;
_veh setPos [_vehPos # 0, _vehPos # 1, 0];
if !(_vehName isEqualTo "") then {
missionNamespace setVariable [_vehName, _veh];
publicVariable _vehName;
};
_veh call _vehInit;
_veh setdamage 0;
};
};
};
};