Jump to content
Sign in to follow this  
arthur666

Help me with this AI artillery script?

Recommended Posts

I can't remember who gave me this, but I'ld like to make it so a fire mission won't be called if there are friendlies within a certain distance of the enemies being engaged. Is there a line I could add?

 #define __debug false

_mortarTgtPos = _this select 0;

if (__debug) then { player sideChat "Executing mortar.sqf" };

if ([CDF_mortar, _mortarTgtPos, fireMission select 1] call BIS_ARTY_F_PosInRange) then
{
[CDF_mortar, 200] call BIS_ARTY_F_SetDispersion; 
[CDF_mortar, _mortarTgtPos, fireMission] spawn BIS_ARTY_F_ExecuteTemplateMission;
_mrk = createMarker ["MortarTarget", _mortarTgtPos];
_mrk setMarkerColor "ColorBlack";
_mrk setMarkerShape "ICON";
_mrk setMarkerType "mil_objective";

waitUntil {CDF_mortar getVariable "ARTY_ONMISSION"};
if (__debug) then { player sideChat "mortars are on a mission" };
if (__debug) then { player sideChat format["ammo used: %1", CDF_mortar getVariable "ARTY_AMMO"] };
waitUntil {CDF_mortar getVariable "ARTY_COMPLETE"};
if (__debug) then { player sideChat "mortars have finished fire mission" };
waitUntil {CDF_mortar getVariable "ARTY_SPLASH"};
if (__debug) then { player sideChat "mortars about to splash!" };

sleep 10;

deleteMarker _mrk;
}
else
{
hint "W Guns";
};

if (__debug) then { player sideChat "Exiting mortar.sqf" }; 

Share this post


Link to post
Share on other sites

Hey please help me,

I am fairly new to the arma 2 editor...

can someone explain how I set up AI artillery?

pretty much I want to set up some usmc mortars,

and then be able to call in barrages with my radio when ever I want.

THANKS FOR ANY HELP!

Share this post


Link to post
Share on other sites
Hey please help me,

I am fairly new to the arma 2 editor...

can someone explain how I set up AI artillery?

pretty much I want to set up some usmc mortars,

and then be able to call in barrages with my radio when ever I want.

THANKS FOR ANY HELP!

Well, the simplest way is to use the simple support module. Just put it on the map and sync it to your unit. Then use the command key, I think 0,8 to access menu.

Back to my question, I forgot to mention that in a "OPFOR detected by BLUFOR" trigger I have in the init line:

firemission = ["IMMEDIATE","HE",0,3]; nul=[getPosASL (thisList select 0)] execVM "CDF mort.sqf";oldtime = time

Share this post


Link to post
Share on other sites

Had an idea, but I don't know how to do it. Could you spawn a temporary trigger, of a set size, at the targeted OPFOR location that will cancel the firemission if there is a BLUFOR inside that trigger? Anyone know how that would look? Sorry, I really don't speak the scripting language that well.

Share this post


Link to post
Share on other sites
Had an idea, but I don't know how to do it. Could you spawn a temporary trigger, of a set size, at the targeted OPFOR location that will cancel the firemission if there is a BLUFOR inside that trigger? Anyone know how that would look? Sorry, I really don't speak the scripting language that well.

You can do it without a trigger, this would give something like:

#define __debug false

_mortarTgtPos = _this select 0;

if (__debug) then { player sideChat "Executing mortar.sqf" };

_radius = 200;
_friendlyInArea = if ((west countSide (_mortarTgtPos nearEntities _radius)) > 0) then {true} else {false};

if (([CDF_mortar, _mortarTgtPos, fireMission select 1] call BIS_ARTY_F_PosInRange) && !_friendlyInArea) then
{
[CDF_mortar, _radius] call BIS_ARTY_F_SetDispersion; 
[CDF_mortar, _mortarTgtPos, fireMission] spawn BIS_ARTY_F_ExecuteTemplateMission;
_mrk = createMarker ["MortarTarget", _mortarTgtPos];
_mrk setMarkerColor "ColorBlack";
_mrk setMarkerShape "ICON";
_mrk setMarkerType "mil_objective";

waitUntil {CDF_mortar getVariable "ARTY_ONMISSION"};
if (__debug) then { player sideChat "mortars are on a mission" };
if (__debug) then { player sideChat format["ammo used: %1", CDF_mortar getVariable "ARTY_AMMO"] };
waitUntil {CDF_mortar getVariable "ARTY_COMPLETE"};
if (__debug) then { player sideChat "mortars have finished fire mission" };
waitUntil {CDF_mortar getVariable "ARTY_SPLASH"};
if (__debug) then { player sideChat "mortars about to splash!" };

sleep 10;

deleteMarker _mrk;
}
else
{
hint "W Guns";
};

if (__debug) then { player sideChat "Exiting mortar.sqf" };

Share this post


Link to post
Share on other sites

Thanks Benny, can't wait to try it. As it was, a town would be full of my troops, one straggler OPFOR would be found amongst them and a mortar strike would get called in on their own position.

I'll run it tonite and tell you how it works. I think 200m seems like a good minimal distance.

EDIT: in your line

[CDF_mortar, _radius] call BIS_ARTY_F_SetDispersion; 

can I put in a number instead of _radius to set the fireing radius, or does it have to use the aformentioned 200 or whatever?

Edited by arthur666

Share this post


Link to post
Share on other sites

Works great!

For anyone interested, I'll write a quick "how to" here to add AI controlled mortar support to a mission that will try to avoid shelling friendlies.

This is from a CDF vs OPFOR in a large battle setting with multiple assaults on different towns.

1. Put a "Game Logic\Object" on your map. In the init add

oldtime = 0;

2. Put down some manned friendly artillery pieces in a group, in a nice open area, like a field. I used Podnos mortars. Then put down a regular Artillery module and in the name field, put CDF_mortar. Sync the module to the group leader. Add extra ammo in the init field of each mortar

this addMagazine "ARTY_8Rnd_82mmHE_2B14";

(use correct ammo depending on unit used, add more as desired).

3. Add a trigger to your map. Make it as big as the area you want to be covered by mortar support. Set activation to OPFOR and detected by BLUFOR. Set as "repeatedly". Set to "countdown" to whatever time. I used 10, 20 and 30 seconds. In condition field add

this and oldtime != time

in init field add

firemission = ["IMMEDIATE","HE",0,5]; nul=[getPosASL (thisList select 0)] execVM "CDF mort.sqf";oldtime = time

(I think 5 is the number of shots fired or time that shots are fired. Not sure).

4. Make a file called CDF Mort.sqf that contains

#define __debug false

_mortarTgtPos = _this select 0;

if (__debug) then { player sideChat "Executing mortar.sqf" };

_radius = 250;
_friendlyInArea = if ((west countSide (_mortarTgtPos nearEntities _radius)) > 0) then {true} else {false};

if (([CDF_mortar, _mortarTgtPos, fireMission select 1] call BIS_ARTY_F_PosInRange) && !_friendlyInArea) then
{
[CDF_mortar, 150] call BIS_ARTY_F_SetDispersion; 
[CDF_mortar, _mortarTgtPos, fireMission] spawn BIS_ARTY_F_ExecuteTemplateMission;
_mrk = createMarker ["MortarTarget", _mortarTgtPos];
_mrk setMarkerColor "ColorBlack";
_mrk setMarkerShape "ICON";
_mrk setMarkerType "mil_objective";

waitUntil {CDF_mortar getVariable "ARTY_ONMISSION"};
if (__debug) then { player sideChat "mortars are on a mission" };
if (__debug) then { player sideChat format["ammo used: %1", CDF_mortar getVariable "ARTY_AMMO"] };
waitUntil {CDF_mortar getVariable "ARTY_COMPLETE"};
if (__debug) then { player sideChat "mortars have finished fire mission" };
waitUntil {CDF_mortar getVariable "ARTY_SPLASH"};
if (__debug) then { player sideChat "mortars about to splash!" };

sleep 10;

deleteMarker _mrk;
}
else
{
hint "Firemission Denied";
};

if (__debug) then { player sideChat "Exiting mortar.sqf" };

and drop it into your mission folder.

Take it out for a spin.

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  

×