Jump to content

Nametag problem!


Recommended Posts

Ok i really don't know what the problem is so here I go

I tried, and i tried to create colorcoded namtags but no mather what it still remains white.

Please help finding out what the problem is

addEventHandler ( "onClientRender", g_Root, 
    function() 
        -- Hideous quick fix -- 
        for i,player in ipairs(g_Players) do 
            if player ~= g_Me then 
                setPlayerNametagShowing ( player, false ) 
                if not nametags[player] then 
                    nametag.create ( player ) 
                end 
            end 
        end 
        if bHideNametags then 
            return 
        end 
        local x,y,z = getCameraMatrix() 
        for player in pairs(nametags) do  
            while true do 
                if not isPedInVehicle(player) or isPlayerDead(player) then break end 
                local vehicle = getPedOccupiedVehicle(player) 
                local px,py,pz = getElementPosition ( vehicle ) 
                local pdistance = getDistanceBetweenPoints3D ( x,y,z,px,py,pz ) 
                if pdistance <= NAMETAG_DISTANCE then 
                    --Get screenposition 
                    local sx,sy = getScreenFromWorldPosition ( px, py, pz+0.95, 0.06 ) 
                    if not sx or not sy then break end 
                    --Calculate our components 
                    local scale = 1/(NAMETAG_SCALE * (pdistance / NAMETAG_DISTANCE)) 
                    local alpha = ((pdistance - NAMETAG_ALPHA_DISTANCE) / NAMETAG_ALPHA_DIFF) 
                    alpha = (alpha < 0) and NAMETAG_ALPHA or NAMETAG_ALPHA-(alpha*NAMETAG_ALPHA) 
                    scale = math.evalCurve(maxScaleCurve,scale) 
                    local textscale = math.evalCurve(textScaleCurve,scale) 
                    local textalpha = math.evalCurve(textAlphaCurve,alpha) 
                    local outlineThickness = NAMETAG_OUTLINE_THICKNESS*(scale) 
                    --Draw our text 
                    local r,g,b = 255,255,255 
                    local team = getPlayerTeam(player) 
                    if team then 
                        r,g,b = getTeamColor(team) 
                    end 
                    local offset = (scale) * NAMETAG_TEXT_BAR_SPACE/2 
                    --dxDrawText ( getPlayerName(player), sx, sy - offset, sx, sy - offset, tocolor(r,g,b,textalpha), textscale*NAMETAG_TEXTSIZE, "default", "center", "bottom", false, false, false ) 
                    dxDrawText ( getPlayerName(player), sx + 1, sy - offset + 1, sx + 1, sy - offset + 1, tocolor(0,0,0,255), textscale*NAMETAG_TEXTSIZE, "bankgothic", "center", "bottom", false, false, false ) 
                    dxDrawColorText( getPlayerName(player,true), sx, sy - offset, sx, sy - offset, tocolor(r,g,b,textalpha), textscale*NAMETAG_TEXTSIZE, 'bankgothic', 'center', 'bottom' ) 
                    --We draw three parts to make the healthbar.  First the outline/background 
                    local drawX = sx - NAMETAG_WIDTH*scale/2 
                    drawY = sy + offset 
                    local width,height =  NAMETAG_WIDTH*scale, NAMETAG_HEIGHT*scale 
                    dxDrawRectangle ( drawX, drawY, width, height, tocolor(0,0,0,alpha) ) 
                    --Next the inner background  
                    local health = getElementHealth(vehicle) 
                    health = math.max(health - 250, 0)/750 
                    local p = -510*(health^2) 
                    --local r,g = math.max(math.min(p + 255*health + 255, 255), 0), math.max(math.min(p + 765*health, 255), 0) 
                     
          dxDrawRectangle (     drawX + outlineThickness,  
                                        drawY + outlineThickness,  
                                        width - outlineThickness*2,  
                                        height - outlineThickness*2,  
                                        tocolor(178,178,178,0.4*alpha)  
                                    ) 
                    --Finally, the actual health 
           
                    dxDrawRectangle (   drawX + outlineThickness,  
                                        drawY + outlineThickness,  
                                        health*(width - outlineThickness*2),  
                                        height - outlineThickness*2,  
                                        tocolor(r,g,b,alpha)  
                                    )            
                end 
                break 
            end 
        end 
    end 
) 

Link to comment

@ binSlayer1 it is in it i just did'nt paste it here..

but here you got it:

addEventHandler ( "onClientRender", g_Root, 
    function() 
        -- Hideous quick fix -- 
        for i,player in ipairs(g_Players) do 
            if player ~= g_Me then 
                setPlayerNametagShowing ( player, false ) 
                if not nametags[player] then 
                    nametag.create ( player ) 
                end 
            end 
        end 
        if bHideNametags then 
            return 
        end 
        local x,y,z = getCameraMatrix() 
        for player in pairs(nametags) do  
            while true do 
                if not isPedInVehicle(player) or isPlayerDead(player) then break end 
                local vehicle = getPedOccupiedVehicle(player) 
                local px,py,pz = getElementPosition ( vehicle ) 
                local pdistance = getDistanceBetweenPoints3D ( x,y,z,px,py,pz ) 
                if pdistance <= NAMETAG_DISTANCE then 
                    --Get screenposition 
                    local sx,sy = getScreenFromWorldPosition ( px, py, pz+0.95, 0.06 ) 
                    if not sx or not sy then break end 
                    --Calculate our components 
                    local scale = 1/(NAMETAG_SCALE * (pdistance / NAMETAG_DISTANCE)) 
                    local alpha = ((pdistance - NAMETAG_ALPHA_DISTANCE) / NAMETAG_ALPHA_DIFF) 
                    alpha = (alpha < 0) and NAMETAG_ALPHA or NAMETAG_ALPHA-(alpha*NAMETAG_ALPHA) 
                    scale = math.evalCurve(maxScaleCurve,scale) 
                    local textscale = math.evalCurve(textScaleCurve,scale) 
                    local textalpha = math.evalCurve(textAlphaCurve,alpha) 
                    local outlineThickness = NAMETAG_OUTLINE_THICKNESS*(scale) 
                    --Draw our text 
                    local r,g,b = 255,255,255 
                    local team = getPlayerTeam(player) 
                    if team then 
                        r,g,b = getTeamColor(team) 
                    end 
                    local offset = (scale) * NAMETAG_TEXT_BAR_SPACE/2 
                    --dxDrawText ( getPlayerName(player), sx, sy - offset, sx, sy - offset, tocolor(r,g,b,textalpha), textscale*NAMETAG_TEXTSIZE, "default", "center", "bottom", false, false, false ) 
                    dxDrawText ( getPlayerName(player), sx + 1, sy - offset + 1, sx + 1, sy - offset + 1, tocolor(0,0,0,255), textscale*NAMETAG_TEXTSIZE, "bankgothic", "center", "bottom", false, false, false ) 
                    dxDrawColorText( getPlayerName(player,true), sx, sy - offset, sx, sy - offset, tocolor(r,g,b,textalpha), textscale*NAMETAG_TEXTSIZE, 'bankgothic', 'center', 'bottom' ) 
                    --We draw three parts to make the healthbar.  First the outline/background 
                    local drawX = sx - NAMETAG_WIDTH*scale/2 
                    drawY = sy + offset 
                    local width,height =  NAMETAG_WIDTH*scale, NAMETAG_HEIGHT*scale 
                    dxDrawRectangle ( drawX, drawY, width, height, tocolor(0,0,0,alpha) ) 
                    --Next the inner background  
                    local health = getElementHealth(vehicle) 
                    health = math.max(health - 250, 0)/750 
                    local p = -510*(health^2) 
                    --local r,g = math.max(math.min(p + 255*health + 255, 255), 0), math.max(math.min(p + 765*health, 255), 0) 
                     
          dxDrawRectangle (     drawX + outlineThickness,  
                                        drawY + outlineThickness,  
                                        width - outlineThickness*2,  
                                        height - outlineThickness*2,  
                                        tocolor(178,178,178,0.4*alpha)  
                                    ) 
                    --Finally, the actual health 
           
                    dxDrawRectangle (   drawX + outlineThickness,  
                                        drawY + outlineThickness,  
                                        health*(width - outlineThickness*2),  
                                        height - outlineThickness*2,  
                                        tocolor(r,g,b,alpha)  
                                    )            
                end 
                break 
            end 
        end 
    end 
) 
  
function dxDrawColorText(str, ax, ay, bx, by, color, scale, font, alignX, alignY) 
  if alignX then 
    if alignX == "center" then 
      local w = dxGetTextWidth(str:gsub("#%x%x%x%x%x%x",""), scale, font) 
      ax = ax + (bx-ax)/2 - w/2 
    elseif alignX == "right" then 
      local w = dxGetTextWidth(str:gsub("#%x%x%x%x%x%x",""), scale, font) 
      ax = bx - w 
    end 
  end 
   
  if alignY then 
    if alignY == "center" then 
      local h = dxGetFontHeight(scale, font) 
      ay = ay + (by-ay)/2 - h/2 
    elseif alignY == "bottom" then 
      local h = dxGetFontHeight(scale, font) 
      ay = by - h 
    end 
  end 
   
  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) 
      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) 
  end 
end 

Link to comment

Here is :D

addEventHandler ( "onClientRender", g_Root, 
    function() 
        -- Hideous quick fix -- 
        for i,player in ipairs(g_Players) do 
            if player ~= g_Me then 
                setPlayerNametagShowing ( player, false ) 
                if not nametags[player] then 
                    nametag.create ( player ) 
                end 
            end 
        end 
        if bHideNametags then 
            return 
        end 
        local x,y,z = getCameraMatrix() 
        for player in pairs(nametags) do 
            while true do 
                if not isPedInVehicle(player) or isPlayerDead(player) then break end 
                local vehicle = getPedOccupiedVehicle(player) 
                local px,py,pz = getElementPosition ( vehicle ) 
                local pdistance = getDistanceBetweenPoints3D ( x,y,z,px,py,pz ) 
                if pdistance <= NAMETAG_DISTANCE then 
                    --Get screenposition 
                    local sx,sy = getScreenFromWorldPosition ( px, py, pz+0.95, 0.06 ) 
                    if not sx or not sy then break end 
                    --Calculate our components 
                    local scale = 1/(NAMETAG_SCALE * (pdistance / NAMETAG_DISTANCE)) 
                    local alpha = ((pdistance - NAMETAG_ALPHA_DISTANCE) / NAMETAG_ALPHA_DIFF) 
                    alpha = (alpha < 0) and NAMETAG_ALPHA or NAMETAG_ALPHA-(alpha*NAMETAG_ALPHA) 
                    scale = math.evalCurve(maxScaleCurve,scale) 
                    local textscale = math.evalCurve(textScaleCurve,scale) 
                    local textalpha = math.evalCurve(textAlphaCurve,alpha) 
                    local outlineThickness = NAMETAG_OUTLINE_THICKNESS*(scale) 
                    --Draw our text 
                    local r,g,b = 255,255,255 
                    local team = getPlayerTeam(player) 
                    if team then 
                        r,g,b = getTeamColor(team) 
                    end 
                    local offset = (scale) * NAMETAG_TEXT_BAR_SPACE/2 
                    --dxDrawText ( getPlayerName(player), sx, sy - offset, sx, sy - offset, tocolor(r,g,b,textalpha), textscale*NAMETAG_TEXTSIZE, "default", "center", "bottom", false, false, false ) 
                    dxDrawText ( getPlayerName(player), sx + 1, sy - offset + 1, sx + 1, sy - offset + 1, tocolor(0,0,0,255), textscale*NAMETAG_TEXTSIZE, "bankgothic", "center", "bottom", false, false, false ) 
                    dxDrawColorText( getPlayerNametagText(player), sx, sy - offset, sx, sy - offset, tocolor(r,g,b,textalpha), textscale*NAMETAG_TEXTSIZE, 'bankgothic', 'center', 'bottom' ) 
                    --We draw three parts to make the healthbar.  First the outline/background 
                    local drawX = sx - NAMETAG_WIDTH*scale/2 
                    drawY = sy + offset 
                    local width,height =  NAMETAG_WIDTH*scale, NAMETAG_HEIGHT*scale 
                    dxDrawRectangle ( drawX, drawY, width, height, tocolor(0,0,0,alpha) ) 
                    --Next the inner background 
                    local health = getElementHealth(vehicle) 
                    health = math.max(health - 250, 0)/750 
                    local p = -510*(health^2) 
                    --local r,g = math.max(math.min(p + 255*health + 255, 255), 0), math.max(math.min(p + 765*health, 255), 0) 
                    
          dxDrawRectangle (     drawX + outlineThickness, 
                                        drawY + outlineThickness, 
                                        width - outlineThickness*2, 
                                        height - outlineThickness*2, 
                                        tocolor(178,178,178,0.4*alpha) 
                                    ) 
                    --Finally, the actual health 
          
                    dxDrawRectangle (   drawX + outlineThickness, 
                                        drawY + outlineThickness, 
                                        health*(width - outlineThickness*2), 
                                        height - outlineThickness*2, 
                                        tocolor(r,g,b,alpha) 
                                    )           
                end 
                break 
            end 
        end 
    end 
) 
  
function dxDrawColorText(str, ax, ay, bx, by, color, scale, font, alignX, alignY) 
  if alignX then 
    if alignX == "center" then 
      local w = dxGetTextWidth(str:gsub("#%x%x%x%x%x%x",""), scale, font) 
      ax = ax + (bx-ax)/2 - w/2 
    elseif alignX == "right" then 
      local w = dxGetTextWidth(str:gsub("#%x%x%x%x%x%x",""), scale, font) 
      ax = bx - w 
    end 
  end 
  
  if alignY then 
    if alignY == "center" then 
      local h = dxGetFontHeight(scale, font) 
      ay = ay + (by-ay)/2 - h/2 
    elseif alignY == "bottom" then 
      local h = dxGetFontHeight(scale, font) 
      ay = by - h 
    end 
  end 
  
  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) 
      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) 
  end 
end 

Link to comment

debug it so you see if getPlayerName(player) actually returns the name with hex code.

it's possible that race is editing that function so hex codes are cut off for when they draw it.

i do not know for sure, but debugging will point this out.

EDIT:

Yes, I was right.

resources/race/_common.lua

Lines 81-84

getPlayerName() is altered by race to remove the hex code from the string.

Race creates _getPlayerName() which will have the hex code.

What you need to do is use your code + you have to change getPlayerName with _getPlayerName in the dxDrawColorText

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