Jump to content

dxGetTextWidth, help please


Vinspire

Recommended Posts

Posted

Hello, I'm stuck at some place I really don't know what to do at this point. It's a clanwar script for race.

I drawed a rectangle that the points&name for the enemyteam and hometeam should be placed in, and I need to use dxGetTextWidth incase the names are too long to fit to the rectangle.

/tsn 1 = team set new name for the hometeam.

When I do /tsn 1 awdawdawdawdawd for example, then the name goes outside the rectangle. So the rectangle length should be = dxGetTextWidth, I hope you get it.

  
  
local maiFont = "default-bold" 
local myText = "" 
local scale = sW/800 
local width, height = dxGetTextWidth(myText, scale, maiFont)+10, dxGetFontHeight(scale, maiFont)+4 
  
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), screenWidth, screenHeight, tocolor ( 255, 102, 1, 255 ),  
            1, "default-bold", nil, nil, nil, nil, nil, true) 
dxDrawText ( hexColorVisit..visitName.."("..visitAlivePlayers.."):".."#ffffff "..displayVisit, sW-80, (sH/2.17), screenWidth, screenHeight, tocolor ( 255, 0, 0, 255 ),  
            1, "default-bold", nil, nil, nil, nil, nil, true ) 
end 
addEventHandler("onClientRender",root,drawText) 

I have no idea what should stand in the myText, obviously 'drawText' if it could..

Thanks!

Posted

Why should you do that? And why do you set the parameters in dxDrawText which should be strings, booleans, floats to nil? Just set clip parameter to false and alignX to 'right'.

Posted
Why should you do that? And why do you set the parameters in dxDrawText which should be strings, booleans, floats to nil? Just set clip parameter to false and alignX to 'right'.

?

Posted

Okay, I see you are zero in scripting..

  
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) 
  

Posted
Okay, I see you are zero in scripting..
  
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) 
  

That works, but that's not the point, 1 problem solved.

The real thing is to make the drawed rectangle in the drawtext function FOLLOW the homeName and visitName as you can see.

so when the homeName = awd) then the rectangle should fit the homeName.

when homeName = wadesrthfytgrfedwsaesfrgth) then the rectangle should fit the homeName.

dxGetTextWidth, the rectangle's lenght should be dxGetTextWidth thing, (I THINK THAT'S THE SOLUTION, BUT I DON'T KNOW HOW TO MAKE IT LIKE THAT)

^, that's my problem.

Thanks

Regards,

chris

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