Advertisement
Guest User

ff7_aiDistributor.sqf

a guest
Oct 18th, 2016
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 1.85 KB | None | 0 0
  1. /*
  2.     Author: Whigital
  3.  
  4.     AI Distribution script, based on ALIVE_fnc_AI_Distributor by Highhead.
  5.  
  6.     - Added dynamic detection of HCs.
  7.     - Variable to keep groups local on server (FF7_AI_Distributor_serverLocal).
  8.  
  9. */
  10.  
  11. private ["_alive_mod", "_alive_status", "_check_interval"];
  12.  
  13. _alive_main     = ((entities "ALiVE_require") select 0);
  14. _alive_status   = (_alive_main getVariable ["startupComplete", false]);
  15. _check_interval = 15;
  16.  
  17. ["ff7_aiDistributor", "Waiting for ALiVE to initialize ...."] call FF7_fnc_debugLog;
  18.  
  19. while {!_alive_status} do
  20. {
  21.     sleep 10;
  22.  
  23.     _alive_status = (_alive_main getVariable ["startupComplete", false]);
  24. };
  25.  
  26. sleep 60;
  27.  
  28. ["ff7_aiDistributor", "Starting group distribution"] call FF7_fnc_debugLog;
  29.  
  30. FF7_AI_Distributor = [_check_interval] spawn
  31. {
  32.     params ["_interval", 30];
  33.  
  34.     private ["_currHC", "_hcIndex"];
  35.  
  36.     FF7_AI_Distributor_enabled = true;
  37.  
  38.     while {FF7_AI_Distributor_enabled} do
  39.     {
  40.         FF7_AI_Distributor_HCList = [];
  41.  
  42.         _hcIndex = 0;
  43.  
  44.         {
  45.             if ((typeOf _x) == "HeadlessClient_F") then
  46.             {
  47.                 FF7_AI_Distributor_HCList pushBack _x;
  48.             };
  49.         } forEach allPlayers;
  50.  
  51.         {
  52.             if ((count FF7_AI_Distributor_HCList) == 0) exitWith {};
  53.  
  54.             if (local _x && {{alive _x && {!((vehicle _x) getVariable ["ALiVE_CombatSupport", false])}} count units _x > 0}) then
  55.             {
  56.                 if !(_x getVariable ["FF7_AI_Distributor_serverLocal", false]) then
  57.                 {
  58.                     if (_hcIndex > ((count FF7_AI_Distributor_HCList) - 1)) then
  59.                     {
  60.                         _hcIndex = 0;
  61.                     };
  62.  
  63.                     _currHC = (FF7_AI_Distributor_HCList select _hcIndex);
  64.                    
  65.                     _hcIndex = _hcIndex + 1;
  66.  
  67.                     _x setGroupOwner (owner _currHC);
  68.  
  69.                     ["ff7_aiDistributor", (format ["Group '%1' with %2 units transferred to HC %3", _x, (count (units _x)), (name _currHC)])] call FF7_fnc_debugLog;
  70.                 };
  71.             };
  72.  
  73.             sleep 1;
  74.  
  75.         } foreach allGroups;
  76.  
  77.         sleep _interval;
  78.     };
  79. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement