Jump to content
Jayd33

Enemy AI using artillery.

Recommended Posts

How to configure the script so instead of using single mortars/arty units I can order a whole group of units to fire?

Thanks guys!

{
   for "_i" from 0 to 5 do {  //--- 5 = how many rounds you want fired

       _mortar = _x;                //--- name of the mortar
       _center = markerPos "target1";  //--- central point around which the mortar rounds will hit
       _radius = 100;                       //--- random radius from the center

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

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

   };
} forEach units group mortar1;

Script looks okay but there is NOTHING happening. :-/ Mortars are not doing anything.

Edited by megagoth1702

Share this post


Link to post
Share on other sites
How to configure the script so instead of using single mortars/arty units I can order a whole group of units to fire?

Script looks okay but there is NOTHING happening. :-/ Mortars are not doing anything.

Try this on for size, I changed a few things around, and just defined the type of mortar round used instead of using getArtilleryAmmo (and re-did some formatting :p):

{
   for "_i" from 0 to 5 do //--- 5 = how many rounds you want fired
{  

       _mortar = _x;                //--- name of the mortar
       _center = (getMarkerPos "target1");  //--- central point around which the mortar rounds will hit
       _radius = 100;                       //--- random radius from the center

	_pos = [[[_center, _radius]], "ground", ["water", "out"], {}] call BIS_fnc_randomPos;

	_mortar commandArtilleryFire 
	[
		_pos,
           "8Rnd_82mm_Mo_shells",
           1
       ];

   };
} forEach units group mortar1;

Share this post


Link to post
Share on other sites
If I want the artillery is a Sandstorm launcher and fire in a marker like a loop while every five minutes?

Maybe a bit more than needed, but eh, fun with functionality :D:

//null = [this,"mrkName",12,300] execVM "sandstormFire.sqf";

//sandstormFire.sqf
_sandstorm = [_this,0,objNull,[objNull]] call BIS_fnc_param;
_markerPos = getMarkerPos ([_this,1,"",[""]] call BIS_fnc_param);
_numRnds = [_this,2,12,[0]] call BIS_fnc_param;
_timeBetween = [_this,3,300,[0]] call BIS_fnc_param;

if (isNull _sandstorm) exitWith { systemChat "Sandstorm is undefined or dead >> sandstormFire.sqf"; };

while {true} do
{
if (isNull _sandstorm || !alive _sandstorm) exitWith {};

_sandstorm commandArtilleryFire [_markerPos,"12Rnd_230mm_rockets",_numRnds];

sleep _timeBetween;
};

You can put the call line in the init field of the object, or name the object something and put it in place of "this".

So first argument in the call line is the object that will be doing the firing.

Second argument is the marker position it's firing at.

Third argument is the number of rounds to be fired in the burst (defaults to 12).

Fourth argument is the time between firings (defaults to 300 seconds >> 5 minutes).

Share this post


Link to post
Share on other sites
Maybe a bit more than needed, but eh, fun with functionality :D:

//null = [this,"mrkName",12,300] execVM "sandstormFire.sqf";

//sandstormFire.sqf
_sandstorm = [_this,0,objNull,[objNull]] call BIS_fnc_param;
_markerPos = getMarkerPos ([_this,1,"",[""]] call BIS_fnc_param);
_numRnds = [_this,2,12,[0]] call BIS_fnc_param;
_timeBetween = [_this,3,300,[0]] call BIS_fnc_param;

if (isNull _sandstorm) exitWith { systemChat "Sandstorm is undefined or dead >> sandstormFire.sqf"; };

while {true} do
{
if (isNull _sandstorm || !alive _sandstorm) exitWith {};

_sandstorm commandArtilleryFire [_markerPos,"12Rnd_230mm_rockets",_numRnds];

sleep _timeBetween;
};

You can put the call line in the init field of the object, or name the object something and put it in place of "this".

So first argument in the call line is the object that will be doing the firing.

Second argument is the marker position it's firing at.

Third argument is the number of rounds to be fired in the burst (defaults to 12).

Fourth argument is the time between firings (defaults to 300 seconds >> 5 minutes).

I have a problem, the sandstorm dont want to reload their ammo, gets stuck. Why? :confused:

I placed a ammo truck, but dont want reload.

Share this post


Link to post
Share on other sites
I have a problem, the sandstorm dont want to reload their ammo, gets stuck. Why? :confused:

I placed a ammo truck, but dont want reload.

Well, I don't know if AI will use the ammo truck, but in any case, below should make life easy in that regard:

//null = [this,"mrkName",12,300] execVM "sandstormFire.sqf"; 

//sandstormFire.sqf 
_sandstorm = [_this,0,objNull,[objNull]] call BIS_fnc_param; 
_markerPos = getMarkerPos ([_this,1,"",[""]] call BIS_fnc_param); 
_numRnds = [_this,2,12,[0]] call BIS_fnc_param; 
_timeBetween = [_this,3,300,[0]] call BIS_fnc_param; 

if (isNull _sandstorm) exitWith { systemChat "Sandstorm is undefined or dead >> sandstormFire.sqf"; }; 

while {true} do 
{ 
   if (isNull _sandstorm || !alive _sandstorm) exitWith {}; 

   _sandstorm commandArtilleryFire [_markerPos,"12Rnd_230mm_rockets",_numRnds]; 

   sleep _timeBetween;

_sandstorm setVehicleAmmo 1;
};  

Share this post


Link to post
Share on other sites
Well, I don't know if AI will use the ammo truck, but in any case, below should make life easy in that regard:

//null = [this,"mrkName",12,300] execVM "sandstormFire.sqf"; 

//sandstormFire.sqf 
_sandstorm = [_this,0,objNull,[objNull]] call BIS_fnc_param; 
_markerPos = getMarkerPos ([_this,1,"",[""]] call BIS_fnc_param); 
_numRnds = [_this,2,12,[0]] call BIS_fnc_param; 
_timeBetween = [_this,3,300,[0]] call BIS_fnc_param; 

if (isNull _sandstorm) exitWith { systemChat "Sandstorm is undefined or dead >> sandstormFire.sqf"; }; 

while {true} do 
{ 
   if (isNull _sandstorm || !alive _sandstorm) exitWith {}; 

   _sandstorm commandArtilleryFire [_markerPos,"12Rnd_230mm_rockets",_numRnds]; 

   sleep _timeBetween;

_sandstorm setVehicleAmmo 1;
};  

Just right now I put the setVehicleAmmo 1 exactly your code, the AI does not want to reload... AI derp... :butbut: T_T

Share this post


Link to post
Share on other sites
Just right now I put the setVehicleAmmo 1 exactly your code, the AI does not want to reload... AI derp... :butbut: T_T

Yea, my fault, didn't look deep enough into the setVehicleAmmo command, has a bit more needed information to work properly, so we will try this instead :p:

//null = [this,"mrkName",12,300] execVM "sandstormFire.sqf";  

//sandstormFire.sqf  
_sandstorm = [_this,0,objNull,[objNull]] call BIS_fnc_param;  
_markerPos = getMarkerPos ([_this,1,"",[""]] call BIS_fnc_param);  
_numRnds = [_this,2,12,[0]] call BIS_fnc_param;  
_timeBetween = [_this,3,300,[0]] call BIS_fnc_param;  

if (isNull _sandstorm) exitWith { systemChat "Sandstorm is undefined or dead >> sandstormFire.sqf"; };  

while {true} do  
{  
   if (isNull _sandstorm || !alive _sandstorm) exitWith {};  

   _sandstorm commandArtilleryFire [_markerPos,"12Rnd_230mm_rockets",_numRnds];  

   sleep _timeBetween; 

   _sandstorm addMagazineTurret ["12Rnd_230mm_rockets",[0]]; 
};

Share this post


Link to post
Share on other sites

Sorry JShock

Do you have any other ideas?, sandstorm still not reload ammo :confused:

Share this post


Link to post
Share on other sites

After more digging, and personally testing stuff this time, setVehicleAmmo would work...

_sandstorm = [_this,0,objNull,[objNull]] call BIS_fnc_param;   
_markerPos = getMarkerPos ([_this,1,"",[""]] call BIS_fnc_param);   
_numRnds = [_this,2,12,[0]] call BIS_fnc_param;   
_timeBetween = [_this,3,300,[0]] call BIS_fnc_param;   

if (isNull _sandstorm) exitWith { systemChat "Sandstorm is undefined or dead >> sandstormFire.sqf"; };   

_sandstorm setVehicleAmmo 1;

while {true} do   
{   
   if (isNull _sandstorm || !alive _sandstorm) exitWith {};   

   _fireSequence = [_sandstorm,_markerPos,_numRnds] spawn
{
	(_this select 0) commandArtilleryFire [(_this select 1),"12Rnd_230mm_rockets",(_this select 2)];   
};
   sleep _timeBetween;

_sandstorm setVehicleAmmo 1;
};

Share this post


Link to post
Share on other sites

It now works!!, this creates new expectations to my insipid missions

Thank you Sir. :yay:

Share this post


Link to post
Share on other sites

Nope, don't work, only fire once time, the loop while don't work and not reload the ammo with a truck, maybe it's a bug of bohemia?

Share this post


Link to post
Share on other sites

Yes, it works I just try again .

It would be perfect if could be an random explosion radio, Right now the rockets impact in the center of marker.

Edited by Rapax

Share this post


Link to post
Share on other sites
Nope, don't work, only fire once time, the loop while don't work and not reload the ammo with a truck, maybe it's a bug of bohemia?

Could you provide the call line that you used? And this script is meant to negate the need to load from a truck, and I believe earlier I stated that AI's don't reload from trucks as far as I know.

---------- Post added at 11:06 ---------- Previous post was at 11:05 ----------

Yes, it works I just try again .

It would be perfect if could be an random explosion radio, Right now the rockets impact in the center of marker.

I had orginally thought the same thing, but it was stated that it was wanted "on a marker position", so they are :p, let me get to my computer (on my phone atm) and I will try and alter it a bit for radius firing.

---------- Post added at 12:05 ---------- Previous post was at 11:06 ----------

Here it is, added another parameter for radius at the end, default is 150m:

//null = [this,"mrkName",12,300,150] execVM "sandstormFire.sqf";   

//sandstormFire.sqf   
_sandstorm = [_this,0,objNull,[objNull]] call BIS_fnc_param;   
_markerPos = getMarkerPos ([_this,1,"",[""]] call BIS_fnc_param);   
_numRnds = [_this,2,12,[0]] call BIS_fnc_param;   
_timeBetween = [_this,3,300,[0]] call BIS_fnc_param;
_radius = [_this,4,150,[0]] BIS_fnc_param;

if (isNull _sandstorm) exitWith { systemChat "Sandstorm is undefined or dead >> sandstormFire.sqf"; };   

_sandstorm setVehicleAmmo 1;

while {_sandstorm getVariable ["continueFiring",true]} do   
{   
   if (isNull _sandstorm || !alive _sandstorm) exitWith {};   

   _fireSequence = [_sandstorm,_markerPos,_numRnds,_radius] spawn
   {
	for "_i" from 0 to (_this select 2) step 1 do
	{
		_pos = [[(_this select 1), (_this select 3)], "ground", ["water", "out"]] call BIS_fnc_randomPos;
		(_this select 0) commandArtilleryFire [(_pos),"12Rnd_230mm_rockets",1];   
	};
   };
waitUntil {scriptDone _fireSequence};
   sleep _timeBetween;

   _sandstorm setVehicleAmmo 1;
};

I also added a way to allow the continuous firing to stop, all you have to do is make sure to name the sandstorm, and on whatever triggered event put this:

sandstormName setVariable ["continueFiring",false];

Edited by JShock

Share this post


Link to post
Share on other sites

Hey JShock

Have you tried yourself this modified script ?

i named sanstorm and marker but now sandstorm dont shoot.

this is the the call line: null = [t1,"mrk1",12,300] execVM "sandstormFire.sqf"; in sandstorm init

Thank you for your patience!.

Share this post


Link to post
Share on other sites
Hey JShock

Have you tried yourself this modified script ?

i named sanstorm and marker but now sandstorm dont shoot.

this is the the call line: null = [t1,"mrk1",12,300] execVM "sandstormFire.sqf"; in sandstorm init

Thank you for your patience!.

Yea sorry about that, I had to be somewhere and rushed the code, missed typing "call" for the "_radius" BIS_fnc_param line :p, but now that I've sat down and looked at it I have the following workaround, but it works incompletely and inconsistently, and it's really bugging the shit out of me why it's doing so, so hopefully someone else can clue us into why that's happening:

_sandstorm = [_this,0,objNull,[objNull]] call BIS_fnc_param;    
_marker = [_this,1,"",[""]] call BIS_fnc_param;    
_numRnds = [_this,2,12,[0]] call BIS_fnc_param;    
_timeBetween = [_this,3,300,[0]] call BIS_fnc_param; 
_radius = [_this,4,150,[0]] call BIS_fnc_param;

if (isNull _sandstorm) exitWith { systemChat "Sandstorm is undefined or dead >> sandstormFire.sqf"; };    

_sandstorm setVehicleAmmo 1;

while {_sandstorm getVariable ["continueFiring",true]} do    
{    
   if (isNull _sandstorm || !alive _sandstorm) exitWith {}; 

_sandstorm setVariable ["sandstormFired",false];
_sandstormFiredEH = _sandstorm addEventHandler ["Fired",
{
	(_this select 0) setVariable ["sandstormFired",true];
}];	

   _fireSequence = [_sandstorm,_marker,_numRnds,_radius] spawn 
   {
       for "_i" from 0 to (_this select 2) step 1 do 
       { 
		(_this select 0) setVariable ["sandstormFired",false];
		_pos = [[[getMarkerPos (_this select 1), (_this select 3)],[]],["water","out"]] call BIS_fnc_randomPos;
           (_this select 0) commandArtilleryFire [(_pos),"12Rnd_230mm_rockets",1];
		waitUntil {((_this select 0) getVariable ["sandstormFired",false])};
       };
	hint "5";
   }; 
   waitUntil {scriptDone _fireSequence}; 
_sandstorm removeEventHandler _sandstormFiredEH;
   sleep _timeBetween; 

   _sandstorm setVehicleAmmo 1;
};

And since it's a bit hard to explain the issues, below is an example mission so whomever wants to can see the issues themselves:

https://www.dropbox.com/s/q7f8hr4eb7pp4hj/sandstorm_Fire_example.Stratis.7z?dl=0

Share this post


Link to post
Share on other sites
continue without shoot :/

My last code block, as I stated, isn't working properly, the ones before I started messing with the "fire on area" effect, were working perfectly fine, so you have set something up wrong, could you supply your mission folder?

Last working version being in post #35: http://forums.bistudio.com/showthread.php?150180-Enemy-AI-using-artillery&p=2832704&viewfull=1#post2832704

Share this post


Link to post
Share on other sites
My last code block, as I stated, isn't working properly, the ones before I started messing with the "fire on area" effect, were working perfectly fine, so you have set something up wrong, could you supply your mission folder?

Last working version being in post #35: http://forums.bistudio.com/showthread.php?150180-Enemy-AI-using-artillery&p=2832704&viewfull=1#post2832704

Nope, I don't know what happen whit Sandstorm that don't fire more one time T-T

Share this post


Link to post
Share on other sites

I've read through this thread and have tried other searches, so please forgive me if I missed it but is there any way to have the AI be able to smartly call in artillery and close air support?  I've tried using the same method as with humans, dropping the support requestor and support giver, synching them and giving control to the AI squad leader but they never call it in despite being under heavy fire.  I've tested it out as a player so I know I have it set up right for that part at least.

 

I know this is an old thread, but thought this may be better than starting a new one.  Let me know if anyone has any good ideas.  I'm not even sure if this is possible or not.

 

PS, I'm making a mission where I want to give players the option of taking out the bases where the support is located, but do not want them to have to do this option before assaulting the final enemy location.  I really want it to be open ended with what plans they make.  I'm a little new to editing so all that scripting language stuff is kind of confusing, but it didn't sound like it would work because if I understand correctly, they are talking about scripting artillery in specific locations.

 

 

Thanks all.

 

Share this post


Link to post
Share on other sites

I need some help

 

I am using the original script here

 

https://forums.bistudio.com/topic/141357-enemy-ai-using-artillery/?p=2283929

 

 

but I need to modify it and don't know how

 

The situation is as follows.  My BLUFOR squad will try to defend a position and the OPFOR enemy will soften it up with random mortar fire before assaulting it with waves of infantry.  I would like the mortar fire to stop when the enemy approach the BLUFOR defensive position to avoid hitting their own people and resume firing if there are no more OPFOR in the vicinity of the BLUFOR position.

 

I have a trigger covering the BLUFOR area

 

OPFOR

Not present

repeat (yes)

on act: bombardment = true

on deact: bombardment = false

 

and another trigger with the condition "bombardment" that actually calls the script

 

But in the script the bombardment is to run for a number of rounds.  How do I change that so  that  the bombardment (the script) works with the trigger described above so bombardment stops  if OPFOR infantry get in  the vicinity of the BLUFOR position and re-start the bombardment if the condition is true again?

 

I guess I should change line 1 of the script and replace it by something that would check if the trigger is activated or deactivated?, but unfortunately i know nothing of programming and I am completely lost.  

 

Some help would be greatly appreciated!

Share this post


Link to post
Share on other sites

Personally if i can avoid adding scripts i do without them, this is how I do enemy artillery using 2 waypoints and a trigger

 

let's say you have 3 OPFOR mortars that need to guard a certain area

 

//trigger
name: PERIMETER1

setup: REPEATABLE, BLUFOR detected by OPFOR

 

now give the mortar group two waypoints close to the mortars

//waypoint1

type: scripted

condition: triggeractivated PERIMETER1

activation:

TARGET = GETPOS (list PERIMETER1 call bis_fnc_selectRandom);

{_x commandArtilleryFire [TARGET,"8Rnd_82mm_Mo_shells", 1];} foreach thislist;

//waypoint2, remember that it must be close enough to waypoint1 to cycle with it
type: cycle
countdown: <whatever delay between shellings you want>
 
result: Blufor enters an area, gets spotted by any enemy, mortars pick a random trespasser and fre at him

Share this post


Link to post
Share on other sites

Vrae, thanks for your input, but that is not what I intend to do.

 

My troops are defending a position, the enemy bombards us with a random pattern arround a point and stop firing when enemy assault  troops approach our position. If we are successful on defense and the enemy infantry is pushed out of our zone, the mortars resume fire.

Share this post


Link to post
Share on other sites

Apologies about replying to this old thread but its similar to my issue and I cannot create a thread of my own. 

 

I'm trying to make one friendly AI artillery fire at 3 separate targets using script.
The friendly artillery is a Zamak MRL with the variable name "art1"
I have placed 3 markers down in the editor and called them "target1" "target2" and "target3"
The script is activated by a trigger

The script works with no errors and actually fires 3 rounds on the first target, "target1" but it doesn't seem to be looping and is not proceeding to fire 3 rounds at the next target, "target2"

Here is the script named "ambient_art.sqf":


target_array = ["target1","target2","target3"];
target_index = 0;

while {(target_index <= 2)} do{

     target_choice = (target_array select target_index);
     ammo1 = getArtilleryAmmo [art1] select 0;
     tgt = getMarkerPos target_choice;
     art1 doArtilleryFire[tgt,ammo1,3];

     target_index = target_index + 1;
     sleep 3;
     }


in the trigger, which is fired when the player walk in I have in the activation field
script = [] execVM "ambient_art.sqf"

Any help will be deeply appreciated

Share this post


Link to post
Share on other sites

Just pointing out that I found the solution from a very helpful person from the steam forums. The issue was due to the target number being switched before the unit had fired at the first one, the target currently being fired upon was the final target I had in the array.

The solution was removing the sleep 3; at the end and replacing it with

waitUntil {unitReady art1};

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

×