Minsky Posted May 9, 2023 Posted May 9, 2023 Hey guys, Can someone please help me with a simple script? I need to get the list of all runways (their names, to be specific) at all airbases on any given map and dump it into the DCS log. Formatting doesn't matter, it just have to be human readable, something akin to this: Kerman 16 34 Khasab 1 19 I know it seems super trivial, and I've tried reading a couple LUA tutorials before posting this, but my brain simply isn't wired for programming Dima | My DCS uploads
Kanelbolle Posted May 10, 2023 Posted May 10, 2023 (edited) Look here for functions and script examples: https://wiki.hoggitworld.com/view/DCS_func_getRunways https://wiki.hoggitworld.com/view/DCS_func_getAirbases Edited May 10, 2023 by Kanelbolle WARGAMES Servers: https://forum.dcs.world/topic/301046-wargames-server-pvp-and-pve-campaign-servers/ Scripts: RGC & SPGG https://github.com/AGluttonForPunishment/
Minsky Posted May 10, 2023 Author Posted May 10, 2023 2 hours ago, Kanelbolle said: Look here for functions and script examples: Thanks, I'm aware of these pages, but neither explains how to actually see the data I need. The first draws some gray boxes, and the second saves the stuff into table I don't know how to print. Dima | My DCS uploads
Grimes Posted May 10, 2023 Posted May 10, 2023 getRunways returns a table entry called "Name" that gives you the heading name. But it doesn't account for parallel runways. You should have enough data there to derive it via code if needed. 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
Kanelbolle Posted May 10, 2023 Posted May 10, 2023 (edited) 43 minutes ago, Minsky said: Thanks, I'm aware of these pages, but neither explains how to actually see the data I need. The first draws some gray boxes, and the second saves the stuff into table I don't know how to print. If you want it to the log file: local base = world.getAirbases() local myBaseTbl = {} for i = 1, #base do local info = {} info.desc = Airbase.getDesc(base[i]) info.callsign = Airbase.getCallsign(base[i]) info.id = Airbase.getID(base[i]) info.cat = Airbase.getCategory(base[i]) info.point = Airbase.getPoint(base[i]) if Airbase.getUnit(base[i]) then info.unitId = Airbase.getUnit(base[i]):getID() end -- Write Airbase name to DCS logfile env.info(info.callsign) -- See it in the text window in DCS trigger.action.outText(info.callsign , 10 , false) myBaseTbl[info.callsign] = info end If you want it to a separate file you can use LUA IO local mypath = [[C:\Log\]] local myfilename = "logout.txt" -- Open file wFile = io.open(mypath .. myfilename, 'w') local base = world.getAirbases() local myBaseTbl = {} for i = 1, #base do local info = {} info.desc = Airbase.getDesc(base[i]) info.callsign = Airbase.getCallsign(base[i]) info.id = Airbase.getID(base[i]) info.cat = Airbase.getCategory(base[i]) info.point = Airbase.getPoint(base[i]) if Airbase.getUnit(base[i]) then info.unitId = Airbase.getUnit(base[i]):getID() end -- Write Airbase name to file and a new line (\n) wFile:write(info.callsign .. '\n') myBaseTbl[info.callsign] = info end -- Close the file wFile:close() wFile = nil How to remove sanitizeing of LFS and IO Step 1 - Removing LFS and IO sanitation It is not recommended to use this script if you are not aware of the risks of using “lfs” and “io” in DCS lua scripts. Scripts can access your filesystem if you enable LFS! This functionality is off by default in DCS to protect the players from malicious code. Use at your own risk! Enable “lfs” and “io” in DCS Game Folder -> disk:\DCS World OpenBeta\Scripts\MissionScripting.lua Change from: do sanitizeModule('os') sanitizeModule('io') sanitizeModule('lfs') _G['require'] = nil _G['loadlib'] = nil _G['package'] = nil end Change to: do sanitizeModule('os') --sanitizeModule('io') --sanitizeModule('lfs') _G['require'] = nil _G['loadlib'] = nil _G['package'] = nil end Remember to change this back when you are not using this to get out data. You should never join a Multiplayer server or missions you did not make your self with sanitizeModules! Edited May 10, 2023 by Kanelbolle 1 WARGAMES Servers: https://forum.dcs.world/topic/301046-wargames-server-pvp-and-pve-campaign-servers/ Scripts: RGC & SPGG https://github.com/AGluttonForPunishment/
cfrag Posted May 10, 2023 Posted May 10, 2023 (edited) Here's a script that dumps all runways to your screen (use message history to view all), adapt to write to preferred file as you like allYourBase = {} function allYourBase.getInfo() local allBases = world.getAirbases() for idx, aBase in pairs(allBases) do trigger.action.outText("Airbase <" .. aBase:getName() .. "> runways: ", 30 ) local allRunways = aBase:getRunways() for idy, aRunway in pairs(allRunways) do trigger.action.outText(" RWY " .. aRunway.Name, 30) end end end allYourBase.getInfo() Supports naval airfields (carriers) and FARPs And here's the demo miz. Works on all maps. null all your base.miz Edited May 10, 2023 by cfrag 1
Minsky Posted May 10, 2023 Author Posted May 10, 2023 @Kanelbolle @cfrag this is awesome guys No way I could've figured this out myself. I modified your scripts to simultaneously write to the DCS log, in-game messages, and their custom log files. Works like a charm. Thank you both very much! Dima | My DCS uploads
Recommended Posts