Jump to content
Sign in to follow this  
masterfulninja

AI controlled mortars

Recommended Posts

Im having trouble getting the AI to use the mortars properly. My mission has soldiers who join the player after you accomplish tasks, one soldier I want to man a mortar and fire at targets before he joins. Getting him to man is no problem but i cant get him to fire on his own and i don't want to preprogram the mortar impacts. Ive had no luck with the few AI artillery scripts Ive found im not sure if its because im using a soldier to man the empty weapon or if im just not getting it. need help.

Share this post


Link to post
Share on other sites

My AI List has section that covers this

Artillery, Mortars, & AT soldiers

Make launcher carrier AI fire launchers on command only

http://tinyurl.com/or29un3

How to make AI mortar fire at position?

http://tinyurl.com/kg9923r

Force AI to Fire Launcher

http://tinyurl.com/p5wtzpx

How to make AI shoot artillery in a specific way

http://tinyurl.com/mxf497d

Enemy AI using artillery

http://tinyurl.com/m84qme6

AI Artillery - Aiming without firing

http://tinyurl.com/od5ng4y

==========

In the future suggest reviewing my list for any questions, or problems related to AI if it hasn't already been asked.

Share this post


Link to post
Share on other sites
Quote Originally Posted by leecarter View Post

Hi all,

Just thought I'd drop in and share how I managed to do this. First off, as of this post I can not get this to work with artillery units, only mortars.

This is a script I wrote that allows the mortar to fire at any enemy land target that enters the target zone. Basically, the effect is that the mortar will "lock on" to any enemy that strays into the target zone(s) you set up for it and will re-adjust it's targeting as the enemy moves around.

First, here's the script you'll need.

Code:

_mortar = _this select 0;

_targetArray = _this select 1;

_target = _targetArray select 0;

_theAmmo = getArtilleryAmmo [_mortar] select 0;

_idx = 0;

//-- prevents firing at aircraft

if(isTouchingGround _target) then {

//-- The number of times you want the _mortar to check for range

while {(_idx < 10)} do{

_tgtPos = position _target;

_isInRange = _tgtPos inRangeOfArtillery [[_mortar], _theAmmo ];

if (_isInRange) then {

_mortar commandArtilleryFire [_tgtPos, _theAmmo , 1 ];

};

sleep 5;

_idx = _idx + 1;

};

};

Of course you can tinker with the values to suit your taste.

Next, make a mortar and name it whatever you want. In this example I used mortar1.

Then make a trigger that goes off repeatedly any time an enemy enters and put this in the on act section:

Code:

script=[mortar1, thislist] execVM "fireMortar.sqf";

You can reuse this script with as many different mortars and as many different targets as you want, so:

Code:

script=[mortar1, thislist] execVM "fireMortar.sqf";

script=[mortar2, thislist] execVM "fireMortar.sqf";

script=[mortar3, thislist] execVM "fireMortar.sqf";

Would all be valid as actions for targets assuming you created mortars with those names.

I've only been tinkering around with the editor for a few days, but this is the first thing I wanted to script out and I thought I would share it.

EDIT: Prevent firing at aircraft

This is the functionality im looking for code wise, i want the mortars to actually pick out targets and fire at them within a certian area. Problem is I still cant get this code to work. I got one of the other fixes mentioned to somewhat work where at least they fired a few rounds but it wasnt reliable performance. Ive been stuck on getting mortars to work properly since i first started i dont know what the issue is.

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  

×