kleinToHCs.sqf 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * kleinToHCs.sqf
  3. *
  4. * In the mission editor, name the Headless Clients "HC1", "HC2", "HC3" without the quotes
  5. *
  6. * In the mission init.sqf, call kleinToHCs.sqf with:
  7. * execVM "kleinToHCs.sqf";
  8. *
  9. * It seems that the dedicated server and headless client processes never use more than 20-22% CPU each.
  10. * With a dedicated server and 3 headless clients, that's about 88% CPU with 10-12% left over. Far more efficient use of your processing power.
  11. *
  12. */
  13. if (!isServer) exitWith {};
  14. diag_log "kleinToHCs: Started";
  15. //waitUntil {!isNil "HC1_1"};
  16. //waitUntil {!isNull HC1_1};
  17. //_HC_ID = -1; // Will become the Client ID of HC
  18. //_HC2_ID = -1; // Will become the Client ID of HC2
  19. //_HC3_ID = -1; // Will become the Client ID of HC3
  20. diag_log format["kleinToHCs: First pass will begin in %1 seconds", rebalanceTimer];
  21. [] spawn {
  22. rebalanceTimer = 120; // Rebalance sleep timer in seconds
  23. cleanUpThreshold = 50; // Threshold of number of dead bodies + destroyed vehicles before forcing a clean up
  24. while {true} do {
  25. // Rebalance every rebalanceTimer seconds to avoid hammering the server
  26. sleep rebalanceTimer;
  27. // Force clean up dead bodies and destroyed vehicles
  28. if (count allDead > cleanUpThreshold) then {
  29. _numDeleted = 0;
  30. {
  31. deleteVehicle _x;
  32. _numDeleted = _numDeleted + 1;
  33. } forEach allDead;
  34. diag_log format ["kleinToHCs: Cleaned up %1 dead bodies/destroyed vehicles", _numDeleted];
  35. };
  36. };
  37. };