· 7 years ago · Feb 03, 2019, 01:58 AM
1/*
2
3 Remove the comments on the MARMA logs if you want to log the spawns to MARMA.
4
5 The _uid variable MUST be changed to a valid UID that already exists in the account table.
6
7 How it works -
8
9 On server init, the script will count AllMissionObjects (X) on a per vehicle basis listed in the array below. If there is less than the defined amount the server will spawn a persistent vehicle with a random pin number
10 UNLOCKED at the defined or random road position.
11
12 This script can be used to replace the standard EXILE world vehicle spawns, so that the vehicles that are spawned are persistent. Players will not know the pin number, but its still a "benefit" to them as the vehicle they find
13 is persistent. And hey, they might just guess the number..
14
15 This script accounts for ALL vehicles, purchased or other wise. So if players have bought vehicles, and those vehicles exceed the maximum defined number in tbe below array, the server wont spawn anymore.
16
17 Configure the _vehicleArray below
18 Adjust the safePos parameters line 132 - 138
19
20*/
21
22uiSleep 30;
23
24diag_log ["ExileServer - Spawning persistent vehicle spawns"];
25//["ExileServer - Spawning world persistent vehicles"] call MAR_fnc_log;
26
27private ["_count","_uid","_debugForSP","_vehicle","_vehicleArray","_count","_vehicleClass","_position","_positionCount","_pinCode","_vehicleObject","_nearVehicles","_nearVechicleCount","_marker","_cancelSpawn","_isRandomRoadPos","_road","_scriptComplete"];
28
29_scriptComplete = false;
30_debugForSP = false; // If true , when the script is run in the editor it will create markers on the vehicle spawns.
31
32_uid = "76561198079956410"; // Needs to be a valid UID that exists in the account table (best to use a server owners uid)
33
34/*
35 How the vehicle array works -
36
37 Select 0 - Vehicle class name
38 Select 1 - Number - amount limit, will only maintain this many vehicles on the server
39 Select 2 - Array of positions EG [[0,0,0].[0,0,0]] - Will randomly select one of the positions per vehicle, if the position is occupied it will try for the other positions
40 Select 3 - Boolean - If true, will spawn the vehicle on a random road, if false, will look to the positions above.
41
42*/
43
44_vehicleArray =
45[
46// Quads
47 ["Exile_Bike_QuadBike_Black",1,[],true],
48 ["Exile_Bike_QuadBike_Csat",1,[],true],
49 //Vans
50 ["Exile_Car_Van_Box_Black",1,[],true],
51 //Offroads
52 ["Exile_Car_Offroad_White",1,[],true],
53 //["Exile_Car_Offroad_Rusty",1,[],true],
54 //["Exile_Car_Offroad_Armed_Guerilla",1,[],true],
55 //Hatchbacks
56 ["Exile_Car_MB4WDOpen",1,[],true],
57 ["Exile_Car_MB4WD",1,[],true],
58 //Hatchback sports
59 ["Exile_Car_Hatchback_Sport_Red",1,[],true],
60 ["Exile_Car_ProwlerLight",1,[],true],
61 ["Exile_Car_ProwlerUnarmed",1,[],true],
62 //SUV
63 ["Exile_Car_QilinUnarmed",1,[],true],
64 ["Exile_Car_SUV_Black",1,[],true],
65 ["Exile_Car_SUV_Grey",1,[],true],
66 ["Exile_Car_SUV_Orange",1,[],true],
67 //Volha
68 ["Exile_Car_Volha_Blue",1,[],true],
69 ["Exile_Car_Volha_White",1,[],true],
70 ["Exile_Car_Volha_Black",1,[],true],
71 // Bus
72 ["Exile_Car_Ikarus_Blue",1,[],true],
73 // Zamak
74 ["Exile_Car_Zamak",1,[],true],
75 // Urals
76 ["Exile_Car_Ural_Covered_Blue",1,[],true],
77 ["Exile_Car_Ural_Covered_Yellow",1,[],true],
78 ["Exile_Car_Ural_Covered_Worker",1,[],true],
79 ["Exile_Car_Ural_Covered_Military",1,[],true],
80 // Land rovers
81 ["Exile_Car_LandRover_Red",1,[],true],
82 ["Exile_Car_LandRover_Urban",1,[],true],
83 ["Exile_Car_LandRover_Green",1,[],true],
84 ["Exile_Car_LandRover_Sand",1,[],true],
85 ["Exile_Car_LandRover_Desert",1,[],true],
86 //armored
87 ["B_APC_Tracked_01_AA_F",1,[],true],
88 ["B_APC_Tracked_01_CRV_F",1,[],true],
89 ["B_APC_Tracked_01_rcws_F",1,[],true],
90 ["B_MBT_01_TUSK_F",1,[],true],
91 ["B_MBT_01_arty_F",1,[],true],
92 ["B_MBT_01_cannon_F",1,[],true],
93 ["B_MBT_01_mlrs_F",1,[],true],
94 ["I_APC_tracked_03_cannon_F",1,[],true],
95 ["I_MBT_03_cannon_F",1,[],true],
96 ["O_APC_Tracked_02_AA_F",1,[],true],
97 ["O_APC_Tracked_02_cannon_F",1,[],true],
98 ["O_APC_Wheeled_02_rcws_F",1,[],true],
99 ["O_APC_Wheeled_02_rcws_v2_F",1,[],true],
100 ["B_APC_Wheeled_03_cannon_F",1,[],true],
101 ["O_MBT_02_arty_F",1,[],true],
102 ["O_MBT_02_cannon_F",1,[],true],
103 //car
104 ["B_MRAP_01_F",1,[],true],
105 ["B_MRAP_01_hmg_F",1,[],true],
106 ["B_MRAP_01_gmg_F",1,[],true],
107 ["O_G_Offroad_01_F",1,[],true],
108 ["O_G_Offroad_01_armed_F",1,[],true],
109 ["O_Quadbike_01_F",1,[],true],
110 ["O_G_Quadbike_01_F",1,[],true],
111 ["B_Truck_01_covered_F",1,[],true],
112 ["B_Truck_01_transport_F",1,[],true],
113 ["O_G_Van_01_transport_F",1,[],true],
114 ["B_T_MRAP_01_hmg_F",1,[],true],
115 ["O_T_MRAP_02_hmg_ghex_F",1,[],true],
116 ["O_T_MRAP_02_gmg_ghex_F",1,[],true],
117 ["C_Quadbike_01_black_F",1,[],true],
118 ["O_Truck_02_transport_F",1,[],true],
119 ["O_Truck_03_covered_F",1,[],true],
120 ["O_Truck_03_device_F",1,[],true],
121 ["B_G_Offroad_01_armed_F",1,[],true],
122 ["B_G_Van_01_transport_F",1,[],true],
123 ///truck
124 ["O_G_Offroad_01_repair_F",1,[],true],
125 ["B_T_Truck_01_box_F",1,[],true],
126 ["B_T_Truck_01_medical_F",1,[],true],
127 ["O_G_Van_01_fuel_F",1,[],true],
128 ["B_Truck_01_Repair_F",1,[],true],
129 ["B_T_Truck_01_fuel_F",1,[],true],
130 ["B_Truck_01_medical_F",1,[],true],
131 //Choppers
132 ["RHS_AH1Z",1,[],true],
133 ["RHS_AH64D",1,[],true],
134 ["RHS_CH_47F",1,[],true],
135 ["RHS_UH1Y",1,[],true],
136 ["RHS_UH60M",1,[],true],
137 ["RHS_UH60M_MEV",1,[],true],
138 ["RHS_CH_47F",1,[],true],
139 ["O_Heli_Light_02_dynamicLoadout_F",1,[],true],
140 ["O_Heli_Transport_04_covered_black_F",1,[],true],
141 ["B_Heli_Light_01_F",1,[],true],
142 ["B_Heli_Transport_01_F",1,[],true],
143 ["B_Heli_Transport_01_camo_F",1,[],true],
144 ["B_Heli_Transport_01_camo_F",1,[],true],
145 ["I_Heli_light_03_dynamicLoadout_F",1,[],true],
146 ["B_Heli_Transport_03_unarmed_green_F",1,[],true],
147 ["B_Heli_Transport_03_unarmed_F",1,[],true],
148 ["B_T_VTOL_01_armed_F",1,[],true],
149 ["O_T_VTOL_02_vehicle_ghex_F",1,[],true],
150 //Wheeled Vehicle
151 ["rhsusf_M1078A1P2_B_M2_WD_fmtv_usarmy",1,[],true],
152 ["rhsusf_M1078A1P2_B_d_fmtv_usarmy",1,[],true],
153 ["rhsusf_M1078A1P2_B_wd_fmtv_usarmy",1,[],true],
154 ["rhsusf_M1078A1P2_d_fmtv_usarmy",1,[],true],
155 ["rhsusf_M1083A1P2_B_M2_D_fmtv_usarmy",1,[],true],
156 ["rhsusf_M1083A1P2_B_M2_wd_fmtv_usarmy",1,[],true],
157 ["rhsusf_M1083A1P2_B_D_fmtv_usarmy",1,[],true],
158 ["rhsusf_M1084A1P2_D_fmtv_usarmy",1,[],true],
159 ["rhsusf_M1084A1P2_WD_fmtv_usarmy",1,[],true],
160 ["rhsusf_m1025_w_mk19",1,[],true],
161 ["rhsusf_m998_w_2dr",1,[],true],
162 ["rhsusf_m998_w_4dr",1,[],true],
163 ["rhsusf_rg33_d",1,[],true],
164 ["rhsusf_rg33_m2_wd",1,[],true],
165 ["RHS_M2A3",1,[],true],
166 ["RHS_M2A3_BUSKI",1,[],true],
167 ["rhsusf_m109_usarmy",1,[],true],
168 ["rhsusf_m109d_usarmy",1,[],true],
169 ["rhsusf_m113_usarmy_M240",1,[],true],
170 ["rhsusf_m113_usarmy_MK19",1,[],true],
171 ["rhsusf_m113d_usarmy_medical",1,[],true],
172 ["rhsusf_m113_usarmy_supply",1,[],true],
173 ["rhsusf_m113_usarmy_unarmed",1,[],true],
174 ["rhsusf_m113d_usarmy",1,[],true],
175 ["rhsusf_m113d_usarmy_M240",1,[],true],
176 ["rhsusf_m113d_usarmy_MK19",1,[],true],
177 ["rhsusf_m113d_usarmy_medical",1,[],true],
178 ["rhsusf_m113d_usarmy_supply",1,[],true],
179 ["rhsusf_m113d_usarmy_unarmed",1,[],true],
180 ["rhsusf_m1a1aim_tuski_d",1,[],true],
181 ["rhsusf_m1a1aim_tuski_wd",1,[],true],
182 ["rhsusf_m1a1aimd_usarmy",1,[],true],
183 ["rhsusf_m1a2sep1tuskiwd_usarmy",1,[],true],
184 ["rhsusf_m1a1fep_d",1,[],true],
185 ["rhsusf_m1a1fep_od",1,[],true],
186 ["rhsusf_m1a1fep_wd",1,[],true],
187 ["rhsusf_m1a2sep1d_usarmy",1,[],true],
188 ["rhsusf_m1a2sep1tuskid_usarmy",1,[],true],
189 ["rhsusf_m1a2sep1tuskiid_usarmy",1,[],true],
190 ["rhsusf_m1a2sep1tuskiiwd_usarmy",1,[],true],
191 ["rhsusf_m1a2sep1tuskiwd_usarmy",1,[],true],
192 ["rhsusf_m1a2sep1wd_usarmy",1,[],true]
193 // Choppers
194 /*
195 ["Exile_Chopper_Hellcat_Green",1,[[23483.9,21144.8,0],[25240.1,21828.6,0]],false],
196 ["Exile_Chopper_Hummingbird_Green",1,[[12834.2,16735.8,0],[23079.8,7299.1,0]],false],
197 ["Exile_Chopper_Mohawk_FIA",1,[[17550.5,13240.5,0],[26783.6,24673,0]],false],
198 ["Exile_Chopper_Orca_CSAT",1,[[3732.07,12976.3,20]],false]*/
199];
200
201{
202 for "_i" from 0 to (_x select 1) do
203 {
204 _cancelSpawn = false;
205 _obj = _x select 0;
206 _count = count allMissionObjects _obj;
207 _positionCount = (count (_x select 2));
208 _isRandomRoadPos = _x select 3;
209
210 if !(_count >= _x select 1) then
211 {
212 _vehicleClass = _x select 0;
213 _position = selectRandom (_x select 2);
214
215 if !(_isRandomRoadPos) then
216 {
217 _foundSafePos = false;
218 _failSafe = 15;
219 _checks = 0;
220 waitUntil
221 {
222 _position = selectRandom (_x select 2);
223 _nearVehicles = nearestObjects [_position, ["car","air"], 10];
224 _nearVechicleCount = count _nearVehicles;
225 if (_nearVechicleCount == 0) then
226 {
227 _foundSafePos = true;
228 };
229 _checks = _checks + 1;
230 if (_checks >= _failSafe) then {_cancelSpawn = true; _foundSafePos = true;};
231 _foundSafePos
232 };
233 }
234 else
235 {
236 _foundSafePos = false;
237 waitUntil
238 {
239 _spawnCenter = getArray(configFile >> "CfgWorlds" >> worldName >> "centerPosition"); //Center of your map
240 _min = 15; // minimum distance from the center position (Number) in meters
241 _max = 30000; // maximum distance from the center position (Number) in meters
242 _mindist = 5; // minimum distance from the nearest object (Number) in meters, ie. spawn at least this distance away from anything within x meters..
243 _water = 0; // water mode 0: cannot be in water , 1: can either be in water or not , 2: must be in water
244 _shoremode = 0; // 0: does not have to be at a shore , 1: must be at a shore
245 _blackList = [[[0, 0],[0,0]]];
246
247 _startPosRoad = [_spawnCenter,_min,_max,_mindist,_water,10,_shoremode,_blackList] call BIS_fnc_findSafePos; //Find random spot on the map
248 _onRoadCheck = _startPosRoad nearRoads 100; //Find road objects 100m from spot
249 _countPossibleRoads = count _onRoadCheck; // count road objects
250
251 if (_countPossibleRoads == 0) then
252 {
253 }
254 else
255 {
256 _road = _onRoadCheck select 0;
257 _position = getPos _road;
258 _foundSafePos = true;
259 };
260 uiSleep 0.1;
261 _foundSafePos
262 };
263 };
264 if !(_cancelSpawn) then
265 {
266 if !(_debugForSP) then
267 {
268 _pinCode = format ["%1%2%3%4",round (random 8 +1),round (random 8 +1),round (random 8 +1),round (random 8 +1)];
269 _vehicleObject = [_vehicleClass, _position, (random 360), true,_pinCode] call ExileServer_object_vehicle_createPersistentVehicle;
270 _vehicleObject setDamage 0.6;
271 _vehicleObject setFuel round (random 15 +10);
272
273 if !((_x select 0) isKindOf "AIR") then
274 {
275 _wheels = ["HitLF2Wheel","HitLFWheel","HitRFWheel","HitRF2Wheel"];
276 {
277 if (random 1 > 0.5) then
278 {
279 _vehicleObject setHitPointDamage [_x,1];
280 };
281 } forEach _wheels;
282 };
283 _vehicleObject setVariable ["ExileOwnerUID", _uid];
284 _vehicleObject setVariable ["ExileIsLocked",0];
285 _vehicleObject lock 0;
286 _vehicleObject call ExileServer_object_vehicle_database_insert;
287 _vehicleObject call ExileServer_object_vehicle_database_update;
288
289 diag_log format ["[Event: Persistent Spawns] -- Spawned a %1 at location: %2 -- Max allowed: %3",_x select 0,_position, _x select 1];
290 //[format["[Event: Persistent Spawns] -- Spawned a %1 at location: %2 -- Max allowed: %3",_x select 0,_position, _x select 1]] call MAR_fnc_log;
291 }
292 else
293 {
294 _vehicleObject = createVehicle [_vehicleClass,_position,[], 0, "NONE"];
295
296 if !((_x select 0) isKindOf "AIR") then
297 {
298 _wheels = ["HitLF2Wheel","HitLFWheel","HitRFWheel","HitRF2Wheel"];
299 {
300 _vehicleObject setHitPointDamage [_x,1];
301 } forEach _wheels;
302 };
303
304 _marker = createMarker [format["HeliCrash%1", diag_tickTime], _position];
305 _marker setMarkerType "mil_dot";
306 _marker setMarkerText "Vehicle";
307 };
308 }
309 else
310 {
311 if !(_debugForSP) then
312 {
313 //[format["[Event: Persistent Spawns] -- Could not find valid spawn position for %1 at position %2 -- exiting try for this vehicle",_x select 0,_position]] call MAR_fnc_log;
314 diag_log format["[Event: Persistent Spawns] -- Could not find valid spawn position for %1 at position %2 -- exiting try for this vehicle",_x select 0,_position];
315 }
316 else
317 {
318 hint format["[Event: Persistent Spawns] -- Could not find valid spawn position for %1 at position %2 -- exiting try for this vehicle",_x select 0,_position];
319 };
320 };
321 };
322 };
323
324} forEach _vehicleArray;
325
326_scriptComplete = true;
327
328waitUntil
329{
330 diag_log format ["ExileServer - Finished spawning world vehicles"];
331 //["ExileServer - Finished spawning world vehicles"] call MAR_fnc_log;
332 _scriptComplete
333};