Jump to content
Sign in to follow this  
tryteyker

action "useweapon" on empty target

Recommended Posts

Hey,

I'm still working on a little Airstrike script, but I'm running into issues when telling the AI to target an empty object and drop bombs.

This is the full script (from the point where the plane gets created to the drop):

// Creating the plane & pilot

_grp = creategroup WEST;
setfire = true;


hintSilent "Select your firedirection";
onMapSingleClick {
  //We only need this event to fire once, once that happens we reset it
  onMapSingleClick {};

  //ASL height
  _height = getTerrainHeightASL _pos;

  //Move the object
  ASTarget setPosASL [_pos select 0, _pos select 1, _height];

  //Set variable
  setfire = false;
};  

waituntil {!setfire};
hint "end";
if (!setfire) then {
"Firedirection" setMarkerPos getpos ASTarget;
plane = createvehicle ["AV8B", getmarkerpos "unitspawn",[],0,"FLY"];
plane setposATL [(getposATL plane select 0), getposATL plane select 1, 200];
plane setspeedmode "full";
plane setDir 90;
plane setvelocity [100,0,0];
plane allowDamage false;
pilot = _grp createunit ["USMC_Soldier_Pilot",getmarkerpos "unitspawn",[],0,"FORM"];
pilot moveindriver plane;
pilot action ["LandGearUp", plane];
pilot doMove getpos ASTarget;
pilot flyinheight 300;
pilot allowDamage false;
};

_pwp = _grp addWaypoint [getmarkerpos "planewp",0];
hintSilent "WP added";

// Dropping MK82
while {pilot distance ASTarget < 2000} do {
gamelogic action ["useWeapon",plane,pilot,5];
};
/*while loop to repair damage (not working)

while {(damage plane) > 0.1} do {
plane setDamage 0;
}; 
*/

I've been reading about this on Armaholic that the AI has general issues with firing on empty objects, to prevent this I've placed 3 T-72's in the middle of the empty object.

I'm not entirely sure if the while-loop is the best way to go about this, but an if-statement only seems to check once.

So, what the plane does is the following:

It gets created at a static marker, flies towards the position selected via onmapsingleclick (it's an invisible HPad and the HPad has the correct height ASL (18), tested it with a radio tower).

The plane flies over the position, but does not drop the bomb. Then, it apparently flies to the assigned waypoint and gets deleted. Instead, it comes back and bombs the living hell out of the T-72s until it gets shot down and everybody's dead.

For testing purposes I've done 2-3 additional missions testing this and in one mission I got the AV8B to drop an Mk82 once, and that Mk82 went directly towards the T-72. Directly, hit it spot on.

I've tested the index numbers of the harrier up to 10, and 5 is definitely the index number for the Mk82 (unless using ACE, but I don't use ACE for this testing mission).

During another testing mission, I've created the same scenario, only giving the plane a range of 2000 in the while loop. Dropped all 5 bombs and got deleted. On the other hand, when giving the plane a range below 2000, it doesn't seem to work.

In my current mission (the one with the 3 T-72's and the onmapsingleclick), range doesn't seem to affect anything.

At the early stages I've played with the range a bit and gave the plane 4000 range, dropped one bomb right infront of the fence of Utes airport. 2000 range, same result. This issue is still there, just that the plane doesn't drop any bombs now.

I also took a look at Mr Murrays Airstrike script in his guide, and very early on I've tried to do this, and eventually got it to work (using sqs obviously, I just copied his whole script really, but it makes me wonder why it won't work now, since I'm using almost the same concept).

Also, I tried "fire", but since that is broken, I've been using "useweapon" instead.

Maybe I mixed up the syntax there?

Anyway, I'd appreciate some help here.

//Edit1:

So, I cleaned up my code a bit, made sure everything's correct.

I also made use of nearestObject, so instead of telling the Harrier to target the HPad, as soon as the HPad has been moved, it gets the nearest object. That variable gets passed to the plane eventually and the plane will target that object. Since it is supposed to cause collateral damage this method seems to be sufficient enough, since it shouldn't target a specific unit only (Who drops 3 bombs to kill 1 tank anyway)

So as it stands it looks like this:

// Creating the plane & pilot

_grp = creategroup WEST;
setfire = true;


hintSilent "Select your firedirection";
onMapSingleClick {
  //We only need this event to fire once, once that happens we reset it
  onMapSingleClick {};

  //ASL height
  _height = getTerrainHeightASL _pos;

  //Move the object
  ASTarget setPosASL [_pos select 0, _pos select 1, _height];

  //Set variable
  setfire = false;
};  

waituntil {!setfire};
_targets = nearestObject [ASTarget, "Tank"];
hintSilent format ["%1",_targets];
if (!setfire) then {
"Firedirection" setMarkerPos getpos ASTarget;
plane = createvehicle ["AV8B2", getmarkerpos "unitspawn",[],0,"FLY"];
plane setposATL [(getposATL plane select 0), getposATL plane select 1, 200];
plane setspeedmode "full";
plane setDir 90;
plane setvelocity [100,0,0];
plane allowDamage false;
pilot = _grp createunit ["USMC_Soldier_Pilot",getmarkerpos "unitspawn",[],0,"FORM"];
pilot moveindriver plane;
pilot action ["LandGearUp", plane];
pilot doMove getpos _targets;
pilot doTarget _targets;
pilot flyinheight 300;
pilot allowdamage false;
};

//Adding a plane waypoint & declaring a variable to limit bomb usage

_pwp = _grp addWaypoint [getmarkerpos "planewp",0];
_i = 0;
// Dropping MK82
while {pilot distance _targets < 1050 && _i <= 1} do {
pilot flyinheight 150;
MyGameLogic action ["useWeapon",plane,pilot,5];
hintsilent "used";
_i = _i + 1;
sleep 0.2;
/* if (pilot distance _targets > 2000) then {
_pwp = _grp addWaypoint [getmarkerpos "planewp",0];
pilot moveTo _pwp;
}; */
};
/*while loop to repair damage (not working)

while {(damage plane) > 0.1} do {
plane setDamage 0;
}; 
*/

I've also include an if-statement within the while-loop to break it, but that doesn't seem to work.

The problem with range also persists. Anything below 1500 and the while-statement will not activate. 1500m is basically just about the spawn distance, so the code gets activated instantly. This causes the bombs to drop roughly 100-200 m off the target, so it's extremely unreliable. I'm still trying to narrow it down to 50-100m max, but the while-statement refuses to work if it is being initialized AFTER spawn. (Maybe it's terminating itself after a while since it's getting started via the unit's init line?)

I'll continue experimenting.

//edit2

Apparently the script likes skipping the whole while-loop and moves onto the next one instead (I included a test while loop to see if he skips the other one). So he apparently only runs the loop once and then ignores it.

Edited by tryteyker

Share this post


Link to post
Share on other sites

I hope it's alright if I make a new post for this (since my original post was a bit long).

I managed to get it working for the A10 and the AV8B (the one without LGBs, so AV8B2). The issue seemed to be that I spawned the unit too close. There's also an issue with the AV8B, it seems to randomly drop a bomb before actually entering the loop (in the test mission below this hits the cars).

So far the spawn has to be defined, but doing it dynamically might be an easy task.

So, for anyone who wants to use it, here's the script (It has it's flaws, but it's something):

// Creating the plane & pilot

_grp = creategroup WEST;
setfire = true;


hintSilent "Select your firedirection";
onMapSingleClick {
  //We only need this event to fire once, once that happens we reset it
  onMapSingleClick {};

  //ASL height
  _height = getTerrainHeightASL _pos;

  //Move the object
  ASTarget setPosASL [_pos select 0, _pos select 1, _height];

  //Set variable
  setfire = false;
};  

waituntil {!setfire};
_targets = nearestObject [ASTarget, "Tank"];
hintSilent format ["%1",_targets];
if (!setfire) then {
"Firedirection" setMarkerPos getpos ASTarget;
// plane = createvehicle ["AV8B2", getmarkerpos "unitspawn",[],0,"FLY"];
plane = createvehicle ["A10", getmarkerpos "unitspawn",[],0,"FLY"];
plane setposATL [(getposATL plane select 0), getposATL plane select 1, 200];
plane setspeedmode "full";
plane setDir 90;
plane setvelocity [100,0,0];
plane allowDamage false;
pilot = _grp createunit ["USMC_Soldier_Pilot",getmarkerpos "unitspawn",[],0,"FORM"];
pilot moveindriver plane;
pilot action ["LandGearUp", plane];
pilot doMove getpos _targets;
pilot doTarget _targets;
pilot flyinheight 300;
pilot allowdamage false;
};

// Dropping MK82

/* for [{_i = 0},{pilot distance _targets < 1500 && _i <= 2},{_i = _i + 1}] do {
MyGameLogic action ["useWeapon",plane,pilot,5];
hintSilent format ["%1",_i];
sleep 0.2;
}; */
waituntil {pilot distance _targets < 500};

//Declaring variable to limit bomb usage
_i = 0;

// A10 
while {_i <= 3} do {
MyGameLogic action ["useWeapon",plane,pilot,7];
sleep 1;
_i = _i + 1;
hintSilent format ["%1",_i];
};

/* AV8B2
while {_i <= 4} do {
MyGameLogic action ["useWeapon",plane,pilot,5];
sleep 2;
_i = _i + 1;
hintSilent format ["%1",_i];
}; */

_pwp = _grp addWaypoint [getmarkerpos "planewp",0];
pilot doMove (getMarkerPos "planewp");

There's both a for-loop and a while-loop, both work. I also left both methods, for the AV8B2 and the A10.

For anyone interested, here's an example mission (You can change between AV8B2 and A10 in the createUnit line):

http://www.speedyshare.com/MkEDK/AV8BTestMission.utes.rar

(Couldn't find a better host so yeah)

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  

×