M MY Multiplayer: Wiki
Side
Kind

dxGetTextWidth

Client

Measures how wide a text is on the screen, at its widest line.

float|false dxGetTextWidth(string text [, float scale = 1, string|element font = default, bool colorCoded = false])

Parameters

NameTypeDescription
textstringThe text.
scalefloatText scale.default 1
fontstring|elementA font's name (from a pack or given to dxCreateFont) or a font element from dxCreateFont.default default
colorCodedboolLeave #RRGGBB colour codes out of the measure.default false

Returns

The width in pixels, or false when the font does not exist.

Example

local text = "Bem-vindo"
local width = dxGetTextWidth(text, 2, "default")

addEventHandler("onClientRender", root, function()
    local sx = getScreenSize()
    dxDrawText(text, (sx - width) / 2, 40, 0, 0, tocolor(255, 255, 255), 2)
end)

See also