Jump to content

Clicked On World Map


Z4Zy

Recommended Posts

Hellow again ! ^_^

              Can you help me to find the answer to the simple question o.O, 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
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

 

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 by Dimos7
Link to comment
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 by DeadthStrock
Link to comment
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 by MrTasty
  • Like 1
  • Thanks 1
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...