Jump to content

One question


Cadu12

Recommended Posts

I can do it, but i dont knows how do it center

We can make X and Y?

edit:

there is code:

function dxDrawColorText(str, ax, ay, bx, by, color, scale, font) 
    local pat = "(.-)#(%x%x%x%x%x%x)" 
    local s, e, cap, col = str:find(pat, 1) 
    local last = 1 
    while s do 
    if cap == "" and col then color = tocolor(tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)), 255) end 
        if s ~= 1 or cap ~= "" then 
            local w = dxGetTextWidth(cap, scale, font) 
            dxDrawText(cap, ax, ay, ax + w, by, color, scale, font, "center", "bottom", false, false, false ) 
            ax = ax + w 
            color = tocolor(tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)), 255) 
        end 
        last = e + 1 
        s, e, cap, col = str:find(pat, last) 
    end 
    if last <= #str then 
        cap = str:sub(last) 
        local w = dxGetTextWidth(cap, scale, font) 
        dxDrawText(cap, ax, ay, ax + w, by, color, scale, font, "center", "bottom", false, false, false ) 
    end 
end 

Link to comment

It's very simple to get it centered:

local sx,sy = guiGetScreenSize() --get player's current resolution 
dxDrawText('Text',sx/2-70,sy/2-20,sx/2+70,sy/2+20,tocolor(255,170,0,255),1.0,'bankgothic','center','center') -- draw text in the center according to resolution  

Link to comment

Then, you should have told us that before.

function dxDrawColorText(str, ax, ay, bx, by, color, scale, font) 
    local pat = "(.-)#(%x%x%x%x%x%x)" 
    local s, e, cap, col = str:find(pat, 1) 
    local last = 1 
    while s do 
    if cap == "" and col then color = tocolor(tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)), 255) end 
        if s ~= 1 or cap ~= "" then 
            local w = dxGetTextWidth(cap, scale, font) 
            dxDrawText(cap, ax, ay, ax + w, by, color, scale, font, "center", "bottom", false, false, false ) 
            ax = ax + w 
            color = tocolor(tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)), 255) 
        end 
        last = e + 1 
        s, e, cap, col = str:find(pat, last) 
    end 
    if last <= #str then 
        cap = str:sub(last) 
        local w = dxGetTextWidth(cap, scale, font) 
        dxDrawText(cap, ax, ay, ax + w, by, color, scale, font, "center", "bottom", false, false, false ) 
    end 
end 
  
function drawPlayerTags() 
for i,v in ipairs(getElementsByType("player")) do 
if not v == getLocalPlayer() then 
local name = getPlayerName(v) 
local x,y,z = getElementPosition(v) 
local cx,cy,cz = getCameraMatrix() 
if isLineOfSightClear(cx,cy,cz,x,y,z,true,true,false,true,false,true,false,v) then 
if getDistanceBetweenPoints3D(cx,cy,cz,x,y,z) <= 45 then 
local px,py = getScreenFromWorldPosition(x,y,z+0.3,0.06) 
if px then 
r,g,b = getPlayerNametagColor(v) 
dxDrawColorText(name, px-60, py, px, py, tocolor(r, g, b, 255), 2, "default") 
           end 
         end  
      end 
    end 
  end 
end 
addEventHandler("onClientRender",getRootElement(),drawPlayerTags) 

There, it works fine here, should work "there" too.

And please, don't think we're your "slaves" our something like that ;)

Link to comment

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