NoX_NWO

persistent_vehicles

Aug 1st, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.21 KB | None | 0 0
  1. uiSleep 30;
  2.  
  3. diag_log ["ExileServer - Spawning persistent vehicle spawns"];
  4. //["ExileServer - Spawning world persistent vehicles"] call MAR_fnc_log;
  5.  
  6. private ["_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 = "76561197974176270"; // 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. Select 0 - Vehicle class name
  16. Select 1 - Number - amount limit, will only maintain this many vehicles on the server
  17. 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
  18. Select 3 - Boolean - If true, will spawn the vehicle on a random road, if false, will look to the positions above.
  19. */
  20.  
  21. _vehicleArray =
  22. [
  23. // Quads
  24. ["Exile_Bike_QuadBike_Black",10,[],true],
  25. ["Exile_Bike_QuadBike_Csat",10,[],true],
  26. // Vans
  27. ["Exile_Car_Van_Box_Black",5,[],true],
  28. // Offroads
  29. ["Exile_Car_Offroad_White",5,[],true],
  30. ["Exile_Car_Offroad_Rusty1",5,[],true],
  31. // Hatchbacks
  32. ["Exile_Car_MB4WDOpen",2,[],true],
  33. ["Exile_Car_MB4WD",2,[],true],
  34. // Hatchback sports
  35. ["Exile_Car_Hatchback_Sport_Red",1,[],true],
  36. ["Exile_Car_ProwlerLight",2,[],true],
  37. ["Exile_Car_ProwlerUnarmed",2,[],true],
  38. // SUV
  39. ["Exile_Car_QilinUnarmed",2,[],true],
  40. ["Exile_Car_SUV_Black",1,[],true],
  41. ["Exile_Car_SUV_Grey",1,[],true],
  42. ["Exile_Car_SUV_Orange",1,[],true],
  43. // Volha
  44. ["Exile_Car_Volha_Blue",1,[],true],
  45. ["Exile_Car_Volha_White",1,[],true],
  46. ["Exile_Car_Volha_Black",1,[],true],
  47. // Bus
  48. ["Exile_Car_Ikarus_Blue",1,[],true],
  49. // Zamak
  50. ["Exile_Car_Zamak",1,[],true],
  51. // Urals
  52. ["Exile_Car_Ural_Covered_Blue",1,[],true],
  53. ["Exile_Car_Ural_Covered_Yellow",1,[],true],
  54. ["Exile_Car_Ural_Covered_Worker",1,[],true],
  55. ["Exile_Car_Ural_Covered_Military",1,[],true],
  56. // Land rovers
  57. ["Exile_Car_LandRover_Red",1,[],true],
  58. ["Exile_Car_LandRover_Urban",1,[],true],
  59. ["Exile_Car_LandRover_Green",1,[],true],
  60. // Choppers
  61. ["Exile_Chopper_Hellcat_Green",1,[],true],
  62. ["Exile_Chopper_Hummingbird_Green",1,[],true],
  63. ["Exile_Chopper_Orca_CSAT",1,[],true]
  64. ];
  65.  
  66. {
  67. for "_i" from 0 to (_x select 1) do
  68. {
  69. _cancelSpawn = false;
  70. _obj = _x select 0;
  71. _count = count allMissionObjects _obj;
  72. _positionCount = (count (_x select 2));
  73. _isRandomRoadPos = _x select 3;
  74.  
  75. if !(_count >= _x select 1) then
  76. {
  77. _vehicleClass = _x select 0;
  78. _position = selectRandom (_x select 2);
  79.  
  80. if !(_isRandomRoadPos) then
  81. {
  82. _foundSafePos = false;
  83. _failSafe = 15;
  84. _checks = 0;
  85. waitUntil
  86. {
  87. _position = selectRandom (_x select 2);
  88. _nearVehicles = nearestObjects [_position, ["car","air"], 10];
  89. _nearVechicleCount = count _nearVehicles;
  90. if (_nearVechicleCount == 0) then
  91. {
  92. _foundSafePos = true;
  93. };
  94. _checks = _checks + 1;
  95. if (_checks >= _failSafe) then {_cancelSpawn = true; _foundSafePos = true;};
  96. _foundSafePos
  97. };
  98. }
  99. else
  100. {
  101. _foundSafePos = false;
  102. waitUntil
  103. {
  104. _spawnCenter = getArray(configFile >> "CfgWorlds" >> worldName >> "centerPosition"); //Center of your map
  105. _min = 30; // minimum distance from the center position (Number) in meters
  106. _max = 40000; // maximum distance from the center position (Number) in meters
  107. _mindist = 5; // minimum distance from the nearest object (Number) in meters, ie. spawn at least this distance away from anything within x meters..
  108. _water = 0; // water mode 0: cannot be in water , 1: can either be in water or not , 2: must be in water
  109. _shoremode = 0; // 0: does not have to be at a shore , 1: must be at a shore
  110. _blackList = [[[0, 0],[0,0]]];
  111.  
  112. _startPosRoad = [_spawnCenter,_min,_max,_mindist,_water,10,_shoremode,_blackList] call BIS_fnc_findSafePos; //Find random spot on the map
  113. _onRoadCheck = _startPosRoad nearRoads 100; //Find road objects 100m from spot
  114. _countPossibleRoads = count _onRoadCheck; // count road objects
  115.  
  116. if (_countPossibleRoads == 0) then
  117. {
  118. }
  119. else
  120. {
  121. _road = _onRoadCheck select 0;
  122. _position = getPos _road;
  123. _foundSafePos = true;
  124. };
  125. uiSleep 0.1;
  126. _foundSafePos
  127. };
  128. };
  129. if !(_cancelSpawn) then
  130. {
  131. if !(_debugForSP) then
  132. {
  133. _pinCode = format ["%1%2%3%4",round (random 8 +1),round (random 8 +1),round (random 8 +1),round (random 8 +1)];
  134. _vehicleObject = [_vehicleClass, _position, (random 360), true,_pinCode] call ExileServer_object_vehicle_createPersistentVehicle;
  135. _vehicleObject setDamage 0.8;
  136. _vehicleObject setFuel 0;
  137.  
  138. if !((_x select 0) isKindOf "AIR") then
  139. {
  140. _wheels = ["HitLF2Wheel","HitLFWheel","HitRFWheel","HitRF2Wheel"];
  141. {
  142. if (random 1 > 0.5) then
  143. {
  144. _vehicleObject setHitPointDamage [_x,1];
  145. };
  146. } forEach _wheels;
  147. };
  148. _vehicleObject setVariable ["ExileOwnerUID", _uid];
  149. _vehicleObject setVariable ["ExileIsLocked",0];
  150. _vehicleObject lock 0;
  151. _vehicleObject call ExileServer_object_vehicle_database_insert;
  152. _vehicleObject call ExileServer_object_vehicle_database_update;
  153.  
  154. diag_log format ["[Event: Persistent Spawns] -- Spawned a %1 at location: %2 -- Max allowed: %3",_x select 0,_position, _x select 1];
  155. //[format["[Event: Persistent Spawns] -- Spawned a %1 at location: %2 -- Max allowed: %3",_x select 0,_position, _x select 1]] call MAR_fnc_log;
  156. }
  157. else
  158. {
  159. _vehicleObject = createVehicle [_vehicleClass,_position,[], 0, "NONE"];
  160.  
  161. if !((_x select 0) isKindOf "AIR") then
  162. {
  163. _wheels = ["HitLF2Wheel","HitLFWheel","HitRFWheel","HitRF2Wheel"];
  164. {
  165. _vehicleObject setHitPointDamage [_x,1];
  166. } forEach _wheels;
  167. };
  168.  
  169. _marker = createMarker [format["HeliCrash%1", diag_tickTime], _position];
  170. _marker setMarkerType "mil_dot";
  171. _marker setMarkerText "Vehicle";
  172. };
  173. }
  174. else
  175. {
  176. if !(_debugForSP) then
  177. {
  178. //[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;
  179. 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];
  180. }
  181. else
  182. {
  183. 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];
  184. };
  185. };
  186. };
  187. };
  188.  
  189. } forEach _vehicleArray;
  190.  
  191. _scriptComplete = true;
  192.  
  193. waitUntil
  194. {
  195. diag_log format ["ExileServer - Finished spawning world vehicles"];
  196. //["ExileServer - Finished spawning world vehicles"] call MAR_fnc_log;
  197. _scriptComplete
  198. };
Advertisement
Add Comment
Please, Sign In to add comment