· 9 years ago · Oct 19, 2016, 10:24 PM
1uiSleep 30;
2
3diag_log ["ExileServer - Spawning persistent vehicle spawns"];
4//["ExileServer - Spawning world persistent vehicles"] call MAR_fnc_log;
5
6private ["_count","_uid","_debugForSP","_vehicle","_vehicleArray","_count","_vehicleClass","_position","_positionCount","_pinCode","_vehicleObject","_nearVehicles","_nearVechicleCount","_marker","_cancelSpawn","_isRandomRoadPos","_road","_scriptComplete"];
7
8_scriptComplete = false;
9_debugForSP = false; // If true , when the script is run in the editor it will create markers on the vehicle spawns.
10
11_uid = "12345"; // Needs to be a valid UID that exists in the account table (best to use a server owners uid)
12
13/*
14 How the vehicle array works -
15
16
17 Select 0 - Vehicle class name
18 Select 1 - Number - amount limit, will only maintain this many vehicles on the server
19 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
20 Select 3 - Boolean - If true, will spawn the vehicle on a random road, if false, will look to the positions above.
21
22
23*/
24
25
26_vehicleArray =
27[
28 // Quads
29 ["Exile_Bike_QuadBike_Black",1,[],true],
30 ["Exile_Bike_QuadBike_Blue",1,[],true],
31 ["Exile_Bike_QuadBike_Red",1,[],true],
32 ["Exile_Bike_QuadBike_White",1,[],true],
33 ["Exile_Bike_QuadBike_Nato",1,[],true],
34 ["Exile_Bike_QuadBike_Fia",1,[],true],
35 ["Exile_Bike_QuadBike_Guerilla01",1,[],true],
36 ["Exile_Bike_QuadBike_Guerilla02",1,[],true],
37 // Vans
38 ["Exile_Car_Van_Box_Black",1,[],true],
39 // Offroads
40 ["Exile_Car_Offroad_White",1,[],true],
41 ["Exile_Car_Offroad_Rusty1",1,[],true],
42 ["Exile_Car_Offroad_Rusty2",1,[],true],
43 ["Exile_Car_Offroad_Rusty3",1,[],true],
44 ["Exile_Car_Offroad_Armed_Guerilla01",1,[],true],
45 // Hatchbacks
46 ["Exile_Car_Hatchback_Green",1,[],true],
47 ["Exile_Car_Hatchback_Grey",1,[],true],
48 // Hatchback sports
49 ["Exile_Car_Hatchback_Sport_Red",1,[],true],
50 ["Exile_Car_Hatchback_Sport_Blue",1,[],true],
51 ["Exile_Car_Hatchback_Sport_Orange",1,[],true],
52 // SUV
53 ["Exile_Car_SUV_Red",1,[],true],
54 ["Exile_Car_SUV_Black",1,[],true],
55 ["Exile_Car_SUV_Grey",1,[],true],
56 ["Exile_Car_SUV_Orange",1,[],true],
57 ["Exile_Car_SUV_Rusty1",1,[],true],
58 ["Exile_Car_SUV_Rusty2",1,[],true],
59 ["Exile_Car_SUV_Rusty3",1,[],true],
60 // SUV XL
61 ["Exile_Car_SUVXL_Black",1,[],true],
62 // UAZ
63 ["Exile_Car_UAZ_Green",1,[],true],
64 // Tractor
65 ["Exile_Car_OldTractor_Red",1,[],true],
66 // Volha
67 ["Exile_Car_Volha_Blue",1,[],true],
68 ["Exile_Car_Volha_White",1,[],true],
69 ["Exile_Car_Volha_Black",1,[],true],
70 // Bus
71 ["Exile_Car_Ikarus_Blue",1,[],true],
72 ["Exile_Car_Ikarus_Party",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 // V3S
81 ["Exile_Car_V3S_Covered",1,[],true],
82 ["Exile_Car_V3S_Open",1,[],true],
83 // HMMWV
84 ["Exile_Car_HMMWV_UNA_Green",1,[],true],
85 // Land rovers
86 ["Exile_Car_LandRover_Red",1,[],true],
87 ["Exile_Car_LandRover_Urban",1,[],true],
88 ["Exile_Car_LandRover_Green",1,[],true],
89 ["Exile_Car_LandRover_Sand",1,[],true],
90 ["Exile_Car_LandRover_Desert",1,[],true],
91 // Choppers
92 ["Exile_Chopper_Hellcat_Green",1,[],true],
93 ["Exile_Chopper_Hummingbird_Green",1,[],true],
94 ["Exile_Chopper_Mohawk_FIA",1,[],true],
95 ["Exile_Chopper_Orca_CSAT",1,[],true],
96 ["Exile_Chopper_Huey_Armed_Desert",1,[[10529.669922,2272.835449,13.584515]],false]
97];
98
99{
100 for "_i" from 0 to (_x select 1) do
101 {
102 _cancelSpawn = false;
103 _obj = _x select 0;
104 _count = count allMissionObjects _obj;
105 _positionCount = (count (_x select 2));
106 _isRandomRoadPos = _x select 3;
107
108 if !(_count >= _x select 1) then
109 {
110 _vehicleClass = _x select 0;
111 _position = selectRandom (_x select 2);
112
113 if !(_isRandomRoadPos) then
114 {
115 _foundSafePos = false;
116 _failSafe = 15;
117 _checks = 0;
118 waitUntil
119 {
120 _position = selectRandom (_x select 2);
121 _nearVehicles = nearestObjects [_position, ["car","air"], 10];
122 _nearVechicleCount = count _nearVehicles;
123 if (_nearVechicleCount == 0) then
124 {
125 _foundSafePos = true;
126 };
127 _checks = _checks + 1;
128 if (_checks >= _failSafe) then {_cancelSpawn = true; _foundSafePos = true;};
129 _foundSafePos
130 };
131 }
132 else
133 {
134 _foundSafePos = false;
135 waitUntil
136 {
137 _spawnCenter = getArray(configFile >> "CfgWorlds" >> worldName >> "centerPosition"); //Center of your map
138 _min = 15; // minimum distance from the center position (Number) in meters
139 _max = 30000; // maximum distance from the center position (Number) in meters
140 _mindist = 5; // minimum distance from the nearest object (Number) in meters, ie. spawn at least this distance away from anything within x meters..
141 _water = 0; // water mode 0: cannot be in water , 1: can either be in water or not , 2: must be in water
142 _shoremode = 0; // 0: does not have to be at a shore , 1: must be at a shore
143 _blackList = [[[0, 0],[0,0]]];
144
145 _startPosRoad = [_spawnCenter,_min,_max,_mindist,_water,10,_shoremode,_blackList] call BIS_fnc_findSafePos; //Find random spot on the map
146 _onRoadCheck = _startPosRoad nearRoads 100; //Find road objects 100m from spot
147 _countPossibleRoads = count _onRoadCheck; // count road objects
148
149 if (_countPossibleRoads == 0) then
150 {
151 }
152 else
153 {
154 _road = _onRoadCheck select 0;
155 _position = getPos _road;
156 _foundSafePos = true;
157 };
158 uiSleep 0.1;
159 _foundSafePos
160 };
161 };
162 if !(_cancelSpawn) then
163 {
164 if !(_debugForSP) then
165 {
166 _pinCode = format ["%1%2%3%4",round (random 8 +1),round (random 8 +1),round (random 8 +1),round (random 8 +1)];
167 _vehicleObject = [_vehicleClass, _position, (random 360), true,_pinCode] call ExileServer_object_vehicle_createPersistentVehicle;
168 _damage = (floor(random 75) + 1)/100;
169 _fuel = (floor(random 25) + 1)/100;
170 _vehicleObject setDamage _damage;
171 _vehicleObject setFuel _fuel;
172
173 if !((_x select 0) isKindOf "AIR") then
174 {
175 _wheels = ["HitLF2Wheel","HitLFWheel","HitRFWheel","HitRF2Wheel"];
176 {
177 if (random 1 > 0.5) then
178 {
179 _vehicleObject setHitPointDamage [_x,1];
180 };
181 } forEach _wheels;
182 };
183 _vehicleObject setVariable ["ExileOwnerUID", _uid];
184 _vehicleObject setVariable ["ExileIsLocked",0];
185 _vehicleObject lock 0;
186 _vehicleObject call ExileServer_object_vehicle_database_insert;
187 _vehicleObject call ExileServer_object_vehicle_database_update;
188
189 diag_log format ["[Event: Persistent Spawns] -- Spawned a %1 at location: %2 -- Max allowed: %3",_x select 0,_position, _x select 1];
190 //[format["[Event: Persistent Spawns] -- Spawned a %1 at location: %2 -- Max allowed: %3",_x select 0,_position, _x select 1]] call MAR_fnc_log;
191 }
192 else
193 {
194 _vehicleObject = createVehicle [_vehicleClass,_position,[], 0, "NONE"];
195
196 if !((_x select 0) isKindOf "AIR") then
197 {
198 _wheels = ["HitLF2Wheel","HitLFWheel","HitRFWheel","HitRF2Wheel"];
199 {
200 _vehicleObject setHitPointDamage [_x,1];
201 } forEach _wheels;
202 };
203
204 _marker = createMarker [format["HeliCrash%1", diag_tickTime], _position];
205 _marker setMarkerType "mil_dot";
206 _marker setMarkerText "Vehicle";
207 };
208 }
209 else
210 {
211 if !(_debugForSP) then
212 {
213
214 //[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;
215 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];
216 }
217 else
218 {
219 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];
220 };
221 };
222 };
223 };
224
225} forEach _vehicleArray;
226
227_scriptComplete = true;
228
229waitUntil
230{
231 diag_log format ["ExileServer - Finished spawning world vehicles"];
232 //["ExileServer - Finished spawning world vehicles"] call MAR_fnc_log;
233 _scriptComplete
234};