Advertisement
Guest User

cache_units.sqf

a guest
Apr 8th, 2015
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.83 KB | None | 0 0
  1. /**
  2.  
  3. Please take my Special Thanks,
  4. - RimBlock ( http://epochmod.com/forum/index.php?/user/12612-rimblock/ ) ***
  5. - MGM ( http://epochmod.com/forum/index.php?/user/16852-mgm/ )
  6.  
  7. Author: Martin ( http://epochmod.com/forum/index.php?/user/30755-ukmartin/ )
  8.  
  9.     This program is free software: you can redistribute it and/or modify
  10.     it under the terms of the GNU General Public License as published by
  11.     the Free Software Foundation, either version 1 of the License, or
  12.     (at your option) any later version.
  13.  
  14.     This program is distributed in the hope that it will be useful,
  15.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.     GNU General Public License for more details.
  18.  
  19.     You should have received a copy of the GNU General Public License
  20.     along with this program.  If not, see <http://www.gnu.org/licenses/>.
  21.  
  22. **/
  23. private ["_unitGroup","_countRange","_timeTillFreeze","_state","_stateFroze","_timeFroze","_matchingObjectsArray","_numberOfMatchingObjectsNumber","_playerCount"];
  24.  
  25. _unitGroup = _this select 0;
  26.  
  27. /**************************************/
  28. /**Range for Re-Activation*************/
  29. /****** Default: 800 ******************/
  30. _countRange = 800;
  31. /**************************************/
  32. /**************************************/
  33. /**Time untill units are Frozen again**/
  34. /************* Default: 30 ************/
  35. _timeTillFreeze = 30;
  36. /**************************************/
  37. /**************************************/
  38. /****** Log Actions to RPT File? ******/
  39. /*********** Default: true ************/
  40. freeze_log = true;
  41. /**************************************/
  42. /**************************************/
  43.  
  44.  
  45. /**
  46. fnc_freeze: Used to Freeze the Units of the Group
  47. Parameters: Unit Group (Type: Object / Group)
  48. Behaviour: For Each Unit of the given Group the AI will be disabled (force them to freeze)
  49. Addition: Set's a Variable with the time the AI is frozen and the state
  50. **/
  51. fnc_freeze = {
  52.     private ["_unitGroup"];
  53.     _unitGroup = _this select 0;
  54.    
  55.     if (freeze_log) then {
  56.         diag_log(format["[DEBUG] Freezing Units of Group: %1", _unitGroup]);
  57.     };
  58.    
  59.     {
  60.         _x disableAI "TARGET";
  61.         sleep 0.05;
  62.         _x disableAI "AUTOTARGET";
  63.         sleep 0.05;
  64.         _x disableAI "MOVE";
  65.         sleep 0.05;
  66.         _x disableAI "ANIM";
  67.         sleep 0.05;
  68.         _x disableAI "FSM";
  69.         sleep 0.05;
  70.     } foreach units _unitGroup;
  71.    
  72.     _unitGroup setVariable["FrozenState",[time,true],true];
  73. };
  74.  
  75. /**
  76. fnc_unfreeze: Used to Unfreeze the Units of the Group
  77. Parameters: Unit Group (Type: Object / Group)
  78. Behaviour: For Each Unit of the given Group the AI will be enabled
  79. Addition: Set's a Variable with the time the AI is Unfrozen and the state
  80. **/
  81. fnc_unfreeze = {
  82.     private ["_unitGroup"];
  83.     _unitGroup = _this select 0;
  84.    
  85.     if (freeze_log) then {
  86.         diag_log(format["[DEBUG] Un-Freezing Units of Group: %1", _unitGroup]);
  87.     };
  88.    
  89.     {
  90.         _x enableAI "TARGET";
  91.         sleep 0.05;
  92.         _x enableAI "AUTOTARGET";
  93.         sleep 0.05;
  94.         _x enableAI "MOVE";
  95.         sleep 0.05;
  96.         _x enableAI "ANIM";
  97.         sleep 0.05;
  98.         _x enableAI "FSM";
  99.         sleep 0.05;
  100.     } foreach units _unitGroup;
  101.    
  102.     _unitGroup setVariable["FrozenState",[time,false],true];
  103. };
  104.  
  105. //Call the Freeze Function, in Order to make the Units freeze
  106. [_unitGroup] spawn fnc_freeze;
  107.  
  108.  
  109. /**
  110. While {true}: Infinite Loop, that runs every 15 Seconds
  111. Parameters: None
  112. Behaviour: Counts nearby Units, if it found a Unit it will check if the Unit is a Player
  113. Behaviour: If the Unit is a Player, the Frozen Group will be defrosted.
  114. Behaviour: If there is no Player near that Group for _timeTillFreeze the AI will be frozen again
  115. Addition: None
  116. **/
  117. while {true} do {
  118.     _matchingObjectsArray = ((units _unitGroup) select 0) nearEntities ["CAManBase",_countRange];
  119.     _numberOfMatchingObjectsNumber = (count _matchingObjectsArray);
  120.    
  121.     if (_numberOfMatchingObjectsNumber >= 1) then {
  122.        
  123.         _state = _unitGroup getVariable["FrozenState",[time,true]];
  124.         _timeFroze = _state select 0;
  125.         _stateFroze = _state select 1;
  126.        
  127.         if (_stateFroze) then {
  128.        
  129.             {
  130.                 if (isPlayer _x) then {
  131.                    
  132.                     if (freeze_log) then {
  133.                         diag_log(format["[DEBUG] %1 Triggered Un-Freezing of Group: %2", _x, _unitGroup]);
  134.                     };
  135.                     [_unitGroup] spawn fnc_unfreeze;
  136.                    
  137.                 } else {
  138.                
  139.                     if (!_stateFroze && ((time - _timeFroze) > _timeTillFreeze)) then {
  140.            
  141.                         if (freeze_log) then {
  142.                             diag_log(format["[DEBUG] Re-Freezing Group: %1", _unitGroup]);
  143.                         };
  144.                        
  145.                         [_unitGroup] spawn fnc_freeze;
  146.                    
  147.                     };
  148.                 };
  149.                
  150.             } foreach _matchingObjectsArray;
  151.            
  152.         } else {
  153.            
  154.             if (!_stateFroze && ((time - _timeFroze) > _timeTillFreeze)) then {
  155.            
  156.                 if (freeze_log) then {
  157.                     diag_log(format["[DEBUG] Re-Freezing Group: %1", _unitGroup]);
  158.                 };
  159.                 [_unitGroup] spawn fnc_freeze;
  160.                
  161.             };
  162.            
  163.         };
  164.        
  165.     };
  166.    
  167.     sleep 15;
  168.    
  169. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement