Trying to learn scripting, is this the right place to ask for scripting help.
redpilot007
Printable View
Trying to learn scripting, is this the right place to ask for scripting help.
redpilot007
Ask away.
I want an AI plane to change course, that is overall purpose. But problem is identifying the A.I. plane. It is not finding it in my script so not using the correct identifier. (is it the name?)
I think it worked once, but not reliably.
Also, not sure if the setting of new waypoints is functional.
Anyway, I attached what I have done.
Thanks for attention.
redpilot007
Some thing like this.
Code:int ARMY = 2;
string groupName = "BoB_LW_JG51_II";
AiAirGroup[] aig = GamePlay.gpAirGroups(ARMY);
foreach (AiAirGroup ag in aig)
{
if (ag.Name().Contains(groupName))
{
return ag;
}
}
return null;
Are you referring to what I have done? Because I cant get further on (no debug messages) and the plane does not change course.
What values should you be using for Point3d? I used the mouse cursor , so am unsure that is the correct way.
If I could see your script, that would be good.
Are you comfortable with multi-threaded code?
Do you have a good development environment?
You need to start by getting a path parameters object. Here's how it looks for ground units.
Then you need to check for completion.Code:IRecalcPathParams pathParams = GamePlay.gpFindPath(start, 10.0, targetPoint, 20.0, PathType.GROUND, ARMY_AXIS);
Code:if (pathParams.State == RecalcPathState.SUCCESS) {
groundGroup.SetWay(pathParams.Path);
}
I made the changes with the code you gave, to be sure: start , targetPoint are x, y values from mouse cursor, 10,20 are z height.
It passed debug, so good so far, but still no change of course.
I didn't attempt to multi thread, I know little about it, but works without it?
I use Visual Studio Express
Thanks anyway
You can/should set an 'action' for each waypoint. There are a bunch of different actions, everything from just flying from point to point to attacking nearby aircraft or ground targets, or taking off or landing.
So maybe your waypoints don't have the right action attached to them? I don't know what the default action would be, if you don't set one.
Example:
Other example actions:Code:aaWP = new AiAirWayPoint(ref point, speed);
aaWP.Action = AiAirWayPointType.NORMFLY;
You can find all this info in the 'object browser' in Visual Studio if you go & load all the CloD .dlls into it. There are instructions for doing this online somewhere.Code:AiAirWayPointType.GATTACK_TARG
AiAirWayPointType.GATTACK_POINT
aawp == AiAirWayPointType.COVER
aawp == AiAirWayPointType.ESCORT
aawp == AiAirWayPointType.FOLLOW
Also, your code seems to assume that "Timeout" waits for 10 seconds or whatever? It delays only the things that are within the Timeout call. Then it moves on to the next line of code instantly.
For example this code will settask agt then agt2 immediately, then 1 second later a message will pop up:
The other tip is, I'm pretty sure you need to set the first waypoint to the aircraft's current position. I can't remember what happens if the first waypoint is just way off somewhere, but I don't think it is good.Code:aiAirGroup.setTask(agt, aiAirGroup);
Timeout(initTime += 1, () =>
{
GamePlay.gpHUDLogCenter("Wait 1 s" );
});
aiAirGroup.setTask(agt2, aiAirGroup);
Here is a routine I've used to get a waypoint with the current speed/position, etc:
But to answer your basic question: yes, it is very possible to reprogram an aircraft (or ship, vehicle, etc) path on the fly and so modify their flightplan and behavior.Code:public AiWayPoint CurrentPosWaypoint(AiAirGroup airGroup, AiAirWayPointType aawpt = AiAirWayPointType.NORMFLY)
{
try
{
AiAirWayPoint aaWP = null;
//double speed = (airGroup.GetItems()[0] as AiAircraft).getParameter(part.ParameterTypes.Z_VelocityTAS, -1);
Vector3d Vwld = airGroup.Vwld();
double vel_mps = CalculatePointDistance(Vwld);
if (vel_mps < 70) vel_mps = 70;
if (vel_mps > 160) vel_mps = 160;
Point3d CurrentPos = airGroup.Pos();
aaWP = new AiAirWayPoint(ref CurrentPos, vel_mps);
aaWP.Action = aawpt;
return aaWP;
}
catch (Exception ex) { Console.WriteLine("CurrentPosWaypoint: " + ex.ToString()); return null; }
}
public double CalculatePointDistance(
Vector3d startPoint)
{
//Calculate the length of the adjacent and opposite
double diffX = Math.Abs(startPoint.x);
double diffY = Math.Abs(startPoint.y);
return distance(diffX, diffY);
}
Here is a module we use that makes extensive use of this idea - might give you some examples to look at:
https://github.com/bhugh/TWC_Mission...tsubmission.cs