Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.11 KB | None | 0 0
  1. /*
  2. How to USE:
  3. Script is dynamic, it should launch as soon as first trigger or mission starts depending on your preference. When the enemy faction knows of the players on the ground, all enemy forces in specified radius will start hunting the players. They will not follow if players are extracted via helicopters or hunt helilcopters on their own. Ground vehicles will be hunted.
  4.  
  5. Code to Launch:
  6. null = [ENEMYFACTION,RANGE] execVM "Oksman_Dynamic_Hunt.sqf";
  7.  
  8. Example:
  9. null = [WEST,1000] execVM "Oksman_Dynamic_Hunt.sqf";
  10. */
  11.  
  12.  
  13.  
  14. _EnemyFaction = _this select 0;
  15. _Range = _this select 1;
  16.  
  17. publicVariable "oks_hunted";
  18. publicVariable "oks_activated";
  19. publicVariable "oks_debug";
  20. oks_hunted = false;
  21. oks_activated=true;
  22. oks_debug=true;
  23.  
  24. if (oks_debug) then {SystemChat "hunt.sqf started"};
  25. if (hasInterface && !isServer) exitWith {false}; // Ensures only server or HC runs this script - Tack Neky
  26.  
  27.  
  28. /*
  29. * Loop and find out if AllPlayers are KnownTo Enemy Faction. Once known is true, then fill the knownPlayers into Array.
  30. * Then for each Enemy Group look for allPlayers if Inside Array & Within Range. If so then Hunt, if not then cancel until next KnownTo Loop?
  31. */
  32.  
  33.  
  34. OKS_Hunt =
  35. {
  36.  
  37. params ["_Player","_PlayerArray"];
  38.  
  39. /*
  40. * This code is run for all known players. Take the player, find the nearest enemies of the players.
  41. * When you have the list of all Enemies, run the OKS_Hunting for all enemies near the player.
  42. */
  43. _list = _Player nearEntities [["Man", "Car", "Motorcycle", "Tank"], _Range];
  44. _listAir = _Player nearEntities ["Air", _Range + _Range];
  45.  
  46. _nearenemies = _list select {side _X == _EnemyFaction && isFormationLeader _X;};
  47. {
  48. _X setVariable ["isHunting", false];
  49. if !(_X getVariable ["isHunting",false]) then
  50. {
  51. _X setVariable ["isHunting", true];
  52. [_X,_PlayerArray] call OKS_Hunting;
  53. }
  54.  
  55. } foreach _nearenemies;
  56.  
  57. _nearAir = _listAir select {side _X == _EnemyFaction && isFormationLeader _X;};
  58. {
  59. _X setVariable ["isHunting", false];
  60. if !(_X getVariable ["isHunting",false]) then
  61. {
  62. _X setVariable ["isHunting", true];
  63. [_X,_PlayerArray] call OKS_Hunting;
  64. }
  65.  
  66. } foreach _nearAir;
  67.  
  68. };
  69.  
  70. OKS_Hunting =
  71. {
  72.  
  73. params ["_Hunter","_PlayerArray"];
  74.  
  75.  
  76. /*
  77. The Hunter Group is known and the PlayerArray is sent into code. Use the Hunter and the PlayerArray to sort the array
  78. Find the nearest target in PlayerArray and hunt that.
  79. */
  80.  
  81. _sorted = [_PlayerArray,[],{_x distance _Hunter},"ASCEND"] call BIS_fnc_sortBy;
  82. _nearestPlayer = _sorted select 0;
  83.  
  84. if(oks_debug) then {hint format ["Array: %1\n\nTarget: %2",_sorted,_nearestPlayer]};
  85.  
  86.  
  87. /*
  88. If Hunter has more than 1 waypoint. Delete, doStop and Reset.
  89. */
  90. /// For future use: getVariable ["ACE_isUnconscious", false];
  91.  
  92. { if(_X getVariable ["ACE_isUnconscious", false]) then{_X setDamage 1;} } foreach units group _Hunter;
  93.  
  94. if(count waypoints group _Hunter>0)
  95. then
  96. {
  97. {deleteWaypoint((waypoints group _Hunter)select 0)}forEach waypoints group _Hunter;
  98.  
  99. if !(Vehicle _Hunter isKindOf "LandVehicle") then
  100. {
  101. {doStop _X; _X doFollow leader group _X} foreach units group _Hunter;
  102. };
  103. };
  104.  
  105.  
  106.  
  107. if(oks_debug) then {SystemChat format ["Nearest Player: %1 Hunter: %2",_nearestPlayer,_Hunter]};
  108.  
  109. _wp1 = group _Hunter addWaypoint [position _nearestPlayer, 0];
  110. _wp1 setWaypointType "MOVE";
  111. _wp1 setWaypointSpeed "NORMAL";
  112. group _Hunter setSpeedMode "NORMAL";
  113. if (vehicle _Hunter isKindOf "LandVehicle") then { group _Hunter setBehaviourStrong "SAFE"; }
  114. else { group _Hunter setBehaviourStrong "AWARE"; };
  115. group _Hunter setCurrentWaypoint _wp1;
  116.  
  117. if (vehicle _hunter isKindOf "LandVehicle") then
  118. {
  119. _null = [group _Hunter, position _nearestPlayer, 600] call bis_fnc_taskPatrol;
  120. };
  121. if (vehicle _hunter isKindOf "Air") then
  122. {
  123. _null = [group _Hunter, position _nearestPlayer, 1000] call bis_fnc_taskPatrol;
  124. };
  125. if (vehicle _hunter isKindOf "Man") then
  126. {
  127. _null = [group _Hunter, position _nearestPlayer, 300] call bis_fnc_taskPatrol;
  128. };
  129.  
  130. { _X setWaypointSpeed "FULL"; } foreach waypoints _Hunter;
  131.  
  132.  
  133. };
  134.  
  135.  
  136.  
  137. while {oks_activated} do
  138. {
  139. if (oks_debug) then {systemChat "oks_activated True"};
  140. _playerHunted = [];
  141.  
  142. /* Original AllPlayers Control for MP
  143. {
  144. if ((_EnemyFaction knowsAbout _X > 0.5 || _EnemyFaction knowsAbout vehicle _X > 0.5 ) && isTouchingGround _X)
  145. then
  146. {_playerHunted pushBack _X; hunted = true; systemChat format ["Hunted true. KnowsAbout: %1",_EnemyFaction knowsAbout _X]; sleep 0.5;}
  147.  
  148. } foreach AllPlayers;
  149. */
  150.  
  151. /*
  152. *Check if EnemyFaction knows about All OPFOR units on Map, if they know about them, add to array _PlayerHunted
  153. *Set Hunted to true then oks_debug message the Knowsabout Value.
  154. */
  155. {
  156. if (Side _X == WEST &&(_EnemyFaction knowsAbout _X > 0.5 || _EnemyFaction knowsAbout vehicle _X > 0.5 ) && isTouchingGround (vehicle _X))
  157. then
  158. {_playerHunted pushBackUnique _X; oks_hunted = true;
  159. if (oks_debug) then {systemChat format ["oks_hunted true. KnowsAbout: %1",_EnemyFaction knowsAbout _X]}; sleep 0.5;}
  160.  
  161. } foreach AllUnits;
  162.  
  163.  
  164. if (oks_debug) then {SystemChat Format ["AllPlayers Done. List: %1",_playerHunted]};
  165.  
  166. /*
  167. *If a target is above 0.5 & isTouchinGround then Hunted is true. Initiate the OKS_Hunt for all Players in _PlayerHunted AKA all players known to enemy faction.
  168. */
  169. if (oks_hunted) then
  170. {
  171.  
  172. if (oks_debug) then {systemChat "Initiated Hunted"};
  173.  
  174. {
  175. if (alive _X && !(_x getVariable ["ACE_isUnconscious", false])) then { [_X,_playerHunted] call OKS_Hunt; }
  176. } foreach _playerHunted;
  177.  
  178.  
  179.  
  180. };
  181.  
  182. sleep 60;
  183.  
  184. };
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221. /* OBSOLETE
  222.  
  223. _selectedPlayer = selectRandom _playerHunted;
  224. systemChat format ["%1 _selectedPlayer",_selectedPlayer];
  225. sleep 2;
  226.  
  227. _list = _selectedPlayer nearEntities ["Man", 1000];
  228. _nearenemies = _list select {side _X == _EnemyFaction && isFormationLeader _X;};
  229. { [_playerHunted,_X] call OKS_Hunting; } foreach _nearenemies;
  230. */
  231.  
  232.  
  233.  
  234. /* OBSOLETE
  235. OKS_Hunting =
  236. {
  237.  
  238. params ["_TargetArray", "_Hunter"];
  239.  
  240. if(count waypoints _Hunter>0)
  241. then
  242. {
  243. {deleteWaypoint((waypoints _Hunter)select 0)}forEach waypoints _Hunter;
  244. {doStop _X; _X doFollow leader group _X} foreach units group _Hunter;
  245. };
  246.  
  247.  
  248.  
  249. _sorted = [_TargetArray,[],{_x distance _Hunter},"ASCEND"] call BIS_fnc_sortBy;
  250. _nearestunit = _sorted select 0;
  251. hint format ["Array: %1 Target: %2",_sorted,_nearestunit];
  252.  
  253. //{deleteWaypoint[group _Hunter,_X]}forEach waypoints _Hunter;
  254. SystemChat format ["Test: %1 %2",_nearestunit,_Hunter];
  255.  
  256. _wp1 = group _Hunter addWaypoint [position _nearestunit, 0];
  257. _wp1 setWaypointType "MOVE";
  258. _wp1 setWaypointSpeed "NORMAL";
  259. group _Hunter setSpeedMode "NORMAL";
  260. group _Hunter setBehaviourStrong "AWARE";
  261. group _Hunter setCurrentWaypoint _wp1;
  262.  
  263. _null = [group _Hunter, position _Target, 300] call bis_fnc_taskPatrol;
  264. {_X setWaypointSpeed "FULL"; _X setWaypointBehaviour "AWARE"; } foreach waypoints _Hunter;
  265. {_X setBehaviour "AWARE"; } foreach units group _Hunter;
  266.  
  267.  
  268. };
  269. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement