chromium Posted December 15, 2014 Posted December 15, 2014 Hi, I need to build a simple airbase table, with those information: 1 - id 2 - name 3 - coalition id owning 4 - position given that if I know "1" I can simply retrieve the others, I don't understand how to handle the results of: _G.world.getAirbases() Do you have a suggestion about how I can populate a table with this structure: AFBtable = { [1] = { ["id"] = 1 ["name"] = "airbasename" ["pos"] = {airbasetable VEC3 or VEC2} ["coa"] = 1 (0, 1 or 2 depending of the coalition) }, ... ... ... } thanks in advance. 1 Author of DSMC, mod to enable scenario persistency and save updated miz file Stable version & site: https://dsmcfordcs.wordpress.com/ Openbeta: https://github.com/Chromium18/DSMC The thing is, helicopters are different from planes. An airplane by it's nature wants to fly, and if not interfered with too strongly by unusual events or by a deliberately incompetent pilot, it will fly. A helicopter does not want to fly. It is maintained in the air by a variety of forces in opposition to each other, and if there is any disturbance in this delicate balance the helicopter stops flying; immediately and disastrously.
SNAFU Posted December 15, 2014 Posted December 15, 2014 MIST has a quite useful function to show the content of tables. I would try to get a look into the results of the function blueairfields = {} blueairfields = coalition.getAirbases(2) local airbasetableprintout = mist.utils.tableShow(blueairfields) trigger.action.outText("This is how the table looks like: \n\n"..airbasetableprintout , 10) Then I would see how to retrieve the parameters. [sIGPIC][/sIGPIC] Unsere Facebook-Seite
chromium Posted December 15, 2014 Author Posted December 15, 2014 Great idea: I forgot about the mist.utils.tableShow function. I'll see that this night if you don't see that first :) Author of DSMC, mod to enable scenario persistency and save updated miz file Stable version & site: https://dsmcfordcs.wordpress.com/ Openbeta: https://github.com/Chromium18/DSMC The thing is, helicopters are different from planes. An airplane by it's nature wants to fly, and if not interfered with too strongly by unusual events or by a deliberately incompetent pilot, it will fly. A helicopter does not want to fly. It is maintained in the air by a variety of forces in opposition to each other, and if there is any disturbance in this delicate balance the helicopter stops flying; immediately and disastrously.
sniperwolfpk5 Posted December 15, 2014 Posted December 15, 2014 What I suggest. just create an empty mission save it then open .miz file and there is mission file open it with any editor. Here you can see all airports with their ids, name etc Win10, Intel 3rd Gen. Core i7 3.8Ghz, 20GB ram, Nvidia Geforce 1060 6GB Opentrack (Download it from HERE), PS3 Eye, Saitek x52-pro Joystick, DIY Rudder Pedals, Google Cardboard with DCS World English is not my native language
chromium Posted December 15, 2014 Author Posted December 15, 2014 What I suggest. just create an empty mission save it then open .miz file and there is mission file open it with any editor. Here you can see all airports with their ids, name etc I already have the entire list, but which coalition owe an airport will depend by the mission file. Instead, I need a table that for that particoular mission file would retrieve the complete list, and I also want that script to work with any mission file whitout further work or modification. So, the fastest way to get it is to use the SSE to retrieve that specific mission data :). I'm working on a script intended to create AI flights only by putting a zone in the mission editor, using parameters that depends by the zone naming (mission type, Aircraft, ETA on target). it already work as intended, but I want to overcame the limitation about using only "THOSE" airfield actually present in the script as red or blue :) Author of DSMC, mod to enable scenario persistency and save updated miz file Stable version & site: https://dsmcfordcs.wordpress.com/ Openbeta: https://github.com/Chromium18/DSMC The thing is, helicopters are different from planes. An airplane by it's nature wants to fly, and if not interfered with too strongly by unusual events or by a deliberately incompetent pilot, it will fly. A helicopter does not want to fly. It is maintained in the air by a variety of forces in opposition to each other, and if there is any disturbance in this delicate balance the helicopter stops flying; immediately and disastrously.
chromium Posted December 16, 2014 Author Posted December 16, 2014 This one is working in producing a lua Table that contain the information I need, but as you may see it starts by a manual list of AFB name and id's. -- airfield DB AFBlist = { [12] = {name = 'Anapa-Vityazevo', id = 12}, [14] = {name = 'Novorossiysk', id = 14}, [15] = {name = 'Krymsk', id = 15}, [16] = {name = 'Maykop-Khanskaya', id = 16}, [17] = {name = 'Gelendzhik', id = 17}, [18] = {name = 'Sochi-Adler', id = 18}, [19] = {name = 'Krasnodar-Pashkovsky', id = 19}, [20] = {name = 'Sukhumi-Babushara', id = 20}, [21] = {name = 'Gudauta', id = 21}, [22] = {name = 'Batumi', id = 22}, [23] = {name = 'Senaki-Kolkhi', id = 23}, [24] = {name = 'Kobuleti', id = 24}, [25] = {name = 'Kutaisi', id = 25}, [26] = {name = 'Mineralnye Vody', id = 26}, [27] = {name = 'Nalchik', id = 27}, [28] = {name = 'Mozdok', id = 28}, [29] = {name = 'Tbilisi-Lochini', id = 29}, [30] = {name = 'Soganlug', id = 30}, [31] = {name = 'Vaziani', id = 31}, [32] = {name = 'Beslan', id = 32} } local AFBtable = {} fillAFBtable = function() for afbId, afbData in pairs(AFBlist) do local FltAirbaseData = Airbase.getByName(afbData.name) local FltAirbasePos = nil local FltAirbaseCoa = nil if FltAirbaseData == nil then FltAirbaseData = "noData" FltAirbasePos = "noPos" FltAirbaseCoa = "noCoa" else FltAirbasePos = Airbase.getPosition(FltAirbaseData).p FltAirbaseCoa = Airbase.getCoalition(FltAirbaseData) if FltAirbasePos == nil then FltAirbasePos = "noPos" end if FltAirbaseCoa == nil then FltAirbaseCoa = "noCoa" end end AFBtable[#AFBtable + 1] = {name = afbData.name, id = afbData.id, pos = FltAirbasePos, coaId = FltAirbaseCoa} end end fillAFBtable() Author of DSMC, mod to enable scenario persistency and save updated miz file Stable version & site: https://dsmcfordcs.wordpress.com/ Openbeta: https://github.com/Chromium18/DSMC The thing is, helicopters are different from planes. An airplane by it's nature wants to fly, and if not interfered with too strongly by unusual events or by a deliberately incompetent pilot, it will fly. A helicopter does not want to fly. It is maintained in the air by a variety of forces in opposition to each other, and if there is any disturbance in this delicate balance the helicopter stops flying; immediately and disastrously.
ajax Posted December 16, 2014 Posted December 16, 2014 This little routine might help: http://forums.eagle.ru/showpost.php?p=2242689&postcount=7
chromium Posted December 16, 2014 Author Posted December 16, 2014 This little routine might help: http://forums.eagle.ru/showpost.php?p=2242689&postcount=7 Thanks! I'll look at it :) Author of DSMC, mod to enable scenario persistency and save updated miz file Stable version & site: https://dsmcfordcs.wordpress.com/ Openbeta: https://github.com/Chromium18/DSMC The thing is, helicopters are different from planes. An airplane by it's nature wants to fly, and if not interfered with too strongly by unusual events or by a deliberately incompetent pilot, it will fly. A helicopter does not want to fly. It is maintained in the air by a variety of forces in opposition to each other, and if there is any disturbance in this delicate balance the helicopter stops flying; immediately and disastrously.
ajax Posted December 17, 2014 Posted December 17, 2014 (edited) I had a little time so I went ahead and modified the code at the link. I think this will do exactly what you want: function getAllAirbases() -- Returns a table of all airbases having the following structure: -- returnTable.id --ID -- returnTable.coa --Coalition -- returnTable.name --Name -- returnTable.pos --Position -- Returns nil if no airbases found (should never happen) local coalitions = {} coalitions[1] = coalition.side.RED coalitions[2] = coalition.side.BLUE coalitions[3] = coalition.side.NEUTRAL local airdromes = {} for k = 1, #coalitions do local tmp = coalition.getAirbases(coalitions[k]) for i=1, #tmp do local j = #airdromes + 1 airdromes[j] = {} airdromes[j].id = tmp[i]:getID() airdromes[j].coa = coalitions[k] airdromes[j].name = tmp[i]:getName() airdromes[j].pos = tmp[i]:getPosition() end end if #airdromes > 0 then return airdromes else return nil end end Edited December 17, 2014 by ajax 1
chromium Posted December 17, 2014 Author Posted December 17, 2014 Yes! It seems perfect :)! EDIT: So bad: "must spread rep"... you deserve it a lot. Author of DSMC, mod to enable scenario persistency and save updated miz file Stable version & site: https://dsmcfordcs.wordpress.com/ Openbeta: https://github.com/Chromium18/DSMC The thing is, helicopters are different from planes. An airplane by it's nature wants to fly, and if not interfered with too strongly by unusual events or by a deliberately incompetent pilot, it will fly. A helicopter does not want to fly. It is maintained in the air by a variety of forces in opposition to each other, and if there is any disturbance in this delicate balance the helicopter stops flying; immediately and disastrously.
chromium Posted December 17, 2014 Author Posted December 17, 2014 I tested this modification: -- build AFB & Country Tables DAWS.fillAFBandCOUNTRYtable = function() local debugAirbases = "" -- Returns a table of all airbases having the following structure: -- returnTable.id --ID -- returnTable.coa --Coalition -- returnTable.name --Name -- returnTable.pos --Position -- Returns nil if no airbases found (should never happen) local coalitions = {} coalitions[1] = coalition.side.RED coalitions[2] = coalition.side.BLUE coalitions[3] = coalition.side.NEUTRAL --local CNR AFBtable = {} for k = 1, #coalitions do local tmp = coalition.getAirbases(coalitions[k]) for i=1, #tmp do local j = #AFBtable + 1 AFBtable[j] = {} AFBtable[j].id = tmp[i]:getID() AFBtable[j].coa = coalitions[k] AFBtable[j].name = tmp[i]:getName() AFBtable[j].pos = tmp[i]:getPosition() end end --[[ if #AFBtable > 0 then return AFBtable else return nil end --]]-- --debug debugAirbasesFunc = function() local fName = "debugAFBlist.txt" local debugAirbasesCSV = io.open(lfs.writedir() .. DAWS_debugdirectory .. fName, "w") for afbid, afbData in pairs(AFBtable) do debugAirbases = debugAirbases .. "testo" .. DAWS_tss .. afbData.name .. DAWS_tss .. afbData.coa .. DAWS_tss .. afbData.id .. DAWS_tss .. afbData.pos.x .. DAWS_tss .. afbData.pos.y .. DAWS_tss .. afbData.pos.z .. "\n" end debugAirbasesCSV:write(debugAirbases) debugAirbasesCSV:close() end debugAirbasesFunc() end It seems that the table "AFBtable" is there, but it's void.... can't retrieve any parameter with the debug function. Author of DSMC, mod to enable scenario persistency and save updated miz file Stable version & site: https://dsmcfordcs.wordpress.com/ Openbeta: https://github.com/Chromium18/DSMC The thing is, helicopters are different from planes. An airplane by it's nature wants to fly, and if not interfered with too strongly by unusual events or by a deliberately incompetent pilot, it will fly. A helicopter does not want to fly. It is maintained in the air by a variety of forces in opposition to each other, and if there is any disturbance in this delicate balance the helicopter stops flying; immediately and disastrously.
ajax Posted December 18, 2014 Posted December 18, 2014 Hmmm... I inserted a bunch of print statements, and the code seems to work for me. Here is the output: 00128.536 INFO SCRIPTING: # coalitions = 1 00128.536 INFO SCRIPTING: getAirbases returned 8 airbases for coalition 1 00128.536 INFO SCRIPTING: 18 1 Sochi-Adler 00128.536 INFO SCRIPTING: 23 1 Senaki-Kolkhi 00128.536 INFO SCRIPTING: 24 1 Kobuleti 00128.536 INFO SCRIPTING: 25 1 Kutaisi 00128.536 INFO SCRIPTING: 70 1 Senaki FARP A 1-01 00128.536 INFO SCRIPTING: 71 1 Senaki FARP B 1-01 00128.536 INFO SCRIPTING: 26 1 Black-sea fleet-01 00128.536 INFO SCRIPTING: 29 1 Black-sea fleet-02 00128.536 INFO SCRIPTING: # coalitions = 2 00128.536 INFO SCRIPTING: getAirbases returned 3 airbases for coalition 2 00128.536 INFO SCRIPTING: 20 2 Sukhumi-Babushara 00128.536 INFO SCRIPTING: 21 2 Gudauta 00128.536 INFO SCRIPTING: 22 2 Batumi 00128.536 INFO SCRIPTING: # coalitions = 3 00128.536 INFO SCRIPTING: getAirbases returned 14 airbases for coalition 0 00128.536 INFO SCRIPTING: 12 0 Anapa-Vityazevo 00128.536 INFO SCRIPTING: 13 0 Krasnodar-Center 00128.537 INFO SCRIPTING: 14 0 Novorossiysk 00128.537 INFO SCRIPTING: 15 0 Krymsk 00128.537 INFO SCRIPTING: 16 0 Maykop-Khanskaya 00128.537 INFO SCRIPTING: 17 0 Gelendzhik 00128.537 INFO SCRIPTING: 19 0 Krasnodar-Pashkovsky 00128.537 INFO SCRIPTING: 26 0 Mineralnye Vody 00128.537 INFO SCRIPTING: 27 0 Nalchik 00128.537 INFO SCRIPTING: 28 0 Mozdok 00128.537 INFO SCRIPTING: 29 0 Tbilisi-Lochini 00128.537 INFO SCRIPTING: 30 0 Soganlug 00128.537 INFO SCRIPTING: 31 0 Vaziani 00128.537 INFO SCRIPTING: 32 0 Beslan 00128.537 INFO SCRIPTING: getAllAirbases success! Are you sure your debug code works as expected?
ajax Posted December 18, 2014 Posted December 18, 2014 (edited) Ah. I think I see the problem. AFBTable.pos is a position vector. It has p, x, y, and z components, each of which is another vector. So I think you need to change afbData.pos.x to afbData.pos.p.x, afbData.pos.y to afbData.pos.p.y, and afbData.pos.z to afbData.pos.p.z . Edit: Alternatively, you can change tmp:getPosition() to tmp:getPoint(). Edited December 18, 2014 by ajax
chromium Posted December 18, 2014 Author Posted December 18, 2014 Uh, I didn't noticed that! Thanks :) Author of DSMC, mod to enable scenario persistency and save updated miz file Stable version & site: https://dsmcfordcs.wordpress.com/ Openbeta: https://github.com/Chromium18/DSMC The thing is, helicopters are different from planes. An airplane by it's nature wants to fly, and if not interfered with too strongly by unusual events or by a deliberately incompetent pilot, it will fly. A helicopter does not want to fly. It is maintained in the air by a variety of forces in opposition to each other, and if there is any disturbance in this delicate balance the helicopter stops flying; immediately and disastrously.
ajax Posted December 19, 2014 Posted December 19, 2014 (edited) Also, be aware that getAirbases() returns FARPs and certain ships (aircraft carriers and those with helidecks), too. If you only want actual airports then you will have to test each one before adding it to the AFBtable table. Edited December 19, 2014 by ajax
piXel496 Posted December 19, 2014 Posted December 19, 2014 (edited) ..modified the code at the link. I think this will do exactly what you want.. post #9 :thumbup: Nice, useful snipped Thanks! . Edited December 19, 2014 by piXel496 You must spread some Reputation around before giving it to ajax again... Can't +. Apparently I already like you :) old stuff I made
chromium Posted December 19, 2014 Author Posted December 19, 2014 Also, be aware that getAirbases() returns FARPs and certain ships (aircraft carriers and those with helidecks), too. If you only want actual airports then you will have to test each one before adding it to the AFBtable table. This actually is a plus for me :D. PS: tested Yesterday: works like a charm. Author of DSMC, mod to enable scenario persistency and save updated miz file Stable version & site: https://dsmcfordcs.wordpress.com/ Openbeta: https://github.com/Chromium18/DSMC The thing is, helicopters are different from planes. An airplane by it's nature wants to fly, and if not interfered with too strongly by unusual events or by a deliberately incompetent pilot, it will fly. A helicopter does not want to fly. It is maintained in the air by a variety of forces in opposition to each other, and if there is any disturbance in this delicate balance the helicopter stops flying; immediately and disastrously.
Recommended Posts