player2_dz

Untitled

Nov 22nd, 2014
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.92 KB | None | 0 0
  1. /*---------------------------------------------------------------------------
  2. Extra Zeds (Headless Client) by Player2
  3. www.ZombZ.net
  4. ---------------------------------------------------------------------------*/
  5.  
  6. //  Configuration
  7. P2DZ_HC_playerZedRadius =       150;    //Distance around the player we should check for zeds (meters)
  8. P2DZ_HC_maxZedsPerPlayer =      100;    //Max zeds around a player at a time (number)
  9. P2DZ_HC_zedRespawnTime  =       10;     //Time between checks for spawning new zeds (secs)
  10. P2DZ_HC_playerSpeedCap =        25;     //Past this speed the player won't spawn zeds (kmh)
  11. P2DZ_HC_debug   =               true;   //Enables logging outputs
  12.  
  13. //  Functions
  14. zombie_findTargetAgent =        compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\zombie_findTargetAgent.sqf";
  15. zombie_loiterHC =               compile preprocessFileLineNumbers "HC\zeds\zombie_loiterHC.sqf";
  16. zombie_generateHC =             compile preprocessFileLineNumbers "HC\zeds\zombie_generateHC.sqf";
  17. building_spawnZombiesHC =       compile preprocessFileLineNumbers "HC\zeds\building_spawnZombiesHC.sqf";
  18. wild_spawnZombiesHC =           compile preprocessFileLineNumbers "HC\zeds\wild_spawnZombiesHC.sqf";
  19. player2_spawnZedsHC =           compile preprocessFileLineNumbers "HC\zeds\player2_spawnZedsHC.sqf";
  20. nearest_player =                compile preprocessFileLineNumbers "HC\zeds\nearest_player.sqf";
  21.  
  22. //  Instructions
  23. private["_slp","_pos","_rd","_mz","_ms","_zc","_mn","_d"];
  24.  
  25. //Variable Initialization
  26. _zc =   0;
  27. _mn =   [];
  28. _pos =  [];
  29. _rd =   P2DZ_HC_playerZedRadius;
  30. _mz =   P2DZ_HC_maxZedsPerPlayer;
  31. _slp =  P2DZ_HC_zedRespawnTime;
  32. _ms =   P2DZ_HC_playerSpeedCap;
  33. _d =    P2DZ_HC_debug;
  34.  
  35. //Debugging output
  36. if (_d) then {
  37.     diag_log(format["P2HC:ZedSpawns: Initializing..."]);
  38.     diag_log(format["P2HC:ZedSpawns: "]);
  39.     diag_log(format["P2HC:ZedSpawns: Configuration: "]);
  40.     diag_log(format["P2HC:ZedSpawns: "]);
  41.     diag_log(format["P2HC:ZedSpawns: ZedCheckRadius:    %1",P2DZ_HC_playerZedRadius]);
  42.     diag_log(format["P2HC:ZedSpawns: MaxPerPlayer:      %1",P2DZ_HC_maxZedsPerPlayer]);
  43.     diag_log(format["P2HC:ZedSpawns: RespawnTimer:      %1",P2DZ_HC_zedRespawnTime]);
  44.     diag_log(format["P2HC:ZedSpawns: MaxSpeed:          %1",P2DZ_HC_playerSpeedCap]);
  45.     diag_log(format["P2HC:ZedSpawns: "]);
  46. };
  47.  
  48. if (_d) then { diag_log(format["P2HC:ZedSpawns: Waiting for BIS Functions..."]); };
  49.  
  50. //Wait for BIS Functions to load
  51. waitUntil {!isNil "BIS_fnc_init"};
  52.  
  53. if (_d) then { diag_log(format["P2HC:ZedSpawns: Loop Starting..."]); };
  54.  
  55. /* Main Loop */
  56. while {true} do {
  57.     if (_d) then { diag_log(format["P2HC:ZedSpawns: Loop has Awoken from its sleep..."]); };
  58.  
  59.     //for each Player on Server run zombie spawn check
  60.     {
  61.         _zc =    0; //reset zed count
  62.         _mn =   []; //reset nearby array
  63.         _pos =  []; //reset player pos
  64.  
  65.         if (_d) then { diag_log(format["P2HC:ZedSpawns: Loop: PlayerObj: %1, Alive: %2, Speed: %3, InDebug?: %4", (typeOf _x), (alive _x), (speed _x), !((getMarkerPos 'respawn_west') distance (position _x) > 3000)]); };
  66.        
  67.         //Check player is alive and not survivor1 or headless itself
  68.         if ({(_x != player) && _x != (vehicle player)} && {(alive _x) && ((typeOf _x) != "Survivor1_DZ")}) then {
  69.             //Check players speed
  70.             if (_ms > speed _x) then {
  71.                 //Check player is not in debug
  72.                 if ((getMarkerPos 'respawn_west') distance (position _x) > 3000) then {
  73.                     //Count All living zeds in radius
  74.                     _mn = (position _x) nearEntities ["CAManBase",_rd];
  75.                     { if (_x isKindof "zZombie_Base" && alive _x) then { _zc = _zc + 1; }; } foreach _mn;
  76.                     if (_d) then { diag_log(format["P2HC:ZedSpawns: Loop: PlayerPos: %1, ZedsNear: %2, SpawnMoreZed?: %3", (position _x), (_zc), ((_mz > _zc))]); };
  77.                     if (_mz > _zc) then {
  78.                         //Spawn Zeds
  79.                         [_x,_zc,_mz] call player2_spawnZedsHC;
  80.                     };
  81.                 };
  82.             };
  83.         };
  84.     } count playableUnits;
  85.  
  86.     if (_d) then { diag_log(format["P2HC:ZedSpawns: Loop Sleeping for %1 seconds",_slp]); };
  87.  
  88.     //Sleep for zed respawn time
  89.     uiSleep _slp;
  90. };
  91.  
  92. diag_log(format["P2HC:ZedSpawns: FATAL ERROR: While {true} Loop Ended!"])
Advertisement
Add Comment
Please, Sign In to add comment