Advertisement
secondcoming

Occupation.sqf

Mar 15th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 4.77 KB | None | 0 0
  1. ////////////////////////////////////////////////////////////////////////
  2. //
  3. //      Server Occupation script by second_coming
  4. //      http://www.exilemod.com/profile/60-second_coming/
  5. //
  6. //      This script uses the fantastic DMS by Defent and eraser1
  7. //
  8. //      http://www.exilemod.com/topic/61-dms-defents-mission-system/
  9. //
  10. ////////////////////////////////////////////////////////////////////////
  11.  
  12. if (!isServer) exitWith {};
  13. diag_log format ["[OCCUPATION]:: Starting Occupation Monitor"];
  14.  
  15. _middle = worldSize/2;
  16. _spawnCenter    = [_middle,_middle,0];
  17. _max = _middle;
  18.  
  19. _maxAIcount = 100;
  20.  
  21. if (worldName == 'Chernarus') then
  22. {
  23.     _maxAIcount = 80;
  24. };
  25. if (worldName == 'Namalsk') then
  26. {
  27.     _maxAIcount = 60;
  28. };
  29.  
  30. _minFPS = 15;
  31. _debug = false;
  32.  
  33. _currentPlayerCount = count playableUnits;
  34. if(_currentPlayerCount > 10) then
  35. {
  36.     _maxAIcount = _maxAIcount - _currentPlayerCount ;
  37. };
  38.  
  39. // Don't spawn additional AI if the server fps is below 8
  40. if(diag_fps < _minFPS) exitWith { diag_log format ["[OCCUPATION]:: Held off spawning more AI as the server FPS is only %1",diag_fps]; };
  41.  
  42. _aiActive = count(_spawnCenter nearEntities ["O_recon_F", 20000]);
  43. if(_aiActive > _maxAIcount) exitWith { diag_log format ["[OCCUPATION]:: %1 active AI, so not spawning AI this time",_aiActive]; };
  44.  
  45. _locations = (nearestLocations [_spawnCenter, ["NameVillage","NameCity", "NameCityCapital"], _max]);
  46. {
  47.     _okToSpawn = true;
  48.     _temppos = position _x;
  49.     _locationName = text _x;
  50.     _locationType = type _x;
  51.     _pos = [_temppos select 0, _temppos select 1, 0];
  52.    
  53.     if(_debug) then { diag_log format ["[OCCUPATION]:: Testing location name: %1 position: %2",_locationName,_pos];};
  54.    
  55.     while{_okToSpawn} do
  56.     {
  57.            
  58.         // Percentage chance to spawn (roll 80 or more to spawn AI)
  59.         _spawnChance = round (random 100);
  60.         if(_spawnChance < 80) exitWith { _okToSpawn = false; if(_debug) then { diag_log format ["[OCCUPATION]:: Rolled %1 so not spawning AI this time",_spawnChance,_locationName];};};
  61.            
  62.         // Don't spawn if too near a player base
  63.         _nearBase = (nearestObjects [_pos,["Exile_Construction_Flag_Static"],500]) select 0;
  64.         if (!isNil "_nearBase") exitwith { _okToSpawn = false; if(_debug) then { diag_log format ["[OCCUPATION]:: %1 is too close to player base",_locationName];};};
  65.        
  66.         // Don't spawn AI near traders and spawn zones
  67.         _nearestMarker = [allMapMarkers, _pos] call BIS_fnc_nearestPosition; // Nearest Marker to the Location     
  68.         _posNearestMarker = getMarkerPos _nearestMarker;
  69.         if(_pos distance _posNearestMarker < 500) exitwith { _okToSpawn = false; if(_debug) then { diag_log format ["[OCCUPATION]:: %1 is too close to a %2",_locationName,_nearestMarker];}; };
  70.        
  71.         // Don't spawn additional AI if there are already AI in range
  72.         _aiNear = count(_pos nearEntities ["O_recon_F", 500]);
  73.         if(_aiNear > 0) exitwith { _okToSpawn = false; if(_debug) then { diag_log format ["[OCCUPATION]:: %1 already has %2 active AI patrolling",_locationName,_aiNear];}; };
  74.  
  75.         // Don't spawn additional AI if there are players in range
  76.         if([_pos, 200] call ExileClient_util_world_isAlivePlayerInRange) exitwith { _okToSpawn = false; if(_debug) then { diag_log format ["[OCCUPATION]:: %1 has players too close",_locationName];}; };
  77.        
  78.         if(_okToSpawn) then
  79.         {
  80.             //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  81.             // Get AI to patrol the town
  82.             //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  83.             _aiCount = 1;
  84.             _groupRadius = 100;
  85.             if(_locationType isEqualTo "NameCityCapital") then { _aiCount = 4 + (round (random 5)) - _aiNear; _groupRadius = 300; };
  86.             if(_locationType isEqualTo "NameCity") then { _aiCount = 2 + (round (random 3)) - _aiNear; _groupRadius = 200; };
  87.             if(_locationType isEqualTo "NameVillage") then { _aiCount = 1 + (round (random 2)) - _aiNear; _groupRadius = 100; };
  88.                
  89.             if(_aiCount < 1) then { _aiCount = 1; };
  90.             _difficulty = "random";
  91.             _side = "bandit";
  92.             _spawnPos = [_pos,10,100,5,0,20,0] call BIS_fnc_findSafePos;       
  93.             _spawnPosition = [_spawnPos select 0, _spawnPos select 1,0];
  94.            
  95.             DMS_ai_use_launchers = false;
  96.             _group = [_spawnPosition, _aiCount, _difficulty, "random", _side] call DMS_fnc_SpawnAIGroup;
  97.             DMS_ai_use_launchers = true;
  98.                        
  99.             // Get the AI to shut the fuck up :)
  100.             enableSentences false;
  101.             enableRadio false;
  102.            
  103.             [_group, _pos, _groupRadius] call bis_fnc_taskPatrol;
  104.             _group setBehaviour "SAFE";
  105.             _group setCombatMode "RED";
  106.             //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  107.             diag_log format ["[OCCUPATION]:: Spawning %2 AI in at %3 to patrol %1",_locationName,_aiCount,_spawnPosition];
  108.             _okToSpawn = false;    
  109.         };
  110.    
  111.     };
  112. } forEach _locations;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement