I wrote this script with the purpose of having AI controlled artillery pieces continually fire rounds without lowering the main cannon to re-adjust their aim each time. I figured I'd share it with the community so that others might benefit. It can be useful for a fire base to add ambience, an objective to destroy an enemy artillery piece firing on imaginary friendlies far away, at a firing range to make it look like the AI is practicing, or any other idea you can come up with where this would be useful.
This script is not designed for accurate AI artillery fire; do not try and use it for this purpose. There are other scripts out there that handle this. If you want to make this work on a mortar be sure you see below** for instructions!
The script is run on an artillery unit and forces the unit to aim at an object (a marker will not work, I will explain why below*) with a set barrel angle and fire continuously until the loop is canceled, either by destroying the unit itself, or deleting/destroying the object that is the target. Other parameters include the ability to delete the projectile after it is fired so it never impacts the ground anywhere, have the unit be set as captive, have the unit auto reload when it runs out of shells/rockets, and have a minimum and random delay time between shots if desired.
You are free to modify this for personal use within your own mission to achieve your desired effect, but please do not redistribute a modified version publically as it will make it harder for me to keep track of and potentially liable.
The only limitation is you may not use or distribute this script on any monetized platform. No exceptions without written consent from myself.
Google Drive Link: Mynock's Ambient Artillery Battery Script v1.0
Sorry my mic is so garbage :(
Extensive documentation is provided within the script including all parameter default values, what changing the parameters will do, etc. It should provide you with a very easy to follow guide to get it to work how you want.
Special thanks to: kydoimos, Radioman, kylania
*The reason for not using a marker is for ease of exiting the while/do loop in the mission editor. All that's required to exit the loop (if you want the artillery unit to remain) is to delete the object that is the target via a trigger, another script, an addAction, however you want to do it. There are multiple invisible objects you can place, which is what I recommend using.
**I guess mortars function differently than artillery units, so if you want the mortar to stop firing after killing the gunner for that mortar, you'll need to name the unit that is the gunner for the mortar, then place a trigger with the condition of !alive mygunnername and in the on activation field use the deleteVehicle command to delete the target. That will allow the loop to be exited and the mortar will stop firing on it's own. I have no clue why it does that with mortars, sorry. Thanks to meaty for pointing that out.