Advertisement
Guest User

Untitled

a guest
Jul 19th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.34 KB | None | 0 0
  1. /*
  2. SSSB - Sarogahtyps Simple Suicide Bomber
  3.  
  4. Description:
  5. Function can be called wherever u want even in init line.
  6. It waits for player who is in range and follows him until reached and then BOOOOM!
  7. The bomber is walking if player can see the bomber. If there is no line of sight to player then the bomber will run.
  8. Works even if the bomber is driving a vehicle.
  9. If player is out of range before bomber can reach him then the bomber will just wait for the next player in range.
  10. You can pass a chance to get a bomber to the function.
  11. This is useful for implementing the script into COS - Civilian Occupation System.
  12. You can apply the script to all civilians and if u pass e.g. 1 % as chance then only every 100th civ will become a bomber and wait for near players.
  13. Enjoy the boom. :-)
  14. Cheers Saro.
  15.  
  16. Paramameters:
  17. object - the object of your unit which should become a bomber
  18. number (optional) - range to seek for players (default is 300 m)
  19. number (optional) - chance to turn the unit into a bomber. (default is 100 %)
  20.  
  21. Return values:
  22. number - handle of spawned script if someone likes to check if bombers script has ended (scriptDone)
  23. will return -1 if script ends without spawning code (in case no civ was turned into bomber)
  24. */
  25.  
  26. params [["_civ", objNull,[objNull]], ["_act_range", 300, [0]], ["_chance", 100, [0]]];
  27.  
  28. _root = parsingNamespace getVariable "MISSION_ROOT";
  29.  
  30.  
  31. if ((random 100 > _chance) || !(alive _civ)) exitWith {-1};
  32.  
  33. _handle = [_civ, _act_range] spawn
  34. {
  35. params ["_bomber", "_act_range"];
  36. private _melee_dist = 50;
  37. private _boom_dist = 5;
  38.  
  39. private _dist_target = _act_range;
  40. private _lost_range = round (_act_range * 1.2);
  41.  
  42. private _act_range_sqr = _act_range ^ 2;
  43. private _melee_dist_sqr = _melee_dist ^ 2;
  44. private _boom_dist_sqr = _boom_dist ^ 2;
  45. private _dist_target_sqr = _act_range ^ 2;
  46. private _lost_range_sqr = _lost_range ^ 2;
  47.  
  48. private _grp_bomber = group _bomber;
  49. private _is_vec = if (isNull objectParent _bomber) then {false} else {true};
  50.  
  51. private _target_players = [];
  52. private _wp =[];
  53.  
  54. while {(alive _bomber) && (_dist_target_sqr > _boom_dist_sqr)} do
  55. {
  56. private _shouted = false;
  57. // wait until players are in range
  58. waitUntil
  59. {
  60. sleep (2 + random 1);
  61. _target_players = (allPlayers - entities "HeadlessClient_F") select {(alive _x) && ((_x distanceSqr _bomber) < _act_range_sqr)};
  62. ((count _target_players > 0) || !(alive _bomber))
  63. };
  64.  
  65. // end everything if suicide bomber is already dead
  66. if !(alive _bomber) exitWith {};
  67.  
  68. // follow nearest player as long as bomber lives, target is in range and target is not close enough to boom
  69. while {alive _bomber && (_dist_target_sqr < _lost_range_sqr) && (_dist_target_sqr > _boom_dist_sqr)} do
  70. {
  71. _target_players = (allPlayers - entities "HeadlessClient_F") select {(alive _x) && ((_x distanceSqr _bomber) < _act_range_sqr)};
  72. // get nearest player
  73. _target_players = _target_players apply {[(_x distanceSqr _bomber), _x]};
  74. _target_players sort true;
  75. _target_plyr = _target_players select 0 select 1;
  76.  
  77. // check distance and visibility
  78. _dist_target_sqr = if(count _target_players > 0) then {_target_players select 0 select 0} else {_lost_range_sqr};
  79. _can_see = [_target_plyr, "VIEW", _bomber] checkVisibility [(eyePos _target_plyr), (eyePos _bomber)];
  80.  
  81. // add waypoint and set bombers behavior
  82. if (count _wp > 0) then {_grp_bomber setCurrentWaypoint _wp;}
  83. else {_wp = _grp_bomber addWaypoint [position _target_plyr, 0];};
  84.  
  85. _wp setWaypointPosition [position _target_plyr, 0];
  86. _wp setWaypointBehaviour "CARELESS";
  87. _wp setWaypointCombatMode "BLUE";
  88. _wp setWaypointCompletionRadius 0;
  89.  
  90. _grp_bomber setBehaviour "CARELESS";
  91. _grp_bomber setCombatMode "BLUE";
  92.  
  93. if ( !_shouted && (((_dist_target < _melee_dist) && !_is_vec) ||
  94. ((_dist_target < (2 * _melee_dist)) && _is_vec)) ) then
  95. {
  96. _shouted = true;
  97. //_playsound = _root + "alluha.ogg";
  98. //[_bomber, ["SuicideSound", 150]] remoteExec ["say3D", -2]; // << ADJUST SOUNDNAME HERE (has to be defined in CfgSounds, see link below)!!
  99. //playsound3d ["SuicideSound", _bomber,false, getposasl _bomber,10,1,50];
  100. // https://community.bistudio.com/wiki/Description.ext#CfgSounds
  101. //playsound3D ["SuicideSound", _bomber, false, getposASL _bomber, 1, 1, 0]
  102.  
  103. _soundPath = [(str missionConfigFile), 0, -15] call BIS_fnc_trimString;
  104. _soundToPlay = _soundPath + "sound\alluha.ogg";
  105. //playSound3D [_soundToPlay, _bomber, false, getPos _bomber, 10, 1, 200];
  106. //_bomber Say3D [_SoundToPlay,300,1];
  107. _bomber say3D ["music1",250,1];
  108. //Volume db+10, volume drops off to 0 at 50 meters from _sourceObject
  109.  
  110.  
  111. };
  112.  
  113.  
  114. //run if close enough or if target cant see bomber
  115. if ( (_can_see < 0.3) ||
  116. ((_dist_target_sqr < _melee_dist_sqr) && !_is_vec) ||
  117. ((_dist_target_sqr < (2 * _melee_dist_sqr)) && _is_vec) ) then
  118. {
  119. _wp setWaypointSpeed "FULL";
  120. }
  121. else
  122. {
  123. _wp setWaypointSpeed "LIMITED";
  124. };
  125. sleep (0.5 + random 0.5);
  126. }; // end follow while
  127. _wp = [];
  128. }; // main while end
  129.  
  130. if (_is_vec) then
  131. {
  132. _boom = createVehicle ["Bo_GBU12_LGB", getPos _bomber, [], 0, "CAN_COLLIDE"];
  133. }
  134. else
  135. {
  136. _boom = createVehicle ["R_60mm_HE", getPos _bomber, [], 0, "CAN_COLLIDE"];
  137. };
  138. deleteVehicle _bomber;
  139. }; //spawn end
  140.  
  141. _handle
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement