MarketDay – a random suicide bomber script.


Here’s a version of a “random hunter killer suicide bomber” script. The best part is if called right, you’ll never know who the bomber is till it might be too late.

Call the script from a Trigger to pick a random bomber:

Code:
nul = [thislist select floor(random count thislist), WEST, 7, 20, true, true] execVM "hkRandom.sqf";

or from a unit’s init field to specify the bomber:

Code:
nul = [this] execVM "hkRandom.sqf";

There are optional arguments for the side to attack, percentage chance to attack once a target is found, range to start looking for targets within, whether or not to warn the group that’s being attacked and an optional sound file to be played by the attacking bomber.

MarketDay is a demo mission where you can see this script in action. Here’s the code:

Code:
//////////////////////////////////////////////////////////////////
// Function file for Armed Assault 2
// Created by: kylania
// 
// Based on code from SNKMAN
// http://forums.bistudio.com/showpost.php?p=1623731&postcount=4
//////////////////////////////////////////////////////////////////
//  Examples: 
//
//  Called from a trigger, Civilians - Present - Once to set 1 bomber out of preset Civs, attacking WEST, 70% chance of attack and 50m range.
//  nul = [thislist select floor(random count thislist), WEST, 7, 50] execVM "hkRandom.sqf";
//
//  Called from a unit's init, 100% chance to attack EAST units within 100m with a warning and shout.
//  nul = [this, EAST, 10, 100, true, true];
//
//  Default, attacking WEST targets 30% of the time within 20m warning the group but not yelling out a shout.
//  nul = [this] execVM "hkRandom.sqf";
//
//////////////////////////////////////////////////////////////////

_unit = _this select 0;  // Bomber unit, set randomly by trigger.
_side = if (count _this > 1) then {_this select 1} else {WEST};  // Side to attack, default West.
_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);
_range = if (count _this > 3) then {_this select 3} else {20};  // Range to look for targets in, default 20m.
_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.
_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.
_sound = "allahu";  // Sound file declared in CfgSounds in description.ext for use with _shout option.

// Defaults.
_looking = true;
_target = objNull;

// Set to true to see status messages from the bomber.
_demo = true; 

if (isServer) then {

  // Init the target array.
  if (isNil "TargetArray") then {TargetArray = [];};

  // Start hunting.
  while {_looking} do {
	_targets = _unit nearTargets _range;  // Check targets within range.

	if (count TargetArray > 0) then {_targets = _targets - TargetArray;};

	// We have targets in range...
	if (count _targets > 0) then
	{
		_count = 0;
		while { (_count < count _targets) } do
		{
			_selectTarget = (_targets select _count);
			// Make sure we know about the target and that they match the side we want to attack.
			if ( (_unit knowsAbout (_selectTarget select 4) > 0) && (_selectTarget select 2 == _side) ) then
			{
				TargetArray = TargetArray + [_selectTarget select 4];  // Grab the target unit objects
			};
		_count = _count + 1;
		};
	};

	// If we have valid target objects...
	if (count TargetArray > 0) then {
	
		// Lets see if we're ready to die...
		_chance = round(random 9) + 1;
		
		// Demo text.
		if (_demo) then {_txt = format["Probability: %1, Roll: %2",_prob, _chance]; titleText[_txt, "PLAIN"];};
		
		// If the bomber is ready to die, stop looking and pick one of the random targets found...
		if (_chance <= _prob) then {
			if (_demo) then {hint format["Found these targets: %1", TargetArray];};
			_looking = false;
			_target = TargetArray select floor(random count TargetArray);
		} else {
			// The bomber is NOT ready to die, so do nothing.
			if (_demo) then {hintSilent "Sill hunting, not ready to die...";};
		};
	
	} else {
		// No targets found so do nothing.
		if (_demo) then { hintSilent "Still hunting...";};
	};

	// Wait a while and clear any targets previously found.
	sleep 5;
	TargetArray = [];
  };

  // At this point we've found a target (broke out of loop via _looking = false)

  // Charge at the target!
  _unit SetUnitPos "Up";
  _unit SetSpeedMode "Full";
  _unit SetCombatMode "Red";
  _unit SetBehaviour "Careless";
  if (_demo) then {hint format["INCOMING for you %1!", _target];};

  // Shout or warn per options
  if (_shout) then {_unit say [_sound,5]};
  if (_warn) then {units (group _target) commandTarget _unit};

  // Make the bomber keep chasing the target till dead or within 3m.
  while {alive _unit && (_unit distance _target > 3)} do {
	_unit doMove getPos _target;
	sleep 3;
  };

  // We're in range, make sure we're still alive then pull the pin!
  if (alive _unit) then {"grenade" createVehicle getPos _unit};
  
};

  1. #1 by Morgan on August 10, 2010 - 4:55 AM

    Very cool.

  2. #2 by Tyler on August 12, 2010 - 10:53 PM

    I’ve DL the mission. Do I need to input the code somewhere?? or is it already part of the file I DL??

    I’ve have tried to play the mission >But nothing happens for 10 minutes or more??

    • #3 by kylania on August 17, 2010 - 6:52 PM

      That’s quite possible that nothing would happen, especially if you have Demo mode turned off. If you turn on Demo you’ll see the various checks it’s doing and see why nothing would be happening.

      I recently learned how to better do sounds in Multiplayer, so I’ll be updating this with that new code Soonâ„¢.

  3. #4 by Cytreen on August 27, 2010 - 3:36 PM

    I have it working but dont know how to define the shout option in the description.ext. I am using a trigger to set everything off

    nul = [thislist select floor(random count thislist), WEST, 7, 100, true, true] execVM “scripts\hkRandom.sqf”; but have no clue on how to define the alahu sound thing for the Civ thats active. Now i know how to define one for custom music
    class CfgMusic
    {
    tracks[]={};

    class intro
    {
    name = “”;
    sound[] = {“\sound\Heat.ogg”, db+0, 1.0};
    };
    }

    Im thinking the class CfgSound and set the class intro to class _Sound and using a custom sound from my own mission pbo but if theres one already in OA i dont know how to define it from there as the
    sound[] = {“\sound\Heat.ogg”, db+0, 1.0}; points ot the sounds folder in my mission.pbo and not what comes with oa.

  4. #5 by Rooty.Localhost on November 10, 2010 - 11:53 AM

    This page is quiet awesome mate!

    And this piece of script here is quiet funny as hell, thanks for sharing this and keep up!

    Best regards,
    Rooty Localhost.

Comments are closed.