Jump to content
roguetrooper

How to make AI mortar fire at position?

Recommended Posts

How can you make an AI-controlled mortar (not subordinated to human player) to fire at a certain position?

I've tried a hundred variations with these and related commands. Nothing works. The mortar moves some degrees but nothing happens.

enableEngineArtillery true;
(gunner mortar) commandArtilleryFire [[position tower select 0,position tower select 1,0], "Sh_82mm_AMOS", 1];

Share this post


Link to post
Share on other sites
yourMortarNameHere commandArtilleryFire 
[
  getPosATL tower,
  "8Rnd_82mm_Mo_shells",
  1
];

Share this post


Link to post
Share on other sites

I'm bumping this topic as it fits exactly my issue.

 

Even using @jshock 's script, they won't fire. It seems that they aim the correct way, but they won't actually fire.

 

I've tried the ammo type above, as well as the ammo types specific for the mortar.

 

Any ideas? Also, the mortars aren't vanilla, if that helps.

Share this post


Link to post
Share on other sites

Make sure the mortar is actually able to fire at its target position.

Optimum distance to the target location would be anywhere between 250-4000m.

Place and mount a mortar near the AI mortar to check for yourself.

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites
1 hour ago, Grumpy Old Man said:

Make sure the mortar is actually able to fire at its target position.

Optimum distance to the target location would be anywhere between 250-4000m.

Place and mount a mortar near the AI mortar to check for yourself.

 

Cheers

Appreciate the quick reply. I tested this out as well. I could shoot well beyond the distance required on the default range setting, and even moved the named target objects closer, with no luck.

 

Here's what I've got, in a script run by the game logic on mission start:

 

mortar1 commandArtilleryFire 
[
  getPosATL mortar_target1,
  "ARTY_LIB_8Rnd_81mmHE_GRWR34",
  5
];

I've tried doArtilleryFire as well to no avail. 

Share this post


Link to post
Share on other sites

Try using this:

 

_arty = mortar1;
_target = mortar_target1;

_artyAmmo = getArtilleryAmmo [_arty] select 0;
_artyETA = _arty getArtilleryETA [getPosATL _target, _artyAmmo];
_inRange = (getPosATL _target) inRangeOfArtillery [[_arty], _artyAmmo];
systemchat format ["In range: %1",_inRange];

if (_artyETA > 0 AND _inRange) then {

systemchat "Cleared to fire!";
systemchat format ["Impact ETA: %1s",_artyETA];
_arty commandArtilleryFire [getPosATL _target, _artyAmmo, 5];

};

There's already checks available to see if the arty piece is able to hit that position, use them.

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites
50 minutes ago, Grumpy Old Man said:

Try using this:

 


_arty = mortar1;
_target = mortar_target1;

_artyAmmo = getArtilleryAmmo [_arty] select 0;
_artyETA = _arty getArtilleryETA [getPosATL _target, _artyAmmo];
_inRange = (getPosATL _target) inRangeOfArtillery [[_arty], _artyAmmo];
systemchat format ["In range: %1",_inRange];

if (_artyETA > 0 AND _inRange) then {

systemchat "Cleared to fire!";
systemchat format ["Impact ETA: %1s",_artyETA];
_arty commandArtilleryFire [getPosATL _target, _artyAmmo, 5];

};

There's already checks available to see if the arty piece is able to hit that position, use them.

 

Cheers

 

 

Cheers.

 

Edit: Script now says they are in range and provides the ETA; however, they still aren't firing.

 

The AI adjusts his mortar to the correct direction, but won't fire.

Edited by SkillerPenguin

Share this post


Link to post
Share on other sites

Has _arty got ammo?

 

_arty setVehicleAmmo 1;

Share this post


Link to post
Share on other sites
Quote

The mortar moves some degrees but nothing happens.

 

I saw same behavior for custom mortar (Iron Front's german mortar) with analogous code, while same code for sure works fine with vanilla artillery (and some other mods too IIRC). So indeed main question here is about the mod. Or, to be exact, why artillery from some mods doesn't work with these script commands and how to fix them. 

Share this post


Link to post
Share on other sites
6 minutes ago, Rydygier said:

 

I saw same behavior for custom mortar (Iron Front's german mortar) with analogous code, while same code for sure works fine with vanilla artillery (and some other mods too IIRC). So indeed main question here is about the mod. Or, to be exact, why artillery from some mods doesn't work with these script commands and how to fix them. 

 

14 minutes ago, Grumpy Old Man said:

What mod are your arty units from?

 

Cheers

 

 

It is actually the German mortar from Iron Front.

Share this post


Link to post
Share on other sites

When you name the Arty make sure you name the Mortar  and not the AI or group.

 

Also just try placing a firemission  waypoint for the artillery  and see if that's working if it isn't then it's either mods or Arma3 installation.

 

Share this post


Link to post
Share on other sites
34 minutes ago, f2k sel said:

When you name the Arty make sure you name the Mortar  and not the AI or group.

 

Also just try placing a firemission  waypoint for the artillery  and see if that's working if it isn't then it's either mods or Arma3 installation.

 

 

Yeah, still no beans.

 

 

If I could just create the mortars without the AI firing them off, I'd be very happy with that as well; even explosions with a mortar whistle sound effect would do - think you could point me to some you'd recommend? 

Share this post


Link to post
Share on other sites

Tried it with the GrWr 34 mortar from iron front lite.

Like SkillerPenguin stated, the mortar aims, but doesn't fire.

Seems to be some config problem with the mortar.

 

Cheers

Share this post


Link to post
Share on other sites
7 minutes ago, Grumpy Old Man said:

Tried it with the GrWr 34 mortar from iron front lite.

Like SkillerPenguin stated, the mortar aims, but doesn't fire.

Seems to be some config problem with the mortar.

 

Cheers

 

It's official - after some testing, it officially looks like the Iron Front German & Soviet mortars don't work for AI. I put Germans in modern mortars, which worked but modern soldiers in German mortars didn't work.

 

Got any scripts handy for mortars hitting a target without needing an actual mortar?

 

Share this post


Link to post
Share on other sites

Don't know about now, but in Arma 2 times there was at least few/several threads showing, how to. Same code with only changed ammo class should work in Arma 3. Two examples:

 

 

Share this post


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

 

It's official - after some testing, it officially looks like the Iron Front German & Soviet mortars don't work for AI. I put Germans in modern mortars, which worked but modern soldiers in German mortars didn't work.

 

Got any scripts handy for mortars hitting a target without needing an actual mortar?

 


Give this a go, by no means perfect but it expands on what @Grumpy Old Man mentioned:
 

/*
	Author: HallyG
	Artillery barrage(s) at the desired location. 
	Configurable number of barrages, rounds per barrage, time between rounds/barrages
	Radius of barrage is given in an array
		[Min distance, Max distance]
	

	Arguments(s):
		0: Centre - <MARKER, OBJECT, LOCATION, GROUP, TASK, POSITION>
		1: Radius [min, max] - <ARRAY>
		2: Rounds in each barrage- <SCALAR>
		3: Number of barrages- <SCALAR>
		4: Time between rounds- <SCALAR>
		5: Time between barrages- <SCALAR>
		6: Use smoke? (FALSE = HE rounds) - <BOOLEAN>

	Return Value:
		<NOTHING>
	
	Example:
		[
			player,
			[0,50],
			8, 2, 1, 5,
			false
		] spawn FUNCTIONNAME;
__________________________________________________________________*/
params [
	["_centre", [], ["", [], objNull]],
	["_radius", [10, 50], [[]], [2]],
	["_rounds", 10, [0]],
	["_barrage", 4, [0]],
	["_roundTime", 1, [0]],
	["_barrageTime", 5, [0]],
	["_smoke", false, [true]]
];

_centre = _centre call {
	if (_this isEqualType objNull) exitWith {getPosASL _this};
	if (_this isEqualType grpNull) exitWith {getPosASL (leader _this)};
	if (_this isEqualType "") exitWith {getMarkerPos _this};
	if (_this isEqualType locationNull) exitWith {locationPosition _this};
	if (_this isEqualType taskNull) exitWith {taskDestination  _this};
	if (_this isEqualType [] && {_this isEqualTypeArray [0,0] || _this isEqualTypeArray [0,0,0]}) exitWith {_this};
	[]
};
	
if (_centre isEqualTo [0,0,0]) exitWith {};
	
private _radiusFnc = {
	params [
		["_min", 10, [0]],
		["_max", 50, [0]]
	];
	linearConversion [0, 1, random 1, abs (_this select 0), abs (_this select 1)]
};
	

for "_j" from 1 to _barrage do {
	for "_i" from 1 to _rounds step 1 do {
		_mrtRnd = createVehicle [
			["M_Mo_82mm_AT_LG", "Smoke_82mm_AMOS_White"] select _smoke,
			(_centre getPos [_radius call _radiusFnc, random 360]) vectorAdd [0,0,1000],
			[], 0, "NONE"
		];
			
		[_mrtRnd, -90, 0] call BIS_fnc_setPitchBank;
		_mrtRnd setVelocity [0,0,-100];
			
		sleep _roundTime;
	};
		
	sleep _barrageTime
};

 

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

×