Jump to content
sarogahtyp

[Release] SSSB - Sarogahtyps Simple Suicide Bomber V-1.0

Recommended Posts

Hey guys!

This is a simple script to turn a unit into a suicide bomber which waits for a nearby player and then follows and explodes. Have fun with it.

In those spoiler below u can see how to use this script with COS - Civilian Occupation System

 

/*
 SSSB - Sarogahtyps Simple Suicide Bomber

 Description:
	Function can be called wherever u want even in init line.
	It waits for player who is in range and follows him until reached and then BOOOOM!
	The bomber is walking if player can see the bomber. If there is no line of sight to player then the bomber will run.
	Works even if the bomber is driving a vehicle. 
	If player is out of range before bomber can reach him then the bomber will just wait for the next player in range.
	You can pass a chance to get a bomber to the function. 
	This is useful for implementing the script into COS - Civilian Occupation System.
	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.
	Enjoy the boom. :-)
	Cheers Saro.	
	
 Paramameters:
	object - the object of your unit which should become a bomber
	number (optional) - range to seek for players (default is 300 m)
	number (optional) - chance to turn the unit into a bomber. (default is 100 %)

Return values:
number - handle of spawned script if someone likes to check if bombers script has ended (scriptDone)
         will return -1 if script ends without spawning code (in case no civ was turned into bomber)
*/

params [["_civ", objNull,[objNull]], ["_act_range", 300, [0]], ["_chance", 100, [0]]];

if ((random 100 > _chance) || !(alive _civ)) exitWith {-1};

_handle = [_civ, _act_range] spawn
{ 
 params ["_bomber", "_act_range"];
 private _melee_dist = 15;
 private _boom_dist = 5;

 private _dist_target = _act_range;
 private _lost_range = round (_act_range * 1.2); 

 private _act_range_sqr = _act_range ^ 2;
 private _melee_dist_sqr = _melee_dist ^ 2;
 private _boom_dist_sqr = _boom_dist ^ 2;
 private _dist_target_sqr = _act_range ^ 2;
 private _lost_range_sqr =  _lost_range ^ 2; 

 private _grp_bomber = group _bomber;
 private _is_vec = if (isNull objectParent _bomber) then {false} else {true};

 private _target_players = [];
 private _wp =[];
 
 while {(alive _bomber) && (_dist_target_sqr > _boom_dist_sqr)} do
 {
  // wait until players are in range
  waitUntil 
  {
   sleep (2 + random 1);
   _target_players = (allPlayers - entities "HeadlessClient_F") select {(alive _x) && ((_x distanceSqr _bomber) < _act_range_sqr)};
   ((count _target_players > 0) || !(alive _bomber))
  };

  // end everything if suicide bomber is already dead
  if !(alive _bomber) exitWith {};

   // follow nearest player as long as bomber lives, target is in range and target is not close enough to boom
  while {alive _bomber && (_dist_target_sqr < _lost_range_sqr) && (_dist_target_sqr > _boom_dist_sqr)} do
  {
   _target_players = (allPlayers - entities "HeadlessClient_F") select {(alive _x) && ((_x distanceSqr _bomber) < _act_range_sqr)};
   // get nearest player
   _target_players = _target_players apply {[(_x distanceSqr _bomber), _x]};
   _target_players sort true;
   _target_plyr = _target_players select 0 select 1;

   // check distance and visibility
   _dist_target_sqr = if(count _target_players > 0) then {_target_players select 0 select 0} else {_lost_range_sqr};
   _can_see = [_target_plyr, "VIEW", _bomber] checkVisibility [(eyePos _target_plyr), (eyePos _bomber)];

   // add waypoint and set bombers behavior
   if (count _wp > 0) then {_grp_bomber setCurrentWaypoint _wp;}
   else {_wp = _grp_bomber addWaypoint [position _target_plyr, 0];};

   _wp setWaypointPosition [position _target_plyr, 0];
   _wp setWaypointBehaviour "CARELESS";
   _wp setWaypointCombatMode "BLUE";
   _wp setWaypointCompletionRadius 0;

   _grp_bomber setBehaviour "CARELESS";
   _grp_bomber setCombatMode "BLUE";

   //run if close enough or if target cant see bomber
   if ( (_can_see < 0.3) || 
   ((_dist_target_sqr < _melee_dist_sqr) && !_is_vec) || 
   ((_dist_target_sqr < (2 * _melee_dist_sqr)) && _is_vec) ) then
   {
    _wp setWaypointSpeed "FULL";
   }
   else
   {
    _wp setWaypointSpeed "LIMITED";
   }; 
   sleep (0.5 + random 0.5);
  }; // end follow while
  _wp = [];
 }; // main while end
                      
 if (_is_vec) then 
 {
  _boom = createVehicle ["Bo_GBU12_LGB", getPos _bomber, [], 0, "CAN_COLLIDE"];
 }
 else 
 {
  _boom = createVehicle ["R_60mm_HE", getPos _bomber, [], 0, "CAN_COLLIDE"];
 };
 deleteVehicle _bomber;
}; //spawn end
_handle

 

