GTFreeFlyer Posted June 1, 2020 Posted June 1, 2020 I’m not looking for a list of dead map objects in zone. I already know about that function. I’m looking to place a trigger zone over a town and get a table (list) of object ID’s of all existing buildings, bridges, etc. Any ideas? Thanks! My DCS Missions: Band of Buds series | The End of the T-55 Era | Normandy PvP | Host of the Formation Flight Challenge server Supercarrier Reference Kneeboards IRL: Private Pilot, UAS Test Pilot, Aircraft Designer, and... eh hem... DCS Enthusiast
davidp57 Posted June 2, 2020 Posted June 2, 2020 This may help : --- --- lists all units and statics (and their groups names) in a trigger zone --- function veafCombatZone.findUnitsInTriggerZone(triggerZoneName) local triggerZone = trigger.misc.getZone(triggerZoneName) local units_by_name = {} local l_units = mist.DBs.units --local reference for faster execution local units = {} local groupNames = {} local alreadyAddedGroups = {} local zoneCoordinates = {} zoneCoordinates = {radius = triggerZone.radius, x = triggerZone.point.x, y = triggerZone.point.y, z = triggerZone.point.z} -- the following code is liberally adapted from MiST (thanks Grimes !) for coa, coa_tbl in pairs(l_units) do for country, country_table in pairs(coa_tbl) do for unit_type, unit_type_tbl in pairs(country_table) do if type(unit_type_tbl) == 'table' then for group_ind, group_tbl in pairs(unit_type_tbl) do if type(group_tbl) == 'table' then for unit_ind, mist_unit in pairs(group_tbl.units) do local unitName = mist_unit.unitName local unit = Unit.getByName(unitName) if not unit then unit = StaticObject.getByName(unitName) end if unit then local unit_pos = unit:getPosition().p if unit_pos then if (((unit_pos.x - zoneCoordinates.x)^2 + (unit_pos.z - zoneCoordinates.z)^2)^0.5 <= zoneCoordinates.radius) then veafCombatZone.logTrace(string.format("adding unit [%s]", unitName)) veafCombatZone.logTrace(string.format("unit:getCategory() = [%d]", unit:getCategory())) local groupName = nil if (unit:getCategory() == 3) or (unit:getCategory() == 4) then groupName = unitName -- default for static objects = groups themselves else groupName = unit:getGroup():getName() end veafCombatZone.logTrace(string.format("groupName = %s", groupName)) if string.sub(groupName:upper(),1,string.len(triggerZoneName))==triggerZoneName:upper() then units[#units + 1] = unit if not alreadyAddedGroups[groupName] then alreadyAddedGroups[groupName] = groupName groupNames[#groupNames + 1] = groupName end end end end end end end end end end end end 1 Zip - VEAF :pilotfly: If you want to learn, talk and fly with french-speaking friends, the Virtual European Air Force is here for you ! Meet us on our Discord and our forum If you're a mission creator, you may want to check the VEAF Mission Creation Tools (and its GitHub repository) a set of open-source scripts and tools that make creating a dynamic mission a breeze !
GTFreeFlyer Posted June 2, 2020 Author Posted June 2, 2020 Have you tried it out or did you just find it? Units and statics are different than map objects when trying to use the lua functions to find things. Just curious if you got it working with map objects. My DCS Missions: Band of Buds series | The End of the T-55 Era | Normandy PvP | Host of the Formation Flight Challenge server Supercarrier Reference Kneeboards IRL: Private Pilot, UAS Test Pilot, Aircraft Designer, and... eh hem... DCS Enthusiast
Grimes Posted June 2, 2020 Posted June 2, 2020 https://wiki.hoggitworld.com/view/DCS_func_searchObjects Change the object catergory to Object.Category.SCENERY and just save the object itself, so change foundItem:getName() to foundItem. 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
GTFreeFlyer Posted June 3, 2020 Author Posted June 3, 2020 https://wiki.hoggitworld.com/view/DCS_func_searchObjects Change the object catergory to Object.Category.SCENERY and just save the object itself, so change foundItem:getName() to foundItem. You rock dude! And thanks for the other help the other day. I got it working :) My DCS Missions: Band of Buds series | The End of the T-55 Era | Normandy PvP | Host of the Formation Flight Challenge server Supercarrier Reference Kneeboards IRL: Private Pilot, UAS Test Pilot, Aircraft Designer, and... eh hem... DCS Enthusiast
GTFreeFlyer Posted June 6, 2020 Author Posted June 6, 2020 Thanks Grimes, it worked perfectly. Now I'm trying to compare locations of two scenery objects, but I'm not sure this is possible. There is no VEC3 or any other information attached to the object other than its ID number. I see that when building the list of found objects, the return is... {{id_ = 1234567}, {id_ = 2345456}, {id_ = 92847476}, ...} No way to find the coordinates of a scenery object if all you have is its ID number, correct? My DCS Missions: Band of Buds series | The End of the T-55 Era | Normandy PvP | Host of the Formation Flight Challenge server Supercarrier Reference Kneeboards IRL: Private Pilot, UAS Test Pilot, Aircraft Designer, and... eh hem... DCS Enthusiast
davidp57 Posted June 6, 2020 Posted June 6, 2020 Have you tried it out or did you just find it? Units and statics are different than map objects when trying to use the lua functions to find things. Just curious if you got it working with map objects. Oh sorry, I did misread "objects", without the "map" part ! Zip - VEAF :pilotfly: If you want to learn, talk and fly with french-speaking friends, the Virtual European Air Force is here for you ! Meet us on our Discord and our forum If you're a mission creator, you may want to check the VEAF Mission Creation Tools (and its GitHub repository) a set of open-source scripts and tools that make creating a dynamic mission a breeze !
Grimes Posted June 7, 2020 Posted June 7, 2020 Thanks Grimes, it worked perfectly. Now I'm trying to compare locations of two scenery objects, but I'm not sure this is possible. There is no VEC3 or any other information attached to the object other than its ID number. I see that when building the list of found objects, the return is... {{id_ = 1234567}, {id_ = 2345456}, {id_ = 92847476}, ...} No way to find the coordinates of a scenery object if all you have is its ID number, correct? That is the object. Like from my sample on the wiki it runs getName() for the units it finds. You can also use foundItem:getPoint() for the location of it. 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
GTFreeFlyer Posted June 7, 2020 Author Posted June 7, 2020 That is the object. Like from my sample on the wiki it runs getName() for the units it finds. You can also use foundItem:getPoint() for the location of it. Oh duh. Not sure what I was thinking there. Cheers. My DCS Missions: Band of Buds series | The End of the T-55 Era | Normandy PvP | Host of the Formation Flight Challenge server Supercarrier Reference Kneeboards IRL: Private Pilot, UAS Test Pilot, Aircraft Designer, and... eh hem... DCS Enthusiast
Recommended Posts