Vinspire Posted May 6, 2014 Share Posted May 6, 2014 Hello, I've been struggling with this for weeks now and I'd really love to get it to work (which I dont) The problem are the following: /tsn 1 = team set name homeName /tsn 2 = team set name visitName The lua code below is what I have, and when I do /tsn 1or2 awdawdawddawwdawd the rectangle width should follow the homeName or visitName, depends on if you do /tsn 1 or 2.. If any of you could help me with this, I'd be so thankful, I guess I have to use dxGetTextWidth but I have no idea how. function drawText() dxDrawRectangle(sW-90,(sH/2)-50,70,40, tocolor(0,0,0,110)) dxDrawText ( hexColorHome..homeName.."("..homeAlivePlayers.."):".."#ffffff "..displayHome, sW-80, (sH/2.26), sW, sH, tocolor(255, 102, 1, 255), 1, "default-bold", 'right', 'center', false, false, false, true, true, 0, 0, 0) dxDrawText ( hexColorVisit..visitName.."("..visitAlivePlayers.."):".."#ffffff "..displayVisit, sW-80, (sH/2.17), sW, sH, tocolor(255, 0, 0, 255), 1, "default-bold", 'right', 'center', false, false, false, true, true, 0, 0, 0) end addEventHandler("onClientRender", root, drawText) Thanks alot! Link to comment
Ab-47 Posted May 7, 2014 Share Posted May 7, 2014 Can you post the rest of the code please? Link to comment
Vinspire Posted May 7, 2014 Author Share Posted May 7, 2014 Can you post the rest of the code please? local sW, sH = guiGetScreenSize() addEventHandler("onClientResourceStart", resourceRoot, function() end ) addEventHandler("onClientRender", root, function() dxDrawImage(sW-35, (sH/2.26), 12, 12, ":ccw/skull.png", 0, 0, 0, tocolor(255, 255, 255, 255), true) dxDrawImage(sW-35, (sH/2.16), 12, 12, ":ccw/comments.png", 0, 0, 0, tocolor(255, 255, 255, 255), true) end ) displayHome=0 displayVisit=0 ALPHA = 0 RED, GREEN,BLUE = 255, 255, 255 homeName="l" visitName="i" homeAlivePlayers=0 visitAlivePlayers=0 hexColorHome = "#0080FF" hexColorVisit = "#0080FF" hexColorRounds = "#FFFF00" addEvent("sync:shiet", true) addEventHandler("sync:shiet", root, function(R, G, B, A) RED, GREEN, BLUE, ALPHA = R, G, B, A end) function displayPoints(home, visit) displayHome=home displayVisit=visit end addEvent("sync:points", true) addEventHandler("sync:points",root,displayPoints) function displayAlive(home, visit) homeAlivePlayers=home visitAlivePlayers=visit end addEvent("sync:alive", true) addEventHandler("sync:alive",root,displayAlive) function setNames(home, visit) homeName=home visitName=visit end addEvent("sync:names", true) addEventHandler("sync:names",root,setNames) function setColors(home,visit,rounds) hexColorHome = home hexColorVisit = visit hexColorRounds = rounds end addEvent("sync:colors", true) addEventHandler("sync:colors",root,setColors) function drawText() dxDrawRectangle(sW-90,(sH/2)-50,70,40, tocolor(0,0,0,110)) dxDrawText ( hexColorHome..homeName.."("..homeAlivePlayers.."):".."#ffffff "..displayHome, sW-80, (sH/2.26), sW, sH, tocolor(255, 102, 1, 255), 1, "default-bold", 'right', 'center', false, false, false, true, true, 0, 0, 0) dxDrawText ( hexColorVisit..visitName.."("..visitAlivePlayers.."):".."#ffffff "..displayVisit, sW-80, (sH/2.17), sW, sH, tocolor(255, 0, 0, 255), 1, "default-bold", 'right', 'center', false, false, false, true, true, 0, 0, 0) end addEventHandler("onClientRender", root, drawText) Link to comment
JR10 Posted May 7, 2014 Share Posted May 7, 2014 dxGetTextWidth will return the width of the text when drawn with the same font and scale, you can use that width with dxDrawRectangle (third parameter) to draw the rectangle with the same width as the text. A really basic example: local width = dxGetTextWidth('test') dxDrawRectangle(0, 0, width, 20) Link to comment
Vinspire Posted May 7, 2014 Author Share Posted May 7, 2014 dxGetTextWidth will return the width of the text when drawn with the same font and scale, you can use that width with dxDrawRectangle (third parameter) to draw the rectangle with the same width as the text.A really basic example: local width = dxGetTextWidth('test') dxDrawRectangle(0, 0, width, 20) local width = dxGetTextWidth(drawText) dxDrawRectangle(0, 0, width, 20) function drawText() dxDrawRectangle(sW-90,(sH/2)-50,70,40, tocolor(0,0,0,110)) dxDrawText ( hexColorHome..homeName.."("..homeAlivePlayers.."):".."#ffffff "..displayHome, sW-80, (sH/2.26), sW, sH, tocolor(255, 102, 1, 255), 1, "default-bold", 'right', 'center', false, false, false, true, true, 0, 0, 0) dxDrawText ( hexColorVisit..visitName.."("..visitAlivePlayers.."):".."#ffffff "..displayVisit, sW-80, (sH/2.17), sW, sH, tocolor(255, 0, 0, 255), 1, "default-bold", 'right', 'center', false, false, false, true, true, 0, 0, 0) end addEventHandler("onClientRender", root, drawText) Would this do? Link to comment
JR10 Posted May 7, 2014 Share Posted May 7, 2014 That was just an example of how the function works. Here: function drawText() local width = dxGetTextWidth(hexColorHome..homeName.."("..homeAlivePlayers.."):".."#ffffff "..displayHome, 1, 'default-bold') dxDrawRectangle(sW-90,(sH/2)-50,width,40, tocolor(0,0,0,110)) dxDrawText ( hexColorHome..homeName.."("..homeAlivePlayers.."):".."#ffffff "..displayHome, sW-80, (sH/2.26), sW, sH, tocolor(255, 102, 1, 255), 1, "default-bold", 'right', 'center', false, false, false, true, true, 0, 0, 0) dxDrawText ( hexColorVisit..visitName.."("..visitAlivePlayers.."):".."#ffffff "..displayVisit, sW-80, (sH/2.17), sW, sH, tocolor(255, 0, 0, 255), 1, "default-bold", 'right', 'center', false, false, false, true, true, 0, 0, 0) end addEventHandler("onClientRender", root, drawText) Now just add another dxGetTextWidth for the second dxDrawText. Link to comment
Vinspire Posted May 7, 2014 Author Share Posted May 7, 2014 That was just an example of how the function works. Here: function drawText() local width = dxGetTextWidth(hexColorHome..homeName.."("..homeAlivePlayers.."):".."#ffffff "..displayHome, 1, 'default-bold') dxDrawRectangle(sW-90,(sH/2)-50,width,40, tocolor(0,0,0,110)) dxDrawText ( hexColorHome..homeName.."("..homeAlivePlayers.."):".."#ffffff "..displayHome, sW-80, (sH/2.26), sW, sH, tocolor(255, 102, 1, 255), 1, "default-bold", 'right', 'center', false, false, false, true, true, 0, 0, 0) dxDrawText ( hexColorVisit..visitName.."("..visitAlivePlayers.."):".."#ffffff "..displayVisit, sW-80, (sH/2.17), sW, sH, tocolor(255, 0, 0, 255), 1, "default-bold", 'right', 'center', false, false, false, true, true, 0, 0, 0) end addEventHandler("onClientRender", root, drawText) Now just add another dxGetTextWidth for the second dxDrawText. function drawText() local width = dxGetTextWidth(hexColorHome..homeName.."("..homeAlivePlayers.."):".."#ffffff "..displayHome, 1, 'default-bold') local width = dxGetTextWidth(hexColorVisit..visitName.."("..visitAlivePlayers.."):".."#ffffff "..displayVisit, 1, 'default-bold') dxDrawRectangle(sW-90,(sH/2)-50,width,40, tocolor(0,0,0,110)) dxDrawText ( hexColorHome..homeName.."("..homeAlivePlayers.."):".."#ffffff "..displayHome, sW-80, (sH/2.26), sW, sH, tocolor(255, 102, 1, 255), 1, "default-bold", 'right', 'center', false, false, false, true, true, 0, 0, 0) dxDrawText ( hexColorVisit..visitName.."("..visitAlivePlayers.."):".."#ffffff "..displayVisit, sW-80, (sH/2.17), sW, sH, tocolor(255, 0, 0, 255), 1, "default-bold", 'right', 'center', false, false, false, true, true, 0, 0, 0) end addEventHandler("onClientRender", root, drawText) Like this yes? That doesn't work =/ When I do /tsn 1 awdawdawdawd then it doesn't change width of the rectangle (or /tsn 2) Link to comment
JR10 Posted May 7, 2014 Share Posted May 7, 2014 You store the two values in the same variable so it will only point to the width of the visitName text. Plus you're only drawing one rectangle. You need to learn more. Link to comment
Vinspire Posted May 7, 2014 Author Share Posted May 7, 2014 You store the two values in the same variable so it will only point to the width of the visitName text. Plus you're only drawing one rectangle. You need to learn more. It's supposed to be 1 rectangle with the visitName and homeName inside of it, and when I do /tsn 1-2 awdawdawdwdaawddawd then the rectangle should be the same length as the text length Link to comment
JR10 Posted May 7, 2014 Share Posted May 7, 2014 Try this: function drawText() local width1 = dxGetTextWidth(hexColorHome..homeName.."("..homeAlivePlayers.."):".."#ffffff "..displayHome, 1, 'default-bold') local width2 = dxGetTextWidth(hexColorVisit..visitName.."("..visitAlivePlayers.."):".."#ffffff "..displayVisit, 1, 'default-bold') local width = width1 > width2 and width1 or width2 dxDrawRectangle(sW-90,(sH/2)-50,width,40, tocolor(0,0,0,110)) dxDrawText ( hexColorHome..homeName.."("..homeAlivePlayers.."):".."#ffffff "..displayHome, sW-80, (sH/2.26), sW, sH, tocolor(255, 102, 1, 255), 1, "default-bold", 'right', 'center', false, false, false, true, true, 0, 0, 0) dxDrawText ( hexColorVisit..visitName.."("..visitAlivePlayers.."):".."#ffffff "..displayVisit, sW-80, (sH/2.17), sW, sH, tocolor(255, 0, 0, 255), 1, "default-bold", 'right', 'center', false, false, false, true, true, 0, 0, 0) end addEventHandler("onClientRender", root, drawText) Link to comment
Vinspire Posted May 8, 2014 Author Share Posted May 8, 2014 Try this:function drawText() local width1 = dxGetTextWidth(hexColorHome..homeName.."("..homeAlivePlayers.."):".."#ffffff "..displayHome, 1, 'default-bold') local width2 = dxGetTextWidth(hexColorVisit..visitName.."("..visitAlivePlayers.."):".."#ffffff "..displayVisit, 1, 'default-bold') local width = width1 > width2 and width1 or width2 dxDrawRectangle(sW-90,(sH/2)-50,width,40, tocolor(0,0,0,110)) dxDrawText ( hexColorHome..homeName.."("..homeAlivePlayers.."):".."#ffffff "..displayHome, sW-80, (sH/2.26), sW, sH, tocolor(255, 102, 1, 255), 1, "default-bold", 'right', 'center', false, false, false, true, true, 0, 0, 0) dxDrawText ( hexColorVisit..visitName.."("..visitAlivePlayers.."):".."#ffffff "..displayVisit, sW-80, (sH/2.17), sW, sH, tocolor(255, 0, 0, 255), 1, "default-bold", 'right', 'center', false, false, false, true, true, 0, 0, 0) end addEventHandler("onClientRender", root, drawText) That doesn't work too man This is what I mean about how it's supposed to be: http://i62.tinypic.com/2q1v5w8.png http://i58.tinypic.com/2cz7kg2.jpg Thanks! 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