Flyingsix Posted February 21, 2018 Share Posted February 21, 2018 (edited) Hey Guys, it's time for another little test object. I want to detect an aircraft within a polygonzone. Here are the facts: The polygon is created by a late activated helicopter (poly1) with 4 points. No closed loop (lines are not crossing each other) One A-10 is flying towards this polygon @ 200ft AGL Passing the Entry-Line of the Polygon a text message should be triggerd via DCS-Editor Trigger condition: Flag is True (101) As detection function I choosed: do mist.flagFunc.units_in_polygon{ units = {'[blue][plane]'}, zone = mist.getGroupPoints('poly1'), flag = 101 } endIt doesn't work! No Error Message till now, so I assume the MIST.lua is loaded correctly. May u can help me? Cheers! Edited February 21, 2018 by Flyingsix Link to comment Share on other sites More sharing options...
Grimes Posted February 21, 2018 Share Posted February 21, 2018 Is it a player aircraft entering the zone? Can you upload the mission file so I can test it out? I made a quick test mission and copied the code from the post verbatim, it worked on first try. 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 Link to comment Share on other sites More sharing options...
Flyingsix Posted February 22, 2018 Author Share Posted February 22, 2018 Hey Grimes, sure. Yes, it's a client-aircraft. How does this matter?xx_PolygonTest.miz Link to comment Share on other sites More sharing options...
Grimes Posted February 22, 2018 Share Posted February 22, 2018 Ok, so that zone is way to small. The flagFuncs check at a rate of once a second. Your zone was at best 5m wide. So it would simply be down to luck for being within that zone during each check. I made the zone bigger and it worked. You could try to directly use the point in polygon function and much more quickly check the zone. Something like this: local function fastPIP(units, poly, flag) for i = 1, #units do if Unit.getByName(units[i]) and Unit.getByName(units[i]):getLife() > 0 then if mist.pointInPolygon(Unit.getByName(units[i]):getPoint(), poly) then trigger.action.setUserFlag(flag, true) end end end end mist.scheduleFunction(fastPIP, {{'[blue][plane]'}, mist.getGroupPoints('poly1'), flag = 101 }, timer.getTime() + 1, 0.05) 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 Link to comment Share on other sites More sharing options...
Flyingsix Posted February 23, 2018 Author Share Posted February 23, 2018 Hey Grimes, thank you for your fast answer. I tried it with your code, but it doesn't work. No Error Messages, but also no Message when passing the 'gate'. In sum, I think, I understand the mechanics behind the function fastPIP. You say, that all units, which are alive should tell it's point inbound the polygon and set a specific flag true. Outbound the polygon, the won't tell any point, because the haven't any points inbound. As soon as they pass the first polygon line they will tell their points. In detail...What means the #units argument? Never seen the '#' in according with a for-loop. Is it the argument which says --> 'give me all units out of the units-class in this mission' (mist-database?) ? Also I don't understand this... timer.getTime() + 1, 0.05 Why the +1 sec argument? Would i not have a first measurement with 1 sec delay? In the moment I'm not at home, so I can't do any tests. I'll try some troubleshooting later. Greetz Link to comment Share on other sites More sharing options...
Grimes Posted February 23, 2018 Share Posted February 23, 2018 I'm using the mist.scheduleFunction call for it. http://wiki.hoggit.us/view/ScheduleFunction The 1 second delay is mostly just out of habit. The # is used in conjunction with a table that simply is used as a "size of" the table when indexed numerically. In this example these two tables are exactly the same: local units = {'Rezky', 'Molniya', 'Grisha'} local units = { [1] = 'Rezky', [2] = 'Molniya', [3] = 'Grisha', } In this case #units would be 3. The # does have its drawbacks, for instance if an index is blank then it only counts up to it. So if 2 was nil then # of the table would be 1. Also it can't index anything if you have a string in there. Thus iterating via 'for index, val in pairs do' or 'for x in val do' is more comprehensive. I know for a fact that this specific table can't have a nil index, so it uses for i = 1, #units do. 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 Link to comment Share on other sites More sharing options...
VAF [136] Striker Posted October 7, 2018 Share Posted October 7, 2018 Is it only possible to make a polygon using a units waypoints or units on the map? I had thought I read somewhere that you could make a polygon using map coordinates. Nvidia GTX-1080 Intel i7-4820K 3.7 Ghz ASUS ROG Rampage IV Extreme MB 32 GB Memory Windows 7 Pro 64 Bit [sIGPIC][/sIGPIC] Link to comment Share on other sites More sharing options...
Grimes Posted October 7, 2018 Share Posted October 7, 2018 Its just a series of coordinates. It accepts vec2/vec3 since it converts the values anyways. So you can get it however you want. Manual entry like this: local tbl = { [1] = {x = 50, y = -50}, [2] = {x = -50, y = -50}, [3] = {x = -50, y = 50}, [4] = {x = 50, y = 50}, } Or from zones: local tbl = { [1] = trigger.misc.getZone('p1').point, [2] = trigger.misc.getZone('p2').point, [3] = trigger.misc.getZone('p3').point, [4] = trigger.misc.getZone('p4').point, } 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 Link to comment Share on other sites More sharing options...
VAF [136] Striker Posted October 8, 2018 Share Posted October 8, 2018 Thank you! Nvidia GTX-1080 Intel i7-4820K 3.7 Ghz ASUS ROG Rampage IV Extreme MB 32 GB Memory Windows 7 Pro 64 Bit [sIGPIC][/sIGPIC] Link to comment Share on other sites More sharing options...
Recommended Posts