· 7 years ago · Sep 18, 2018, 07:30 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"];
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 = "76561197982307357"; // 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",2,[[9604.18,2664.24,0.000457764]],false],
48 ["Exile_Bike_QuadBike_Csat",2,[],true],
49 ["Exile_Bike_OldBike",1,[],true],
50 // Vans
51 ["Exile_Car_Van_Box_Black",2,[],true],
52 // Offroads
53 ["Exile_Car_Offroad_White",2,[],true],
54 ["Exile_Car_Offroad_Rusty1",2,[],true],
55 ["Exile_Car_Offroad_Armed_Guerilla01",1,[],true],
56 // Hatchbacks
57 ["Exile_Car_MB4WDOpen",2,[],true],
58 ["Exile_Car_MB4WD",2,[],true],
59 // Hatchback sports
60 ["Exile_Car_Hatchback_Sport_Red",1,[],true],
61 ["Exile_Car_ProwlerLight",1,[],true],
62 ["Exile_Car_ProwlerUnarmed",1,[],true],
63 // SUV
64 ["Exile_Car_QilinUnarmed",1,[],true],
65 ["Exile_Car_SUV_Black",1,[],true],
66 ["Exile_Car_SUV_Grey",1,[],true],
67 ["Exile_Car_SUV_Orange",1,[],true],
68 // Volha
69 ["Exile_Car_Volha_Blue",1,[],true],
70 ["Exile_Car_Volha_White",1,[],true],
71 ["Exile_Car_Volha_Black",1,[],true],
72 // Bus
73 ["Exile_Car_Ikarus_Blue",1,[],true],
74 // Zamak
75 ["Exile_Car_Zamak",1,[],true],
76 // Urals
77 ["Exile_Car_Ural_Covered_Blue",1,[],true],
78 ["Exile_Car_Ural_Covered_Yellow",1,[],true],
79 ["Exile_Car_Ural_Covered_Worker",1,[],true],
80 ["Exile_Car_Ural_Covered_Military",1,[],true],
81 // Land rovers
82 ["Exile_Car_LandRover_Red",1,[],true],
83 ["Exile_Car_LandRover_Urban",1,[],true],
84 ["Exile_Car_LandRover_Green",1,[],true],
85 ["Exile_Car_LandRover_Sand",1,[],true],
86 ["Exile_Car_LandRover_Desert",1,[],true],
87 // Choppers
88
89 ["Exile_Chopper_Hellcat_Green",1,[[23483.9,21144.8,0],[25240.1,21828.6,0]],false],
90 ["Exile_Chopper_Hummingbird_Green",1,[[12834.2,16735.8,0],[23079.8,7299.1,0]],false],
91 ["Exile_Chopper_Mohawk_FIA",1,[[17550.5,13240.5,0],[26783.6,24673,0]],false],
92 ["Exile_Chopper_Orca_CSAT",1,[[3732.07,12976.3,20]],false]
93];
94
95{
96 for "_i" from 0 to (_x select 1) do
97 {
98 _cancelSpawn = false;
99 _obj = _x select 0;
100 _count = count allMissionObjects _obj;
101 _positionCount = (count (_x select 2));
102 _isRandomRoadPos = _x select 3;
103
104 if !(_count >= _x select 1) then
105 {
106 _vehicleClass = _x select 0;
107 _position = selectRandom (_x select 2);
108
109 if !(_isRandomRoadPos) then
110 {
111 _foundSafePos = false;
112 _failSafe = 15;
113 _checks = 0;
114 waitUntil
115 {
116 _position = selectRandom (_x select 2);
117 _nearVehicles = nearestObjects [_position, ["car","air"], 10];
118 _nearVechicleCount = count _nearVehicles;
119 if (_nearVechicleCount == 0) then
120 {
121 _foundSafePos = true;
122 };
123 _checks = _checks + 1;
124 if (_checks >= _failSafe) then {_cancelSpawn = true; _foundSafePos = true;};
125 _foundSafePos
126 };
127 }
128 else
129 {
130 _foundSafePos = false;
131 waitUntil
132 {
133 _spawnCenter = getArray(configFile >> "CfgWorlds" >> worldName >> "centerPosition"); //Center of your map
134 _min = 15; // minimum distance from the center position (Number) in meters
135 _max = 30000; // maximum distance from the center position (Number) in meters
136 _mindist = 5; // minimum distance from the nearest object (Number) in meters, ie. spawn at least this distance away from anything within x meters..
137 _water = 0; // water mode 0: cannot be in water , 1: can either be in water or not , 2: must be in water
138 _shoremode = 0; // 0: does not have to be at a shore , 1: must be at a shore
139 _blackList = [[[0, 0],[0,0]]];
140
141 _startPosRoad = [_spawnCenter,_min,_max,_mindist,_water,10,_shoremode,_blackList] call BIS_fnc_findSafePos; //Find random spot on the map
142 _onRoadCheck = _startPosRoad nearRoads 100; //Find road objects 100m from spot
143 _countPossibleRoads = count _onRoadCheck; // count road objects
144
145 if (_countPossibleRoads == 0) then
146 {
147 }
148 else
149 {
150 _road = _onRoadCheck select 0;
151 _position = getPos _road;
152 _foundSafePos = true;
153 };
154 uiSleep 0.1;
155 _foundSafePos
156 };
157 };
158 if !(_cancelSpawn) then
159 {
160 if !(_debugForSP) then
161 {
162 _pinCode = format ["%1%2%3%4",round (random 8 +1),round (random 8 +1),round (random 8 +1),round (random 8 +1)];
163 _vehicleObject = [_vehicleClass, _position, (random 360), true,_pinCode] call ExileServer_object_vehicle_createPersistentVehicle;
164 _vehicleObject setDamage 0.8;
165 _vehicleObject setFuel 0;
166
167 if !((_x select 0) isKindOf "AIR") then
168 {
169 _wheels = ["HitLF2Wheel","HitLFWheel","HitRFWheel","HitRF2Wheel"];
170 {
171 if (random 1 > 0.5) then
172 {
173 _vehicleObject setHitPointDamage [_x,1];
174 };
175 } forEach _wheels;
176 };
177 _vehicleObject setVariable ["ExileOwnerUID", _uid];
178 _vehicleObject setVariable ["ExileIsLocked",0];
179 _vehicleObject lock 0;
180 _vehicleObject call ExileServer_object_vehicle_database_insert;
181 _vehicleObject call ExileServer_object_vehicle_database_update;
182
183 //diag_log format ["[Event: Persistent Spawns] -- Spawned a %1 at location: %2 -- Max allowed: %3",_x select 0,_position, _x select 1];
184 //[format["[Event: Persistent Spawns] -- Spawned a %1 at location: %2 -- Max allowed: %3",_x select 0,_position, _x select 1]] call MAR_fnc_log;
185 }
186 else
187 {
188 _vehicleObject = createVehicle [_vehicleClass,_position,[], 0, "NONE"];
189
190 if !((_x select 0) isKindOf "AIR") then
191 {
192 _wheels = ["HitLF2Wheel","HitLFWheel","HitRFWheel","HitRF2Wheel"];
193 {
194 _vehicleObject setHitPointDamage [_x,1];
195 } forEach _wheels;
196 };
197
198 _marker = createMarker [format["HeliCrash%1", diag_tickTime], _position];
199 _marker setMarkerType "mil_dot";
200 _marker setMarkerText "Vehicle";
201 };
202 }
203 else
204 {
205 if !(_debugForSP) then
206 {
207 //[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;
208 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];
209 }
210 else
211 {
212 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];
213 };
214 };
215 };
216 };
217
218} forEach _vehicleArray;
219
220_scriptComplete = true;
221
222waitUntil
223{
224 diag_log format ["ExileServer - Finished spawning world vehicles"];
225 //["ExileServer - Finished spawning world vehicles"] call MAR_fnc_log;
226 _scriptComplete
227};