Advertisement
Guest User

cache_units.sqf

a guest
Apr 8th, 2015
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.37 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. - Gr8 ( http://epochmod.com/forum/index.php?/user/15884-gr8/ )
  7. - halvhjearne ( http://epochmod.com/forum/index.php?/user/10011-halvhjearne/ ) PS: God sake, that name is hard to write!
  8.  
  9.  
  10. Author: Martin ( http://epochmod.com/forum/index.php?/user/30755-ukmartin/ )
  11.  
  12.     This program is free software: you can redistribute it and/or modify
  13.     it under the terms of the GNU General Public License as published by
  14.     the Free Software Foundation, either version 1 of the License, or
  15.     (at your option) any later version.
  16.  
  17.     This program is distributed in the hope that it will be useful,
  18.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20.     GNU General Public License for more details.
  21.  
  22.     You should have received a copy of the GNU General Public License
  23.     along with this program.  If not, see <http://www.gnu.org/licenses/>.
  24.  
  25. **/
  26. private ["_unitGroup","_countRange","_timeTillFreeze","_state","_stateFroze","_timeFroze","_matchingObjectsArray","_numberOfMatchingObjectsNumber","_playerCount"];
  27.  
  28. _unitGroup = _this select 0;
  29.  
  30. /**************************************/
  31. /**Range for Re-Activation*************/
  32. /****** Default: 800 ******************/
  33. _countRange = 800;
  34. /**************************************/
  35. /**************************************/
  36. /**Time untill units are Frozen again**/
  37. /************* Default: 30 ************/
  38. _timeTillFreeze = 30;
  39. /**************************************/
  40. /**************************************/
  41. /****** Log Actions to RPT File? ******/
  42. /*********** Default: true ************/
  43. freeze_log = true;
  44. /**************************************/
  45. /**************************************/
  46. /******** Unassign Waypoints?  ********/
  47. /*********** Default: false ***********/
  48. unassign_waypoints = false;
  49. /**************************************/
  50. /**************************************/
  51. /******** Randomize Position?  ********/
  52. /******** Distance to Randomize *******/
  53. /*********** Default: true ************/
  54. /*********** Distance: 20 *************/
  55. randomize_position = true;
  56. randomize_distance = 20;
  57. /**************************************/
  58. /**************************************/
  59. /********** Hide un-used AI?  *********/
  60. /*********** Default: true ************/
  61. hide_ai = true;
  62. /**************************************/
  63. /**************************************/
  64.  
  65. /**
  66. fnc_freeze: Used to Freeze the Units of the Group
  67. Parameters: Unit Group (Type: Object / Group)
  68. Behaviour: For Each Unit of the given Group the AI will be disabled (force them to freeze)
  69. Addition: Set's a Variable with the time the AI is frozen and the state
  70. **/
  71. fnc_freeze = {
  72.     private ["_unitGroup","_nic"];
  73.     _unitGroup = _this select 0;
  74.    
  75.     if (freeze_log) then {
  76.         diag_log(format["[DEBUG] Freezing Units of Group: %1", _unitGroup]);
  77.     };
  78.    
  79.     {
  80.         _x disableAI "TARGET";
  81.         sleep 0.05;
  82.         _x disableAI "AUTOTARGET";
  83.         sleep 0.05;
  84.         _x disableAI "MOVE";
  85.         sleep 0.05;
  86.         _x disableAI "ANIM";
  87.         sleep 0.05;
  88.         if (unassign_waypoints) then {
  89.             _x disableAI "FSM";
  90.             sleep 0.05;
  91.         };
  92.        
  93.         if (hide_ai) then {
  94.             //_x hideObjectGlobal true;
  95.             _nic = [nil, _x, "per", rHideObject, true ] call RE;
  96.         };
  97.        
  98.     } foreach units _unitGroup;
  99.    
  100.     _unitGroup setVariable["FrozenState",[time,true],true];
  101. };
  102.  
  103. /**
  104. fnc_unfreeze: Used to Unfreeze the Units of the Group
  105. Parameters: Unit Group (Type: Object / Group)
  106. Behaviour: For Each Unit of the given Group the AI will be enabled
  107. Addition: Set's a Variable with the time the AI is Unfrozen and the state
  108. **/
  109. fnc_unfreeze = {
  110.     private ["_unitGroup","_posX","_posY","_posZ","_pos","_nic"];
  111.     _unitGroup = _this select 0;
  112.    
  113.     if (freeze_log) then {
  114.         diag_log(format["[DEBUG] Un-Freezing Units of Group: %1", _unitGroup]);
  115.     };
  116.    
  117.     {
  118.         _x enableAI "TARGET";
  119.         sleep 0.05;
  120.         _x enableAI "AUTOTARGET";
  121.         sleep 0.05;
  122.         _x enableAI "MOVE";
  123.         sleep 0.05;
  124.         _x enableAI "ANIM";
  125.         sleep 0.05;
  126.        
  127.         if (unassign_waypoints) then {
  128.             _x enableAI "FSM";
  129.             sleep 0.05;
  130.         };
  131.        
  132.         if (randomize_position) then {
  133.             _pos = getPos _x;
  134.             _posX = _pos select 0;
  135.             _posY = _pos select 1;
  136.             _posZ = _pos select 2;
  137.             _posX = _posX + round(random randomize_distance);
  138.             _posY = _posY + round(random randomize_distance);
  139.             sleep 0.05;
  140.             _x setPos [_posX,_posY,_posZ];
  141.             sleep 0.05;
  142.         };
  143.        
  144.         if (hide_ai) then {
  145.             //_x hideObjectGlobal false;
  146.             _nic = [nil, _x, "per", rHideObject, false ] call RE;
  147.         };
  148.        
  149.     } foreach units _unitGroup;
  150.    
  151.     _unitGroup setVariable["FrozenState",[time,false],true];
  152. };
  153.  
  154. //Call the Freeze Function, in Order to make the Units freeze
  155. [_unitGroup] spawn fnc_freeze;
  156.  
  157.  
  158. /**
  159. While {true}: Infinite Loop, that runs every 15 Seconds
  160. Parameters: None
  161. Behaviour: Counts nearby Units, if it found a Unit it will check if the Unit is a Player
  162. Behaviour: If the Unit is a Player, the Frozen Group will be defrosted.
  163. Behaviour: If there is no Player near that Group for _timeTillFreeze the AI will be frozen again
  164. Addition: None
  165. **/
  166. while {true} do {
  167.     _matchingObjectsArray = ((units _unitGroup) select 0) nearEntities ["CAManBase",_countRange];
  168.     _numberOfMatchingObjectsNumber = (count _matchingObjectsArray);
  169.    
  170.     if (_numberOfMatchingObjectsNumber >= 1) then {
  171.        
  172.         _state = _unitGroup getVariable["FrozenState",[time,true]];
  173.         _timeFroze = _state select 0;
  174.         _stateFroze = _state select 1;
  175.        
  176.         if (_stateFroze) then {
  177.        
  178.             {
  179.                 if (isPlayer _x) then {
  180.                    
  181.                     if (freeze_log) then {
  182.                         diag_log(format["[DEBUG] %1 Triggered Un-Freezing of Group: %2", _x, _unitGroup]);
  183.                     };
  184.                     [_unitGroup] spawn fnc_unfreeze;
  185.                    
  186.                 } else {
  187.                
  188.                     if (!_stateFroze && ((time - _timeFroze) > _timeTillFreeze)) then {
  189.            
  190.                         if (freeze_log) then {
  191.                             diag_log(format["[DEBUG] Re-Freezing Group: %1", _unitGroup]);
  192.                         };
  193.                        
  194.                         [_unitGroup] spawn fnc_freeze;
  195.                    
  196.                     };
  197.                 };
  198.                
  199.             } foreach _matchingObjectsArray;
  200.            
  201.         } else {
  202.            
  203.             if (!_stateFroze && ((time - _timeFroze) > _timeTillFreeze)) then {
  204.            
  205.                 if (freeze_log) then {
  206.                     diag_log(format["[DEBUG] Re-Freezing Group: %1", _unitGroup]);
  207.                 };
  208.                 [_unitGroup] spawn fnc_freeze;
  209.                
  210.             };
  211.            
  212.         };
  213.        
  214.     };
  215.    
  216.     sleep 15;
  217.    
  218. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement