Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- Please take my Special Thanks,
- - RimBlock ( http://epochmod.com/forum/index.php?/user/12612-rimblock/ ) ***
- - MGM ( http://epochmod.com/forum/index.php?/user/16852-mgm/ )
- Author: Martin ( http://epochmod.com/forum/index.php?/user/30755-ukmartin/ )
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 1 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- **/
- private ["_unitGroup","_countRange","_timeTillFreeze","_state","_stateFroze","_timeFroze","_matchingObjectsArray","_numberOfMatchingObjectsNumber","_playerCount"];
- _unitGroup = _this select 0;
- /**************************************/
- /**Range for Re-Activation*************/
- /****** Default: 800 ******************/
- _countRange = 800;
- /**************************************/
- /**************************************/
- /**Time untill units are Frozen again**/
- /************* Default: 30 ************/
- _timeTillFreeze = 30;
- /**************************************/
- /**************************************/
- /****** Log Actions to RPT File? ******/
- /*********** Default: true ************/
- freeze_log = true;
- /**************************************/
- /**************************************/
- /**
- fnc_freeze: Used to Freeze the Units of the Group
- Parameters: Unit Group (Type: Object / Group)
- Behaviour: For Each Unit of the given Group the AI will be disabled (force them to freeze)
- Addition: Set's a Variable with the time the AI is frozen and the state
- **/
- fnc_freeze = {
- private ["_unitGroup"];
- _unitGroup = _this select 0;
- if (freeze_log) then {
- diag_log(format["[DEBUG] Freezing Units of Group: %1", _unitGroup]);
- };
- {
- _x disableAI "TARGET";
- sleep 0.05;
- _x disableAI "AUTOTARGET";
- sleep 0.05;
- _x disableAI "MOVE";
- sleep 0.05;
- _x disableAI "ANIM";
- sleep 0.05;
- _x disableAI "FSM";
- sleep 0.05;
- } foreach units _unitGroup;
- _unitGroup setVariable["FrozenState",[time,true],true];
- };
- /**
- fnc_unfreeze: Used to Unfreeze the Units of the Group
- Parameters: Unit Group (Type: Object / Group)
- Behaviour: For Each Unit of the given Group the AI will be enabled
- Addition: Set's a Variable with the time the AI is Unfrozen and the state
- **/
- fnc_unfreeze = {
- private ["_unitGroup"];
- _unitGroup = _this select 0;
- if (freeze_log) then {
- diag_log(format["[DEBUG] Un-Freezing Units of Group: %1", _unitGroup]);
- };
- {
- _x enableAI "TARGET";
- sleep 0.05;
- _x enableAI "AUTOTARGET";
- sleep 0.05;
- _x enableAI "MOVE";
- sleep 0.05;
- _x enableAI "ANIM";
- sleep 0.05;
- _x enableAI "FSM";
- sleep 0.05;
- } foreach units _unitGroup;
- _unitGroup setVariable["FrozenState",[time,false],true];
- };
- //Call the Freeze Function, in Order to make the Units freeze
- [_unitGroup] spawn fnc_freeze;
- /**
- While {true}: Infinite Loop, that runs every 15 Seconds
- Parameters: None
- Behaviour: Counts nearby Units, if it found a Unit it will check if the Unit is a Player
- Behaviour: If the Unit is a Player, the Frozen Group will be defrosted.
- Behaviour: If there is no Player near that Group for _timeTillFreeze the AI will be frozen again
- Addition: None
- **/
- while {true} do {
- _matchingObjectsArray = ((units _unitGroup) select 0) nearEntities ["CAManBase",_countRange];
- _numberOfMatchingObjectsNumber = (count _matchingObjectsArray);
- if (_numberOfMatchingObjectsNumber >= 1) then {
- _state = _unitGroup getVariable["FrozenState",[time,true]];
- _timeFroze = _state select 0;
- _stateFroze = _state select 1;
- if (_stateFroze) then {
- {
- if (isPlayer _x) then {
- if (freeze_log) then {
- diag_log(format["[DEBUG] %1 Triggered Un-Freezing of Group: %2", _x, _unitGroup]);
- };
- [_unitGroup] spawn fnc_unfreeze;
- } else {
- if (!_stateFroze && ((time - _timeFroze) > _timeTillFreeze)) then {
- if (freeze_log) then {
- diag_log(format["[DEBUG] Re-Freezing Group: %1", _unitGroup]);
- };
- [_unitGroup] spawn fnc_freeze;
- };
- };
- } foreach _matchingObjectsArray;
- } else {
- if (!_stateFroze && ((time - _timeFroze) > _timeTillFreeze)) then {
- if (freeze_log) then {
- diag_log(format["[DEBUG] Re-Freezing Group: %1", _unitGroup]);
- };
- [_unitGroup] spawn fnc_freeze;
- };
- };
- };
- sleep 15;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement