--// When you can't trust #table local function getTableCount(tbl) local c = 0; if tbl == nil then return 0; end for k,v in pairs(tbl) do c=c+1; end return c; end --//feed it table of latitude=\longitude= and get back Y= X= ;for use with inPolygon(); -- ie you can feed it a zone.area and then just use result as input to inPolygon. local function fnConvertLatLonToYXtable(lltable) if (lltable ~=nil and getTableCount(lltable) > 0) then local retval = {} local tcount = getTableCount(lltable); for i=1, getTableCount(lltable) do table.insert(retval,{y=lltable[i].latitude,x=lltable[i].longitude}); --lowercase required. end if #retval > 0 then return retval; else print('fnConvertLatLonToYXtable():: generated table has no data, returning nil.'); return nil; end else print('fnConvertLatLonToYXtable():: table missing or zero entries, returning nil.'); return nil; end end --This totally may not work in some very specific cases?? --I may have to just live with it. Think it may fail when zone crosses 179|180|-179 globe split in pacific or polar regions? --https://stackoverflow.com/questions/31730923/check-if-point-lies-in-polygon-lua#31744797 --lots of samples out there but none it seems when comes to core-lua and handling all geo cases properly. --Wonder if related to polar regions in the game. local function insidePolygon(polygon, point) local oddNodes = false local j = #polygon for i = 1, #polygon do if (polygon[i].y < point.y and polygon[j].y >= point.y or polygon[j].y < point.y and polygon[i].y >= point.y) then if (polygon[i].x + ( point.y - polygon[i].y ) / (polygon[j].y - polygon[i].y) * (polygon[j].x - polygon[i].x) < point.x) then oddNodes = not oddNodes; end end j = i; end return oddNodes end print('---- Sample tests ----'); --//Table representing the polygon to check. local poly={ {y=-2.17371659770207, x=-4.86607715718033}, {y=-2.11459848946334, x=-3.18048722275834}, {y=-3.77456725501735, x=-3.23996283292925}, {y=-3.68063657943523, x=-5.15867707489552}, {y=-2.7429662365217, x=-5.60898162815377} } --//table that simulates an zone's .area return value of RP's local tmpZoneDotAreaReplica={ {name='RP-bla1',latitude=-2.17371659770207, longitude=-4.86607715718033}, {name='RP-bla2',latitude=-2.11459848946334, longitude=-3.18048722275834}, {name='RP-bla3',latitude=-3.77456725501735, longitude=-3.23996283292925}, {name='RP-bla4',latitude=-3.68063657943523, longitude=-5.15867707489552}, {name='RP-bla5',latitude=-2.7429662365217, longitude=-5.60898162815377} } local middle = {y=-3.00439118080036, x=-4.08700082745286}; local edge = {y=-3.54497201361856, x=-4.24574572930585}; local random = {y=-2.30874447451051, x=-3.5247459460433}; local outside = {y=2.02568621285042,x=4.57013931632061}; --//test when using nonavzone.area return value that is table of RP's. local ctbl = fnConvertLatLonToYXtable(tmpZoneDotAreaReplica); if(ctbl) then local pt = {y=-2.30874447451051, x=-3.5247459460433}; if insidePolygon(ctbl,pt) then print('pt inside area.') else print('pt outside area') end end if insidePolygon(poly,middle) then print('point inside area.') else print('point outside area') end if insidePolygon(poly,edge) then print('point inside area.') else print('point outside area') end if insidePolygon(poly,random) then print('point inside area.') else print('point outside area') end if insidePolygon(poly,outside) then print('point inside area.') else print('point outside area') end