Jump to content

map teleport


Recommended Posts

With some calculations you may achieve your goal:

addEventHandler -- onClientClick
getPlayerMapBoundingBox -- calculations to get X,Y of the map
getGroundPosition -- to get the Z position.
setElementPosition -- send your player.

 

Link to comment
  • 2 weeks later...
local sx, sy = guiGetScreenSize()

function centerWindow(center_window)
    local screenW,screenH=guiGetScreenSize()
    local windowW,windowH=guiGetSize(center_window,false)
    local x,y = (screenW-windowW)/2,(screenH-windowH)/2
    guiSetPosition(center_window,x,y,false)
end

wndTpMap = guiCreateWindow(0,0,700,700,"Teleport map",false)
centerWindow(wndTpMap)
mapBlip = guiCreateStaticImage(40, 30, 610, 610, 'map.png', false, wndTpMap)
close_TpMap = guiCreateButton(520,655,130,20,"Cancel",false,wndTpMap)
wndTpMapX = guiCreateEdit(40,655,150,20,"",false,wndTpMap)
wndTpMapY = guiCreateEdit(200,655,150,20,"",false,wndTpMap)
wndTpMapZ = guiCreateEdit(360,655,150,20,"",false,wndTpMap)

local targetBlipIcon = 41 

local screenSize = Vector2(guiGetScreenSize())
local wasLeftMouseButtonPressed, wasRightMouseButtonPressed, targetBlip = false, false

local function handleMapTargetBlip()
    if not isPlayerMapVisible() then
        showCursor(false, false)
        wasLeftMouseButtonPressed, wasRightMouseButtonPressed = false, false
        return
    end
	
    if not isCursorShowing() then
        showCursor(true, false)
    end

    local isLeftMouseButtonPressed = getKeyState("mouse1")
    if isLeftMouseButtonPressed and isLeftMouseButtonPressed ~= wasLeftMouseButtonPressed then
        local cursorPos, mapMin, mapMax = Vector2(getCursorPosition())
        cursorPos.x, cursorPos.y = cursorPos.x * screenSize.x, cursorPos.y * screenSize.y
        do
            local mx, my, Mx, My = getPlayerMapBoundingBox()
            mapMin = Vector2(mx, my)
            mapMax = Vector2(Mx, My)
        end
        if cursorPos.x >= mapMin.x and cursorPos.y >= mapMin.y and cursorPos.x <= mapMax.x and cursorPos.y <= mapMax.y then
            local relPos = Vector2((cursorPos.x - mapMin.x) / (mapMax.x - mapMin.x), (cursorPos.y - mapMin.y) / (mapMax.y - mapMin.y))
            local worldPlanePos = Vector2(6000 * (relPos.x - 0.5), 3000 - (relPos.y * 6000))
            local worldPos = Vector3(worldPlanePos.x, worldPlanePos.y, getGroundPosition(worldPlanePos.x, worldPlanePos.y, 3000))
            if not targetBlip then
                targetBlip = createBlip(worldPos, targetBlipIcon)
            else
                setElementPosition(targetBlip, worldPos)
				guiSetText(wndTpMapX,worldPlanePos.x)
            end
        end
    end
    local isRightMouseButtonPressed = getKeyState("mouse2")
    if targetBlip then
        if isRightMouseButtonPressed and isRightMouseButtonPressed ~= wasRightMouseButtonPressed then
            destroyElement(targetBlip)
            targetBlip = nil
        end
    end

    wasLeftMouseButtonPressed, wasRightMouseButtonPressed = isLeftMouseButtonPressed, isRightMouseButtonPressed
end
addEventHandler("onClientRender", root, handleMapTargetBlip)

Now it's put a red mark on the map with a left click.

How to use it in the picture? "mapBlip = guiCreateStaticImage(40, 30, 610, 610, 'map.png', false, wndTpMap)"

Now it works for the map on f11 but i need for "mapBlip"

Edited by slapz0r
Link to comment
14 hours ago, WorthlessCynomys said:

I do not understand what you want to achieve. Please provide further explanation of your goal so I/others can understand It and become able to help you!

Above code:

1) Used map on f11

2) Left-clicking on the map creates a red mark 

3) Coordinate(x) are recorded in edit (in the same way and (y) coordinate record on edit.)

How to use a similar method, but for my map(map.png)? I mean, I created a window with a staticimage(map.png) 

and how to use the same method, but for this picture instead of the map on f11 ?

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...