Results 1 to 10 of 10

Thread: Scripting help

  1. #1
    Student Pilot
    Join Date
    Jul 2017
    Posts
    7
    Post Thanks / Like
    Total Downloaded
    443.01 MB

    Scripting help

    Trying to learn scripting, is this the right place to ask for scripting help.


    redpilot007

  2. #2
    ATAG Member ATAG_Oskar's Avatar
    Join Date
    Nov 2017
    Location
    Canada
    Posts
    986
    Post Thanks / Like
    Total Downloaded
    908.31 MB

    Re: Scripting help

    Ask away.

  3. #3
    Student Pilot
    Join Date
    Jul 2017
    Posts
    7
    Post Thanks / Like
    Total Downloaded
    443.01 MB

    Re: Scripting help

    Quote Originally Posted by redpilot007 View Post
    Trying to learn scripting, is this the right place to ask for scripting help.


    redpilot007

    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
    Attached Files Attached Files

  4. #4
    ATAG Member ATAG_Oskar's Avatar
    Join Date
    Nov 2017
    Location
    Canada
    Posts
    986
    Post Thanks / Like
    Total Downloaded
    908.31 MB

    Re: Scripting help

    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;

  5. #5
    Student Pilot
    Join Date
    Jul 2017
    Posts
    7
    Post Thanks / Like
    Total Downloaded
    443.01 MB

    Re: Scripting help

    Quote Originally Posted by ATAG_Oskar View Post
    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;

    Thanks, that part works.
    Maybe wrong but I dont think you can enter waypoints by script/hand, so overall wont work.

  6. #6
    ATAG Member ATAG_Oskar's Avatar
    Join Date
    Nov 2017
    Location
    Canada
    Posts
    986
    Post Thanks / Like
    Total Downloaded
    908.31 MB

    Re: Scripting help

    Quote Originally Posted by redpilot007 View Post
    I dont think you can enter waypoints by script
    That should work. I've written code to control movement of formations of ground units and to designate targets for AI air support.

  7. #7
    Student Pilot
    Join Date
    Jul 2017
    Posts
    7
    Post Thanks / Like
    Total Downloaded
    443.01 MB

    Re: Scripting help

    Quote Originally Posted by ATAG_Oskar View Post
    That should work. I've written code to control movement of formations of ground units and to designate targets for AI air support.



    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.

  8. #8
    ATAG Member ATAG_Oskar's Avatar
    Join Date
    Nov 2017
    Location
    Canada
    Posts
    986
    Post Thanks / Like
    Total Downloaded
    908.31 MB

    Re: Scripting help

    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.

    Code:
    IRecalcPathParams pathParams = GamePlay.gpFindPath(start, 10.0, targetPoint, 20.0, PathType.GROUND, ARMY_AXIS);
    Then you need to check for completion.

    Code:
    	if (pathParams.State == RecalcPathState.SUCCESS) {
    		groundGroup.SetWay(pathParams.Path);
           }

  9. #9
    Student Pilot
    Join Date
    Jul 2017
    Posts
    7
    Post Thanks / Like
    Total Downloaded
    443.01 MB

    Re: Scripting help

    Quote Originally Posted by ATAG_Oskar View Post
    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.

    Code:
    IRecalcPathParams pathParams = GamePlay.gpFindPath(start, 10.0, targetPoint, 20.0, PathType.GROUND, ARMY_AXIS);
    Then you need to check for completion.

    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

  10. #10
    Ace
    Join Date
    May 2015
    Location
    Kansas City, Missouri area
    Posts
    515
    Post Thanks / Like
    Total Downloaded
    130.02 MB

    Re: Scripting help

    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:

    Code:
            aaWP = new AiAirWayPoint(ref point, speed);
            aaWP.Action = AiAirWayPointType.NORMFLY;
    Other example actions:

    Code:
                     AiAirWayPointType.GATTACK_TARG
                                AiAirWayPointType.GATTACK_POINT
                                aawp == AiAirWayPointType.COVER
                                aawp == AiAirWayPointType.ESCORT 
                                aawp == AiAirWayPointType.FOLLOW
    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.

    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:

    Code:
                            aiAirGroup.setTask(agt, aiAirGroup);
    
                              Timeout(initTime += 1, () =>
                              {
                              GamePlay.gpHUDLogCenter("Wait 1 s" );
    
    
                               });
    
                            aiAirGroup.setTask(agt2, aiAirGroup);
    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.

    Here is a routine I've used to get a waypoint with the current speed/position, etc:

    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);
        }
    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.

    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
    Last edited by TWC_Flug; Dec-13-2022 at 22:34.
    System: Microsoft Windows 10 Pro 64 bit, 10.0.18362 N/A Build 18362, 20,437 MB |
    ASUS GeForce GTX 1060 3GB | Intel Core i5-2500 Quad-Core Processor 3.3 GHz 6 MB Cache LGA 1155 | Intel DB65AL motherboard | ARCTIC Freezer i11 CPU Cooler | SVGA 500 watt power supply | Microsoft Sidewinder 2 Force Feedback joystick

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •