Jump to content

I need help


Hero192

Recommended Posts

it's topbarchat system, i want let the first rectangle shows with dark color and others shows with alpha 100 for example ,

local timer = nil 
local text = "" 
local text2 = "" 
local messages =  { } 
local r,g,b = 255,255,255 
local isColorCoded = false 
  
function sendMessage( message, red, green, blue, colorCoded ) 
    if colorCoded == nil then 
        colorCoded = false 
    end  
    text = message 
    r = red 
    g = green 
    b = blue 
    isColorCoded = colorCoded 
  
    if isTimer( timer ) then 
        killTimer( timer ) 
    end 
    timer = setTimer( function() text = "" end,   200, 1 ) 
end 
addEvent( "onTextAdd", true ) 
addEventHandler( "onTextAdd", getRootElement(), sendMessage ) 
  
addEventHandler ( "onClientRender", root, function ( ) 
    local tick = getTickCount ( ) 
    local sx,sy = guiGetScreenSize ( ) 
    if ( text ~= text2 and text ~= "" ) then 
        table.insert ( messages, { text, true, tick + 7100, 120, r, g, b, isColorCoded }) 
    end 
     text2 = text 
   
    if ( #messages > 5 ) then 
        table.remove ( messages, 1 ) 
    end 
  
    for index, data in ipairs ( messages ) do 
        local v1 = data[1] 
        local v2 = data[2] 
        local v3 = data[3] 
        local v4 = data[4] 
        local v5 = data[5] 
        local v6 = data[6] 
        local v7 = data[7] 
        local v8 = data[8] 
  
        dxDrawRectangle ( 390, (-22)+(index*21), 593, 21, tocolor( 0, 0, 0, v4+90 ) ) 
        dxDrawText ( v1, 700, (-21)+(index*42), sx/2, 0, tocolor( v5, v6, v7, v4+100 ), 0.85, "default-bold", "center", "center", false, true, false, v8 ) 
        if ( tick >= v3 ) then 
            messages[index][4] = v4-120 
            if ( v4 <= 1 ) then 
                table.remove ( messages, index ) 
            end 
        end 
    end 
end) 
  
  

Link to comment

Just check if the index is equal to 1, if is you draw the text with alpha 240, otherwise with alpha 140

if index == 1 then 
    dxDrawText ( v1, 700, (-21)+(index*42), sx/2, 0, tocolor( 0, 0, 0, 240), 0.85, "default-bold", "center", "center", false, true, false, v8 ) 
else 
    dxDrawText ( v1, 700, (-21)+(index*42), sx/2, 0, tocolor( 0, 0, 0, 140), 0.85, "default-bold", "center", "center", false, true, false, v8 ) 
end 

lines 38~49.

is this what you want?.

Link to comment

Still close enough, the rectangle is drawn on line 48 and the text on line 49. You just have to move the if statement one line up and it does exactly what you want. Sometimes it's wise to read the code you try to edit.

if index == 1 then 
    dxDrawRectangle ( 390, (-22)+(index*21), 593, 21, tocolor( 0, 0, 0, 240 )) 
else 
    dxDrawRectangle ( 390, (-22)+(index*21), 593, 21, tocolor( 0, 0, 0, 120 )) 
end 

Link to comment

I mean always the lastest message be with 240 Alpha and others with 140.

like if 3 Messages sents, the last message of these 3 lines be with 240 others with 140

and if it draw only one message then it show with 240 so last message shows with this alpha 240

I hope you understand abit more

Link to comment

Use the length of the array "messages" then, obtained by #messages. The code will still be very similar to gl0ck's example.

if index == #messages then 
    dxDrawRectangle ( 390, (-22)+(index*21), 593, 21, tocolor( 0, 0, 0, 240 )) 
else 
    dxDrawRectangle ( 390, (-22)+(index*21), 593, 21, tocolor( 0, 0, 0, 120 )) 
end 

* You may need to use "#messages - 1" if the index never get's equal to the length of table "messages", if that happens you'll see all rectangles with alpha 120. Otherwise it should work as you described.

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