Jump to content
Sign in to follow this  
MANTIA

Enemy Mortar Fire When Player in Radius

Recommended Posts

I want to create a scenario where enemy mortars are firing on a COP or FOB where the mission is to located the enemy mortar tubes and eliminate them.

I want the players to have to recon and track where the sound from the mortars are firing in order to locate the tubes.

So I was thinking of having the enemy mortar tubes fire when players enter a radius via a trigger. However, I'm stuck on how to make an enemy AI mortar team fire on a target when a players enters the radius.

Any ideas?

Share this post


Link to post
Share on other sites

Look up the commandArtilleryFire command and use that in the onAct field of the trigger.

Share this post


Link to post
Share on other sites

"fireMortar.sqf"

_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 < 8)} do{
	_tgtPos = position _target;
	_isInRange = _tgtPos inRangeOfArtillery [[_mortar], _theAmmo  ];

	if (_isInRange) then {
		_mortar commandArtilleryFire [_tgtPos, _theAmmo  , 1 ];			
	};

	sleep 5;
	_idx = _idx + 1;
};	
};

Share this post


Link to post
Share on other sites

so with this sqf the mortars would fire on hostiles within range correct? is there a way to get them to fire on a marker?

Share this post


Link to post
Share on other sites

works perfect!

is there a way to add a delay in between the firing?

I found a few threads similar but it looks like the discussion was with Arma2 and it doesnt seem to work for me.

Edited by DoRo

Share this post


Link to post
Share on other sites

You could split the shots up:

for "_i" from 1 to 3 do
{
   _mortar commandArtilleryFire [getMarkerPos "someMarker", "8Rnd_82mm_Mo_shells", 1]
   sleep 10;
};

But don't forget used that code only inside a spawned block.

Edited by Heeeere's Johnny!

Share this post


Link to post
Share on other sites

Where would I put this code? I'm guessing not in a units init line?

Share this post


Link to post
Share on other sites

Actually, MiguelDarius has already given an example which kinda does as you desire. But just for you, here's a neat summary:

[color=#FF8040]fnc_mortarFire [color=#8B3E2F][b]=[/b][/color]
[color=#8B3E2F][b]{[/b][/color]
   [color=#1874CD]_mortar[/color]           [color=#8B3E2F][b]=[/b][/color] [color=#191970][b]missionNamespace[/b][/color] [color=#191970][b]getVariable[/b][/color] [color=#7A7A7A]"myMortar"[/color][color=#8B3E2F][b];[/b][/color] [color=#006400][i]//however you identify the mortar[/i][/color]
   [color=#1874CD]_ammo[/color]             [color=#8B3E2F][b]=[/b][/color] [color=#191970][b]getArtilleryAmmo[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#1874CD]_mortar[/color][color=#8B3E2F][b]][/b][/color] [color=#191970][b]select[/b][/color] [color=#FF0000]0[/color][color=#8B3E2F][b];[/b][/color]
   [color=#1874CD]_targetPosition[/color]   [color=#8B3E2F][b]=[/b][/color] [color=#191970][b]getMarkerPos[/b][/color] [color=#7A7A7A]"someMarker"[/color][color=#8B3E2F][b];[/b][/color]
   [color=#1874CD]_isInRange[/color]        [color=#8B3E2F][b]=[/b][/color] [color=#1874CD]_targetPosition[/color] [color=#191970][b]inRangeOfArtillery[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#8B3E2F][b][[/b][/color][color=#1874CD]_mortar[/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b],[/b][/color] [color=#1874CD]_ammo[/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b];[/b][/color]

   [color=#191970][b]if[/b][/color][color=#8B3E2F][b]([/b][/color][color=#1874CD]_isInRange[/color][color=#8B3E2F][b])[/b][/color] [color=#191970][b]then[/b][/color]
   [color=#8B3E2F][b]{[/b][/color]
       [color=#191970][b]while[/b][/color] [color=#8B3E2F][b]{[/b][/color][color=#191970][b]alive[/b][/color] [color=#1874CD]_mortar[/color][color=#8B3E2F][b]}[/b][/color] [color=#191970][b]do[/b][/color]    [color=#006400][i]//_mortar fires until it's destroyed[/i][/color]
       [color=#8B3E2F][b]{[/b][/color]
           [color=#1874CD]_mortar[/color] [color=#191970][b]commandArtilleryFire[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#1874CD]_targetPosition[/color][color=#8B3E2F][b],[/b][/color] [color=#1874CD]_ammo[/color][color=#8B3E2F][b],[/b][/color] [color=#FF0000]1[/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b];[/b][/color]            
           [color=#191970][b]sleep[/b][/color] [color=#FF0000]5[/color][color=#8B3E2F][b];[/b][/color]
       [color=#8B3E2F][b]}[/b][/color][color=#8B3E2F][b];[/b][/color]
   [color=#8B3E2F][b]}[/b][/color][color=#8B3E2F][b];[/b][/color]
[color=#8B3E2F][b]}[/b][/color][color=#8B3E2F][b];[/b][/color]

[color=#1874CD]_mortarTrigger[/color] [color=#8B3E2F][b]=[/b][/color] [color=#191970][b]createTrigger[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#7A7A7A]"EmptyDetector"[/color][color=#8B3E2F][b],[/b][/color] [color=#1874CD]_desiredPosition[/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b];[/b][/color]    [color=#006400][i]//insert a proper position for "_desiredPosition"[/i][/color]
[color=#1874CD]_mortarTrigger[/color] [color=#191970][b]setTriggerActivation[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#7A7A7A]"ANY"[/color][color=#8B3E2F][b],[/b][/color] [color=#7A7A7A]"PRESENT"[/color][color=#8B3E2F][b],[/b][/color] [color=#000000]false[/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b];[/b][/color]    [color=#006400][i]//any unit can activate the trigger[/i][/color]
[color=#1874CD]_mortarTrigger[/color] [color=#191970][b]setTriggerArea[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#FF0000]100[/color][color=#8B3E2F][b],[/b][/color] [color=#FF0000]100[/color][color=#8B3E2F][b],[/b][/color] [color=#FF0000]0[/color][color=#8B3E2F][b],[/b][/color] [color=#000000]false[/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b];[/b][/color]    [color=#006400][i]//change the 100 (meters) to any value you want[/i][/color]
[color=#1874CD]_mortarTrigger[/color] [color=#191970][b]setTriggerStatements[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#7A7A7A]"this && {player in thisList}"[/color][color=#8B3E2F][b],[/b][/color] [color=#7A7A7A]"[] spawn fnc_mortarFire;"[/color][color=#8B3E2F][b],[/b][/color] [color=#7A7A7A]""[/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b];[/b][/color]
[/color]

Kudos to Killzone_Kid for his SQF to BBCode Converter.

Edited by Heeeere's Johnny!

Share this post


Link to post
Share on other sites

Where do I put this code? mission init file?

Share this post


Link to post
Share on other sites

He only fires one time. Any way to repeat this every 30 seconds or so?

---------- Post added at 04:30 AM ---------- Previous post was at 03:11 AM ----------

I tried another similar type of loop

{

_mortar = missionNamespace getVariable "mortar1"; //however you identify the mortar

_ammo = getArtilleryAmmo [_mortar] select 0;

_targetPosition = getMarkerPos "marker1";

_isInRange = _targetPosition inRangeOfArtillery [[_mortar], _ammo];

my value = 20;

while (myvalue > 0) do

{

myvalue = myvalue - 1;

sleep 2;

hint format ("%1",myvalue);

_mortar commandArtilleryFire [_targetPosition, _ammo, 2];

sleep 5;

};

};

and still it only fires once and doesnt display any of the hint as well .

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  

×