Jump to content
Sign in to follow this  
Gunter Severloh

Planes spawned in this script dont attack the enemy ground units & vehicles

Recommended Posts

Hey guys,

I have a script (not mine)

How this works is you have an addaction that you can have in a unit, or radio or whatever, it will showup on your screen, you hit enter it activate the script, and a message:

"Click on the map to set planes attack point" comes up asking where you want the planes to attack.

So you go to your map you click on that point and depending on the distance of the invisible helipad object you placed on the map

(see script comments) 2 planes based on what classnames you used for the plane and pilot will spawn at that invisible helipad, and fly to your placed marker.

Only requirement for this to work is the invisible helipad in the corner of the map, and a functions module, I have both set.

Now everything works, planes come, but then the problem is they do not attack any tanks, vehicles, or infantry in my test mission.

This is set for Iron front in Arma2CO btw, and the factions I am playing with is the Allied (USA, US Army) their faction is independent, and the

Germans (enemy faction i am attacking are under Bluefor).

So yes i did take into account that Independent needs to be friendly to Opfor but still, planes come and just fly around the area of the enemy and do not attack, Bluefor (Germans)

enemy wont attack the planes. I have no idea whats wrong.

Can someone please take a look at this script and give me an idea of what needs to be changed or added to fix this? heres the script:

airsupport.sqf

[color="#008000"]// Requires function module
//To run this script you have to place an invisible helipad somewhere on the map and name it: Planestart
//add a unit and in its init write:[/color] [b]act1 = this addAction ["Call Air Support", "airsupport.sqf"];[/b]

player removeaction act1;
while {(count (waypoints _PlaneGroup)) > 1} do
{
deleteWaypoint ((waypoints _PlaneGroup) select 1);
};

titleText ["Click on the map to set planes attack point","PLAIN DOWN"];

_mkruru = createMarker ["attack",getPos Planestart]; [color="#008000"]//Planestart is the name of an invisible helipad[/color]
_mkruru setMarkerColor "colorRed";
_mkruru setMarkerShape "icon";
_mkruru setMarkerSize [1,1];
_mkruru setMarkerDir random -10 +random 20;
_mkruru setMarkerType "destroy";
openMap [true, true];
mapclick = false;
onMapSingleClick {"attack" setMarkerPos _pos; 
mapclick = true;
};
waituntil {mapclick}; 
onMapSingleClick "";
titleText ["","PLAIN DOWN"];

sleep 2;

_spawnPosX = _spawnPosition select 0;
_spawnPosY = _spawnPosition select 1;
_spawnPosZ = _spawnPosition select 2;

_planespawnpos1 = [_spawnPosX - 1000, _spawnPosY - 500, _spawnPosZ + 300];
_pilotspawnpos1 = [_spawnPosX - 1000, _spawnPosY - 500, _spawnPosZ + 300];
_planespawnpos2 = [_spawnPosX - 1100, _spawnPosY - 600, _spawnPosZ + 350];
_pilotspawnpos2 = [_spawnPosX - 1100, _spawnPosY - 600, _spawnPosZ + 350];


_PlaneGroup = creategroup WEST;
_plane1 = createVehicle ["LIB_P47",_planespawnpos1,[], 0, "FLY"];           [color="#008000"]//plane class name goes here[/color]
_plane1 setPos [(getPos _plane1 select 0),(getPos _plane1 select 1),300] ;      
_plane2 = createVehicle ["LIB_P47",_planespawnpos2,[], 0, "FLY"];              [color="#008000"]//plane class name goes here[/color]
_plane2 setPos [(getPos _plane2 select 0),(getPos _plane2 select 1),350] ;      
_plngrppLeader = "LIB_US_pilot" createUnit [getMarkerPos "attack", _PlaneGroup, "plaleader=this"];   [color="#008000"] //pilot class name goes here[/color]
_p2 = "LIB_US_pilot" createUnit [getMarkerPos "attack", _PlaneGroup, "pla2=this"];                   [color="#008000"] //pilot class name goes here[/color]

_plane1 setVelocity [100,0,0] ;
_plane2 setVelocity [100,0,0] ;

plaleader moveinDriver _plane1;
plaleader setDamage 0;
plaleader action ["gear_up", vehicle plaleader] ;

pla2 moveinDriver _plane2;
pla2 setDamage 0;
pla2 action ["gear_up", vehicle pla2] ;


_pos1 = getMarkerPos "attack";
_way1 = (_PlaneGroup) addWaypoint [_pos1, 0];
[_PlaneGroup, 0] setWaypointType "SAD";
[_PlaneGroup, 0] setWaypointBehaviour "COMBAT";
[_PlaneGroup, 0] setWaypointCombatMode "RED";
[_PlaneGroup, 0] setWaypointSpeed "FULL";
[_PlaneGroup, 0] setWaypointFormation "DIAMOND";
openMap [false, false];

_mkrend = createMarker ["attackend",getPos Planestart]; [color="#008000"]//Planestart is the name of an invisible helipad[/color]
_mkrend setMarkerColor "Default";
_mkrend setMarkerShape "icon";
_mkrend setMarkerSize [1,1];
_mkrend setMarkerDir random -10 +random 20;
_mkrend setMarkerType "Empty";

Sleep 200; 

_Endpos = getMarkerPos "attackend";
_way2 = (_PlaneGroup) addWaypoint [_Endpos, 1];
[_PlaneGroup, 1] setWaypointType "MOVE";
[_PlaneGroup, 1] setWaypointBehaviour "CARELESS";
[_PlaneGroup, 1] setWaypointCombatMode "BLUE";
[_PlaneGroup, 1] setWaypointSpeed "FULL";
[_PlaneGroup, 1] setWaypointFormation "DIAMOND";

Sleep 120;

deleteVehicle _plane1; [color="#008000"]//this deletes planes[/color]
deleteVehicle _plane2; [color="#008000"]//this deletes planes[/color]

deleteGroup _PlaneGroup; [color="#008000"]//this deletes plane group[/color]
deleteVehicle plaleader; [color="#008000"]//this deletes plane pilot[/color]
deleteVehicle pla2; [color="#008000"]//this deletes plane pilot[/color]
deleteMarker "attack";
deleteMarker "attackend";

sleep 1;

act1 = player addAction ["Call Air Support", "airsupport.sqf"];

Edited by Günter Severloh

Share this post


Link to post
Share on other sites

Hi there,

bellow is an Arma 2 script example I have used [this works]. What it might be with AI, you forgot to define a group/side for the units to be spawned. So initially you need to create a group on OPFOR side first, then spawn the crew, then spawn the plane, move the crew in the jet, give the group of the crew the new way point. try it like that see if that works for you.

private ["_pilot", "_co_pilot", "_takistan_airspace", "_random_spawn_time", "_random_plane", "_plane", "_random_1", "_random_2", "_group_pilot", "_plane_dir", "_marker_wp", "_waypoint"];

_random_spawn_time = floor (random 50);

sleep _random_spawn_time;

_takistan_airspace = getMarkerPos "marker_wp_takistan";

_group_pilot = createGroup east;

_pilot = _group_pilot createUnit ["TK_Soldier_Pilot_EP1", _takistan_airspace, [], 0, "FORM"];

_plane_dir = 180;

_random_plane = floor (random 3);

_random_1 = floor (random 150);

_random_2 = floor (random 150);

_marker_wp = getMarkerPos "marker_wp";

if (_random_plane == 0) then

{

_pilot setPosasl [_takistan_airspace select 0 + 1, _takistan_airspace select 1, _takistan_airspace select 2];

_plane = createVehicle ["Su34",[0,0,1000],[], 0, "FLY"];

_plane setPosASL [(_takistan_airspace select 0) + _random_1, (_takistan_airspace select 1) + _random_2, 1000];

_plane setDir _plane_dir;

_plane setVelocity [sin(_plane_dir)*200,cos(_plane_dir)*200,0];

_pilot moveinDriver _plane;

_co_pilot = _group_pilot createUnit ["TK_Soldier_Pilot_EP1", _takistan_airspace, [], 0, "FORM"];

_co_pilot moveinGunner _plane;

[_plane] execVM "ai_rearm_refuel.sqf";

[_plane] execVM "air_opfor_respawn.sqf";

_waypoint = _group_pilot addWaypoint [_marker_wp, 2500];

_waypoint setWaypointStatements ["true", ""];

_waypoint setWaypointType "SAD";

_waypoint setWaypointSpeed "NORMAL";

_waypoint setWaypointCombatMode "RED";

_waypoint setWaypointCompletionRadius 5000;

hintsilent "OPFOR SU34 SPOTED";

};

if (_random_plane == 1) then

{

_pilot setPosasl [_takistan_airspace select 0 + 1, _takistan_airspace select 1, _takistan_airspace select 2];

_plane = createVehicle ["Mi24_D_TK_EP1",[0,0,1000],[], 0, "FLY"];

_plane setPosASL [(_takistan_airspace select 0) + _random_1, (_takistan_airspace select 1) + _random_2, 1000];

_plane setDir _plane_dir;

_plane setVelocity [sin(_plane_dir)*20,cos(_plane_dir)*20,0];

_pilot moveinDriver _plane;

_co_pilot = _group_pilot createUnit ["TK_Soldier_Pilot_EP1", _takistan_airspace, [], 0, "FORM"];

_co_pilot moveinGunner _plane;

[_plane] execVM "ai_rearm_refuel.sqf";

[_plane] execVM "air_opfor_respawn.sqf";

_waypoint = _group_pilot addWaypoint [_marker_wp, 2500];

_waypoint setWaypointStatements ["true", ""];

_waypoint setWaypointType "SAD";

_waypoint setWaypointSpeed "NORMAL";

_waypoint setWaypointCombatMode "RED";

_waypoint setWaypointCompletionRadius 5000;

hintsilent "OPFOR Mi24 SPOTED";

};

if (_random_plane == 2) then

{

_pilot setPosasl [_takistan_airspace select 0 + 1, _takistan_airspace select 1, _takistan_airspace select 2];

_plane = createVehicle ["Su25_TK_EP1",[0,0,1000],[], 0, "FLY"];

_plane setPosASL [(_takistan_airspace select 0) + _random_1, (_takistan_airspace select 1) + _random_2, 1000];

_plane setDir _plane_dir;

_plane setVelocity [sin(_plane_dir)*100,cos(_plane_dir)*100,0];

_pilot moveinDriver _plane;

[_plane] execVM "ai_rearm_refuel.sqf";

[_plane] execVM "air_opfor_respawn.sqf";

_waypoint = _group_pilot addWaypoint [_marker_wp, 2500];

_waypoint setWaypointStatements ["true", ""];

_waypoint setWaypointType "SAD";

_waypoint setWaypointSpeed "NORMAL";

_waypoint setWaypointCombatMode "RED";

_waypoint setWaypointCompletionRadius 5000;

hintsilent "OPFOR SU25 SPOTED";

};

if (_random_plane == 3) then

{

_pilot setPosasl [_takistan_airspace select 0 + 1, _takistan_airspace select 1, _takistan_airspace select 2];

_plane = createVehicle ["L39_TK_EP1",[0,0,1000],[], 0, "FLY"];

_plane setPosASL [(_takistan_airspace select 0) + _random_1, (_takistan_airspace select 1) + _random_2, 1000];

_plane setDir _plane_dir;

_plane setVelocity [sin(_plane_dir)*20,cos(_plane_dir)*100,0];

_pilot moveinDriver _plane;

_co_pilot = _group_pilot createUnit ["TK_Soldier_Pilot_EP1", _takistan_airspace, [], 0, "FORM"];

_co_pilot moveinGunner _plane;

[_plane] execVM "ai_rearm_refuel.sqf";

[_plane] execVM "air_opfor_respawn.sqf";

_waypoint = _group_pilot addWaypoint [_marker_wp, 2500];

_waypoint setWaypointStatements ["true", ""];

_waypoint setWaypointType "SAD";

_waypoint setWaypointSpeed "NORMAL";

_waypoint setWaypointCombatMode "RED";

_waypoint setWaypointCompletionRadius 5000;

hintsilent "OPFOR L39 SPOTED";

};

Exit;

Also try the code first with vanilla units with no mods. Not to offend anyone but all AIA code is "bugged as hell" and breaks a lot of game functionality.

Share this post


Link to post
Share on other sites

Hi, thanks for the reply,

This is not AIA mod btw, this is Iron front converted to a mod

.IFA file extension copied, and reformatted to .pbo so its not dependent on any other mod like the Arma3 (IFA3) version is, and AIA is not used

anymore there is new standalone version for the IFA3 part.

So the same setup in the mission then, the functions module, the invisible helipad, ect,.?

How do i setup the mission, how do i call a plane to attack some ground targets?

I did another test and I was basically attacking the enemy that the planes were supposed to attack, and after I did some damage, I literally got a bomb dropped on me by one of the planes, so something in my script is not set to make the planes be not friendly to bluefor, it seems in the script they may automatically be friendly to blufor when they shouldn't, they are independent faction side planes, and I have it set in the test mission that independent is friendly with Opfor which Ofpor in iron front btw are the Russians.

Edited by Günter Severloh

Share this post


Link to post
Share on other sites

rgr on mods, misunderstood,

basically to call any unit to an action [AI meant here] you need to define it's behaviour and add a waypoint [search & Destroy/Destroy]

still before using mods try a vanilla built mission first to test the work you have done only then apply it to moded game/mission.

_waypoint = _group_pilot addWaypoint [_marker_wp, 2500];

_waypoint setWaypointStatements ["true", ""];

_waypoint setWaypointType "SAD";

_waypoint setWaypointSpeed "NORMAL";

_waypoint setWaypointCombatMode "RED";

_waypoint setWaypointCompletionRadius 5000;

this also might be handy

in your code there is line

[_PlaneGroup, 1] setWaypointBehaviour "CARELESS";

this mean's spawned unit will never attack anything - it's in careless combat mode and will ignore any hostile unit, try changing that as in example above.

Share this post


Link to post
Share on other sites

The Script in my OP already has that, from what im getting in terms of the tests i've done the planes called are somehow friendly to the enemy as in my previous post's test,

i got bombed by them and Im on their side, its like when you attack your own squad they turn on you after a warning.

As for your script you posted, how do you implement that in a mission, with functions module?, and thats it, how do you call the planes to attack, as that is the

point of the OP post script is to call a planes for airsupport and attack any target you specify through a mapclick.

Share this post


Link to post
Share on other sites

the code can be called by any logical mission element [trigger/unit's init] or in a mission init.sqf file just add a line to execute it. Use destroy Waypoint to tell AI to attack specific target, just remember that you need to pass the target ID to code so it know what exactly to destroy.

Functions module is only needed if you wish to use BI's standard functions. So in this case it might be not necessary. Use scripting command AddWaypoint to archive this

Check the mission main settings which faction is set friendly to independent make sure they are set up correctly as you meant to.

Edited by John_Spartan

Share this post


Link to post
Share on other sites
in your code there is line

[_PlaneGroup, 1] setWaypointBehaviour "CARELESS";

this mean's spawned unit will never attack anything - it's in careless combat mode and will ignore any hostile unit, try changing that as in example above.

I see but thats the end of the attack, when the planes are done attacking, they leave, and they do, so the code here

_pos1 = getMarkerPos "attack";

_way1 = (_PlaneGroup) addWaypoint [_pos1, 0];

[_PlaneGroup, 0] setWaypointType "SAD";

[_PlaneGroup, 0] setWaypointBehaviour "COMBAT";

[_PlaneGroup, 0] setWaypointCombatMode "RED";

[_PlaneGroup, 0] setWaypointSpeed "FULL";

[_PlaneGroup, 0] setWaypointFormation "DIAMOND";

openMap [false, false];

_mkrend = createMarker ["attackend",getPos Planestart]; //Planestart is the name of an invisible helipad

_mkrend setMarkerColor "Default";

_mkrend setMarkerShape "icon";

_mkrend setMarkerSize [1,1];

_mkrend setMarkerDir random -10 +random 20;

_mkrend setMarkerType "Empty";

From what i understand, the get position marker is your mapclick, so they go to that with [_PlaneGroup, 0] setWaypointBehaviour "COMBAT"; they follow through with everything but treat the enemy as if their in the same side, I say that as when i attack the enemy and hurt them the planes attack me after so much time, so there some command in the script thats making them friendly to the enemy.

Which the only thing i can think of and see would be this: _PlaneGroup = creategroup WEST;

If they are West group that means they are Bluefor and not independent, im thinking this is why they attack me.

I may chang this and see what happens, but i dont get why put West when the group in the editor (factionwise) are under independent.

Share this post


Link to post
Share on other sites

Günter, your script has:

[color="#FF0000"]_PlaneGroup = creategroup WEST;[/color]
_plane1 = createVehicle ["LIB_P47",_planespawnpos1,[], 0, "FLY"];           //plane class name goes here
_plane1 setPos [(getPos _plane1 select 0),(getPos _plane1 select 1),300] ;      
_plane2 = createVehicle ["LIB_P47",_planespawnpos2,[], 0, "FLY"];              //plane class name goes here
_plane2 setPos [(getPos _plane2 select 0),(getPos _plane2 select 1),350] ;      
_plngrppLeader = "LIB_US_pilot" createUnit [getMarkerPos "attack", [color="#FF0000"]_PlaneGroup,[/color] "plaleader=this"];    //pilot class name goes here
_p2 = "LIB_US_pilot" createUnit [getMarkerPos "attack", [color="#FF0000"]_PlaneGroup,[/color] "pla2=this"];

Your pilots are on BLUFOR side, so they would be attacking whichever side BLUFOR is hostile towards.

Edited by OpusFmSPol

Share this post


Link to post
Share on other sites

@John_Spartan

Tested the mission out, works good, I looked at the script and then tried it in IFA2 (Iron front in Arma2CO) and all i did was replace the

classnames for the plane, and pilot, and renamed the marker on the map I had already set before, and then updated the code in the player's init box,

and called for air support and the P47 came in and bombed the hell out of the enemy tanks, and strafed the infantry ect,. tested it again and had a tank coming at me, and I call

for air support, and within a min, I seen these 2 bombs fly over myhead, lol and boom, took out the take, gees was amazing site.

But this is perfect, works well, was wondering if there was a way to add a timer on it so you can only call airsupport after so much time, and when it becomes

available again a hint would popup and say Air support is available.

Did you build that script?

Your pilots are on BLUFOR side, so they would be attacking whichever side BLUFOR is hostile towards.

Ya that made sense after the last couple tests I did, and i figured that out, however if you change it to any other faction no plane comes.

Share this post


Link to post
Share on other sites

@Gunter,

- yes I built that small piece of code

- yes you can add timer there, just in the code before it initiates add a condition for a timer, and then thru the code rest it as a local variable.

Share this post


Link to post
Share on other sites

Cool, appreciate the help, but have no idea how to add a timer, or a hint when the timer ends saying Airsupport is available,

can you point me to suggested codes to see if I can figure this out myself?

Share this post


Link to post
Share on other sites

I have the script put together and working the way I want, thanks for your help John Spartan, and Rydygier too!

So heres the script:

js_airsupport.sqf

//private ["_pilot", "_co_pilot", "_plane", "_group_pilot", "_plane_dir", "_marker_wp", "_waypoint"];

GS_CASAvailable = false;

hint "Click on the area of the map where you want CAS";

target_marker = createMarkerLocal ["CAS_marker",[0,0]]; 
target_marker setMarkerColorLocal "colorBlack";
target_marker setMarkerShapeLocal "icon";
target_marker setMarkerSizeLocal [1,1];
target_marker setMarkerTypeLocal "mil_destroy";
target_marker setMarkerTextLocal "CAS TGT POS";
target_marker setMarkerAlphaLocal 0;

sleep 1;

mapclick = false;
onMapSingleClick "target_marker setMarkerPosLocal _pos; clickpos = _pos; mapclick = true; target_marker setMarkerAlphaLocal 1;";

waituntil {mapclick};
sleep 0.5;
_marker_wp = clickpos;
onMapSingleClick "";

sleep 0.1;

_plane_spwan_pos = getMarkerPos "Planestart_spawn";
_group_pilot = createGroup  resistance;
_pilot = _group_pilot createUnit ["LIB_US_pilot", [0,0,1000], [], 0, "FORM"];
_pilot setPosasl [(_plane_spwan_pos select 0), (_plane_spwan_pos select 1), 500];
//_co_pilot = _group_pilot createUnit ["LIB_US_pilot", _plane_spwan_pos, [], 0, "FORM"];
//_co_pilot setPosasl [(_plane_spwan_pos select 0), (_plane_spwan_pos select 1), 500];
_plane = createVehicle ["LIB_P47",[0,0,1000],[], 0, "FLY"];
_plane setPosASL [(_plane_spwan_pos select 0), (_plane_spwan_pos select 1), 500];
_pilot moveinDriver _plane;
//_co_pilot moveinGunner _plane;

_plane setDir _dir;
_speed = (getNumber (configFile>>"cfgvehicles">>(typeOf _plane)>>"maxspeed") + getNumber (configFile>>"cfgvehicles">>(typeOf _plane)>>"landingSpeed")) / 2;
_plane setVelocity [sin _dir *(_speed/3.6), cos _dir *(_speed/3.6), 0];

sleep 1;

_waypoint = _group_pilot addWaypoint [_marker_wp, 500];
_waypoint setWaypointStatements ["true", ""];
_waypoint setWaypointType "SAD";
_waypoint setWaypointSpeed "NORMAL";
_waypoint setWaypointCombatMode "RED";
_waypoint setWaypointCompletionRadius 5000;

hintsilent "Airsupport is inbound...";

_tme = time;

waitUntil
{
sleep 5;

(not (alive _plane) or ((time - _tme) > 300))
};

//here you can code in plane deletion (along with the crew and emptied plane's group itself - deleteGroup command) maybe after some "fly away" sequence

sleep 300;// Timer will countdown before cas becomes available again
GS_CASAvailable = true;
hint "CAS available";

init.sqf

GS_CASAvailable = true;

Ingame editor

add this code to the player's init box

this addAction ["Call in airsupport...", "js_airsupport.sqf", [], 1, false, false, "","GS_CASAvailable"];

Place a invisible H marker on the map and name it this:

Planestart_spawn

This marker will be where the plane spawns and comes from.

============

What happens when you call Air support?

1. In your action menu (ingame) you will have an action named: "Call in Airsupport"

2. Calling the airsupport, a message will popup on the screen (hint) and will say: "Click on the area of the map where you want CAS"

3. Going to your map, you click on the area of where you want the air support as the message asks.

4. A few seconds after doing this a message will popup (hint) and sat "Air support inbound...",

depending on the map, and how far away the marker is, the plane will spawn at that marker and fly to your marked position you pointed to on your map.

The Plane will do a CAS (Close air support) basically engaging with guns, rockets, missiles, ect,. (whatever the plane/chopper has).

5. If the plane gets shot down then you will have the option to call for air support again 300sec later, as after you initially call for air support the action

in your action menu is removed.

6. When the timer for the call Air support is available again then a hint will popup saying " Air support is available"

This is basically it, its not coded to have it where you can have the plane do its cas and then fly away and then get deleted, dont know how to set that up.

but thats basically it.

You can thank John Spartan & Rydygier who helped me through pm for putting this together.

this works in Arma3, and Arma2CO.

==========

Defining what plane/chopper & pilot are to be used in the mission

For the pilot (line 29)

_pilot = _group_pilot createUnit ["[b]LIB_US_pilot[/b]", [0,0,1000], [], 0, "FORM"];

Bolded is the classname for the pilot.

For the plane or chopper (line 33)

_plane = createVehicle ["[b]LIB_P47[/b]",[0,0,1000],[], 0, "FLY"];

bolded is the classname for the plane or chopper.

========

Lastly note: For Arma2/CO be sure to place a Functions module on the map in the editor.

For Arma3 version just make sure you add the code for the player, and the marker for where the plane will start, also consider too what faction the enemy is on vs your side.

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  

×