Jump to content

dxDrawColorText Bugged


Cadu12

Recommended Posts

I have 2 bugged

If i have 2 colored it makes left

If i dont have colored it makes right

here is image:

http://img593.imageshack.us/g/mtascreen ... 32140.png/

http://img21.imageshack.us/g/mtascreen2 ... 24847.png/

and here 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+100, 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+100, ay, ax + w, by, color, scale, font, "center", "bottom", false, false, false ) 
    end 
end 
  
local sx, sy = guiGetScreenSize() 
  
function drawPlayerTags() 
    for i,v in ipairs(getElementsByType("player")) do 
        if not v == getLocalPlayer() then 
            local name = getPlayerName(v) 
            local x, y, z = getCameraMatrix() 
            local px,py = getScreenFromWorldPosition(x,y,z+0.3,0.06) 
            local rx, ry, rz = getPedBonePosition(v, 3) 
            local dist = getDistanceBetweenPoints3D(x, y, z, rx, ry, rz) 
            if isLineOfSightClear(x, y, z, rx, ry, rz, true, false, false, true, false, false, false) and dist <= 45 then 
                local r,g,b = getPlayerNametagColor(v) 
                local cx, cy = getScreenFromWorldPosition(rx, ry, rz) 
                if not cx or not cy then return end  
                local nameW = dxGetTextWidth(name, 2, "default") 
                local nameH = dxGetFontHeight(2, "default")     
                local nameX, nameY = cx-(nameW/2), cy-(nameH*2) 
                dxDrawColorText(name, nameX, nameY, sx, sy-300, tocolor(r, g, b, 255), 2, "default") 
            end 
        end 
    end 
end 
addEventHandler("onClientRender",getRootElement(),drawPlayerTags) 
  

Link to comment

Right is fixed now, but left is bugged, here is image:

http://img819.imageshack.us/g/mtascreen ... 82815.png/

here is code:

  
                    local name = getPlayerName(player) 
                    local vehicleE = getPedOccupiedVehicle(player) 
                    local rx, ry, rz = getElementPosition ( vehicleE ) 
                    local cx, cy = getScreenFromWorldPosition(rx, ry, rz) 
                    local nameW = dxGetTextWidth(name, 2, "default") 
                    local nameH = dxGetFontHeight(2, "default")     
                    local nameX, nameY = cx-(nameW/2), cy-(nameH*2) 
                     
                    if nametagscolored[player] == nil then 
                        name = string.format("#%02X%02X%02X", r, g, b) .. getPlayerName(player) 
                        vehicleE = getPedOccupiedVehicle(player) 
                        rx, ry, rz = getElementPosition ( vehicleE ) 
                        cx, cy = getScreenFromWorldPosition(rx, ry, rz) 
                        nameW = dxGetTextWidth(name, 2, "default") 
                        nameH = dxGetFontHeight(2, "default")     
                        nameX, nameY = cx-(nameW/2), cy-(nameH*2) 
                        dxDrawColorText( name, nameX, nameY, sx, sy, tocolor(r, g, b, 255), 2, "default", textscale*NAMETAG_TEXTSIZE) 
                    else 
                        dxDrawColorText( name, nameX, nameY, sx, sy, tocolor(r, g, b, 255), 2, "default", textscale*NAMETAG_TEXTSIZE) 
                    end 
  

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