Jump to content

Absolute to Relative -- Help me !


drk

Recommended Posts

Hi ! I've created a dx joinquit in gui editor, but I want to change absolute coordenates to relative, or better, I want to the text adjust on the screen of the player.

The code is:

  
--[[------------------------------------------------- 
-- client script main 
-- @infoauthor iMortal 
-- @description: client side script dx joinquit 
------------------------------------------------]]-- 
  
local textJoin = " " 
local textQuit = " " 
local textNick = " " 
  
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 when I join the server don't appear anything, I've created the code when on player join the "textJoin" appear ".... entered the game !" and when a player quit "..... left the server !". Anyone can help me ?

Link to comment

1280*720 is your Resolution when you adjust the dx

so don't change it

try this

  
--[[------------------------------------------------- 
-- client script main 
-- @infoauthor iMortal 
-- @description: client side script dx joinquit 
------------------------------------------------]]-- 
  
local textJoin = " " 
local textQuit = " " 
local textNick = " " 
  
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 
) 

Link to comment

Maybe this?

  
--[[------------------------------------------------- 
-- client script main 
-- @infoauthor iMortal 
-- @description: client side script dx joinquit 
------------------------------------------------]]-- 
  
local textJoin = " " 
local textQuit = " " 
local textNick = " " 
  
function AbsoluteToRelativ2( X, Y ) 
    local rX, rY = guiGetScreenSize ( ) 
    return math.floor((X/1280)*rX), math.floor((Y/720)*rY) 
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 
) 

Link to comment

Benxamix2, i've tested my code and working with all resolution.

Edit:

you forgot

function ()

  
--[[------------------------------------------------- 
-- client script main 
-- @infoauthor iMortal 
-- @description: client side script dx joinquit 
------------------------------------------------]]-- 
  
local textJoin = " " 
local textQuit = " " 
local textNick = " " 
  
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, 
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

I want look like this:

local rootElement = getRootElement() 
local sw,sh = guiGetScreenSize() 
  
local windowW = 280 
local windowH = 160 
  
local windowTitle        = "" 
local windowTitleHeight  = 20 
local windowTitleColor   = tocolor(255,255,255,255) 
local windowTitleBGColor = tocolor(0,0,0,255) 
local windowBGColor      = tocolor(0,0,0,0) 
  
local windowX = sw - 350 - windowW 
local windowY = sh / 1.08 - windowH / 2 
  
local localPlayer = getLocalPlayer ( ) 
  
function dx (thePlayer) 
local time      = getRealTime() 
local hours     = time.hour 
local minutes   = time.minute 
local seconds   = time.second 
local playerName = getPlayerName ( getLocalPlayer() )                                                          dxDrawText("Hora: "..hours.." : "..minutes.." : "..seconds,sw/9.120, sh/1.50, sw,sh,tocolor(0,0,255,255),1.2,"default","left","top",false,false,false) 
    local x = windowX 
    local y = windowY + windowTitleHeight 
    local h = windowH - windowTitleHeight 
  
    dxDrawRectangle(x,y,windowW,h,windowBGColor)     
end 
function HandleTheRendering () 
addEventHandler("onClientRender",rootElement, dx) 
end 
addEventHandler("onClientResourceStart",rootElement, HandleTheRendering) 

Link to comment
  
local screenWidth, screenHeight = guiGetScreenSize() 
--This function takes a number from 0 to 100 and returns the absolute x-position on the screen. A value below 0 or over 100 will return values that are off the screen. 
function getX(xcoord) 
    return screenWidth / 100 * xcoord 
end 
  
--This function takes a number from 0 to 100 and returns the absolute y-position on the screen. A value below 0 or over 100 will return values that are off the screen. 
function getY(ycoord) 
    return screenHeight / 100 * ycoord 
end 
  

Note, this uses values between 0 and 100, not 0-1 like most people.

Link to comment
dxDrawText ( textJoin, screenWidth / xcoord, screenHeight / ycoord, tocolor ( 0, 255, 0, 255 ), 0.6, "bankgothic", "left", "top", false, false, false )

How to discover the xcoord and ycoord of the screen ?

guiGetScreenSize, for god :o sake!

-_- It isn't what I've said, I've tryed to say "How to discover the relative x and y position that I have to put after screenWidth / without the method "test, error" Understand me ?

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