Master_MTA Posted September 24, 2018 Share Posted September 24, 2018 (edited) hello there i created useful function that maybe help people a lot it should be a main mta sa function it's used with dxDrawText that function help you to get numbers of lines of text if u was used the wordbreak argument and set it to true in dxDrawText function source code: function getTextNumbersOfLines(text,borderheight,borderwidth,scale,font) if dxGetTextWidth(text,scale,font)>borderwidth then---if it's in new line then local totalHeight=borderheight/dxGetFontHeight(scale,font)----get number of lines that the box can contain it local percent=(borderwidth/dxGetTextWidth(text,scale,font)) *100---calculate some math :D get the percentage from the all width to the width of 1 line local heightoftext=(percent*totalHeight)/100 local result=math.floor(dxGetFontHeight(scale,font)/heightoftext) return result end return 1---else end syntax: getTextNumbersOfLines(string text,float borderheight,float borderwidth,float scale,string/fontelement font) arguments: text: the text that you want to get the numbers of line of it borderheight: the height of the border borderwidth: the width of the border scale: the scale of the text font : can be an font element that created by dxcreating font functions or it can be one of this: "default": Tahoma "default-bold": Tahoma Bold "clear": Verdana "arial": Arial "sans": Microsoft Sans Serif "pricedown": Pricedown (GTA's theme text) "bankgothic": Bank Gothic Medium "diploma": Diploma Regular "beckett": Beckett Regular how to use: example-- addEventHandler('onClientRender',root,function() dxDrawText ( 'hello world this is just test text to check word warp calculate function ', 200,200, 300, 400, tocolor(255,255,255,255),1, "default", "left", "top", true,true, false) end) addCommandHandler('testheight',function() print(getTextNumbersOfLines('hello world this is just test text to check word warp calculate function ',200,100,1,'default')) print(dxGetFontHeight(1,'default')) end) what is the special about this function we all know we can create our word break mechanism without using the word break argument but with this function you can use the wordbreak argument and don't care about the mechanism hope u like it enjoy Edited September 24, 2018 by Master_MTA 2 1 Link to comment
Master_MTA Posted September 25, 2018 Author Share Posted September 25, 2018 Update:(there was bug with dxgettextwidth it doesn't count the space after word warp any way solved) source code: function getTextNumbersOfLines(text,borderwidth,scale,font) local scale=scale or 1 local font=font or 'default' if dxGetTextWidth(text,scale,font)>borderwidth then---if it's in new line then local mytext='' local numoflines=1 for c in string.gmatch(text,"%w+") do mytext=mytext..' '..c local currentwidth=dxGetTextWidth(mytext,scale,font) if currentwidth>borderwidth then numoflines=numoflines+1 mytext=c end end return numoflines end return 1---else end Note:No need any more for borderheight argument Link to comment
Master_MTA Posted September 25, 2018 Author Share Posted September 25, 2018 1 hour ago, #\_oskar_/# said: good job thx dude 1 Link to comment
TOUNSI |, السعأدة Posted September 25, 2018 Share Posted September 25, 2018 Great Job Link to comment
Master_MTA Posted September 25, 2018 Author Share Posted September 25, 2018 2 hours ago, MR.TOUNSI said: Great Job thx bro 1 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