Advertisement
secondcoming

ExileServer_world_spawnVehicles.sqf

Sep 20th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 3.51 KB | None | 0 0
  1. private _debugMarkers       = ((getNumber(configFile >> "CfgSettings" >> "VehicleSpawn" >> "vehiclesDebugMarkers")) isEqualTo 1);
  2. private _vehicleClassNames = getArray (configFile >> "CfgSettings" >> "VehicleSpawn" >> "ground");
  3. private _maximumDamage  = getNumber (configFile >> "CfgSettings" >> "VehicleSpawn" >> "maximumDamage");
  4. private _damageChance       = getNumber (configFile >> "CfgSettings" >> "VehicleSpawn" >> "damageChance");
  5.  
  6.  
  7. private _max                = 40;
  8. private _count              = 0;
  9.  
  10. private _middle             = worldSize/2;
  11. private _pos            = [_middle,_middle,0];
  12. private _maxDist            = _middle;
  13. positionToUse               = [0,0,0];
  14.  
  15. if (worldName == 'Namalsk') then
  16. {
  17.     _max = 30; 
  18. };
  19.  
  20. // Get position of nearest roads
  21. private _nearRoads          = _pos nearRoads _maxDist;
  22.  
  23. for "_i" from 1 to _max do
  24. {  
  25.     private _vehicleToSpawn = (_vehicleClassNames) call BIS_fnc_selectRandom;
  26.     private _validspot      = false;
  27.     while{!_validspot} do
  28.     {
  29.         private _selectedRoad = (_nearRoads) call BIS_fnc_selectRandom;
  30.         //diag_log format["[Random Vehicle Spawning]: Selected road %1 (%2)",_selectedRoad,time];
  31.        
  32.         private _road = position _selectedRoad;
  33.         private _startPosition = [_road select 0, _road select 1, 0];
  34.  
  35.         private _position = _startPosition findEmptyPosition [0,25,_vehicleToSpawn];
  36.        
  37.         if(!isNil "_position" && (count _position != 0)) then
  38.         {
  39.             _validspot = true;
  40.  
  41.             //Check if near player territory
  42.             private _nearBase = (nearestObjects [_position,["Exile_Construction_Flag_Static"],500]) select 0;
  43.             if (!isNil "_nearBase") then { _validspot = false;  }; 
  44.  
  45.             // Don't spawn AI near traders and spawn zones
  46.             {
  47.                 switch (getMarkerType _x) do
  48.                 {
  49.                     case "ExileSpawnZone":
  50.                     {
  51.                         if(_position distance (getMarkerPos _x) < 1500) exitWith
  52.                         {
  53.                             _validspot = false;                        
  54.                         };
  55.                     };
  56.                     case "ExileTraderZone":
  57.                     {
  58.                         if(_position distance (getMarkerPos _x) < 1500) exitWith
  59.                         {
  60.                             _validspot = false;                        
  61.                         };
  62.                     };
  63.                 };
  64.             }
  65.             forEach allMapMarkers;
  66.             //diag_log format["[Random Vehicle Spawning]: valid spot found from %1 @ %2 (%3)",_startPosition,_position,time];
  67.             positionToUse = _position;
  68.         };
  69.     };
  70.  
  71.    
  72.     private _vehicle = [_vehicleToSpawn, positionToUse, random 360, true] call ExileServer_object_vehicle_createNonPersistentVehicle;
  73.  
  74.     // Add items to vehicle
  75.     clearMagazineCargoGlobal _vehicle;
  76.     clearWeaponCargoGlobal _vehicle;
  77.     clearItemCargoGlobal _vehicle;
  78.  
  79.     _vehicle addItemCargoGlobal     ["Exile_Item_DuctTape", (random 1)];
  80.     _vehicle addItemCargoGlobal     ["Exile_Item_InstaDoc", (random 1)];
  81.     _vehicle addItemCargoGlobal     ["Exile_Item_PlasticBottleFreshWater", (random 2)];
  82.     _vehicle addItemCargoGlobal     ["Exile_Item_EMRE", (random 2)];
  83.            
  84.    
  85.     private _hitpoints = (getAllHitPointsDamage _vehicle) select 0;
  86.     {
  87.         if ((random 75) < _damageChance) then
  88.         {
  89.             _vehicle setHitPointDamage [_x, random (_maximumDamage)];
  90.         };
  91.     } forEach _hitpoints;
  92.    
  93.     if (_debugMarkers) then
  94.     {
  95.         private _debugMarker = createMarker ["vehicleMarker#"+str _count, positionToUse];
  96.         _debugMarker setMarkerColor "ColorOrange";
  97.         _debugMarker setMarkerType "mil_dot_noShadow";
  98.     };
  99.        
  100.     private _logDetail = format["[Random Vehicle Spawning]: creating vehicle %1 @  %2 (%3)",_vehicleToSpawn,positionToUse,time];
  101.     diag_log _logDetail;
  102.    
  103.     _count = _count + 1;
  104. };
  105.  
  106. format ["[Random Vehicle Spawning]: Vehicles Spawned: %1", _count] call ExileServer_util_log;
  107. true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement