Jump to content

dx notification


Recommended Posts

:D:D

Client

local sx, sy = guiGetScreenSize () 
  
function notify(x, y, w, h, Title, text, fadeTime) 
    local sx, sy = guiGetScreenSize() 
    local tempTextTable = {} 
    local tempText = "" 
    local isShowing = false; 
    local Alpha = 255; 
    local Alpha2 = 180; 
  
    for token in string.gmatch(text, ".") do 
       table.insert(tempTextTable, token) 
    end 
    local int = 0; 
    for k,v in pairs(tempTextTable) do 
        if ( string.len(tempText) * 10 > w ) then 
            if ( int == 0 ) then 
                tempText = tempText .. "\n" 
                int = 1; 
            end 
        end 
        tempText = tempText .. v; 
    end 
  
    local notify = { 
  
        draw = function () 
            dxDrawRectangle( x, y, w, h, tocolor(0, 0, 0, Alpha2) ) -- main 
            dxDrawText(Title, x + 10, y + 5, 0, 0, tocolor( 255, 0, 0, Alpha ), 2) -- title 
  
            dxDrawLine( x, y, w +x, y, tocolor( 255, 255, 255, Alpha ), 2 ) -- outside 
            dxDrawLine( x, y, x, y + h, tocolor( 255, 255, 255, Alpha ), 2 ) -- outside  
  
            dxDrawLine( x, y + 40, w +x, y + 40, tocolor( 255, 255, 255, Alpha ), 2 ) -- x 
            --outputChatBox(string.len(text) .. ", " .. w) 
            dxDrawText(text, x + 5, y + 45, 0, 0, tocolor(231, 76, 60, Alpha), 1.5) -- text 
        end, 
  
        update = function () 
            if ( x >  sx ) then 
                --removeEventHandler( "onClientRender", getRootElement(), update ) 
                isShowing = false; 
            else 
                x = x + 10; 
            end 
        end, 
  
        isOn = function () 
            return isShowing; 
        end 
  
    } 
  
    function create () 
        addEventHandler( "onClientRender", getRootElement(), notify.draw ) 
        isShowing = true; 
        setTimer(  
            function () 
                addEventHandler( "onClientRender", getRootElement(), notify.update ) 
            end, 
        fadeTime * 1000, 1) 
  
        return notify; 
    end 
  
    return create(); 
end  
  
function ntoX( Title, text, fadeOut ) 
    notify(sx - 300, sy - 100, 300, 100, Title, text, fadeOut) 
end 
  
addEvent( "notify", true ) 
addEventHandler( "notify", getRootElement(), 
    function ( Title, text, fadeIn )  
        ntoX(Title, text, fadeIn) 
    end  
) 

Server

  
function send ( playerSource, commandName, ... ) 
    local arg = {...} 
    if ( arg[1] and arg[2] and arg[3] ) then 
        text = string.gsub(arg[2], "_", " ") 
        Title = string.gsub(arg[1], "_", " ") 
        triggerClientEvent( getElementsByType( "player" ),"notify", getRootElement(), Title, text, tonumber(arg[3]) ) 
    else 
        outputChatBox("use it like so: /notify Title Text fadeTime") 
    end 
end 
addCommandHandler ( "notify", send ) 

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