Jump to content
Gekkibi

Random AA Fire script

Recommended Posts

It seems it's this time again... The release of new Arma means I have to update my old scripts once more.

Because I had a request for this old script, I decided to publish it after tweaking it a little bit & making sure it works in Arma 3.

Ladies and gentlemen, I give you GKB_fnc_randomAAFire. The same one rexehuk praised so much many years ago.

GKB_fnc_randomAAFire.jpg

Old video from Arma 2 version (go to 0:18, this video contains other projects I created as well).

Here's an Arma 2 version in action. An actual mission, not just a showcase. Thanks goes to Havoc Company for using it.

/* ----------------------------------------------------------------------------------------------------
Function:
GKB_fnc_randomAAFire

Author:
Gekkibi

Terms for copying, distribution and modification:
Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0)
http://creativecommons.org/licenses/by-nc-sa/3.0/

Description:
Defined AA-batteries shoot coherently to a randomly selected position, simulating anti-air fire
without creating any in-game aircraft. Script will make sure they will not run out of ammunition.
AA-batteries can be stationary or mobile. Batteries will stop firing at the fake target if they
spot a real one, and continues normally afterwards.

Parameters:
1st	Objects in Array	AA-units
2nd	Arrays in array		Target is created between these coordinates
				[[x1, x2], [y1, y2], [z1, z2]]
3rd	Number			Delay between targets
4th	Number			Secondary weapon chance (from 0 to 1). Use 0 if no such weapon
5th	Code			When true new targets are calculated

Returns:
Nil

Example:
[
	[GKB_aa1, GKB_aa2, GKB_aa3],
	[[0, 4500], [7000, 8000], [1000, 500]],
	20 + random 100,
	0.1,
	{alive GKB_radar}
] spawn GKB_fnc_randomAAFire.sqf;
---------------------------------------------------------------------------------------------------- */

if (isServer) then {
private ["_positionArray", "_runCondition", "_secondaryChance", "_sleepTime", "_unitArray"];
_unitArray = _this select 0;
_positionArray = _this select 1;
_sleepTime = _this select 2;
_secondaryChance = _this select 3;
_runCondition = _this select 4;
{
	_x lock 3;
} forEach _unitArray;
while _runCondition do {
	private ["_direction", "_weapon"];
	{
		if (! alive gunner _x) then {
			_unitArray = _unitArray - [_x];
		};
	} forEach _unitArray;
	if (count _unitArray == 0) exitWith {};
	_direction = [
		(_positionArray select 0 select 0) - random ((_positionArray select 0 select 0) - (_positionArray select 0 select 1)),
		(_positionArray select 1 select 0) - random ((_positionArray select 1 select 0) - (_positionArray select 1 select 1)),
		(_positionArray select 2 select 0) - random ((_positionArray select 2 select 0) - (_positionArray select 2 select 1))
	];
	if (random 1 > _secondaryChance) then {
		_weapon = "cannon";
	} else {
		_weapon = "missile";
	};
	{
		if (alive gunner _x && isNull assignedTarget _x) then {
			[_x, _direction, _weapon] spawn {
				private ["_direction", "_unit", "_weapon"];
				_unit = _this select 0;
				_direction = _this select 1;
				_weapon = _this select 2;
				_unit doWatch _direction;
				sleep 2;
				switch (_weapon) do {
					case "cannon": {
						for "_x" from 1 to 1 + ceil random 5 do {
							sleep random 2;
							for "_x" from 1 to 10 do {
								if (! isNull assignedTarget _unit) exitWith {};
								_unit fire (_unit weaponsTurret [0] select 0);
								sleep 0.05;
							};
							if (! isNull assignedTarget _unit) exitWith {};
							_unit doWatch _direction;
						};
					};
					case "missile": {
						sleep (2 + random 5);
						_unit fire (_unit weaponsTurret [0] select 1);
					};
				};
				if (isNull assignedTarget _unit) then {
					_unit doWatch objNull;
				} else {
					_unit doWatch assignedTarget _unit;
				};
				_unit setVehicleAmmo 1;
			};
		};
	} forEach _unitArray;
	sleep _sleepTime;
};
};

You can download an example mission by clicking here.

As always, feedback, suggestions, questions, bug reports and outright insults are welcome. Feel free to use in your missions (CC BY-NC-SA 3.0).

Edited by Gekkibi

Share this post


Link to post
Share on other sites

Oh, can't believe I never noticed your scripts in ArmA2.

Looks very nice.

Share this post


Link to post
Share on other sites
Oh, can't believe I never noticed your scripts in ArmA2.

That's probably because I publicly shared only a handful of scripts/missions, I have made them since OFP 1.0. I take requests and provide missions / scripts / help as needed for teams and groups, privately.

Share this post


Link to post
Share on other sites
7 hours ago, zombiemanx12 said:

How do you get this to work?

Fairy dust. :rofl:

Quote

Example: [ [GKB_aa1, GKB_aa2, GKB_aa3], [[0, 4500], [7000, 8000], [1000, 500]], 20 + random 100, 0.1, {alive GKB_radar} ] spawn GKB_fnc_randomAAFire.sqf;

Quote

Parameters:
1st	Objects in Array	AA-units
2nd	Arrays in array		Target is created between these coordinates
				[[x1, x2], [y1, y2], [z1, z2]]
3rd	Number			Delay between targets
4th	Number			Secondary weapon chance (from 0 to 1). Use 0 if no such weapon
5th	Code			When true new targets are calculated

 

 

  • Haha 1

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

×