tommymaster Posted January 29, 2018 Share Posted January 29, 2018 Hi! I draw a map on a player's screen, and i would like to make a mod in which the player clicks on the rendered map image, it outputs the coordinates to the debug log. For example if i click on the center of the map, the real coordinates should be like 0, 0, 0 but it outputs the screen coordinates, for example my screen's resoluion is 1920x1080, i click on the center, and i get like 960, 540 instead of 0, 0. First i would like to just display the real coordinates where i clicked, i was trying to fix this but i had no idea how i can solve this. Later on i would like to draw a playerblip where the player is being on the map by adding a blip there, and rendering it on the radar, and i don't really know how to solve this too. And of course, later i would like to add other blips. But i would like the blips to match the real coordinates. I am using MTA San Andreas\MTA\cgui\images\radar.jpg as the radar image. mapVisible = false toggleControl ("radar", false) map = {} map["size"] = 1024 function showMap(button, state) if button == "F11" and state == true then if mapShown == false then mapVisible = true addEventHandler ("onClientRender", root, renderMap) showCursor (true) else mapVisible = false removeEventHandler ("onClientRender", root, renderMap) showCursor (false) end end end addEventHandler ("onClientKey", root, showMap) x, y = guiGetScreenSize() mx, my = 1920, 1080 function renderMap() dxDrawImage (x/2 - map["size"]/2, y/2 - map["size"]/2, map["size"], map["size"], "images/map.jpg") end function click(button, state, aX, aY) if button == "left" and state == "down" then --iprint (x-map["size"]) iprint (aX - map["size"]) --x y z is not accurate end end addEventHandler ("onClientClick", root, click) Link to comment
Moderators IIYAMA Posted January 29, 2018 Moderators Share Posted January 29, 2018 (edited) https://wiki.multitheftauto.com/wiki/OnClientClick string button, string state, int absoluteX, int absoluteY, float worldX, float worldY, float worldZ, element clickedWorld float worldX, float worldY, float worldZ, element clickedWorld https://wiki.multitheftauto.com/wiki/GetScreenFromWorldPosition float float getScreenFromWorldPosition ( float x, float y, float z, [ float edgeTolerance=0, bool relative=true ] ) Edited January 29, 2018 by IIYAMA 1 1 Link to comment
tommymaster Posted January 29, 2018 Author Share Posted January 29, 2018 Thank you, but what i want to do, is click on the image, and get the real x y z coordinates according to the screen position i clicked on the map. Like in the freeroam resource, when i use the map button, select where i want to go, but i don't want to go there, just output the coordinates of the clicked position on the image. Link to comment
Moderators IIYAMA Posted January 29, 2018 Moderators Share Posted January 29, 2018 if aX > (x / 2 - map["size"] / 2) and aX < (x / 2 + map["size"] / 2) and aY > (y / 2 - map["size"] / 2) and aY < (y / 2 + map["size"] / 2) then end local clickX = aX - (x / 2 - map["size"] / 2) local clickY = aY - (y / 2 - map["size"] / 2) local mapX = clickX / map["size"] * 6000 local mapY = clickY / map["size"] * 6000 Everything is untested. 1 Link to comment
tommymaster Posted January 29, 2018 Author Share Posted January 29, 2018 Sadly it is still not working. It outputs like 3000 if i click on the center. Link to comment
Moderators IIYAMA Posted January 29, 2018 Moderators Share Posted January 29, 2018 local mapX = clickX / map["size"] * 6000 - 3000 local mapY = clickY / map["size"] * -6000 + 3000 Try this. Afaik the left + bottom is -3000, -3000. The right + top is 3000, 3000. And the center is 0, 0. 1 Link to comment
tommymaster Posted January 29, 2018 Author Share Posted January 29, 2018 yeah thanks, now it outputs the valid coordinates. but now how can i add blips? i mean i add the blips with create blip, and using "for" i get their positions and blip icons, then draw it on the f11 map using onClientRender, but with what coordinates? could you please write an example for this with commentaries? i learn better from them. Link to comment
NeXuS™ Posted January 29, 2018 Share Posted January 29, 2018 Using this technic the other way. Getting the screen position from the world position, and drawing it. If you don't try it at all, we ain't gonna give you an example. 1 Link to comment
Moderators IIYAMA Posted January 29, 2018 Moderators Share Posted January 29, 2018 map = { size = 1024 } function reCalculateToMap (posX, posY) return posX / map["size"] * 6000 - 3000, posY / map["size"] * -6000 + 3000 end local x, y = reCalculateToMap (500, 800) print(x, y) function reCalculateFromMap (mapX, mapY) return (mapX + 3000) * map["size"] / 6000, (mapY - 3000) * map["size"] / -6000 end local x2, y2 = reCalculateFromMap (x, y) print(x2, y2) This is just old school math. Example: Click X position in image is: 240px Image size is: 1024px Map size is: 6000 X 240 / 1024 = 0.234375 --[[ 0.234375 * 100 = 23.4 240 is 23.4% from 1024 ]] 0.234375 * 6000 = 1406.25 --[[ Append to other value ETC. ]] 1 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