Advertisement
Hellstorm77

Untitled

Jul 5th, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.47 KB | None | 0 0
  1. //////////////////////////////////////////////////////////////////
  2. // Function file for Armed Assault 2
  3. // Created by: kylania
  4. // Edited by bl1p for Arma 2 & Hellstorm77 for Arma 3
  5. // Based on code from SNKMAN
  6. // http://forums.bistudio.com/showpost.php?p=1623731&postcount=4
  7. //////////////////////////////////////////////////////////////////
  8. // Examples:
  9. //
  10. // Called from a trigger, Civilians - Present - Once to set 1 bomber out of preset Civs, attacking WEST, 70% chance of attack and 50m range.
  11. // nul = [thislist select floor(random count thislist), WEST, 7, 50] execVM "hkRandom.sqf";
  12. //
  13. // Called from a unit's init, 100% chance to attack EAST units within 100m with a warning and shout.
  14. // nul = [this, EAST, 10, 100, true, true];
  15. //
  16. // Default, attacking WEST targets 30% of the time within 20m warning the group but not yelling out a shout.
  17. // nul = [this] execVM "hkRandom.sqf";
  18. //
  19. //////////////////////////////////////////////////////////////////
  20.  
  21. _unit = _this select 0; // Bomber unit, set randomly by trigger.
  22. _side = if (count _this > 1) then {_this select 1} else {WEST}; // Side to attack, default West.
  23. _prob = if (count _this > 2) then {_this select 2} else {3}; // Probilitiy of attack once a target is found, Number 1 - 10, higher = more chance. Default 3 (30% chance or so);
  24. _range = if (count _this > 3) then {_this select 3} else {20}; // Range to look for targets in, default 20m.
  25. _warn = if (count _this > 4) then {_this select 4} else {true}; // Option to warn the attacked group, all group members will target the bomber, AI won't shoot civs though. Default true.
  26. _shout = if (count _this > 5) then {_this select 5} else {false}; // Option to make the bomber say a sound (declared below) before attacking. Default false.
  27.  
  28.  
  29. // Defaults.
  30. _looking = true;
  31. _target = objNull;
  32.  
  33. //add search action
  34. _unit addAction ["Search For Weapons", "disarm.sqf", [_unit], 6];
  35.  
  36. // Set to true to see status messages from the bomber.
  37. _demo = FALSE;
  38.  
  39. if (isServer) then {
  40.  
  41. // Init the target array.
  42. if (isNil "TargetArray") then {
  43. TargetArray = [];
  44. };
  45.  
  46.  
  47.  
  48. //give unit either a grenade or make him a bomber
  49. if (random 1 > 0.7) then {
  50. _unit addMagazine "HandGrenade";
  51. _unit addMagazine "HandGrenade";
  52. _unit addMagazine "HandGrenade";
  53. _unit addMagazine "HandGrenade";
  54.  
  55. } else {
  56. _unit addMagazine "SatchelCharge_Remote_Mag";
  57. };
  58.  
  59. // Start hunting.
  60. while {_looking} do {
  61. // this only matters if we are still alive, else exit script
  62. if !(alive _unit) exitWith {};
  63.  
  64. _targets = _unit nearTargets _range; // Check targets within range.
  65.  
  66. if (count TargetArray > 0) then {_targets = _targets - TargetArray;};
  67.  
  68. // We have targets in range...
  69. if (count _targets > 0) then
  70. {
  71. _count = 0;
  72. while { (_count < count _targets) } do
  73. {
  74. _selectTarget = (_targets select _count);
  75. // Make sure we know about the target and that they match the side we want to attack.
  76. if ( (_unit knowsAbout (_selectTarget select 4) > 0) && (_selectTarget select 2 == _side) ) then
  77. {
  78. TargetArray = TargetArray + [_selectTarget select 4]; // Grab the target unit objects
  79. };
  80. _count = _count + 1;
  81. };
  82. };
  83.  
  84. // If we have valid target objects...
  85. if (count TargetArray > 0) then {
  86.  
  87. // Lets see if we're ready to die...
  88. _chance = round(random 9) + 1;
  89.  
  90. // Demo text.
  91. if (_demo) then {
  92. _txt = format["Probability: %1, Roll: %2",_prob, _chance];
  93. titleText[_txt, "PLAIN"];
  94. };
  95.  
  96. // If the bomber is ready to die, stop looking and pick one of the random targets found...
  97. if (_chance <= _prob) then {
  98. if (_demo) then {
  99. hint format["Found these targets: %1", TargetArray];
  100. };
  101. _looking = false;
  102. _target = TargetArray select floor(random count TargetArray);
  103. } else {
  104. // The bomber is NOT ready to die, so do nothing.
  105. if (_demo) then {
  106. hintSilent "Sill hunting, not ready to die...";
  107. };
  108. };
  109.  
  110. } else {
  111. // No targets found so do nothing.
  112. if (_demo) then {
  113. hintSilent "Still hunting...";
  114. };
  115. };
  116.  
  117. // Wait a while and clear any targets previously found.
  118. sleep 5;
  119. TargetArray = [];
  120. };
  121.  
  122. // At this point we've found a target (broke out of loop via _looking = false)
  123.  
  124. // wait until we're not handcuffed anymore (except for if we're dead)
  125. waitUntil {animationState _unit != "CivilLying01" || !(alive _unit) };
  126.  
  127. // make sure we are sill alive
  128. if(alive _unit) then {
  129. // turn us into a killer
  130.  
  131. _mags = magazines _unit;
  132. // hint format ["_mags:\n%1", _mags];
  133. //sleep 2;
  134.  
  135.  
  136. if (({(toUpper "HandGrenade") == (toUpper _x)} count _mags) > 0) then {
  137. // hint "I have a grenade";
  138. // Sleep 2;
  139.  
  140. //add unit to enemy side and remove killed event
  141. _unit addweapon "HandGrenade";
  142. [_unit] joinSilent grpNull;
  143. _dummyGroupEast = createGroup east;
  144. [_unit] joinSilent _dummyGroupEast;
  145. [_unit] doTarget _target;
  146. _unit removeEventHandler ["killed", 0];
  147.  
  148. // change speed and mode
  149. _unit SetUnitPos "Up";
  150. _unit SetSpeedMode "Full";
  151. _unit SetCombatMode "Red";
  152. _unit SetBehaviour "Careless";
  153. } else {
  154.  
  155. if (({(toUpper "SatchelCharge_Remote_Mag") == (toUpper _x)} count _mags) > 0) then {
  156. //hint "I Have A Bomb";
  157. //sleep 2;
  158. //add unit to enemy side
  159. _unit addweapon "HandGrenade";
  160. [_unit] joinSilent grpNull;
  161. _dummyGroupEast = createGroup east;
  162. [_unit] joinSilent _dummyGroupEast;
  163. [_unit] doTarget _target;
  164. _unit removeEventHandler ["killed", 0];
  165.  
  166. // change speed and mode
  167. _unit SetUnitPos "Up";
  168. _unit SetSpeedMode "Full";
  169. _unit SetCombatMode "Red";
  170. _unit SetBehaviour "Careless";
  171.  
  172. // Make the bomber keep chasing the target till dead or within 3m.
  173. while {alive _unit && (_unit distance _target > 10)} do {
  174. _unit doMove getPos _target;
  175. sleep 3;
  176. };
  177.  
  178. // make sure he still has the bomb
  179. if (({(toUpper "SatchelCharge_Remote_Mag") == (toUpper _x)} count magazines _unit) > 0) then {
  180. // remove the bomb - its being used, no turning back now
  181. _unit removemagazine "SatchelCharge_Remote_Mag";
  182.  
  183. // available moves
  184. // _moves = //["amovpercmstpsraswrfldnon_gear","AmovPercMstpSnonWnonDnon_seeWatch","AmovPercMstpSnonWnonDnon_exerciseKata"];
  185. //_Amoves = _moves call mps_getRandomElement;
  186.  
  187. //_Amoves = "AmovPercMstpSnonWnonDnon_exerciseKata";
  188.  
  189. //shout when close then wait 2 seconds
  190. if (_shout) then {_unit setVehicleInit "this say3d ""allahu""";processInitCommands};
  191.  
  192. // animate to pull the pin
  193. //_unit playmove _Amoves;
  194.  
  195. // leave the animation for a few seconds
  196. sleep 2;
  197.  
  198. // We're in range, make sure we're still alive then pull the pin!
  199. // also a 10% chance of a dead-mans-trigger
  200. if (alive _unit || random 1 < 0.1) then {
  201. "8Rnd_82mm_Mo_shells" createVehicle getPos _unit;
  202. };
  203. };
  204.  
  205. //do nothing
  206. } else { _unit doMove getPos _unit;};
  207.  
  208. // continue what we were doing before
  209. _unit doMove getPos _unit;
  210. };
  211. };
  212. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement