CougarFFW04 Posted November 27, 2018 Posted November 27, 2018 Hi DCS scripting gurrus, I would like to know if there is any DCS scripting function that would return true (or whatever) when a flight reach a waypoint in his flight plan. If not is there any simple way to achieve this without having to set any trigger, area,.... as I am interested to do that just with a script. Thanks
Grimes Posted November 27, 2018 Posted November 27, 2018 You can make a command>Do Script task on reaching each waypoint and calling a global function. Its obviously a bit easier to manage if you generate a flight plan via script. In your main code area: local currentWP = {} function passWP(group, wp) currentWP[group] = wp end On each waypoint local gp = ... passWP(gp:getName(), 2) The '...' acts as a "self" variable when used within script call assigned via WP or triggered task for a group. It is basically the group object, but you still need to assign a variable to equal it. You can't just do ...:getName(). Alternatively it is fairly easy to setup a check for each waypoint and seeing if the group passes within a distance of that point. Just iterate the flight plan and check the position relative to the point. However it wouldn't account for if the group happens to get within a distance of a WP without actually passing it. What I mean is if you have a CAP task the AI might get into a dogfight around WP3 without actually "reaching" WP3 and doing any tasking assigned at that WP. The right man in the wrong place makes all the difference in the world. Current Projects: Grayflag Server, Scripting Wiki Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread) SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum
CougarFFW04 Posted November 28, 2018 Author Posted November 28, 2018 (edited) Hi Grimes, Thanks for the tips. Not sure I understand correctly the ... stuff but I will experiment. Alternatively it is fairly easy to setup a check for each waypoint and seeing if the group passes within a distance of that point. Just iterate the flight plan and check the position relative to the point. However it wouldn't account for if the group happens to get within a distance of a WP without actually passing it. What I mean is if you have a CAP task the AI might get into a dogfight around WP3 without actually "reaching" WP3 and doing any tasking assigned at that WP. This is something I was thinking about. Although I think it is quite easy to get the plane position I do not know how to get the waypoints positions attached to the flight. Any good starting point for that ? Thanks again. Edited November 28, 2018 by CougarFFW04
funkyfranky Posted November 28, 2018 Posted November 28, 2018 I would like to know if there is any DCS scripting function that would return true (or whatever) when a flight reach a waypoint in his flight plan. Here is a little MOOSE script I wrote a while back for testing. It does what you want but it might contain too much other stuff. However, it might point you in the right direction: do MYGROUP={} --- Function called when group is passing a waypoint. --@param Wrapper.Group#GROUP group --@param #number i Waypoint number that has been reached. --@param #boolean final True if it is the final waypoint. function MYGROUP._Passing_Waypoint(group, i, final) -- Debug message. local text=string.format("Group %s passing waypoint %d (final=%s)", group:GetName(), i, tostring(final)) local pos=group:GetCoordinate() pos:SmokeRed() local MarkerID=pos:MarkToAll(string.format("Reached Waypoint %d of group %s", i, group:GetName())) MESSAGE:New(text,10):ToAll() env.info(text) end --- Make group run/drive to a certain point. We put in several intermediate waypoints because sometimes the group stops before it arrived at the desired point. --@param Wrapper.Group#GROUP group Group to route. --@param Core.Point#COORDINATE fin Coordinate where we want to go. --@param #number speed Speed of group. function MYGROUP._Run(group, fin, speed) -- Clear all tasks. group:ClearTasks() -- Set formation. local formation = "Off road" -- Current coordinates of group. local ini=group:GetCoordinate() ini:SmokeWhite() -- Distance between current and final point. local dist=ini:Get2DDistance(fin) -- Number of waypoints. local nx=2 -- Number of intermediate waypoints. local dx=dist/(nx-1) -- Waypoint and task arrays. local wp={} local tasks={} -- First waypoint is the current position of the group. wp[1]=ini:WaypointGround(speed, formation) tasks[1]=group:TaskFunction("MYGROUP._Passing_Waypoint", 0, false) -- Info on numer of WPs. env.info(string.format("Number of waypoints %d", nx)) -- Loop over waypoints. for i=2,nx do local x=dx*(i-1) local coord=ini:Translate(x, 0) -- Smoke and put marker at waypoint coord:SmokeWhite() local MarkerID=coord:MarkToAll(string.format("Waypoint %d of group %s", i, group:GetName())) local final=false if i==nx then final=true end wp[#wp+1]=coord:WaypointGround(speed, formation) tasks[#tasks+1]=group:TaskFunction("MYGROUP._Passing_Waypoint", (i-1), final) env.info(string.format("%d x = %4.1f", (i-1), x)) end -- Init waypoints of the group. local Waypoints = {} -- New points are added to the default route. for i,p in ipairs(wp) do table.insert(Waypoints, i, wp[i]) end -- Set task for all waypoints. for i,wp in ipairs(Waypoints) do group:SetTaskWaypoint(Waypoints[i], tasks[i]) end -- Submit task and route group along waypoints. group:Route(Waypoints) end local group1=GROUP:FindByName("Group Slow") local group2=GROUP:FindByName("Group Fast") local fin=group1:GetCoordinate():Translate(5000, 0) MYGROUP._Run(group1, fin , 90) MYGROUP._Run(group2, fin , 999) end It is for group units but would work equally well for air/naval if adapted. A warrior's mission is to foster the success of others. i9-12900K | RTX 4090 | 128 GB Ram 3200 MHz DDR-4 | Quest 3 RAT - On the Range - Rescue Helo - Recovery Tanker - Warehouse - Airboss
Grimes Posted November 28, 2018 Posted November 28, 2018 Hi Grimes, Thanks for the tips. Not sure I understand correctly the ... stuff but I will experiment. This is something I was thinking about. Although I think it is quite easy to get the plane position I do not know how to get the waypoints positions attached to the flight. Any good starting point for that ? Yeah the ... can be a little confusing because people might assume it means just blank place to insert a group name or whatever. I've attached a screenshot of the do script command and the outputted text generated from that script when the unit reaches the waypoint. Routes are saved in the .miz file. Linked below is the code from mist that iterates through the mission table to find a specific group and return a table of the route data. Routes cannot be accessed via any function call at preset, though I've asked for it. However if you are creating a route for AI you can obviously store that route data somewhere for retrieval later. https://github.com/mrSkortch/MissionScriptingTools/blob/master/mist.lua#L5976 The right man in the wrong place makes all the difference in the world. Current Projects: Grayflag Server, Scripting Wiki Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread) SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum
CougarFFW04 Posted November 30, 2018 Author Posted November 30, 2018 Hi, @Grimes : thanks for the clarification :smilewink: @funkyfranky : sounds more or less what I was looking for. @both : Thank you so much. You ROCK :thumbup:
Recommended Posts