Jump to content

How to discover the coordinates using guiGetScreenSize() ?


drk

Recommended Posts

I've created the DX text in GUIEditor, but I want to the text adjust to all resolutions. The text appear in same location but adjusted to the resolution to be visible to the player. If resolution is 800 x 600 the text appear under the HUD but adjusted to resolution, if resolution is, ex: 1280 x 720 - Adjust the text to the screen size but in the same location. Understand ?

Thats how the script i wrote to you is working.. or is it not?

Link to comment

could you take a shot screen to see where is the dx on the screen?

Edit:

try this should work 99.9%

function AbsoluteToRelativ2( X, Y ) 
    local rX, rY = guiGetScreenSize() 
    local x = math.floor(X*rX/1280) 
    local y = math.floor(Y*rY/720) 
    return x, y  
end 
  
function DXdraw() 
    local x1, y1 = AbsoluteToRelativ2( 959,246 ) 
    local x2, y2 = AbsoluteToRelativ2( 956,243 ) 
    dxDrawText("textQuit", x1, y1, 1224, 264, tocolor(0,0,0,255),0.6,"bankgothic","left","top",false,false,false) 
    dxDrawText("textQuit", x2, y2, 1224, 261, tocolor(255,0,0,255),0.6,"bankgothic","left","top",false,false,false) 
end 
addEventHandler("onClientRender", root, DXdraw) 

Link to comment
I've created the DX text in GUIEditor, but I want to the text adjust to all resolutions. The text appear in same location but adjusted to the resolution to be visible to the player. If resolution is 800 x 600 the text appear under the HUD but adjusted to resolution, if resolution is, ex: 1280 x 720 - Adjust the text to the screen size but in the same location. Understand ?

Thats how the script i wrote to you is working.. or is it not?

Is working but isn't what I want, but thanks for try helping me.

Link to comment
could you take a shot screen to see where is the dx on the screen?

Edit:

try this should work 99.9%

function AbsoluteToRelativ2( X, Y ) 
    local rX, rY = guiGetScreenSize() 
    local x = math.floor(X*rX/1280) 
    local y = math.floor(Y*rY/720) 
    return x, y  
end 
  
function DXdraw() 
    local x1, y1 = AbsoluteToRelativ2( 959,246 ) 
    local x2, y2 = AbsoluteToRelativ2( 956,243 ) 
    dxDrawText("textQuit", x1, y1, 1224, 264, tocolor(0,0,0,255),0.6,"bankgothic","left","top",false,false,false) 
    dxDrawText("textQuit", x2, y2, 1224, 261, tocolor(255,0,0,255),0.6,"bankgothic","left","top",false,false,false) 
end 
addEventHandler("onClientRender", root, DXdraw) 

Ok, I will try. And sorry for what I said in another post. When I'm nervous I talk nonsense.

Link to comment

Don't worked, I tried this and this:

function AbsoluteToRelativ2( X, Y ) 
    local rX, rY = guiGetScreenSize() 
    if ( rX == 1280 ) and ( rY == 720 ) then 
    local x = math.floor(X*rX/1280) 
    local y = math.floor(Y*rY/720) 
    return x, y 
    end 
    if ( rX == 1280 ) and ( rY == 600 ) then 
    local x = math.floor(X*rX/1280) 
    local y = math.floor(Y*rY/600) 
    return x, y 
    end 
    if ( rX == 800 ) and ( rY == 600 ) then 
    local x = math.floor(X*rX/800) 
    local y = math.floor(Y*rY/600) 
    return x, y 
    end 
    if ( rX == 640 ) and ( rY == 480 ) then 
    local x = math.floor(X*rX/640) 
    local y = math.floor(Y*rY/480) 
    return x, y 
  end 
end 
  
addEventHandler ( "onClientRender", root, 
    local x1, y1 = AbsoluteToRelativ2( 959,246 ) 
    local x2, y2 = AbsoluteToRelativ2( 956,243 ) 
    local x3, y3 = AbsoluteToRelativ2( 943,217 ) 
    local x4, y4 = AbsoluteToRelativ2( 939,213 ) 
    dxDrawText( textQuit, x1, y1, 1224, 264, tocolor(0,0,0,255),0.6,"bankgothic","left","top",false,false,false) 
    dxDrawText( textQuit, x2, y2, 1224, 261, tocolor(255,0,0,255),0.6,"bankgothic","left","top",false,false,false) 
    dxDrawText( textJoin, x3, y3, 1211.0, 235.0,tocolor(0,0,0,255),0.6,"bankgothic","left","top",false,false,false) 
    dxDrawText( textJoin, x4, y4, 1207.0,231.0,tocolor(0,255,0,255),0.6,"bankgothic","left","top",false,false,false) 
end 
) 

And don't work. Please anyone help.

Link to comment

what is doesn't work?

i tested this and working with all resolution

i don't understand what is not work

can you put an image?

function AbsoluteToRelativ2( X, Y ) 
    local rX, rY = guiGetScreenSize() 
    local x = math.floor(X*rX/1280) 
    local y = math.floor(Y*rY/720) 
    return x, y 
end 
  
function DXdraw() 
    local x1, y1 = AbsoluteToRelativ2( 959,246 ) 
    local x2, y2 = AbsoluteToRelativ2( 956,243 ) 
    dxDrawText("textQuit", x1, y1, 1224, 264, tocolor(0,0,0,255),0.6,"bankgothic","left","top",false,false,false) 
    dxDrawText("textQuit", x2, y2, 1224, 261, tocolor(255,0,0,255),0.6,"bankgothic","left","top",false,false,false) 
end 
addEventHandler("onClientRender", root, DXdraw) 

Link to comment
  
function AbsoluteToRelativ2( X, Y ) 
    local rX, rY = guiGetScreenSize() 
    local x = math.floor(X*rX/1280) 
    local y = math.floor(Y*rY/720) 
    return x, y 
end 
  
addEventHandler ( "onClientRender", root, 
    local x1, y1 = AbsoluteToRelativ2( 959,246 ) 
    local x2, y2 = AbsoluteToRelativ2( 956,243 ) 
    local x3, y3 = AbsoluteToRelativ2( 943,217 ) 
    local x4, y4 = AbsoluteToRelativ2( 939,213 ) 
    dxDrawText( textQuit, x1, y1, 1224, 264, tocolor(0,0,0,255),0.6,"bankgothic","left","top",false,false,false) 
    dxDrawText( textQuit, x2, y2, 1224, 261, tocolor(255,0,0,255),0.6,"bankgothic","left","top",false,false,false) 
    dxDrawText( textJoin, x3, y3, 1211.0, 235.0,tocolor(0,0,0,255),0.6,"bankgothic","left","top",false,false,false) 
    dxDrawText( textJoin, x4, y4, 1207.0,231.0,tocolor(0,255,0,255),0.6,"bankgothic","left","top",false,false,false) 
end 
) 
  

I tried this too:

  
function AbsoluteToRelativ2( X, Y ) 
    local rX, rY = guiGetScreenSize() 
    if ( rX == 1280 ) and ( rY == 720 ) then 
    local x = math.floor(X*rX/1280) 
    local y = math.floor(Y*rY/720) 
    return x, y 
    end 
    if ( rX == 1280 ) and ( rY == 600 ) then 
    local x = math.floor(X*rX/1280) 
    local y = math.floor(Y*rY/600) 
    return x, y 
    end 
    if ( rX == 800 ) and ( rY == 600 ) then 
    local x = math.floor(X*rX/800) 
    local y = math.floor(Y*rY/600) 
    return x, y 
    end 
    if ( rX == 640 ) and ( rY == 480 ) then 
    local x = math.floor(X*rX/640) 
    local y = math.floor(Y*rY/480) 
    return x, y 
  end 
end 
  
addEventHandler ( "onClientRender", root, 
    local x1, y1 = AbsoluteToRelativ2( 959,246 ) 
    local x2, y2 = AbsoluteToRelativ2( 956,243 ) 
    local x3, y3 = AbsoluteToRelativ2( 943,217 ) 
    local x4, y4 = AbsoluteToRelativ2( 939,213 ) 
    dxDrawText( textQuit, x1, y1, 1224, 264, tocolor(0,0,0,255),0.6,"bankgothic","left","top",false,false,false) 
    dxDrawText( textQuit, x2, y2, 1224, 261, tocolor(255,0,0,255),0.6,"bankgothic","left","top",false,false,false) 
    dxDrawText( textJoin, x3, y3, 1211.0, 235.0,tocolor(0,0,0,255),0.6,"bankgothic","left","top",false,false,false) 
    dxDrawText( textJoin, x4, y4, 1207.0,231.0,tocolor(0,255,0,255),0.6,"bankgothic","left","top",false,false,false) 
end 
) 

But don't work.

And don't have any error, I uused /debugscript 3 ;)

Link to comment

You forgot function() here:

addEventHandler ( "onClientRender", root, 
        local x1, y1 = AbsoluteToRelativ2( 959,246 ) 
        local x2, y2 = AbsoluteToRelativ2( 956,243 ) 
        local x3, y3 = AbsoluteToRelativ2( 943,217 ) 
        local x4, y4 = AbsoluteToRelativ2( 939,213 ) 
        dxDrawText( "textQuit", x1, y1, 1224, 264, tocolor(0,0,0,255),0.6,"bankgothic","left","top",false,false,false) 
        dxDrawText( "textQuit", x2, y2, 1224, 261, tocolor(255,0,0,255),0.6,"bankgothic","left","top",false,false,false) 
        dxDrawText( "textJoin", x3, y3, 1211.0, 235.0,tocolor(0,0,0,255),0.6,"bankgothic","left","top",false,false,false) 
        dxDrawText( "textJoin", x4, y4, 1207.0,231.0,tocolor(0,255,0,255),0.6,"bankgothic","left","top",false,false,false) 
end) 

so write function() after root, .. like this:

addEventHandler ( "onClientRender", root, 
function() 
        local x1, y1 = AbsoluteToRelativ2( 959,246 ) 
        local x2, y2 = AbsoluteToRelativ2( 956,243 ) 
        local x3, y3 = AbsoluteToRelativ2( 943,217 ) 
        local x4, y4 = AbsoluteToRelativ2( 939,213 ) 
        dxDrawText( "textQuit", x1, y1, 1224, 264, tocolor(0,0,0,255),0.6,"bankgothic","left","top",false,false,false) 
        dxDrawText( "textQuit", x2, y2, 1224, 261, tocolor(255,0,0,255),0.6,"bankgothic","left","top",false,false,false) 
        dxDrawText( "textJoin", x3, y3, 1211.0, 235.0,tocolor(0,0,0,255),0.6,"bankgothic","left","top",false,false,false) 
        dxDrawText( "textJoin", x4, y4, 1207.0,231.0,tocolor(0,255,0,255),0.6,"bankgothic","left","top",false,false,false) 
end) 

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