Jump to content

color problem


SnoopCat

Recommended Posts

hey guys i have a problem , i want to do my race winner message apear whit color codes of players but when i try to do it , it appears white and color code apears whit letter but not the color on the name :S

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) 
      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 
  
addEvent("onWins", true) 
function drawNexMapString(player) 
local x, y = guiGetScreenSize() 
winner = dxText:create(""..getPlayerNametagText(player).." Ha Ganado!!!", x / 2, y / 2 - 10 + 75 - 41, false, "bankgothic", 1, "center") 
nextmap = dxText:create( "Proximo mapa en!:", x / 2, y / 2 - 10 + 75 + 11, false, "bankgothic", 1, "center") 
winner:type('stroke', 1, 0, 0, 0, 255) 
nextmap:type('stroke', 1, 0, 0, 0, 255) 
local timerTime = 5 
timer = dxText:create( tostring(timerTime), x / 2, y / 2 - 10 + 75 + 41, false, "bankgothic", 1, "center") 
timer:type('stroke', 1, 0, 0, 0, 255) 
setTimer(function()timerTime = timerTime - 1 timer:text(tostring(timerTime)) end, 1000, 4) 
setTimer(function()winner:visible(false) nextmap:visible(false) timer:visible(false)end, 5500, 1) 
end 
addEventHandler("onWins", getRootElement(), drawNexMapString) 

Link to comment

I don't see you using any colour coded function.. AFAIK, dxText doesn't support colour coded strings but you can easily modify it to work fine. You can use dxDrawText or the function you included in your script dxDrawColorText.

Link to comment
  
_dxDrawText = dxDrawText 
function dxDrawText(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) 
      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 
  
addEvent("onWins", true) 
function drawNexMapString(player) 
local x, y = guiGetScreenSize() 
winner = dxText:create(""..getPlayerNametagText(player).." Ha Ganado!!!", x / 2, y / 2 - 10 + 75 - 41, false, "bankgothic", 1, "center") 
nextmap = dxText:create( "Proximo mapa en!:", x / 2, y / 2 - 10 + 75 + 11, false, "bankgothic", 1, "center") 
winner:type('stroke', 1, 0, 0, 0, 255) 
nextmap:type('stroke', 1, 0, 0, 0, 255) 
local timerTime = 5 
timer = dxText:create( tostring(timerTime), x / 2, y / 2 - 10 + 75 + 41, false, "bankgothic", 1, "center") 
timer:type('stroke', 1, 0, 0, 0, 255) 
setTimer(function()timerTime = timerTime - 1 timer:text(tostring(timerTime)) end, 1000, 4) 
setTimer(function()winner:visible(false) nextmap:visible(false) timer:visible(false)end, 5500, 1) 
end 
addEventHandler("onWins", getRootElement(), drawNexMapString) 

Link to comment

open your textlib.lua in race

find there

line 187 like:

addEventHandler ( "onClientRender", getRootElement(), 
    function() 
        for self,_ in pairs(visibleText) do 

replace on this code:

addEventHandler ( "onClientRender", getRootElement(), 
    function() 
        for self,_ in pairs(visibleText) do 
            while true do 
                if self.bDestroyed then 
                    visibleText[self] = nil 
                    break 
                end 
                if self.tColor[4] < 1 then 
                    break 
                end 
                local l,t,r,b 
                --If we arent using a bounding box 
                if not self.tBoundingBox then 
                    --Decide if we use relative or absolute 
                    local p_screenX,p_screenY = 1,1 
                    if self.bRelativePosition then 
                        p_screenX,p_screenY = g_screenX,g_screenY 
                    end 
                    local fX,fY = (self.fX)*p_screenX,(self.fY)*p_screenY 
                    if self.bHorizontalAlign == "left" then 
                        l = fX 
                        r = fX + g_screenX 
                    elseif self.bHorizontalAlign == "right" then 
                        l = fX - g_screenX 
                        r = fX 
                    else 
                        l = fX - g_screenX 
                        r = fX + g_screenX 
                    end 
                    if self.bVerticalAlign == "top" then 
                        t = fY 
                        b = fY + g_screenY 
                    elseif self.bVerticalAlign == "bottom" then 
                        t = fY - g_screenY 
                        b = fY 
                    else 
                        t = fY - g_screenY 
                        b = fY + g_screenY 
                    end 
                elseif type(self.tBoundingBox) == "table" then 
                    local b_screenX,b_screenY = 1,1 
                    if self.bRelativeBoundingBox then 
                        b_screenX,b_screenY = g_screenX,g_screenY 
                    end 
                    l,t,r,b = self.tBoundingBox[1],self.tBoundingBox[2],self.tBoundingBox[3],self.tBoundingBox[4] 
                    l = l*b_screenX 
                    t = t*b_screenY 
                    r = r*b_screenX 
                    b = b*b_screenY 
                end 
                local type,att1,att2,att3,att4,att5 = self:type() 
                if type == "border" or type == "stroke" then 
                    att2 = att2 or 0 
                    att3 = att3 or 0 
                    att4 = att4 or 0 
                    att5 = att5 or self.tColor[4] 
                    outlinesize = att1 or 2 
                    if outlinesize > 0 then 
                        for offsetX=-outlinesize,outlinesize,outlinesize do 
                            for offsetY=-outlinesize,outlinesize,outlinesize do 
                                if not (offsetX == 0 and offsetY == 0) then 
                                    dxDrawText(string.gsub(self.strText, '#%x%x%x%x%x%x', ''), l + offsetX, t + offsetY, r + offsetX, b + offsetY, tocolor(att2, att3, att4, att5), self.fScale, self.strFont, self.bHorizontalAlign, self.bVerticalAlign, self.bClip, self.bWordWrap, self.bPostGUI ) 
                                end 
                            end 
                        end 
                    end 
                elseif type == "shadow" then 
                    local shadowDist = att1 
                    att2 = att2 or 0 
                    att3 = att3 or 0 
                    att4 = att4 or 0 
                    att5 = att5 or self.tColor[4] 
                    dxDrawText(string.gsub(self.strText, '#%x%x%x%x%x%x', ''), l + shadowDist, t + shadowDist, r + shadowDist, b + shadowDist, tocolor(att2, att3, att4, att5), self.fScale, self.strFont, self.bHorizontalAlign, self.bVerticalAlign, self.bClip, self.bWordWrap, self.bPostGUI ) 
                end 
                dxDrawColorText ( self.strText, l, t, r, b, tocolor(unpack(self.tColor)), self.fScale, self.strFont, self.bHorizontalAlign, self.bVerticalAlign, self.bClip, self.bWordWrap, self.bPostGUI ) 
                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 

the you can use

dxText:create 

with color code

Link to comment

lol i replaced this

addEventHandler ( "onClientRender", getRootElement(), 
        function() 
            for self,_ in pairs(visibleText) do 
                while true do 
                    if self.bDestroyed then 
                        visibleText[self] = nil 
                        break 
                    end 
                    if self.tColor[4] < 1 then 
                        break 
                    end 
                    local l,t,r,b 
                    --If we arent using a bounding box 
                    if not self.tBoundingBox then 
                        --Decide if we use relative or absolute 
                        local p_screenX,p_screenY = 1,1 
                        if self.bRelativePosition then 
                            p_screenX,p_screenY = g_screenX,g_screenY 
                        end 
                        local fX,fY = (self.fX)*p_screenX,(self.fY)*p_screenY 
                        if self.bHorizontalAlign == "left" then 
                            l = fX 
                            r = fX + g_screenX 
                        elseif self.bHorizontalAlign == "right" then 
                            l = fX - g_screenX 
                            r = fX 
                        else 
                            l = fX - g_screenX 
                            r = fX + g_screenX 
                        end 
                        if self.bVerticalAlign == "top" then 
                            t = fY 
                            b = fY + g_screenY 
                        elseif self.bVerticalAlign == "bottom" then 
                            t = fY - g_screenY 
                            b = fY 
                        else 
                            t = fY - g_screenY 
                            b = fY + g_screenY 
                        end 
                    elseif type(self.tBoundingBox) == "table" then 
                        local b_screenX,b_screenY = 1,1 
                        if self.bRelativeBoundingBox then 
                            b_screenX,b_screenY = g_screenX,g_screenY 
                        end 
                        l,t,r,b = self.tBoundingBox[1],self.tBoundingBox[2],self.tBoundingBox[3],self.tBoundingBox[4] 
                        l = l*b_screenX 
                        t = t*b_screenY 
                        r = r*b_screenX 
                        b = b*b_screenY 
                    end 
                    local type,att1,att2,att3,att4,att5 = self:type() 
                    if type == "border" or type == "stroke" then 
                        att2 = att2 or 0 
                        att3 = att3 or 0 
                        att4 = att4 or 0 
                        att5 = att5 or self.tColor[4] 
                        outlinesize = att1 or 2 
                        if outlinesize > 0 then 
                            for offsetX=-outlinesize,outlinesize,outlinesize do 
                                for offsetY=-outlinesize,outlinesize,outlinesize do 
                                    if not (offsetX == 0 and offsetY == 0) then 
                                        dxDrawText(string.gsub(self.strText, '#%x%x%x%x%x%x', ''), l + offsetX, t + offsetY, r + offsetX, b + offsetY, tocolor(att2, att3, att4, att5), self.fScale, self.strFont, self.bHorizontalAlign, self.bVerticalAlign, self.bClip, self.bWordWrap, self.bPostGUI ) 
                                    end 
                                end 
                            end 
                        end 
                    elseif type == "shadow" then 
                        local shadowDist = att1 
                        att2 = att2 or 0 
                        att3 = att3 or 0 
                        att4 = att4 or 0 
                        att5 = att5 or self.tColor[4] 
                        dxDrawText(string.gsub(self.strText, '#%x%x%x%x%x%x', ''), l + shadowDist, t + shadowDist, r + shadowDist, b + shadowDist, tocolor(att2, att3, att4, att5), self.fScale, self.strFont, self.bHorizontalAlign, self.bVerticalAlign, self.bClip, self.bWordWrap, self.bPostGUI ) 
                    end 
                    dxDrawColorText ( self.strText, l, t, r, b, tocolor(unpack(self.tColor)), self.fScale, self.strFont, self.bHorizontalAlign, self.bVerticalAlign, self.bClip, self.bWordWrap, self.bPostGUI ) 
                    break 
                end 
            end 
        end 
    ) 
  
  
  

for this:

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 
  
  
  

and nothing happens...

a question i have to add this?

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 
  

Add or Replace??

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