Leo Messi Posted August 4, 2018 Share Posted August 4, 2018 Hello, I want help in something for example I created the a map just like F11, once I click on any place on the map it will create a blip on the x, y of the position I choosed, I tried but didn't work.. -- WINDOW is created but it's useless so I removed it from this code. map = guiCreateStaticImage(10, 25, 700, 685, "map.png", false, window) -- I CREATED Command handler of opening the gui, etc. function createDest() if source ~= map then return end if isElement(blipImg) then destroyElement(blipImg) outputChatBox(getPlayerName(localPlayer).." has removed the group destination.", 0, 255, 0) return end local x, y, worldx, worldy, worldz = getCursorPosition() local x2, y2 = guiGetPosition(source, false) if worldx == x2 and worldy == y2 then outputChatBox(x) outputChatBox(y) blipImg = createBlip(x, y, 10, 3, 2, 255, 0, 0, 255, 0) end end addEventHandler("onClientGUIDoubleClick", guiRoot, createDest) Link to comment
Addlibs Posted August 4, 2018 Share Posted August 4, 2018 (edited) What is this supposed to do? if worldx == x2 and worldy == y2 then Seems like your code requires that world position clicked on using the cursor is exactly the same as the X and Y screen positions of the GUI element clicked. Here's a tip: if something doesn't work - try adding other debug outputs to see the flow control in action - so that you can easily tell if and which flow branch failed, as I can see you only gave yourself a debug output only at the point of success but not at points of potential failure. At this point I think it's also worth pointing out that getCursorPosition world absolutes are related to what the cursor actually points at in the viewport, not on a map image - for the latter, you need to do manual calculations to convert screen position to a range between 0 and 1 of the map image, and then scale it up to world scale (6000x6000 meters) to get the world position indicated by the cursor click on a map image. Edited August 4, 2018 by MrTasty Link to comment
Leo Messi Posted August 5, 2018 Author Share Posted August 5, 2018 On 8/4/2018 at 13:37, MrTasty said: What is this supposed to do? if worldx == x2 and worldy == y2 then Seems like your code requires that world position clicked on using the cursor is exactly the same as the X and Y screen positions of the GUI element clicked. Here's a tip: if something doesn't work - try adding other debug outputs to see the flow control in action - so that you can easily tell if and which flow branch failed, as I can see you only gave yourself a debug output only at the point of success but not at points of potential failure. At this point I think it's also worth pointing out that getCursorPosition world absolutes are related to what the cursor actually points at in the viewport, not on a map image - for the latter, you need to do manual calculations to convert screen position to a range between 0 and 1 of the map image, and then scale it up to world scale (6000x6000 meters) to get the world position indicated by the cursor click on a map image. Can't you give me an example? Link to comment
Addlibs Posted August 5, 2018 Share Posted August 5, 2018 (edited) You want an example of how to calculate position on a 2D map image? Well, you'll want something like this: local pos pos = ((cursorPos-mapPos)/mapSize) -- calculate cursor pos relative to map image pos = pos - Vector2(0.5,0.5) -- change range from 0–1 to -0.5–0.5 so (0,0) is in the center rather than top left corner pos = pos * 6000 -- scale it by map size in meters -- this is equivalent to local pos = ((((cursorPos-mapPos)/mapSize)-Vector2(0.5,0.5))*6000 cursorPos, mapPos and mapSize should be of type Vector2, absolute values used for testing but should work with relatives too. Resulting pos is also a Vector2. This will probably require changes if you want to use it for a zoomed-in section of the map. Edited August 5, 2018 by MrTasty Link to comment
Leo Messi Posted August 5, 2018 Author Share Posted August 5, 2018 On 8/5/2018 at 04:57, MrTasty said: You want an example of how to calculate position on a 2D map image? Well, you'll want something like this: local pos pos = ((cursorPos-mapPos)/mapSize) -- calculate cursor pos relative to map image pos = pos - Vector2(0.5,0.5) -- change range from 0–1 to -0.5–0.5 so (0,0) is in the center rather than top left corner pos = pos * 6000 -- scale it by map size in meters -- this is equivalent to local pos = ((((cursorPos-mapPos)/mapSize)-Vector2(0.5,0.5))*6000 cursorPos, mapPos and mapSize should be of type Vector2, absolute values used for testing but should work with relatives too. Resulting pos is also a Vector2. This will probably require changes if you want to use it for a zoomed-in section of the map. Thank you, I already done it. Thanks bro. 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