Jump to content

DxDrawText Join


Reflex#

Recommended Posts

Hey all.

I want to create dxDrawtText join.

But I think that..what I make is not true..

Help me guys :)

          g_Root = getRootElement() 
          
        addEventHandler('onPlayerJoin',g_Root, 
        function () 
           dxDrawText(Server : ' .. getPlayerName(source) .. ' has joined the game ,3,0,10,10,tocolor(0,0,0,200),0.3,"default") 
  
            end 
        ) 

Link to comment
      g_Root = getRootElement() 
          
        addEventHandler('onPlayerJoin',g_Root, 
        function () 
           dxDrawText('Server : ' .. getPlayerName(source) .. ' has joined the game ',3,0,10,10,tocolor(0,0,0,200),0.3,"default") 
  
            end 
        ) 

Link to comment
onPlayerJoin is a server sided event, and dxDrawText must use "onClientRender" event.

And event is also server-side, but dxDrawText is client-side.

Client-side:

__dxDrawText     = dxDrawText 
local _aDraws    = { } 
  
function dxDrawText( ... ) 
    if( ... ) then 
        _aDraws[{ ... }] = true 
        return true 
    end 
    return false 
end 
  
addEventHandler( 'onClientRender', root, 
    function( ) 
        for arg,v in pairs( _aDraws ) do 
            while true do 
                if( arg[1] == localPlayer ) then 
                    __dxDrawText(  
                        #arg => 2 and arg[2] or false, 
                        #arg => 3 and arg[3] or false, 
                        #arg => 4 and arg[4] or false, 
                        #arg => 5 and arg[5] or false, 
                        #arg => 6 and arg[6] or false, 
                        #arg => 7 and arg[7] or false, 
                        #arg => 8 and arg[8] or false, 
                        #arg => 9 and arg[9] or false, 
                        #arg => 10 and arg[10] or false, 
                        #arg => 11 and arg[11] or false, 
                        #arg => 12 and arg[12] or false, 
                        #arg => 13 and arg[13] or false, 
                        #arg => 14 and arg[14] or false, 
                        #arg => 15 and arg[15] or false, 
                        #arg => 16 and arg[16] or false; 
                    ) 
                end 
            break 
        end 
    end 
) 
  
-- 
  
addEventHandler( 'onPlayerJoin', root, 
    function( ) 
        dxDrawText( root, 'Server: ' .. getPlayerName( source ) .. ' has joined the game!', 3, 0, 10, 10, tocolor( 0, 0, 0, 200 ), 0.3, 'default' ) 
    end 
) 

Server-side:

addEventHandler( 'onPlayerJoin', root, 
    function( ) 
        triggerClientEvent( root, 'onPlayerJoin', source ) 
    end 
) 

Not tested.

Edited by Guest
Link to comment

I don't really understand why you had to do all that Anderl o.O.

local playerJoined 
  
addEventHandler ( "onClientPlayerJoin", root, 
    function ( ) 
        if ( isTimer ( removeTimer ) ) then 
            killTimer ( removeTimer ) 
        end 
        removeEventHandler ( "onClientRender", root, drawJoinMessage ) 
        playerJoined = source 
        addEventHandler ( "onClientRender", root, drawJoinMessage ) 
        removeTimer = setTimer ( 
            function ( ) 
                removeEventHandler ( "onClientRender", root, drawJoinMessage ) 
                playerJoined = nil 
            end 
            ,4000, 1 
        ) 
    end 
) 
  
function drawJoinMessage ( ) 
    if ( playerJoined and isElement ( playerJoined ) ) then 
        dxDrawText ( "Server: ".. getPlayerName ( playerJoined ) .." has joined the game", 3, 0, 10, 10, tocolor ( 0, 0, 0, 200 ), 0.3, "default" ) 
    end 
end 

Link to comment
I don't really understand why you had to do all that Anderl o.O.
local playerJoined 
  
addEventHandler ( "onClientPlayerJoin", root, 
    function ( ) 
        if ( isTimer ( removeTimer ) ) then 
            killTimer ( removeTimer ) 
        end 
        removeEventHandler ( "onClientRender", root, drawJoinMessage ) 
        playerJoined = source 
        addEventHandler ( "onClientRender", root, drawJoinMessage ) 
        removeTimer = setTimer ( 
            function ( ) 
                removeEventHandler ( "onClientRender", root, drawJoinMessage ) 
                playerJoined = nil 
            end 
            ,4000, 1 
        ) 
    end 
) 
  
function drawJoinMessage ( ) 
    if ( playerJoined and isElement ( playerJoined ) ) then 
        dxDrawText ( "Server: ".. getPlayerName ( playerJoined ) .." has joined the game", 3, 0, 10, 10, tocolor ( 0, 0, 0, 200 ), 0.3, "default" ) 
    end 
end 

Because it will be easier than making lots of functions for different texts or declaring lots of variables.

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