Jump to content
Ernst Alfred

AI mortar fire loop -I stan clueless

Recommended Posts

Hey. I am clueless. 

 

I want to make a loop for an AI mortar. 

The goal is to have the mortar shell a specific place every 30 seconds om e activated by a blufor present trigger. And it has to work in mp. 

 

Needless to say, as a very fresh recruit in arma I'm pretty lost. I understa d coding fairly well but this, I don't even know where to start... 

 

Thankfull for ideas or help, 

Ernst Alfred

  • Like 1

Share this post


Link to post
Share on other sites

Create mortar.

Mark the target with say an object (invisible helipad). You can use marker even.

There are a few ways of forcing fire. It all depends on how you set it up I guess. Check the Wiki!

https://community.bistudio.com/wiki/commandArtilleryFire

https://community.bistudio.com/wiki/doFire

https://community.bistudio.com/wiki/forceWeaponFire

https://community.bistudio.com/wiki/fireAtTarget

After fired. Create the explosion at real target using createVehicle. Adjust height and use setVelocity for the splash effect. Or you can properly set up the whole fire at target thing. Have a search on the forums. I think there are a few ready to use. You can look at those for ideas/inspiration too.

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites

First create a sqf file called "arty.sqf"

 

in it place this...

_mortar = arty1;
_radius = 60;

while {true} do
{
_center = markerPos "arty";

_pos = [
    (_center select 0) - _radius + (2 * random _radius),
    (_center select 1) - _radius + (2 * random _radius),
    0
    ];

_mortar commandArtilleryFire [
                    _pos,
                    getArtilleryAmmo [_mortar] select 0,
                    1
                ];

sleep 6;

_pos = [
    (_center select 0) - _radius + (2 * random _radius),
    (_center select 1) - _radius + (2 * random _radius),
    0
    ];

_mortar commandArtilleryFire [
                    _pos,
                    getArtilleryAmmo [_mortar] select 0,
                    1
                ];

sleep 6;

_pos = [
    (_center select 0) - _radius + (2 * random _radius),
    (_center select 1) - _radius + (2 * random _radius),
    0
    ];

_mortar commandArtilleryFire [
                    _pos,
                    getArtilleryAmmo [_mortar] select 0,
                    1
                ];

sleep 6;


};

Now go into game,place a mortar and name it "arty1" (no quotes)

 

Next,create a marker name "arty" (no quotes)

 

Create a trigger with your desired activation ie blufor present.

 

In the on activation field call the script with  " nul = execVM "arty.sqf"; " (no quotes)

 

The mortar will fire a round with about 6 seconds pause(sleep6) in between.If you want to keep firing more rounds add this line after the last "sleep 6" ....

_pos = [
    (_center select 0) - _radius + (2 * random _radius),
    (_center select 1) - _radius + (2 * random _radius),
    0
    ];

_mortar commandArtilleryFire [
                    _pos,
                    getArtilleryAmmo [_mortar] select 0,
                    1
                ];

sleep 6;

again and again depending on how many times you want it to fire.You can change "sleep 6" to "sleep 20" for example if you want 20 seconds between each shot.

 

Place down a vehicle ammo box next to the mortar unit so it should have infinite ammo too if needed or use a fired event handler to give it infinite ammo.Also where radius is written,this is the radius rounds will hit,so increase or decrease depending on how accurate to the target you want shells to hit. i find setting it to 200 in an area that will be defended with cover is good as long as your not dropping round after round after round

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
29 minutes ago, redarmy said:

Place down a vehicle ammo box next to the mortar unit so it should have infinite ammo too if needed or use a fired event handler to give it infinite ammo.Also where radius is written,this is the radius rounds will hit,so increase or decrease depending on how accurate to the target you want shells to hit. i find setting it to 200 in an area that will be defended with cover is good as long as your not dropping round after round after round

very good post but please use code tags  so when you paste/write it in it will actually look like it should with spacing and tabs lol

  • Thanks 1

Share this post


Link to post
Share on other sites
3 minutes ago, gokitty1199 said:

very good post but please use code tags lol

Done,cheers

Share this post


Link to post
Share on other sites

*I deleted this post as it was irrelevant, sry :P *

Edited by Ernst Alfred
Irrelevant

Share this post


Link to post
Share on other sites

@redarmy So if I want your script to be going in a loop until deactivated, all I need to do is adding the last:

_pos = [   

               (_center select 0) - _radius + (2 * random _radius),   

               (_center select 1) - _radius + (2 * random _radius),   

 0   

 ];

_mortar commandArtilleryFire [                     

                                        _pos,                     

                                        getArtilleryAmmo [_mortar] select 0,                     1                 ];

                                          sleep 6;

 

Or did I get it wrong? Because my goal is to get a loop which just continues until deactivation. Otherwise, won't the script become too long?

 

I really appreciate the help!!

Share this post


Link to post
Share on other sites

Just some sidenotes:

Don't use while true loops. If the arty gets destroyed mid-mission you'll constantly get errors and fill up the .rpt.

You can also add some parameters so the function will be more customizeable.

 

The most plain loop would look like this:

//place mortars on the map and put this in the init field:
this setVariable ["GOM_fnc_batteryID","Battery01",true];//"Battery01" can be named however you want, allows to run this script for multiple batteries

//then into init.sqf or wherever you seem fit:
GOM_fnc_artyActive = true;
GOM_fnc_artyLoop = {
	params ["_batteryID","_delay","_targetPos",["_spread",50],["_rounds",4]];
	_battery = vehicles select {_x getVariable ["GOM_fnc_batteryID",""] isEqualTo _batteryID};
	while {GOM_fnc_artyActive AND {alive _x} count _battery > 0} do {
		if (!GOM_fnc_artyActive OR {alive _x} count _battery isEqualTo 0) exitWith {false};
		{
			_x setVehicleAmmoDef 1;
			_pos = _targetPos vectorAdd [random _spread,random _spread,0];
			_wait = [_pos,_x,_rounds] spawn {
				params ["_pos","_gun","_rounds"];
				sleep random 0.8;
				_gun commandArtilleryFire [_pos,currentMagazine _gun,_rounds];
			};
		} forEach _battery;
		sleep _delay;
	};
};


//to call simply use the following:
_batteryID = "Battery01";//variable set to the arty gun in the editor
_delay = 30;//pause between salvoes
_targetPos = getMarkerPos "ArtyTarget";
_spread = 50;//(OPTIONAL) spread of shell impact position
_rounds = 4;//(OPTIONAL) rounds per salvo
_fire = [_batteryID,_delay,_targetPos,_spread,_rounds] spawn GOM_fnc_artyLoop;

//to stop arty from firing:
GOM_fnc_artyActive = false;

Small demo mission.

 

Cheers

  • Like 2
  • Thanks 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

×