drk Posted November 14, 2011 Share Posted November 14, 2011 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
TAPL Posted November 14, 2011 Share Posted November 14, 2011 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
12p Posted November 14, 2011 Share Posted November 14, 2011 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
TAPL Posted November 14, 2011 Share Posted November 14, 2011 what is don't work? any error? post your whole code, i think you have a thing wrong Link to comment
12p Posted November 14, 2011 Share Posted November 14, 2011 No, TAPL. I think the math was wrong. Let him test my edit. Link to comment
TAPL Posted November 14, 2011 Share Posted November 14, 2011 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
drk Posted November 14, 2011 Author Share Posted November 14, 2011 It workeeeeeeeeeeeeeeeeeeeed ! Thaaaanks !! Link to comment
drk Posted November 14, 2011 Author Share Posted November 14, 2011 And how to the text appear in all resolutions ? Link to comment
drk Posted November 16, 2011 Author Share Posted November 16, 2011 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
BinSlayer1 Posted November 18, 2011 Share Posted November 18, 2011 They say third time's a charm but perhaps you need to quintuple post. (5 posts) Link to comment
drk Posted November 23, 2011 Author Share Posted November 23, 2011 Shit, u can help me or u want post noob reply's ? Link to comment
AGENT_STEELMEAT Posted November 23, 2011 Share Posted November 23, 2011 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
drk Posted November 24, 2011 Author Share Posted November 24, 2011 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 ? Link to comment
12p Posted November 24, 2011 Share Posted November 24, 2011 You still don't get it? OMG... We gave you tons of code that do that already! What is it? Do you even test them? Link to comment
Charlie_Jefferson Posted November 24, 2011 Share Posted November 24, 2011 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 fucking sake! Link to comment
drk Posted November 24, 2011 Author Share Posted November 24, 2011 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 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now