Init Line usage:

Spoiler

 

Put the whole script  in a sqf file e.g. SSSB.sqf in missions root folder. In the init line of a unit put this:


d = this execVM "SSSB.sqf";


If you want to adjust the range to seek for players to 666 m then:


d = [this, 666] execVM "SSSB.sqf";

If the unit should only turn into a bomber in 50 percent of all cases then:


d = [this, 666, 50] execVM "SSSB.sqf";

 

 

COS - Integration:

Spoiler

1. create a file "SSSB.sqf" in missions root folder.

2. Put this into ur "initServer.sqf" file;


 Saro_fnc_bomber = compileFinal preProcessFileLineNumbers "SSSB.sqf";

3. In your "cos" folder there is a file called "addScript_Unit.sqf". Add this to it:


params["_unit"];
_d = [_unit, 300, 1] call Saro_fnc_bomber;

300 is the search distance for players.

1 is the chance in percent for a specific civilian to get a bomber

 

 

Changelog

 

SSSB 1.0

-changed from distance to distanceSqr for performance reasons

-fixed bug with targets distance (variable not defined)

-changed return value from true to script handle to make scriptDone check available

SSSB 0.9 (initial version)

-just created it because of so much requests for something like this seen in forum

 

version with sound integration:

 

  • Like 5

Share this post


Link to post
Share on other sites

I think I need some help here. Maybe I m to tired to see my mistake.

I get this error message for the code from the first post:

 

 

EDIT: rpt errors found.

Now there are logical errors (bugs) in it only...

Edited by sarogahtyp

Share this post


Link to post
Share on other sites

Okay, script is working now and upto now i could not detect major issues. Maybe some tweaking of those sleep times is necessary but it works.

 

I would be happy if someone could test it and if somone would take a look on it and tell me his suggestions to improve it.

Share this post


Link to post
Share on other sites

And the great thing about scripted features as opposed to features from an addon, is that users don't see a new addon load and don't know about the new feature. Last time I sneaked in IEDs from a script, I got bug reports from users saying "I suddenly exploded! BUG!". lol. I hope I get the same when I introduce these SSBs.

 

Muhaha.

  • Like 2

Share this post


Link to post
Share on other sites
3 hours ago, Tankbuster said:

And the great thing about scripted features as opposed to features from an addon, is that users don't see a new addon load and don't know about the new feature. Last time I sneaked in IEDs from a script, I got bug reports from users saying "I suddenly exploded! BUG!". lol. I hope I get the same when I introduce these SSBs.

 

Muhaha.

 

You could also use playSound3D to great effect, especially on dark tanoan nights inside the jungle...

 

Spoiler

 

:yay:

 

Pants shall be changed!

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites
2 hours ago, Grumpy Old Man said:

 

You could also use playSound3D to great effect, especially on dark tanoan nights inside the jungle...

 

  Hide contents

 

:yay:

 

 

Pants shall be changed!

 

Cheers

 

You are a bad bad man. And I love it. :)

Share this post


Link to post
Share on other sites

hey this is great. could you possibly detail how to implement this with COS? I had requested this a while back but no takers. thanks for your time.

 

COS link below for anyone needing the folder.

 

 

Share this post


Link to post
Share on other sites

This is very easy to do I ll show it within the next few days.

sent from mobile using Tapatalk

Share this post


Link to post
Share on other sites

COS - Integration

 

1. create a file "SSSB.sqf" in missions root folder.

2. Put this into ur "serverInit.sqf" file;

 Saro_fnc_bomber = compileFinal preProcessFileLineNumbers "SSSB.sqf";

3. In your "cos" folder there is a file called "addScript_Unit.sqf". Add this to it:

params[_unit];
_d = [_unit, 300, 1] call Saro_fnc_bomber;

300 is the search distance for players.

1 is the chance in percent for a specific civilian to get a bomber

Share this post


Link to post
Share on other sites

Is there a sound file already in the game the bomber could shout just before he detonates?

Share this post


Link to post
Share on other sites

Found this...

 

class CfgSounds
    {
        sounds[] = {allahu};

        class allahu
        {
            name = "allahu";
            sound[] = {\sound\allahu.ogg, 1, 1.0};
            titles[] = {	};
        };
    };

 

Share this post


Link to post
Share on other sites

Yeah, but you do that every morning!

 

edit* By which I mean scream, not change your pants. Or erm... wish I hadn't started this now.

  • Like 1

Share this post


Link to post
Share on other sites

@sarogahtyp

Couple of things you might be interested in.

 

The bomber is a civilian so if players shoot him, they get negative score.

 

