Advertisement
Guest User

Untitled

a guest
Mar 30th, 2014
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.60 KB | None | 0 0
  1. private ["_maxControlledZombies","_looted","_zombied","_doNothing","_spawnZedRadius"];
  2.  
  3. // Global zed spawn flag - ^bdc
  4. if (dayz_DisableGlobalZedSpawn) exitWith {};
  5.  
  6. _age = -1;
  7. _position = getPosATL player;
  8. _spawnableObjects = ["building", "SpawnableWreck"];
  9. _speed = speed (vehicle player);
  10. _spawnZedRadius = dayz_LootZedSpawn_SpawnZedRadius;
  11.  
  12. //Current amounts
  13. // we start by the closest buildings.
  14. _nearby = nearestObjects [_position, _spawnableObjects,dayz_LootZedSpawn_MaxSpawnRange];
  15.  
  16. //Total Counts
  17. _maxlocalspawned = round(dayz_spawnZombies);
  18. _maxControlledZombies = round(dayz_maxLocalZombies);
  19. _maxWeaponHolders = dayz_LootZedSpawn_MaxWeaponHolders;
  20. _currentWeaponHolders = round(dayz_currentWeaponHolders);
  21.  
  22. //Limits (Land,Sea,Air)
  23. _inVehicle = (vehicle player != player);
  24. _isAir = vehicle player iskindof "Air";
  25. _isLand =  vehicle player iskindof "Land";
  26. _isSea =  vehicle player iskindof "Sea";
  27.  
  28. _doNothing = false;
  29.  
  30. /*
  31. if (_inVehicle) then {
  32.     //exit if too fast
  33.     if (_speed > 25) exitwith {_doNothing = true;};
  34.    
  35.     //Crew can spawn zeds.
  36.     _totalcrew = count (crew (vehicle player));
  37.     if (_totalcrew > 1) then {
  38.         _maxControlledZombies = _maxControlledZombies / 4;
  39.        
  40.         //Dont allow driver to spawn if we have other crew members.
  41.         if (player == driver (vehicle player)) exitwith {_doNothing = true;};
  42.     } else {
  43.         _maxControlledZombies = 6;
  44.     };
  45. };
  46. */
  47.  
  48. // Added vehicle properties for more precision in-vehicle spawning by ^bdc - variables referenced in init.sqf
  49. if (_inVehicle) then {
  50.     _vel = velocity (vehicle player);
  51.     _speed = (_vel distance [0,0,0]);
  52.     _vAltitude = ((getposATL vehicle player) select 2);  
  53.     //exit if too fast
  54.     //if (_speed > 25) exitwith {_doNothing = true;}; - ^bdc
  55.    
  56.     // Modified vehicle speed/altitude checks for spawning zed/loot by ^bdc
  57.     // Air vehicle check
  58.     if (_isAir and ((_speed > dayz_LootZedSpawn_MaxAirVehicleSpeed) or (_vAltitude > dayz_LootZedSpawn_MaxAirVehicleAltitude))) then {
  59.         _doNothing = true;
  60.     };
  61.     // Exclude spawn while in a plane?
  62.     if ((dayz_LootZedSpawn_ExcludePlanes) and (_vehicle isKindOf "plane")) then {
  63.         _doNothing = true;
  64.     };
  65.     // Ground vehicle check
  66.     if (!_isAir and (_speed > dayz_LootZedSpawn_MaxGroundVehicleSpeed)) then {
  67.         _doNothing = true;
  68.     };
  69.    
  70.     //Crew can spawn zeds.
  71.     _totalcrew = count (crew (vehicle player));
  72.     if (_totalcrew > 1) then {
  73.         _maxControlledZombies = _maxControlledZombies / 4;
  74.        
  75.     //Dont allow driver to spawn if we have other crew members.
  76.     if (player == driver (vehicle player)) exitwith {_doNothing = true;};
  77.     } else {
  78.         _maxControlledZombies = 6;
  79.     };
  80. };
  81.  
  82. if (_doNothing) exitwith {lastSpawned = diag_tickTime;};
  83.  
  84. //Make only 1/5 spawn along player's journey.
  85. _maxlocalspawned = _maxlocalspawned max floor(_maxControlledZombies*.8);
  86.  
  87. //
  88. if (_maxlocalspawned > 0) then { _spawnZedRadius = _spawnZedRadius * 3; };
  89.  
  90. // Spawn routine
  91. {
  92.     _type = typeOf _x;
  93.     //_config = configFile >> "CfgBuildingLoot" >> _type;
  94.     _config = missionConfigFile >> "CfgBuildingLoot" >> _type;
  95.     _canSpawn = isClass (_config);
  96.     _dis = _x distance player;
  97.     _checkLoot = ((count (getArray (_config >> "lootPos"))) > 0);
  98.     _islocal = _x getVariable ["", false]; // object created locally via TownGenerator. See stream_locationFill.sqf
  99.    
  100.     // If given area flagged as false, then include loot spawn as restricted spawn along with zed - ^bdc
  101.     _xpos = getPosATL _x;
  102.     // Change Z coordinate to 0 as workaround destroyed building bug - ^bdc
  103.     _newpos = [(_xpos select 0),(_xpos select 1),0];
  104.     if (count PreventZedSpawnPositions > 0) then { // variables.sqf
  105.         _count = count PreventZedSpawnPositions;
  106.         for "_y" from 0 to _count do {
  107.             _NoSpawnPos = PreventZedSpawnPositions select _y;
  108.             _NoSpawnDis = PreventZedSpawnDistances select _y;
  109.             _NoSpawnLoot = PreventZedSpawnLootInclusions select _y;
  110.             _SpawnDis = _NoSpawnPos distance _newpos;
  111.             if ((_SpawnDis <= _NoSpawnDis) and (_NoSpawnLoot)) then {
  112.                 _canSpawn = false; // skips entire loot/zed spawn routine below
  113.                 //diag_log format["Player_spawnCheck: NoSpawnLoot is %5; Prevent pos %1, Bldg pos %2, distance %3, NoSpawnDis %4",_NoSpawnPos,_newpos,_SpawnDis,_NoSpawnDis,_NoSpawnLoot];
  114.             };
  115.         };
  116.     };
  117.  
  118.     //Loot
  119.     if (_canSpawn) then {
  120.         if (_currentWeaponHolders < _maxWeaponHolders) then {
  121.             //Basic loot checks
  122.             //if ((_dis < 125) and (_dis > 30) and !_inVehicle and _checkLoot) then {
  123.             if ((_dis < dayz_LootZedSpawn_MaxLootSpawnDistance) and (_dis > dayz_LootZedSpawn_MinLootSpawnDistance) and _checkLoot and !(dayz_LootZedSpawn_DisableDynamicLootSpawn)) then {
  124.             /*
  125.                 //Get var Looted
  126.                 //[_object,name,defaultValue]
  127.                 PVDZ_receiveVar = [player,_x,"looted",-0.1];
  128.                 publicVariableServer "PVDZ_receiveVar";
  129.  
  130.                 _looted = (_x getVariable "looted");
  131.                     if (isNil "_looted") then {
  132.                         _looted = -0.1;
  133.                     };
  134.             */
  135.                 _looted = (_x getVariable ["looted",diag_tickTime]);          
  136.                 _age = (diag_tickTime - _looted);
  137.                 //diag_log ("SPAWN LOOT: " + _type + " Building is " + str(_age) + " old" );
  138.                
  139.                 // Added for permanent building loot (bypasses loot respawn timer) - ^bdc
  140.                 _spawnsomeloot = false;
  141.                 if (dayz_LootZedSpawn_PermanentLoot) then { // init.sqf
  142.                     if (_age == 0) then { _spawnsomeloot = true; };
  143.                 } else {
  144.                     if ((_age == 0) or (_age > dayz_LootZedSpawn_LootRespawnTimer)) then { _spawnsomeloot = true; };
  145.                 };
  146.  
  147.                 //if ((_age == 0) or (_age > dayz_LootZedSpawn_LootRespawnTimer)) then {
  148.                 if (_spawnsomeloot) then {
  149.                 /*
  150.                     //[object,name]
  151.                     PVDZ_serverStoreVar = [_x,"looted",(DateToNumber date)];
  152.                     publicVariableServer "PVDZ_serverStoreVar";
  153.                     sleep 0.01;
  154.                 */
  155.                     _x setVariable ["looted",diag_tickTime,!_islocal];                  
  156.                     _x call building_spawnLoot;
  157.                     if (!(_x in dayz_buildingBubbleMonitor)) then {
  158.                         //add active Building to var
  159.                         dayz_buildingBubbleMonitor set [count dayz_buildingBubbleMonitor, _x];
  160.                     };
  161.                 };
  162.             };
  163.         };
  164.    
  165.     //Zeds
  166.     // Check to see if zed are restricted in this area or not - ^bdc
  167.     _NoSpawnZed = false;
  168.     _xpos = getPosATL _x;
  169.     // Change Z coordinate to 0 as workaround destroyed building bug - ^bdc
  170.     _newpos = [(_xpos select 0),(_xpos select 1),0];
  171.     if (count PreventZedSpawnPositions > 0) then { // variables.sqf
  172.         _count = (count PreventZedSpawnPositions - 1);
  173.         for "_y" from 0 to _count do {
  174.             _NoSpawnPos = PreventZedSpawnPositions select _y;
  175.             _NoSpawnDis = PreventZedSpawnDistances select _y;
  176.             _SpawnDis = _NoSpawnPos distance _newpos;
  177.             //diag_log format["Player_spawnCheck: NoSpawnZed currently is %5; Prevent pos %1, Bldg pos %2, distance %3, NoSpawnDis %4 PreventZedSpawnPositions Count %6",_NoSpawnPos,_newpos,_SpawnDis,_NoSpawnDis,_NoSpawnZed,_count];
  178.             if (_SpawnDis <= _NoSpawnDis) then {
  179.                 _NoSpawnZed = true;
  180.                 //diag_log format["Player_spawnCheck: NoSpawn is true; Prevent pos %1, Bldg pos %2, distance %3, NoSpawnDis %4",_NoSpawnPos,_newpos,_SpawnDis,_NoSpawnDis];
  181.             };
  182.         };
  183.     };
  184.    
  185.     // Sarge AI Heli crash check - Let's make sure this spawned helicrash is not flagged for no zed spawn
  186.     if (_x isKindOf "SpawnableWreck") then {
  187.         _SargeHeliCrash = 0;
  188.         _SargeHeliCrash = _x getVariable ["Sarge",0];
  189.         if (_SargeHeliCrash == 1) then {
  190.             _NoSpawnZed = true;
  191.         };
  192.         _noZedSpawn = false;
  193.         _noZedSpawn = _x getVariable ["NoZedSpawn",false];
  194.         if (_noZedSpawn) then {
  195.             _NoSpawnZed = true;
  196.         };
  197.     };
  198.    
  199.         //if (_dis > _spawnZedRadius) then {
  200.         if ((_dis > _spawnZedRadius) and (!_NoSpawnZed)) then {
  201.             if ((dayz_spawnZombies < _maxControlledZombies) and (dayz_CurrentNearByZombies < dayz_maxNearByZombies) and (dayz_currentGlobalZombies < dayz_maxGlobalZeds)) then {
  202.             /*
  203.                 //[_object,name,defaultValue]
  204.                 PVDZ_receiveVar = [player,_x,"zombieSpawn",-0.1];
  205.                 publicVariableServer "PVDZ_receiveVar";
  206.                 sleep 0.01;
  207.                 _zombied = (_x getVariable "zombieSpawn");
  208.                     if (isNil "_zombied") then {
  209.                         _zombied = -0.1;
  210.                     };
  211.             */      
  212.                 _zombied = (_x getVariable ["zombieSpawn",diag_tickTime]);
  213.                 _age = (diag_tickTime - _zombied) * 525948; // in minutes
  214.                 //diag_log format ["Player_SpawnCheck: %4 - %5: %1, %2, %3, player pos %6", _zombied, diag_tickTime, _age, "spawnCheck", _x,_position];
  215.                 if ((_age == 0) or (_age > 300)) then {
  216.                     _bPos = getPosATL _x;
  217.                     _zombiesNum = {alive _x} count (_bPos nearEntities ["zZombie_Base",(((sizeOf _type) * 2) + 10)]);
  218.                     if (_zombiesNum == 0) then {
  219.                     /*
  220.                         //[object,name]
  221.                         PVDZ_serverStoreVar = [_x,"zombieSpawn",(DateToNumber date)];
  222.                         publicVariableServer "PVDZ_serverStoreVar";
  223.                     */  
  224.                         //diag_log format["Player_SpawnCheck.SQF: Passed NoZedSpawn Check; spawning zed at %1",_bPos];
  225.                         [_x] call building_spawnZombies;
  226.                         _x setVariable ["zombieSpawn",diag_tickTime,!_islocal];
  227.                         //waitUntil{scriptDone _handle};
  228.                         if (!(_x in dayz_buildingBubbleMonitor)) then {
  229.                             //add active zed to var
  230.                             dayz_buildingBubbleMonitor set [count dayz_buildingBubbleMonitor, _x];
  231.                         };
  232.                     };  
  233.                 };
  234.                 //diag_log (format["%1 building. %2", __FILE__, _x]);
  235.             };
  236.         };
  237.     };
  238. } forEach _nearby;
  239.  
  240. //Timer system to monitor if running.
  241. lastSpawned = diag_tickTime;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement