Jump to content
Stank4K

Make AI Mortars fire on Random Markers.

Recommended Posts

Looking to make AI fire on random preset markers. I have ripped and tinkered with some bits and pieces of code. Most come from GOM's posts and replies.

Here is what I've come up with:

[] Spawn {

    while {true} do {
    
        _arty = mortar1; 
        _target = ["target1","target2","target3"] call BIS_fnc_selectRandom; 
 
        _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]; 
        sleep 45;
    }

}};

But as far as I can tell, the target cannot be randomly selected.
This bit here seems to break it:

_target = ["target1","target2","target3"] call BIS_fnc_selectRandom; 

It works to fire on one position with it as this:

        _target = target1; 

The artillery fires nicely with the Do While loop and the sleep x; bit. But one other issue is that arty doesn't start firing until the sleep x time has passed. Which is a small issue in itself. Even with sleep being at the end of the code, it waits the full amount of time before firing. I thought these scripts ran top to bottom.

 

TL;DR: Code works only for single target. I want to fire 5 shots, then pick another random preset target (target1,target2,target3,etc.) then fire 5 more with a sleep delay between barrages.

 

Huge bonus: If someone can post a separate bit of code to fire on players current position. Once it fires, I just want it to hit where it was supposed to. As if players are running from the arty fire and if they stay still, RIP. I looked into getRelPos for players, but had no luck. Just errors.

Share this post


Link to post
Share on other sites
1 hour ago, Stank4K said:

getPosATL _target

_target is a STRING of marker name. Use getMarkerPos instead.

Share this post


Link to post
Share on other sites

@Larrow That made things a tad better. I don't error. However. AI seems to think it's not in range. So I assume the values that returns is not what the AI is looking for. Here's what you suggested and how I've implemented it.

[] Spawn { 
 
 for "_time" from 0 to 2 do { 
  
  _arty = mortar1;  
  _target = ["target1","target2","target3"] call BIS_fnc_selectRandom;  
  
  _artyAmmo = getArtilleryAmmo [_arty] select 0;  
  _artyETA = _arty getArtilleryETA [getMarkerPos _target, _artyAmmo];  
  _inRange = (getMarkerPos _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 [getMarkerPos _target, _artyAmmo, 5];  
  sleep 15; 
 } 
 
}};

I should note, the "target1" 2 and 3, are all 3D objects. Not map markers.

Share this post


Link to post
Share on other sites
15 hours ago, Stank4K said:

Looking to make AI fire on random preset markers.

7 hours ago, Stank4K said:

I should note, the "target1" 2 and 3, are all 3D objects. Not map markers.

Make your mind up 🙂

Then they should not be strings( unless using missionNamespace getVariable ).

Remove the quotes from around target1/2/3 and go back to using getPosATL.

 

7 hours ago, Stank4K said:

However. AI seems to think it's not in range.

Due to using getMarkerPos on a non existent marker, which will return [0,0,0] as a position.

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

×