· 8 years ago · Jun 01, 2018, 11:54 PM
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","_groundDamageChance","_groundMaximumDamage"];
28
29_scriptComplete = false;
30_debugForSP = true; // If true , when the script is run in the editor it will create markers on the vehicle spawns.
31
32_uid = "76561198039527862"; // Needs to be a valid UID that exists in the account table (best to use a server owners uid)
33
34_vehicleItemsAllowed = getNumber (configFile >> "CfgSettings" >> "VehicleSpawn" >> "vehicleItemsAllowed");
35_allowedItems = getArray (configFile >> "CfgSettings" >> "VehicleSpawn" >> "allowedItems");
36_maximumItemsPerVehicle = getNumber (configFile >> "CfgSettings" >> "VehicleSpawn" >> "maximumItemsPerVehicle");
37_maximumItemsPerVehicle = _maximumItemsPerVehicle +1;
38
39_groundDamageChance = getNumber (configFile >> "CfgSettings" >> "VehicleSpawn" >> "groundDamageChance");
40_groundMaximumDamage = getNumber (configFile >> "CfgSettings" >> "VehicleSpawn" >> "groundMaximumDamage");
41
42/*
43 How the vehicle array works -
44
45 Select 0 - Vehicle class name
46 Select 1 - Number - amount limit, will only maintain this many vehicles on the server
47 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
48 Select 3 - Boolean - If true, will spawn the vehicle on a random road, if false, will look to the positions above.
49
50*/
51
52_vehicleArray =
53[
54 //Cars&Trucks Civil
55 ["Exile_Car_Lada_Hipster",2,[],true],
56 ["Exile_Car_Lada_Green",2,[],true],
57 ["volha_Civ_03",2,[],true],
58 ["Octavia_Civ_03",2,[],true],
59 ["Exile_Car_SUVXL_Black",2,[],true],
60 ["SUV_civ_04",2,[],true],
61 ["C_Offroad_01_F",2,[],true],
62 ["DDR_Car_MB4WDOpen",2,[],true],
63 ["C_Offroad_02_unarmed_F",2,[],true],
64 ["C_SUV_01_F",2,[],true],
65 ["Exile_Car_Golf_Black",2,[],true],
66 ["C_Hatchback_01_sport_F",2,[],true],
67 ["C_Hatchback_01_F",2,[],true],
68 ["Ikarus_Govnodav_01",2,[],true],
69 ["C_Van_01_box_F",2,[],true],
70 ["C_Van_02_vehicle_F",2,[],true],
71 ["RHS_Ural_Open_Civ_01",2,[],true],
72 ["RHS_Ural_Civ_02",2,[],true],
73 //Cars Miliary Low
74 ["rhssaf_un_uaz_open",1,[],true],
75 ["rhsgref_un_uaz",1,[],true],
76 ["UAZ_Base",1,[],true],
77 ["rhsgref_nat_uaz",1,[],true],
78 ["rhsgref_cdf_b_reg_uaz_open",1,[],true],
79 ["rhsgref_cdf_b_reg_uaz",1,[],true],
80 ["B_G_Offroad_01_F",1,[],true],
81 ["O_G_Offroad_01_F",1,[],true],
82 //Cars Miliary High
83 ["rhsusf_m998_w_s_2dr_fulltop",1,[],true],
84 ["rhsusf_m1025_w_s",1,[],true],
85 ["rhsusf_m1025_w",1,[],true],
86 ["rhsusf_m998_w_4dr_halftop",1,[],true],
87 ["rhsusf_m998_w_4dr_fulltop",1,[],true],
88 ["rhsusf_m998_w_4dr",1,[],true],
89 ["rhsgref_hidf_M998_4dr_halftop",1,[],true],
90 ["rhsgref_hidf_m998_4dr",1,[],true],
91 ["rhsgref_hidf_M998_4dr_fulltop",1,[],true],
92 ["rhsgref_hidf_m1025",1,[],true],
93 ["rhsusf_rg33_usmc_wd",1,[],true],
94 ["rhsgref_BRDM2UM",1,[],true],
95 ["rhsgref_BRDM2UM_msv",1,[],true],
96 ["rhs_tigr_m_3camo_vmf",1,[],true],
97 ["rhs_tigr_3camo_vdv",1,[],true],
98 ["rhs_tigr_m_vdv",1,[],true],
99 ["rhs_tigr_msv",1,[],true],
100 //Tanks Unarmed
101 ["rhsusf_m113_usarmy_unarmed",1,[],true],
102 //Cars Military Armed
103 ["rhsusf_rg33_m2_usmc_wd",1,[],true],
104 ["rhsgref_BRDM2_HQ",1,[],true],
105 ["rhsgref_BRDM2_HQ_msv",1,[],true],
106 ["rhs_tigr_sts_vdv",1,[],true],
107 ["rhsgref_ins_uaz_dshkm",1,[],true],
108 ["rhsusf_m1025_w_m2",1,[],true],
109 ["rhsusf_m1025_w_mk19",1,[],true],
110 ["Exile_Car_Offroad_Armed_Guerilla09",1,[],true],
111 //Trucks Military Armed
112 ["rhsusf_M1078A1P2_B_M2_WD_fmtv_usarmy",1,[],true],
113 ["rhsusf_M1078A1P2_B_M2_WD_flatbed_fmtv_usarmy",1,[],true],
114 //Trucks Military
115 ["rhsgref_un_ural",1,[],true],
116 ["rhsusf_M977A4_usarmy_wd",1,[],true],
117 ["rhsusf_M1078A1P2_B_WD_CP_fmtv_usarmy",1,[],true],
118 ["rhsusf_M1078A1P2_B_WD_fmtv_usarmy",1,[],true],
119 ["rhsusf_M1084A1P2_WD_fmtv_usarmy",1,[],true],
120 ["rhsusf_M1083A1P2_WD_fmtv_usarmy",1,[],true],
121 ["rhsgref_cdf_b_ural_open",2,[],true],
122 ["rhsgref_cdf_b_ural",1,[],true],
123 ["rhsgref_cdf_b_gaz66o",2,[],true],
124 ["rhsgref_cdf_b_gaz66_flat",1,[],true],
125 ["rhsgref_cdf_b_gaz66",1,[],true],
126 ["Exile_Car_Van_Guerilla07",1,[],true],
127 ["rhs_kamaz5350_msv",1,[],true],
128 ["rhs_kamaz5350_open_msv",1,[],true],
129 ["rhs_kamaz5350_flatbed_cover_msv",1,[],true],
130 ["rhs_gaz66_vv",1,[],true],
131 // Choppers
132 ["Exile_Chopper_Hellcat_Green",3,[[4802.56,10243.9,5.00714],[5059.92,2385.6,10.003],[12225.4,12604.1,-0.00332642]],false],
133 ["Exile_Chopper_Hummingbird_Green",4,[[4976.39,2407.29,5.00132],[4716.86,2590.72,13.6383],[12022.1,12797,5.12157],[12240.8,12590.1,0.00131226]],false]
134 //["Exile_Chopper_Mohawk_FIA",1,[[17550.5,13240.5,0],[26783.6,24673,0]],false],
135 //["Exile_Chopper_Orca_CSAT",1,[[3732.07,12976.3,20]],false]*/
136];
137
138{
139 for "_i" from 0 to (_x select 1) do
140 {
141 _cancelSpawn = false;
142 _obj = _x select 0;
143 _count = count allMissionObjects _obj;
144 _positionCount = (count (_x select 2));
145 _isRandomRoadPos = _x select 3;
146
147 if !(_count >= _x select 1) then
148 {
149 _vehicleClass = _x select 0;
150 _position = selectRandom (_x select 2);
151
152 if !(_isRandomRoadPos) then
153 {
154 _foundSafePos = false;
155 _failSafe = 15;
156 _checks = 0;
157 waitUntil
158 {
159 _position = selectRandom (_x select 2);
160 _nearVehicles = nearestObjects [_position, ["car","air"], 10];
161 _nearVechicleCount = count _nearVehicles;
162 if (_nearVechicleCount == 0) then
163 {
164 _foundSafePos = true;
165 };
166 _checks = _checks + 1;
167 if (_checks >= _failSafe) then {_cancelSpawn = true; _foundSafePos = true;};
168 _foundSafePos
169 };
170 }
171 else
172 {
173 _foundSafePos = false;
174 waitUntil
175 {
176 _spawnCenter = [7652.9634, 7870.8076,0]; //Center of your map
177 _min = 250; // minimum distance from the center position (Number) in meters
178 _max = 10000; // maximum distance from the center position (Number) in meters
179 _mindist = 15; // minimum distance from the nearest object (Number) in meters, ie. spawn at least this distance away from anything within x meters..
180 _water = 0; // water mode 0: cannot be in water , 1: can either be in water or not , 2: must be in water
181 _shoremode = 0; // 0: does not have to be at a shore , 1: must be at a shore
182 _blackList = [[[0, 0],[0,0]]];
183
184 _startPosRoad = [_spawnCenter,_min,_max,_mindist,_water,10,_shoremode,_blackList] call BIS_fnc_findSafePos; //Find random spot on the map
185 _onRoadCheck = _startPosRoad nearRoads 100; //Find road objects 100m from spot
186 _countPossibleRoads = count _onRoadCheck; // count road objects
187
188 if (_countPossibleRoads == 0) then
189 {
190 }
191 else
192 {
193 _road = _onRoadCheck select 0;
194 _position = getPos _road;
195 _foundSafePos = true;
196 };
197 uiSleep 0.1;
198 _foundSafePos
199 };
200 };
201 if !(_cancelSpawn) then
202 {
203 if !(_debugForSP) then
204 {
205 _pinCode = format ["%1%2%3%4",round (random 8 +1),round (random 8 +1),round (random 8 +1),round (random 8 +1)];
206 _vehicleObject = [_vehicleClass, _position, (random 360), true,_pinCode] call ExileServer_object_vehicle_createPersistentVehicle;
207 _hitpointsData = getAllHitPointsDamage _vehicleobject;
208
209 if !(_hitpointsData isEqualTo []) then {
210 _hitpoints = _hitpointsData select 0;{
211 if ((random 100) < _groundDamageChance) then{
212 _vehicleobject setHitPointDamage [_x, random _groundMaximumDamage];
213 };
214 }forEach _hitpoints;
215 };
216 _vehicleObject setVariable ["ExileOwnerUID", _uid];
217 _vehicleObject setVariable ["ExileIsLocked",0];
218 _vehicleObject lock 0;
219 _vehicleObject call ExileServer_object_vehicle_database_insert;
220 _vehicleObject call ExileServer_object_vehicle_database_update;
221
222 clearWeaponCargoGlobal _vehicleObject;
223 clearMagazineCargoGlobal _vehicleObject;
224 clearItemCargoGlobal _vehicleObject;
225 clearBackpackCargoGlobal _vehicleObject;
226
227 if (_vehicleItemsAllowed isEqualTo 1) then {
228 _itemsAdded = 0;
229 _itemsPerVehicle = floor (random _maximumItemsPerVehicle);
230 while{_itemsAdded < _itemsPerVehicle} do {
231 _itemAdd = _allowedItems select (floor (random (count _allowedItems)));
232 _cargoType = _itemAdd call ExileClient_util_cargo_getType;
233 switch (_cargoType) do {
234 case 1: { _vehicleObject addMagazineAmmoCargo [_itemAdd, 1, 1]; };
235 case 2: { _vehicleObject addWeaponCargoGlobal [_itemAdd, 1]; };
236 case 3: { _vehicleObject addBackpackCargoGlobal [_itemAdd, 1]; };
237 default { _vehicleObject addItemCargoGlobal [_itemAdd, 1, 1]; };
238 };
239 _itemsAdded = _itemsAdded + 1;
240 };
241 };
242 diag_log format ["[Event: Persistent Spawns] -- Spawned a %1 at location: %2 -- Max allowed: %3",_x select 0,_position, _x select 1];
243 //[format["[Event: Persistent Spawns] -- Spawned a %1 at location: %2 -- Max allowed: %3",_x select 0,_position, _x select 1]] call MAR_fnc_log;
244 }
245 else
246 {
247 _vehicleObject = createVehicle [_vehicleClass,_position,[], 0, "NONE"];
248 _hitpointsData = getAllHitPointsDamage _vehicleobject;
249
250 if !(_hitpointsData isEqualTo []) then {
251 _hitpoints = _hitpointsData select 0;{
252 if ((random 100) < _groundDamageChance) then{
253 _vehicleobject setHitPointDamage [_x, random _groundMaximumDamage];
254 };
255 }forEach _hitpoints;
256 };
257
258 clearWeaponCargoGlobal _vehicleObject;
259 clearMagazineCargoGlobal _vehicleObject;
260 clearItemCargoGlobal _vehicleObject;
261 clearBackpackCargoGlobal _vehicleObject;
262
263 if (_vehicleItemsAllowed isEqualTo 1) then {
264 _itemsAdded = 0;
265 _itemsPerVehicle = floor (random _maximumItemsPerVehicle);
266 while{_itemsAdded < _itemsPerVehicle} do {
267 _itemAdd = _allowedItems select (floor (random (count _allowedItems)));
268 _cargoType = _itemAdd call ExileClient_util_cargo_getType;
269 switch (_cargoType) do {
270 case 1: { _vehicleObject addMagazineAmmoCargo [_itemAdd, 1, 1]; };
271 case 2: { _vehicleObject addWeaponCargoGlobal [_itemAdd, 1]; };
272 case 3: { _vehicleObject addBackpackCargoGlobal [_itemAdd, 1]; };
273 default { _vehicleObject addItemCargoGlobal [_itemAdd, 1, 1]; };
274 };
275 _itemsAdded = _itemsAdded + 1;
276 };
277 };
278 _marker = createMarker [format["HeliCrash%1", diag_tickTime], _position];
279 _marker setMarkerType "mil_dot";
280 _marker setMarkerText "Vehicle";
281 };
282 }
283 else
284 {
285 if !(_debugForSP) then
286 {
287 //[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;
288 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];
289 }
290 else
291 {
292 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];
293 };
294 };
295 };
296 };
297
298} forEach _vehicleArray;
299
300_scriptComplete = true;
301
302waitUntil
303{
304 diag_log format ["ExileServer - Finished spawning world vehicles"];
305 //["ExileServer - Finished spawning world vehicles"] call MAR_fnc_log;
306 _scriptComplete
307};