Jump to content
Sign in to follow this  
PlacidPaul

Ambient Fire loop with random hold

Recommended Posts

I'm using this

/*

fatty's ambient artillery tool (faat) version 1.0

by fatty


Forces an AI gun (e.g. cannon or rocket artillery) to fire at regular intervals at a defined target. Gunners will persist until out of ammo or dead.

CAUTION: the guns fire live ammo, so be careful where you aim!

Required Parameters:
Artillery Piece (object) - object to begin firing.
Target (object) - target at which the artillery piece will fire. Suggested target is an invisible H setPos'd several hundred metres above the gun.

Optional Parameters:
Delay (number) - delay between shots in seconds (default is 10 seconds).
Disable aiming AI (boolean) - prevents AI gunners from engaging other targets (default is true).
Enable auto-rearm (boolean) - enables automatic rearming of gun after every shot (default is false).

Examples:
nul = [big_gun, gun_target] execmVM "faat.sqf";
nul = [rocket_artillery, house, 20, false, true] execmVM "faat.sqf";


*/

private ["_gun","_target","_delay","_disableaim","_autorearm"];

_gun = _this select 0;
_target = _this select 1;
_delay = if (count _this > 2) then {_this select 2} else {10};
_disableaim = if (count _this > 3) then {_this select 3} else {true};
_autorearm = if (count _this > 4) then {_this select 4} else {false};


if (_disableaim) then {
{_gun disableAI "_x";} foreach [move,target,autotarget,anim];
_gun setCombatMode "BLUE";
};


(gunner _gun) lookAt _target;

While {alive (gunner _gun)} do
{
	sleep _delay;
	_gun fire (weapons _gun select 0);
	if (_autorearm) then {_gun setVehicleAmmo 1};
};
};

I have tried, but can't get it. :(

I would like to have a 15 second break for every 5 second or so of fire. If it's random somewhere between that would be nice.

Thanks

Share this post


Link to post
Share on other sites

OK this somewhat works, but is it the right way to do it?

if (alive (gunner _gun)) then
{
   for "_i" from 0 to 20 do
{
	sleep _delay;
	_gun fire (weapons _gun select 0);
	if (_autorearm) then {_gun setVehicleAmmo 1};

};
};




sleep 5;

nul = [tung1, target,.2,true,false] execvm "faat.sqf";

it no random :(

Share this post


Link to post
Share on other sites

For randomization you can try something like that:

	private ["_gun","_target","_delay","_disableaim","_autorearm"];

_gun = _this select 0;
_target = _this select 1;
_delay = if (count _this > 2) then {_this select 2} else {10};
_disableaim = if (count _this > 3) then {_this select 3} else {true};
_autorearm = if (count _this > 4) then {_this select 4} else {false};


if (_disableaim) then {
	{_gun disableAI _x} foreach ["MOVE","TARGET","AUTOTARGET","ANIM"];
	_gun forceSpeed 0;
	_gun setCombatMode "BLUE";
};

(gunner _gun) lookAt _target;
//(gunner _gun) doWatch _target;
//(gunner _gun) doTarget _target;

while {(true)} do
	{
	if (isNull _gun) exitWith {};
	if not (alive _gun) exitWith {};
	if (isNull (gunner _gun)) exitWith {};
	if not (alive (gunner _gun)) exitWith {};
	if not (canFire _gun) exitWith {};
	if not (someAmmo _gun) exitWith {};
	if (isNull _target) exitWith {};

	_amnt = ceil (random 10);

	for "_i" from 1 to _amnt do
		{
		sleep ((_delay/2) + (random (_delay/2)));

		if (isNull _gun) exitWith {};
		if not (alive _gun) exitWith {};
		if (isNull (gunner _gun)) exitWith {};
		if not (alive (gunner _gun)) exitWith {};
		if not (canFire _gun) exitWith {};
		if not (someAmmo _gun) exitWith {};
		if (isNull _target) exitWith {};

		//_gun fireAtTarget [_target];
		_gun fire (weapons _gun select 0);
		if (_autorearm) then {_gun setVehicleAmmo 1};
		};

	sleep (10 + (random 10));

	(gunner _gun) lookAt _target;
	//(gunner _gun) doWatch _target;
	//(gunner _gun) doTarget _target;
	};

but, frankly, do not expect accurate fire. Noted for mortar and LAV-25, that gunner will tend to sweep horizon with increasing sector angle, so accuracy will constantly drop. No time at the moment to go deeper into this.

Share this post


Link to post
Share on other sites

Nice improvements, thanks very much!

increasing sector angle, so accuracy will constantly drop.

This is somewhat annoying, is there any way around this? It eventually goes 360 deg. In my situation it's not terrible, but would love to actually get it to target something, it looks like their drunk.

Edited by PlacidPaul

Share this post


Link to post
Share on other sites

This behavior, I guess, is part of AI that makes the gunner sweeping the horizon looking for real AI target. So, to avoid that, good way may be to give him such target. Instead of empty, non-AI object use as target real AI unit/vehicle, eg of same side, with such init:

this enableSimulation false;

This will make that target invulnerable and immobile (completely static). As for gunner - no more sweeping, only accurate fire at that target. You can do some experiments also with such init of that kind of target:

this enableSimulation false;this hideObject true

In this case target is also invisible, and gunner's behavior changes. Seems, that he doesn't see that target, so during each salvo he starts normal sweeping, but at the beginning of each new salvo, his gun returns to perfect aiming pos. In effect you have simulation of blind, suppresive fire of target area (there is some dispersion, progressing with each shot of salvo, but zeroed after each salvo).

Of course same code can be applied to the target in the sqf code. If you set target of enemy side, use _disableaim feature, or gunner will attack such target out of script control, as usual does.

Tested with LAV-25 and mortar as firing gun versus M1A1 as a target.

Share this post


Link to post
Share on other sites

Just a thought - you could use SHK_pos to move the target object to a new random position within a specified area after every round is fired.

Share this post


Link to post
Share on other sites

In this case target is also invisible, and gunner's behavior changes. Seems, that he doesn't see that target, so during each salvo he starts normal sweeping, but at the beginning of each new salvo, his gun returns to perfect aiming pos. In effect you have simulation of blind, suppresive fire of target area (there is some dispersion, progressing with each shot of salvo, but zeroed after each salvo).

Of course same code can be applied to the target in the sqf code. If you set target of enemy side, use _disableaim feature, or gunner will attack such target out of script control, as usual does.

This worked out exactly as you said. I had thought that using the ACE invisible targets would be the same, but I couldn't get it to work, not sure. SO I have a invisible helo, which now has the ace group marker on the map.:rolleyes: Maybe I can make that work to my advantage.

Thanks for the great help Rydygier!

Could thisbe explained a little, the ceil is the only part of your changes I don't get.

_amnt = ceil (random 10);

Oh, and moving the target to different spots would work nicely now...

Share this post


Link to post
Share on other sites
Ceil command rounds the number up. It is necessary, as random command returns number as floating point (eg. 5.287), and amount (number of shots) obviously must be not negative integer (eg. 6). So ceil provides such integer from 0 to 10 (0 most unlikely).

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
Sign in to follow this  

×