TEMPEST.114 Posted October 11, 2022 Posted October 11, 2022 I see from the hoggit documentation that if I catch the event for TAKEOFF then I get the AirBase that the player is taking off from in the event. However, if a player spawns into an aircraft at an AirBase (or Carrier) and the events (BIRTH of PLAYER ENTER UNIT) are triggered, then I only get a UNIT object from the event and no reference to the current AirBase that the unit is at. However, on the SELECT ROLE screen, it's clear that the backend knows the AirBase that the unit the player is spawning into, so does anyone know how to get that information during those events? What have I missed in the documentation?
Grimes Posted October 11, 2022 Posted October 11, 2022 Birth events occur whenever anything is spawned, an airbase wouldn't matter for ground units for example. However we can't create new client aircraft, so all of their starting data is embedded in the mission file. You can use this information to correlate with airbases. env.mission is the main contents of the mission file, thus you can iterate the table looking for any client skilled aircraft and build a lookup table for spawn points. You may have to also have to check for distance in instances where takeoff from ground is used because those aircraft lack an entry for the airbase. The route in the mission file follows a similar pattern as the mission task and you need to look for either airdromeId, linkUnit, or helipadId. https://wiki.hoggitworld.com/view/DCS_task_mission Below is copied from mist on a function that finds a specific groupId's route table. It is also a bit paranoid via all of the if statements to verify the expected data exists. for coa_name, coa_data in pairs(env.mission.coalition) do if type(coa_data) == 'table' then if coa_data.country then --there is a country table for cntry_id, cntry_data in pairs(coa_data.country) do for obj_cat_name, obj_cat_data in pairs(cntry_data) do if obj_cat_name == "helicopter" or obj_cat_name == "ship" or obj_cat_name == "plane" or obj_cat_name == "vehicle" then -- only these types have points if ((type(obj_cat_data) == 'table') and obj_cat_data.group and (type(obj_cat_data.group) == 'table') and (#obj_cat_data.group > 0)) then --there's a group! for group_num, group_data in pairs(obj_cat_data.group) do if group_data and group_data.groupId == gpId then -- this is the group we are looking for if group_data.route and group_data.route.points and #group_data.route.points > 0 then for point_num, point in pairs(group_data.route.points) do if point.airdromeId then -- airbases end if point.linkUnit then -- FARP and ship spawns end 1 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
ADHS Posted October 14, 2022 Posted October 14, 2022 (edited) Somehow i did got this information. but i can't remember well. Try to listen 1st the BIRTH and 2nd the LAND events. At the spawining stage (MP), both events are triggering (for some reson). Try it and if they do, then (from LAND event) you can have the Airport name ( Event.place:getName() ) Edited October 14, 2022 by ADHS Democracy was already invented, while Scrat was eating oak fruits.
TEMPEST.114 Posted October 14, 2022 Author Posted October 14, 2022 3 hours ago, ADHS said: Somehow i did got this information. but i can't remember well. Try to listen 1st the BIRTH and 2nd the LAND events. At the spawining stage (MP), both events are triggering (for some reson). Try it and if they do, then (from LAND event) you can have the Airport name ( Event.place:getName() ) I've done it by searching world objects for an airbase within 2000 units. Of course, no one says what the units are (Metres? Feet?)
cfrag Posted October 14, 2022 Posted October 14, 2022 (edited) 57 minutes ago, Elphaba said: Of course, no one says what the units are Internally, units in DCS are meters, yes. Makes for much cleaner calculations (convert m/s into km/h and then try the same with fps into knots to find out why ) Edited October 14, 2022 by cfrag
cfrag Posted October 14, 2022 Posted October 14, 2022 1 hour ago, Elphaba said: I've done it by searching world objects for an airbase within 2000 units That would be a bit too brute-force. Since all airports FARPS and aircraft-carrying ships are known to DCS and are usually less than 50 per map, you can use coalition.getAirbases() to assemble all airbases, and then select the one that is closest to the unit that just spawned. Let me see if I can whip up a small function for you that does this
cfrag Posted October 14, 2022 Posted October 14, 2022 OK, here's the code that gives you all air bases (including, as you can see a FARP helo pad, a destroyer and a carrier that I placed on the map). Total with the added bases less than 15 in Marianas. Here's the entire code (including the code that dumps all names to screen. You'd call that same getBases() and run those against your unit to find the closest one). allYourBase = {} function allYourBase.getBases() local factions = {0, 1, 2} -- neutral, red, blue local allBases = {} -- collect bases into this for idx, theFaction in pairs(factions) do local factionsBases = coalition.getAirbases(theFaction) -- fransfer them all for idy, aBase in pairs(factionsBases) do table.insert(allBases, aBase) end end return allBases end -- test this local mapBases = allYourBase.getBases() for idx, aBase in pairs(mapBases) do trigger.action.outText(aBase:getName(), 30) end And here's the demo mission as proof of concept allMyBases.miz
ADHS Posted October 14, 2022 Posted October 14, 2022 (edited) 3 hours ago, Elphaba said: I've done it by searching world objects for an airbase within 2000 units. Of course, no one says what the units are (Metres? Feet?) No my friend. I am talking about YOU to setup a SCRIPT EVENT HANDLER that is watching for these events. Let me know if you can do this, or else, give me 1-2 days to send you a ready mission so you to check out. Glad to help, just let me know how i can help you. Thank you. Edited October 14, 2022 by ADHS Democracy was already invented, while Scrat was eating oak fruits.
TEMPEST.114 Posted October 14, 2022 Author Posted October 14, 2022 2 hours ago, cfrag said: OK, here's the code that gives you all air bases (including, as you can see a FARP helo pad, a destroyer and a carrier that I placed on the map). Total with the added bases less than 15 in Marianas. Here's the entire code (including the code that dumps all names to screen. You'd call that same getBases() and run those against your unit to find the closest one). allYourBase = {} function allYourBase.getBases() local factions = {0, 1, 2} -- neutral, red, blue local allBases = {} -- collect bases into this for idx, theFaction in pairs(factions) do local factionsBases = coalition.getAirbases(theFaction) -- fransfer them all for idy, aBase in pairs(factionsBases) do table.insert(allBases, aBase) end end return allBases end -- test this local mapBases = allYourBase.getBases() for idx, aBase in pairs(mapBases) do trigger.action.outText(aBase:getName(), 30) end And here's the demo mission as proof of concept allMyBases.miz 10.12 kB · 0 downloads I am struggling with vectors and working out distances. That's part of my problem. Thank you for taking the time and effort to make this, but until I can understand vector maths and how to use them etc, then this is still outside my current understanding. 1 hour ago, ADHS said: No my friend. I am talking about YOU to setup a SCRIPT EVENT HANDLER that is watching for these events. Let me know if you can do this, or else, give me 1-2 days to send you a ready mission so you to check out. Glad to help, just let me know how i can help you. Thank you. Thank you for your offer. I do have an Event Handler setup to capture either BIRTH or PLAYER ENTER UNIT and then I look within 2000m of their unit's position and I get only ONE airbase/carrier back. That is thusly their homebase and where they are. Is that not sufficient? Or is there a problem with that?
cfrag Posted October 14, 2022 Posted October 14, 2022 (edited) 1 hour ago, Elphaba said: I am struggling with vectors and working out distances. That's part of my problem. Ha, why didn’t you say so earlier, and we could have nipped that hours ago — unless someone else gets that in before me, I‘ll update the code to calculate the distance and pick the airfield with shortest distance to a unit (it‘ll only be few added lines) by tomorrow - have to leave for the evening. Edited October 14, 2022 by cfrag 1
ADHS Posted October 15, 2022 Posted October 15, 2022 19 hours ago, ADHS said: Try to listen 1st the BIRTH and 2nd the LAND events. At the spawining stage (MP), both events are triggering (for some reson). 11 hours ago, Elphaba said: Is that not sufficient? Or is there a problem with that? No i don't see problem with this approach. I ment that S_EVENT_LAND can give you the Airport's name at once. All good Democracy was already invented, while Scrat was eating oak fruits.
TEMPEST.114 Posted October 15, 2022 Author Posted October 15, 2022 1 hour ago, ADHS said: No i don't see problem with this approach. I ment that S_EVENT_LAND can give you the Airport's name at once. All good Hi. I thought for a minute the game was sending a 'S_EVENT_LAND' when a player (client) entered a new aircraft/spawned for a minute - because whilst that seemed 'silly' it would have been wonderful and just what I needed, however when a client player picks an aircraft from the select role dialog and enters the aircraft the 'S_EVENT_LAND' doesn't fire. But the 'S_EVENT_PLAYER_ENTER_UNIT' does fire (which I've been using) but that event doesn't contain a 'place' table like the one on 'S_EVENT_TAKEOFF / S_EVENT_LAND' does. Shame, as it could have been an empty table if the unit didn't spawn at an airbase/carrier but alas, it's back to the brute force method. Thanks so much though! I really thought you'd found a hidden gem then!
cfrag Posted October 15, 2022 Posted October 15, 2022 (edited) On 10/11/2022 at 5:36 PM, Elphaba said: I only get a UNIT object from the event As promised, here's a small function that spits out the closest airbase (or FARP or Ship) to the unit you pass in: allYourBase = {} function allYourBase.closestBaseToUnit(theUnit) local uLoc = theUnit:getPoint() -- get unit's location local closestBase = nil local shortestDist = math.huge -- now compare to all bases and -- remember shortest base and dist local factions = {0, 1, 2} -- neutral, red, blue local allBases = {} -- collect bases into this for idx, theFaction in pairs(factions) do local factionsBases = coalition.getAirbases(theFaction) -- fransfer them all for idy, aBase in pairs(factionsBases) do local baseLoc = aBase:getPoint() local dx = uLoc.x - baseLoc.x local dz = uLoc.z - baseLoc.z local dist = math.sqrt(dx * dx + dz * dz) if dist < shortestDist then closestBase = aBase shortestDist = dist end end end return closestBase, shortestDist end -- test this local theUnit = Unit.getByName("findMe") local aBase, d = allYourBase.closestBaseToUnit(theUnit) trigger.action.outText("<findMe>: closest base is " .. aBase:getName() ..". " .. math.floor(d) .. "m away", 30) It uses the AI plane 'findMe' in the demo mission to do it's stuff, and it will work on any map The scary vector math is in the dist, dx and dz calculations; once you feel a bit more comfortable with vectors (seeing that you already use them when you are using positions, that won't be long off ) you'll come to realize that they are my neighbors dog: they look scarier than they actually are. allMyBases.miz Edited October 15, 2022 by cfrag 1
TEMPEST.114 Posted October 15, 2022 Author Posted October 15, 2022 Thank you so much @cfrag You get a whole box of doughnuts!
ADHS Posted October 16, 2022 Posted October 16, 2022 (edited) On 10/15/2022 at 2:17 PM, Elphaba said: I really thought you'd found a hidden gem then! Maybe i did found something that (at least) is not documented. If you spawn from a parking slot, the S_EVENT_BIRTH returns EVENT.place which is the Airport/Base name that you seek. Edited October 16, 2022 by ADHS Democracy was already invented, while Scrat was eating oak fruits.
Recommended Posts