Jump to content

calc position from map(image)


Jusonex

Recommended Posts

Here is the code:

  
function spawnMapDoubleClick(relX, relY) 
    setPlayerPosition(relX*6000 - 3000, 3000 - relY*6000, 0) 
    closeWindow(wndSpawnMap) 
end 
  
function closeSpawnMap() 
    showCursor(false) 
    removeEventHandler('onClientRender', g_Root, updatePlayerBlips) 
    for elem,data in pairs(g_PlayerData) do 
        for i,name in ipairs({'mapBlip', 'mapLabelShadow', 'mapLabel'}) do 
            if data.gui[name] then 
                destroyElement(data.gui[name]) 
                data.gui[name] = nil 
            end 
        end 
    end 
end 
  
wndSpawnMap = { 
    'wnd', 
    text = 'Select spawn position', 
    width = g_MapSide + 20, 
    controls = { 
        {'img', id='map', src='map.png', width=g_MapSide, height=g_MapSide, ondoubleclick=spawnMapDoubleClick}, 
        {'lbl', text='Welcome to freeroam. Double click a location on the map to spawn.', width=g_MapSide-60, align='center'}, 
        {'btn', id='close', closeswindow=true} 
    }, 
    oncreate = warpMapInit, 
    onclose = closeSpawnMap 
} 
  

But I don't understand it. Have someone a better and simpler example?

Link to comment

Now, I habe that:

  
function gui() 
    local screenWidth, screenHeight = guiGetScreenSize() 
    if screenHeight < 700 then 
        g_MapSide = 450 
    else 
        g_MapSide = 700 
    end 
     
    local width = g_MapSide + 20 
    local height = g_MapSide 
    local X = 0 
    local Y = 0 
     
    wdwMap = guiCreateWindow( X, Y, width, height, "Map", false ) 
    imgMap = guiCreateStaticImage ( X, Y, g_MapSide, g_MapSide, "map.png", false, wdwMap ) 
     
    addEventHandler("onClientGUIDoubleClick", imgMap, map, false) 
end 
  
function make() 
    gui() 
    if (wdwMap ~= nil) then 
        guiSetVisible(wdwMap, true) 
    else 
        outputChatBox("Ein Problem mit der GUI besteht, bitte benachrichtige einen Admin") 
    end  
  
    showCursor(true) 
    guiSetInputEnabled(true) 
end 
  
function map(button, state, relX, relY) 
    local px = relX*6000 - 3000 
    local py = 3000 - relY*6000 
    outputChatBox(px) 
end 
  
addCommandHandler("taxi", make) 
  

But the results are wrong (if i click in the middle of the map i get cords like 400000.

What is wrong?

Edited by Guest
Link to comment

hey

ClientSide :

function gui() 
    local screenWidth, screenHeight = guiGetScreenSize() 
    if screenHeight < 700 then 
        g_MapSide = 450 
    else 
        g_MapSide = 700 
    end 
  
    local width = g_MapSide + 20 
    local height = g_MapSide 
    local X = 0 
    local Y = 0 
  
    wdwMap = guiCreateWindow( X, Y, width, height, "Map", false ) 
    imgMap = guiCreateStaticImage ( X, Y, g_MapSide, g_MapSide, "map.png", false, wdwMap ) 
  
    addEventHandler("onClientGUIDoubleClick", imgMap, map, false) 
end 
  
function make() 
    gui() 
    if (wdwMap ~= nil) then 
        guiSetVisible(wdwMap, true) 
    else 
        outputChatBox("Ein Problem mit der GUI besteht, bitte benachrichtige einen Admin") 
    end 
  
    showCursor(true) 
    guiSetInputEnabled(true) 
end 
  
function map(button, state, relX, relY) 
    px = ((relX*6000 /g_MapSide)-3000) 
    py = (3000 - (relY*6000/g_MapSide)) 
    triggerServerEvent("sp",getLocalPlayer(),px,py) 
  
    guiSetVisible(wdwMap, false) 
    showCursor(false) 
    guiSetInputEnabled(false) 
    end 
  
addCommandHandler("t", make) 
  

ServerSide

  
function createmaker(x, y) 
createMarker ( x,y,13) 
end 
addEvent("sp",true) 
addEventHandler("sp",getRootElement(),createmaker,px,py) 
  
  

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