CougarFFW04 Posted December 17, 2019 Posted December 17, 2019 Hi everyone, I am wondering if there is any DCS function that would allow to get the closest theater scenery object from a given position ? Thanks
Grimes Posted December 17, 2019 Posted December 17, 2019 For scenery objects you will have to use world.searchObjects(). I'd modify that code example to do something like this: local dist = math.huge local closestObj Then modify the ifFound function to something like. local ifFound = function(foundItem, val) local oPoint = foundItem:getPoint() local cDist = ((sphere.point.x - oPoint.x)^2 + (sphere.point.z - oPoint.z)^2)^0.5 if cDist < dist then dist = cDist closestObj = foundItem end end Once done then closestObj should be the closest scenery object to the zone defined by "town" 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 December 17, 2019 Author Posted December 17, 2019 (edited) Hi Grimes, Thanks. Got it. Two more questions : what are the attributes of SCENERY objets ? I can get there name and typeName but I guess there are much more... In particular life... But I am unable to get it... Or may be I am wrong and SCENERY object have no life score and are either dead or alive... Edited December 17, 2019 by CougarFFW04
Grimes Posted December 18, 2019 Posted December 18, 2019 It is highly variable for the scenery objects. Last I remember so values were just randomly missing stuff, especially the description table. It is weird for the life value because some take different amounts of ammunition to destroy them, but the value itself isn't accessible or given. The scenery class is supposed to have all of the normal object functions plus getLife and getDescByName. 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
Pikey Posted December 18, 2019 Posted December 18, 2019 I couldnt get many of the functions that the hoiggit wiki suyggests should work on scenery to produce anything. I got an ID and a model name and that was it. When they die, they are swapped out for a destructed model. This is how I count my scenery is dead on a running server. It's not science, its dependant on the scenery's new name containing string matches. But it does work. ___________________________________________________________________________ SIMPLE SCENERY SAVING * SIMPLE GROUP SAVING * SIMPLE STATIC SAVING *
CougarFFW04 Posted December 19, 2019 Author Posted December 19, 2019 Hi Guys, Thanks for your help and comments. Another question : I might be interested to get the orientation of a static object on the theater. As far as I understand the getPosition function (which seems to me an extension of the getPoint) would be the right one for that but I do not understand the return... I would have expect a vec3 for the position (as for getPoint) + a scalar for the position angle but the documentation indicate 4 vec3... Anybody ?
Hardcard Posted December 20, 2019 Posted December 20, 2019 (edited) @CougarFFW04 If by orientation you mean heading, you can get it using MOOSE. Alternatively, you can just use the same code MOOSE uses to calculate it: local Static_Object = StaticObject.getByName("Name of the static in ME") if Static_Object then local Position = Static_Object:getPosition() if Position then Static_Heading = math.atan2( Position.x.z, Position.x.x ) if Static_Heading < 0 then Static_Heading = Static_Heading + 2 * math.pi else Static_Heading = Static_Heading * 180 / math.pi end end end As for :getPosition(), it returns a table containing 4 subtables: - Position subtable (object coordinates relative to the map origin, using the map axes) p = {x = n, y = n, z = n} - Orientation subtable for the x axis of the object x = {x = n, y = n, z = n} - Orientation subtable for the y axis of the object y = {x = n, y = n, z = n} - Orientation subtable for the z axis of the object z = {x = n, y = n, z = n} I think that these three orientation subtables contain the results of 3x3 transform matrices, which DCS uses to turn objects around. Just remember that every object in DCS has its own x, y and z axes (used for orientation and vectoring of the object itself), which are separate from the map's x, y and z axes (used for reference and positioning of all objects). Perhaps I'm mistaken somewhere, but this is what I've been able to gather so far. Edited December 20, 2019 by Hardcard [sIGPIC][/sIGPIC]
Recommended Posts