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