Jump to content

[Help] Rectangle Chat


#Black_Hawk

Recommended Posts

hello guys

i'm trying to do an info bar .. which is working fine and everything great

but the problem is .. when i send more than one message it keeps moving the last messages to the new message's position

like let's say that i sent a message and it shows up to me in a rectangle

so if i sent another one the first one i sent will be moved to the second one's position

so how to fix that ?

 

Code:

local screenW, _ = guiGetScreenSize ()
local TABLE = {}
local POSITION = 0

function txt (text)
    POSITION = POSITION + 20
    table.insert (TABLE, {text, 0})
    setTimer (function ()
        setTimer (function ()
            if POSITION > 0 then
                POSITION = POSITION - 1
                for i, v in pairs (TABLE) do
                    TABLE[i] = {v[1], v[2] - 1}
                    if v[2] <= 0 then
                        table.remove (TABLE, i)
                    end
                end
            end
        end, 50, 20)
    end, 5000, 1)
end

addEventHandler ("onClientPreRender", root, 
    function ()
        for i, v in pairs (TABLE) do
            if (v[2] < POSITION) then
                TABLE[i] = {v[1], v[2] + 1}
            end
            dxDrawRectangle ((screenW - 563)/2, v[2] - 25, 563, 21, tocolor (0, 0, 0, 180))
            dxDrawText (v[1], (screenW - 450)/2, v[2] - 28, (screenW - 448) / 2 + 448, v[2], tocolor (255, 0, 0, 255), 1, "default-bold", "center", "center", true, false, false, true)
        end
    end
)

 

help please

Link to comment

that doesn't work correctly ...

i tried your way like this:

local screenW, _ = guiGetScreenSize ()
local TABLE = {}
local POSITION = 0

function txt (text)
    POSITION = POSITION + 20
    table.insert (TABLE, {text, 0})
    setTimer (function ()
        setTimer (function ()
            if POSITION > 0 then
                POSITION = POSITION - 1
                for i, v in pairs (TABLE) do
                    TABLE[i] = {v[1], v[2] - 1}
                    if v[2] <= 0 then
                        table.remove (TABLE, i)
                    end
                end
            end
        end, 50, 20)
    end, 5000, 1)
end

addEventHandler ("onClientPreRender", root, 
    function ()
        for i, v in pairs (TABLE) do
            dxDrawRectangle ((screenW - 563)/2, (i-1) * 20, 563, 21, tocolor (0, 0, 0, 180))
            dxDrawText (v[1], (screenW - 450)/2, (i-1) * 20, (screenW - 448) / 2 + 448, v[2], tocolor (255, 0, 0, 255), 1, "default-bold", "center", "center", true, false, false, true)
        end
    end
)

but it's not moving slowly down it just appears, also the text doesn't fit the rectangle it shows up above the rectangle

my code above makes the text and the rectangle moving slowly down till it shows to you

so .. any other ways or helps ?

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