Jump to content

New Freeroam [Map]


Recommended Posts

  • 1 month later...
addEventHandler("onClientGUIClick", guiRoot, function(button, state, absoluteX, absoluteY) 
    if source == mapImage then 
        local imgX, imgY = guiGetSize(mapImage, false) 
        local relX = absoluteX/imgX 
        local relY = absoluteY/imgY  
        local x = relX*6000 - 3000 
        local y = 3000 - relY*6000 
        local hit, hitX, hitY, hitZ 
        hit, hitX, hitY, hitZ = processLineOfSight(x, y, 3000, x, y, -3000) 
        guiSetText(mapXedit, x) 
        guiSetText(mapYedit, y) 
        guiSetText(mapZedit, hitZ or 0) 
    end 
end) 

It's my code. I did got a sample from Freeroam. But it's not work true. How to make it? Help :(:cry:

Link to comment
addEventHandler("onClientGUIClick", guiRoot, function(button, state, absoluteX, absoluteY) 
    if source == mapImage then 
        local relX, relY = guiGetSize(mapImage, true) 
        local x = relX*6000 - 3000 
        local y = 3000 - relY*6000 
        local hit, hitX, hitY, hitZ = processLineOfSight(x, y, 3000, x, y, -3000) 
        guiSetText(mapXedit, x) 
        guiSetText(mapYedit, y) 
        guiSetText(mapZedit, hitZ or 0) 
    end 
end) 

Maybe this

Edited by Guest
Link to comment
addEventHandler("onClientGUIClick", guiRoot, function(button, state, absoluteX, absoluteY) 
    if source == mapImage then 
        local relX, relY = guiGetSize(mapImage, true) 
        local x = relX*6000 - 3000 
        local y = 3000 - relY*6000 
        local hit, hitX, hitY, hitZ = processLineOfSight(x, y, 3000, x, y, -3000) 
        guiSetText(mapXedit, x) 
        guiSetText(mapYedit, y) 
        guiSetText(mapZedit, hitZ or 0) 
    end 
end) 

Maybe this

No, it's not work. Because you're get the only image size. It's need the clicked position.

Help :(

Link to comment
-- [fr_client.lua] onClick 
function fillInPosition(relX, relY, btn) -- Line 624 
    if (btn == 'right') then 
        closeWindow (wndSetPos) 
        return 
    end 
  
    local x = relX*6000 - 3000 
    local y = 3000 - relY*6000 
    local hit, hitX, hitY, hitZ 
    hit, hitX, hitY, hitZ = processLineOfSight(x, y, 3000, x, y, -3000) 
    setControlNumbers(wndSetPos, { x = x, y = y, z = hitZ or 0 }) 
end 

--  [gui.lua] define the relX and relY 
function _buildWindow(wnd, baseWnd, parentWnd) -- Line 136 
    local wndClass = wnd[1] 
    if wndClass == 'br' then 
        return 
    end 
     
    local relX, relY, relWidth, relHeight 
    if parentWnd then 
        if wnd.x and wnd.y then 
            relX = wnd.x/parentWnd.width 
            relY = wnd.y/parentWnd.height 
        end 
        relWidth = wnd.width / parentWnd.width 
        relHeight = wnd.height / parentWnd.height 
    end 
    local elem 
    if wndClass == 'wnd' then 
        local screenWidth, screenHeight = guiGetScreenSize() 
        if not wnd.x then 
            wnd.x = screenWidth/2 - wnd.width/2 
        else 
            local i, f = math.modf(wnd.x) 
            if f ~= 0 then 
                wnd.x = screenWidth * wnd.x 
            end 
            if wnd.x < 0 then 
                wnd.x = screenWidth - math.abs(wnd.x) - wnd.width 
            end 
        end 
        if not wnd.y then 
            wnd.y = screenHeight/2 - wnd.height/2 
        else 
            local i, f = math.modf(wnd.y) 
            if f ~= 0 then 
                wnd.y = screenHeight * wnd.y 
            end 
            if wnd.y < 0 then 
                wnd.y = screenHeight - math.abs(wnd.y) - wnd.height 
            end 
        end 
        -- Bla bla bla bla 
  
    if wnd.controls then 
        for id, controlwnd in pairs(wnd.controls) do 
            _buildWindow(controlwnd, baseWnd or wnd, wnd) 
        end 
    end 
  
    if wnd.tabs then 
        for id, tab in pairs(wnd.tabs) do 
            _buildWindow(tab, baseWnd, wnd) 
        end 
    end 
        -- Bla bla bla bla 
end 

parentWnd.width = map image x size

parentWnd.height = map image y size

But i dont understand wnd.x and wnd.y

Edited by Guest
Link to comment
--gui.lua:232 
local imgX, imgY = getControlScreenPos(wnd) 
wnd.onclick((x - imgX)/wnd.width, (y - imgY)/wnd.height, btn) 

I figured out that this is where it calculates clicked position. getControlScreenPos returns the window offset to x,y locations.

cs7wuxqnyvg3nvkz5qrn.png

x,y position is 400,80 and gui offset is 200,50. You subtract from clicked position offset position and get exactly map position, which is divided by window size.

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