Z4Zy Posted June 23, 2018 Share Posted June 23, 2018 Hellow again ! Can you help me to find the answer to the simple question , How to find, Is player clicked on the map in F11 ?? And how to get the clicked position according to the world ?? Link to comment
Dimos7 Posted June 23, 2018 Share Posted June 23, 2018 getWorldFromScreenPosition isPlayerMapVisible 1 Link to comment
Z4Zy Posted June 23, 2018 Author Share Posted June 23, 2018 1 hour ago, Dimos7 said: getWorldFromScreenPosition isPlayerMapVisible I haven't know about "isPlayerMapVisible" function, until you mentioned it to me And how to find is player clicked on that map ?? Link to comment
Dimos7 Posted June 23, 2018 Share Posted June 23, 2018 (edited) getCursorPosition addEventHandler("onClientClick") Edited June 23, 2018 by Dimos7 Link to comment
Z4Zy Posted June 25, 2018 Author Share Posted June 25, 2018 On 6/23/2018 at 22:00, Dimos7 said: getCursorPosition addEventHandler("onClientClick") what should be the source name to the event "onClientClick" related to the map ?? Link to comment
Dimos7 Posted June 25, 2018 Share Posted June 25, 2018 24 minutes ago, DeadthStrock said: what should be the source name to the event "onClientClick" related to the map ?? source is the mouse click you will get the postion put with ground and set your player there Link to comment
Z4Zy Posted June 26, 2018 Author Share Posted June 26, 2018 15 hours ago, Dimos7 said: source is the mouse click you will get the postion put with ground and set your player there As I understand below is code created by me, addEventHandler("onClientClick",root, function () local a,b,u,v,w = getCursorPosition() local x,y,z = getWorldFromScreenPosition(u,v,w) if isPlayerMapVisible() then setElementPosition(localPlayer,x,y,z+1) end end ) Here, if map showing, when player click, he will go to the clicked position near living environment. But not the position that was clicked on map. How to fix this, to go player to the position that was clicked on map ? Link to comment
Dimos7 Posted June 26, 2018 Share Posted June 26, 2018 (edited) 1 hour ago, DeadthStrock said: As I understand below is code created by me, addEventHandler("onClientClick",root, function () local a,b,u,v,w = getCursorPosition() local x,y,z = getWorldFromScreenPosition(u,v,w) if isPlayerMapVisible() then setElementPosition(localPlayer,x,y,z+1) end end ) Here, if map showing, when player click, he will go to the clicked position near living environment. But not the position that was clicked on map. How to fix this, to go player to the position that was clicked on map ? That i think happend because mouse it not same position with cursor or try put the u, v, w at element position Edited June 26, 2018 by Dimos7 Link to comment
Z4Zy Posted June 26, 2018 Author Share Posted June 26, 2018 (edited) 1 hour ago, Dimos7 said: That i think happend because mouse it not same position with cursor or try put the u, v, w at element position My code is not detects that player clicked on the world map. It detects that player clicked on screen and then it get screen position related to world and sent player to that position. It looks, whether player's map shown or not. So I think, source element of the event "onClientClick" should be the map. Then the code can find the location of the clicked position of the map. But how to insert it ?? Edited June 26, 2018 by DeadthStrock Link to comment
Addlibs Posted June 26, 2018 Share Posted June 26, 2018 (edited) local screenSize = Vector2(guiGetScreenSize()) local cursorPos = Vector2(getCursorPosition()) local mapMin, mapMax -- Transform the relative cursor position to absolute position cursorPos.x, cursorPos.y = cursorPos.x * screenSize.x, cursorPos.y * screenSize.y -- Calculate our map points vectors inside a block to delete intermediate variables automatically do local mx, my, Mx, My = getPlayerMapBoundingBox() mapMin = Vector2(mx, my) mapMax = Vector2(Mx, My) end -- If the cursor is inside the map rectangle if cursorPos.x >= mapMin.x and cursorPos.y >= mapMin.y and cursorPos.x <= mapMax.x and cursorPos.y <= mapMax.y then -- Get the relative position (in range [0, 1]) of the mouse point from the mapMin point -- 0 in a direction means that the cursor is in mapMin which is the top-left corner of the map -- 1 in a direction means that the cursor is in mapMax which is the bottom-right corner of the map local relPos = Vector2((cursorPos.x - mapMin.x) / (mapMax.x - mapMin.x), (cursorPos.y - mapMin.y) / (mapMax.y - mapMin.y)) -- Translate that relative position to 2D world coordinates -- Assumes the world map is a square whose side is 6000 units long local worldPlanePos = Vector2(6000 * (relPos.x - 0.5), 3000 - (relPos.y * 6000)) -- Get a 3D world position by adding the highest ground Z coordinate, which is what we usually want local worldPos = Vector3(worldPlanePos.x, worldPlanePos.y, getGroundPosition(worldPlanePos.x, worldPlanePos.y, 3000)) -- wordPos = a Vector3 containing the X, Y world position that was highlighted on the map and the Z of the ground position at that X, Y position. end The code used here is taken from the second example for getPlayerMapBoundingBox which is actually more applicable to your situation, I only show the important parts here. Edited June 26, 2018 by MrTasty 1 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