stefutz101 Posted June 29, 2016 Share Posted June 29, 2016 Hi . I want to know how to calculate coords on the minimap (F11) from world coords. I found something like this : local x, y = getElementPosition(player) x = math.floor((x + 3000) * 1024 / 6000) + 10 y = math.floor((3000 - y) * 1024 / 6000) - 10 Thanks in advance . Link to comment
Captain Cody Posted June 29, 2016 Share Posted June 29, 2016 local x, y = getElementPosition(player) x = x/6000*resx -- Resx Put how big your mini map is in X y = y/6000*resy -- Resy Put how big your mini map is in y Not tested at all but in theory it should work. 6000x600 is the size of SA so You get your players location and you divide it by 6000, giving you value in-between 0 and 1 (Bigger if out of bounds) Then you multiply that value by the size of your map. (Pixels in this case) thus accurately giving you the location hopefully. But you also have to take into account a stretched picture. Meaning if your picture is at all stretched, you have to play around with the ResX and Res Y values a bit. Link to comment
stefutz101 Posted June 29, 2016 Author Share Posted June 29, 2016 I will try. EDIT: It don't works . F11 map is a png with size 1024x1024 . But on my screen is 768x768 px. https://postimg.org/image/f7wnxe9mv/ Link to comment
Captain Cody Posted June 29, 2016 Share Posted June 29, 2016 Well you need to account for screen size local x,y = guiGetScreenSize() local valuea, valueb = 1/x,1/y Then multiply the values you get there into the x and y. valuea goes to X valueb goes to y Try that I'm not to sure if it will work. Link to comment
stefutz101 Posted June 29, 2016 Author Share Posted June 29, 2016 local x, y = getElementPosition(player) local sx,sy = guiGetScreenSize() local valuea, valueb = 1/sx,1/sy x = x/6000*1/sx-- Resx Put how big your mini map is in X y = y/6000*1/sy-- Resy Put how big your mini map is in y Like this ? Or i am wrong ? Link to comment
Captain Cody Posted June 29, 2016 Share Posted June 29, 2016 local x, y = getElementPosition(player) local sx,sy = guiGetScreenSize() local Resx = "Put X here" local Resy = "Put Y here" x = (x/6000)*Resx*(1*sx) y = (y/6000)*Resy *(1*sy) Link to comment
stefutz101 Posted June 29, 2016 Author Share Posted June 29, 2016 local x, y = getElementPosition(player) local sx,sy = guiGetScreenSize() local Resx = "Put X here" local Resy = "Put Y here" x = (x/6000)*Resx*(1*sx) y = (y/6000)*Resy *(1*sy) Did you mean 1/sx and 1/xy ? Resx ,Resy = x , y from minimap ? Link to comment
Captain Cody Posted June 29, 2016 Share Posted June 29, 2016 ResX Resy = Size of mini map Link to comment
stefutz101 Posted June 29, 2016 Author Share Posted June 29, 2016 Nope. The name appear in top left of the screen. Still don't work. Link to comment
Captain Cody Posted June 29, 2016 Share Posted June 29, 2016 Check this - https://community.multitheftauto.com/in ... ils&id=344 Link to comment
Discord Moderators AlexTMjugador Posted June 30, 2016 Discord Moderators Share Posted June 30, 2016 Do you guys know about the existence of getPlayerMapBoundingBox? It is a MTA: SA clientside function useful for this kind of calculations. By using that function you can simply and accurately get the absolute screen coordinates (i.e. pixel positions) from world coordinates as it follows: local x, y = getElementPosition(localPlayer) -- Could be any other world position. Note that we only need X and Y (map is 2D) local mx, my, Mx, My = getPlayerMapBoundingBox() -- Returns the screen coordinates of the world coordinates (-3000, -3000) and (3000, 3000) if not mx then -- Do not continue if map is not showing return end -- Calculate a factor in range [0, 1] which represents the relative distance to the max coords point from the min coords point of the given coordinates local fMx, fMy = (x + 3000) / 6000, (y + 3000) / 6000 -- Do the opposite thing for the min coords point local fmx, fmy = 1 - fMx, 1 - fMy -- Use the factors and given screen points to calculate the final screen coords of our element in the map local sx, sy = (fmx * mx) + (fMx * Mx), (fmy * my) + (fMy * My) Please note that the code snippet I posted does not account for out of bounds coordinates and off-screen positions. Link to comment
stefutz101 Posted June 30, 2016 Author Share Posted June 30, 2016 Fixed. Thanks a lot ! Link to comment
Discord Moderators AlexTMjugador Posted July 2, 2016 Discord Moderators Share Posted July 2, 2016 Just a heads-up: I have recently discovered that getPlayerMapBoundingBox returns the screen coordinates of the world coordinates (-3000, 3000) and (3000, -3000), not (-3000, -3000) and (3000, 3000). It seems that the wiki was wrong, so the code I posted is wrong too because it accounts for different reference points. To fix my code, you have to replace this calculation: local fMx, fMy = (x + 3000) / 6000, (y + 3000) / 6000 With this one: local fMx, fMy = (x + 3000) / 6000, -(y - 3000) / 6000 I strongly recommend you to change that if you wondered why my code did calculate wrong positions. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now