If the guy the bomber is chasing dies (I'm using BI revive) _dist_target becomes undefined and gives an error.

 

 

Share this post


Link to post
Share on other sites
On 4/29/2017 at 2:03 AM, Tankbuster said:

And the great thing about scripted features as opposed to features from an addon, is that users don't see a new addon load and don't know about the new feature. Last time I sneaked in IEDs from a script, I got bug reports from users saying "I suddenly exploded! BUG!". lol. I hope I get the same when I introduce these SSBs.

 

Muhaha.

You always have -serverMod :shrug:

 

Share this post


Link to post
Share on other sites
@sarogahtyp
Couple of things you might be interested in.
 
The bomber is a civilian so if players shoot him, they get negative score.
 
If the guy the bomber is chasing dies (I'm using BI revive) _dist_target becomes undefined and gives an error.
 
 

Thanks for ur suggestions. I thought about those negative score thing and I ll turn the civilian to enemy side to fix this.

Are u sure that _dist_target becomes undefined?
I ve an alive check in the while loop for it. And in the condition this alive check is at first position. The loop should simply break before _dist_target gets checked if the civilian is dead. But if it truly throws an error then I ll fix it.

But I be no time for it within the next few days.

sent from mobile using Tapatalk

Share this post


Link to post
Share on other sites

I go about this slightly differently. I have a lot of civilians so instead of having a small chance that any of them could become a bomber, if the random is true, I create a group just for the bomber and create him in that group with 100% chance.

 

I do have the diag_log somwehere, I'll dig it out. I'm pretty sure it was related to the target being incapacitated in BI revive.

 

Two more things for you. I've got a small 'allahu akbar' ogg file which I playsound3d just before he detonates. Adds to the amusement. :)

 

Also, occasionally the bomber gets himself killed while running. Twice he's been run over by other civilians and once, he got himself squashed by a Tigris. :) Realistic feature, not bug! :)

Share this post


Link to post
Share on other sites

Oh, I forgot.. about the side thing... because i'm creating a group for each bomber, I should just make that group east instead of civilian. That should fix that although he will show up on the man in lower difficulty levels and get reported by friendly units.

  • Like 2

Share this post


Link to post
Share on other sites

About killing the bomber before he gets to you. I've been fiddling with this some more. If score and rating are important, (in coop, for example) then this is important too.

 

If your rating goes below -2000 and it will if you kill 2 or more civilians you become sideenemy and everyone will attack you, even your own AI. Not only that, you won't be able to get in vehicles on your own side and your teammates won't be able to get in your vehicles. Also, all subsequent kills of east will count as freindly fire and give you even more negative score.

 

Having the civ bomber in an east group doesn't have any effect on the scoring. You still get rating -1000 and score -1.

 

So we have two options; We can actually create a bomber east group and unit, remove all his uniform and gear and redress him using the handy (relatively) new forceAddUniform command. I suggest making him the lone unit in the group otherwise you'll hear him shouting his orders and stuff.

 

Or we create the civilian bomber as you do now, but add a killed eventhandler to him that does an addrating 1000 and addscore1 to the shooter who kills him. But if you do this in CUP, you might have difficulties as CUP (last time I used it) already has a killed EH on all of its units.

 

Personally, I'm preferring the first option. It's much more elegant for me because I'm creating a unit specifically to be the bomber. If you're choosing a civilian from an existing population, then the eventhandler method will be better.

  • Like 1

Share this post


Link to post
Share on other sites

Put it in a sqf file e.g. SSSB.sqf in missions root folder. In the unit line of a unit put this:

d = this execVM "SSSB.sqf";


If you want to adjust the range to seek for players to 666 m then:

d = [this, 666] execVM "SSSB.sqf";


If the unit should only turn into a bomber in 50 percent of all cases then:

d = [this, 666, 50] execVM "SSSB.sqf";

 

If you want to use it with COS - Civilian Occupation System then you ll find the information in the first post.

Share this post


Link to post
Share on other sites

Having a tough time adding a vest to _bomber for some reason.

 

I've added the following line in several places in SSSB.sqf but no matter what it seems that the suicide bombers don't want to wear vests.

Spoiler

_bomber addvest "Vest_V_DeckCrew_brown_F";

 

Edit: It was the vest. I'm very stupid. 

Share this post


Link to post
Share on other sites

Love the script thank yous so much made the process very easy to understand. I truly appreciate that. Havent found any issues with it. was alot of fun setting it to 100 and having every single civ run at me at once lol.

Share this post


Link to post
Share on other sites

Id really love to know how to add a custom sound to this, like i know some of the basics like adding the cfgsounds etc. (i think ive got that part right) but Id like a sound ive recorded to play when they approach just via the playsound functionality. any help appreciated.

 

can i add something like playsound into this section?

 

if (_is_vec) then
 {
  _boom = createVehicle ["Bo_GBU12_LGB", getPos _bomber, [], 0, "CAN_COLLIDE"];
 }
 else
 {
  _boom = createVehicle ["R_60mm_HE", getPos _bomber, [], 0, "CAN_COLLIDE"];
 };
 deleteVehicle _bomber;

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×