Jump to content

[RACE]Colored Deathlist


Admigo

Recommended Posts

Use function dxDrawColoredText

function dxDrawColoredText(str, ax, ay, bx, by, color, scale, font,left,top) 
left = "left" 
if not top then top = "top" 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,left,top,true) 
      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,left,top,true) 
    end 
end 

( found in forum )

Link to comment

Now i have this:

function createShadowedLabelFromSpare(x, y, width, height, text, align) 
  
    if #spareElems < 2 then 
        if not donePrecreate then 
            outputDebug( 'OPTIMIZATION', 'createShadowedLabel' ) 
        end 
        return createShadowedLabel(x, y, width, height, text, align) 
    else 
        local shadow = table.popLast( spareElems ) 
        guiSetSize(shadow, width, height, false) 
        guiSetText(shadow, text) 
        --guiLabelSetColor(shadow, 0, 0, 0) 
        dxDrawText ( text, x, y, width, height, tocolor ( 255, 255, 0, 255 ), 1.02, "pricedown" ) 
        guiSetPosition(shadow, x + 1, y + 1, false) 
        guiSetVisible(shadow, true) 
  
        local label = table.popLast( spareElems ) 
        guiSetSize(label, width, height, false) 
        guiSetText(label, text) 
        --guiLabelSetColor(label, 255, 255, 255) 
        dxDrawText ( text, x, y, width, height, tocolor ( 255, 255, 0, 255 ), 1.02, "pricedown" ) 
        guiSetPosition(label, x, y, false) 
        guiSetVisible(label, true) 
        if align then 
            guiLabelSetHorizontalAlign(shadow, align) 
            guiLabelSetHorizontalAlign(label, align) 
        else 
            guiLabelSetHorizontalAlign(shadow, 'left') 
            guiLabelSetHorizontalAlign(label, 'left') 
        end 
        return label, shadow 
    end 
end 
  

When i press enter the yellow text appears for a sec.

How can i fix this?

Link to comment
Now i have this:
function createShadowedLabelFromSpare(x, y, width, height, text, align) 
  
    if #spareElems < 2 then 
        if not donePrecreate then 
            outputDebug( 'OPTIMIZATION', 'createShadowedLabel' ) 
        end 
        return createShadowedLabel(x, y, width, height, text, align) 
    else 
        local shadow = table.popLast( spareElems ) 
        guiSetSize(shadow, width, height, false) 
        guiSetText(shadow, text) 
        --guiLabelSetColor(shadow, 0, 0, 0) 
        dxDrawText ( text, x, y, width, height, tocolor ( 255, 255, 0, 255 ), 1.02, "pricedown" ) 
        guiSetPosition(shadow, x + 1, y + 1, false) 
        guiSetVisible(shadow, true) 
  
        local label = table.popLast( spareElems ) 
        guiSetSize(label, width, height, false) 
        guiSetText(label, text) 
        --guiLabelSetColor(label, 255, 255, 255) 
        dxDrawText ( text, x, y, width, height, tocolor ( 255, 255, 0, 255 ), 1.02, "pricedown" ) 
        guiSetPosition(label, x, y, false) 
        guiSetVisible(label, true) 
        if align then 
            guiLabelSetHorizontalAlign(shadow, align) 
            guiLabelSetHorizontalAlign(label, align) 
        else 
            guiLabelSetHorizontalAlign(shadow, 'left') 
            guiLabelSetHorizontalAlign(label, 'left') 
        end 
        return label, shadow 
    end 
end 
  

When i press enter the yellow text appears for a sec.

How can i fix this?

u not use dxDrawColorText here

Example:

dxDrawColoredText( text, x, y, width, height, tocolor ( 255, 255, 0, 255 ), 1.02, "pricedown" ) 

Link to comment

Made This:

function HandleTheRendering ( ) 
    addEventHandler ( "onClientRender", root, createShadowedLabelFromSpare ) -- keep the text visible with onClientRender. 
end 
  
addEventHandler ( "onClientResourceStart", resourceRoot, HandleTheRendering )  

Debugscript 3:

Util_client:attempt to perform arithmetic on local x(a nil valua) 

Link to comment

Still same error:

Util_client:attempt to perform arithmetic on local x(a nil valua) 

Error line:

    local shadow = guiCreateLabel(x + 1, y + 1, width, height, text, false) 

My full code:

function createShadowedLabelFromSpare(x, y, width, height, text, align) 
  
    if #spareElems < 2 then 
        if not donePrecreate then 
            outputDebug( 'OPTIMIZATION', 'createShadowedLabel' ) 
        end 
        return createShadowedLabel(x, y, width, height, text, align) 
    else 
        local shadow = table.popLast( spareElems ) 
        guiSetSize(shadow, width, height, false) 
        guiSetText(shadow, text) 
        --guiLabelSetColor(shadow, 0, 0, 0) 
        dxDrawText ( text, x, y, width, height, tocolor ( 255, 255, 0, 255 ), 1.02, "pricedown" ) 
        guiSetPosition(shadow, x + 1, y + 1, false) 
        guiSetVisible(shadow, true) 
  
        local label = table.popLast( spareElems ) 
        guiSetSize(label, width, height, false) 
        guiSetText(label, text) 
        --guiLabelSetColor(label, 255, 255, 255) 
        dxDrawText ( text, x, y, width, height, tocolor ( 255, 255, 0, 255 ), 1.02, "pricedown" ) 
        guiSetPosition(label, x, y, false) 
        guiSetVisible(label, true) 
        if align then 
            guiLabelSetHorizontalAlign(shadow, align) 
            guiLabelSetHorizontalAlign(label, align) 
        else 
            guiLabelSetHorizontalAlign(shadow, 'left') 
            guiLabelSetHorizontalAlign(label, 'left') 
        end 
        return label, shadow 
    end 
end 
addEventHandler ( "onClientRender", root, createShadowedLabelFromSpare ) 

How can i fix this pls?

Link to comment
I just dont get it:P

there's nothing to get..

you either know how to adapt an existent GUI script to use DX Text or you don't, in which case you're left with 2 choices:

-learn lua and do it yourself

-sit back, relax, enjoy life and have someone else do it for you in exchange for money (unless there's someone willing to do it for free)

Link to comment
  • 2 weeks later...

Off-topic:

I've edited dxDrawColorText and added alignX,alignY,clip,wordbreak and postGUI parameters like dxDrawText.

Here:

    function dxDrawColoredText(str, ax, ay, bx, by, color, scale, font, left, top, clip, wordbreak, postGUI) 
        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, left, top, clip, wordbreak, postGUI ) 
        end 
    end 

Example:

dxDrawColoredText('#ff0000My #00ff00text',posX,posY,width,height,tocolor(r,g,b,a),1.0,"pricedown","left","top",false,false,true) 

I don't know if someone has done this :S

Link to comment
  • 1 month later...

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