Jump to content
Sign in to follow this  
Maguila.gm

BM-21 MLRS Fired by AI scripting

Recommended Posts

I am currently working on a mission that uses AI scripting to provide support. In this mission, when tou call radio alpha, the artillery strike begins. 

The support group providing fire are coposed by 3 BM-21MLRS tht will fire at 3 separetly targets, in order to acheive that i've created 3 flies for each vehicle using the following script:

[] spawn { while {alive gun_1G} do { sleep 5; _ammo = getArtilleryAmmo [gun_1] select 0; 
_tgt = getMarkerPos "arty1";
gun_1 doArtilleryFire[_tgt,_ammo,1];}} 

Where wilhe the gunner is alive, it will fire, in practice, it will fire until the ammo is depleted. The problem is, for each rocket launched it retracts the pod, wait 5 sec, aims again and fires. I want to make it to aim once an fire all the 40 rockets as fast as possible. For that i've tried to put the loop after the aiming command:

[] spawn {
    sleep 5;
    _ammo = getArtilleryAmmo gun_3 select 0;
    _tgt = getMarkerPos "arty3";

    
    while {alive gun_3G} do {
        gun_3 doArtilleryFire [_tgt, _ammo, 1];

        // Small interval between while it recharges
        sleep 1;
    }
    
};

however im getting all sorts of error messages. 

Share this post


Link to post
Share on other sites

_arty = arty;
_target = a1;
 
_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, 40];
 
};

  • Like 1

Share this post


Link to post
Share on other sites
31 minutes ago, Junior Prado said:

_arty = arty;
_target = a1;
 
_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, 40];
 
};

i am still getting an error.

13:38:13 Error in expression <LRS\drop3.sqf"
_arty = arty; 
_target = a1; 

_artyAmmo = getArtilleryAmmo [_art>
13:38:13   Error position: <a1; 

_artyAmmo = getArtilleryAmmo [_art>
13:38:13   Error Variável indefinida na expressão: a1
13:38:13 File c:\users\magui\onedrive\documentos\arma 3\mpmissions\[eap]vá_e_veja_v3.chernarus_2035\MLRS\drop3.sqf..., line 2

It says "error undifined variable at expression a1"

Share this post


Link to post
Share on other sites

For some reason, Junior Prado has used different variables in his code. you need to edit it to use yours.

 

Share this post


Link to post
Share on other sites
4 minutes ago, Harzach said:

For some reason, Junior Prado has used different variables in his code. you need to edit it to use yours.

 

i changed the name of the target and luncher to match those of junior prado's code

 

Share this post


Link to post
Share on other sites

If your target is a marker as it was in your original code, you must reference it with quotation marks.

_arty = arty;
_target = "a1";

 

  • Like 2

Share this post


Link to post
Share on other sites
6 hours ago, Maguila.gm said:

I want to make it to aim once an fire all the 40 rockets as fast as possible.

 

All you need to do is give the artillery a Fire Mission waypoint.

_wp1 = gun_1 addWaypoint [getmarkerpos "arty1", 0];  
_wp1 setWaypointType "SCRIPTED";
_wp1 setWaypointScript "A3\functions_f\waypoints\fn_wpArtillery.sqf";

gun_1 will target and fire on "arty1" until all ammunition is depleted. It will fire at its maximum fire rate.

 

 

 

  • Like 1

Share this post


Link to post
Share on other sites

i corrected doing this

_arty = arty; 
_targetMarker = "a1";  // Substitua "a1" pelo nome do seu marcador 
 
// Obtém as coordenadas do marcador 
_targetPos = getMarkerPos _targetMarker; 
 
if (isNil "_targetPos") then { 
    // Lida com o caso em que o marcador não é encontrado 
    systemchat format ["Marker '%1' não encontrado!", _targetMarker]; 
} else { 
    _artyAmmo = getArtilleryAmmo [_arty] select 0; 
    _artyETA = _arty getArtilleryETA [_targetPos, _artyAmmo]; 
    _inRange = _targetPos inRangeOfArtillery [[_arty], _artyAmmo]; 
    systemchat format ["In range: %1", _inRange]; 
 
    if (_artyETA > 0 && _inRange) then { 
        systemchat "Cleared to fire!"; 
        systemchat format ["Impact ETA: %1s", _artyETA]; 
        _arty commandArtilleryFire [_targetPos, _artyAmmo, 40]; 
    }; 
} 

 

Share this post


Link to post
Share on other sites

If you want the extra checks/systemChat info:

_arty = gun_1; 
_target = "arty1"; 
_pos = getMarkerPos [_target, true]; 

if (isNil "_pos") then { 
    systemchat format ["Marker '%1' não encontrado!", _target]; 
} else { 
	_mag = currentMagazine _arty; 
	_inRange = _pos inRangeOfArtillery [[_arty], _mag]; 
	_artyETA = ceil (_arty getArtilleryETA [_pos, _mag]); 
	systemchat format ["In range: %1", _inRange]; 

	if (_artyETA > 0 && _inRange) then { 
		systemchat 'Cleared to fire!';  
		systemchat format ['Impact ETA: %1s', _artyETA];
				
		_wp1 = group _arty addWaypoint [_pos, 0];  
		_wp1 setWaypointType "SCRIPTED";
		_wp1 setWaypointScript "A3\functions_f\waypoints\fn_wpArtillery.sqf";
	};
};

But then we're writing just as much code, so it's up to your preference.

  • 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
Sign in to follow this  

×