Jump to content

dxDrawText with timer


tosfera

Recommended Posts

hey guys,

I'm trying to create a text, for just a short amount of time (5 seconds). So what I'm basicly trying to do right now, is that a user enters a command (/et), the error msg will be drawn for 5 seconds on the client's screen. So far I got this;

server:

addCommandHandler("et", 
    function ( source ) 
        triggerClientEvent(source, "errorMsg", root, "test") 
    end 
) 

Client:

function errorMsg ( errorStr ) 
    addEventHandler("onClientRender", root, drawErrorMsg(errorStr) ) 
end 
addEvent( "errorMsg", true ) 
addEventHandler( "errorMsg", getRootElement(), errorMsg ) 
  
function drawErrorMsg (errorStr) 
    dxDrawText ( errorStr, screenWidth - (screenWidth /4), screenHeight - (screenHeight/2), screenWidth, screenHeight, tocolor ( 255, 255, 255, 255 ), 1 ) 
end 

it seems like the onClientRender doesn't rly work, cause it just creates the error for 1 frame...

Thanks in advance!

- Tosfera

Link to comment
  • Moderators

Try this (Clientside):

function errorMsg ( errorStr ) 
    addEventHandler("onClientRender", root, drawErrorMsg ) 
    drawErrorMsg(errorStr) 
end 
addEvent( "errorMsg", true ) 
addEventHandler( "errorMsg", getRootElement(), errorMsg ) 
  
function drawErrorMsg (errorStr) 
    dxDrawText ( tostring(errorStr), screenWidth - (screenWidth /4), screenHeight - (screenHeight/2), screenWidth, screenHeight, tocolor ( 255, 255, 255, 255 ), 1 ) 
end 
  

Link to comment

That won't work either.

errorMsg = "" 
  
function errorMsg ( errorStr ) 
    errorMsg = errorStr 
    addEventHandler("onClientRender", root, drawErrorMsg ) 
    setTimer ( 
        function ( ) 
            removeEventHandler("onClientRender", root, drawErrorMsg ) 
        end 
        ,5000, 1 
    ) 
end 
addEvent( "errorMsg", true ) 
addEventHandler( "errorMsg", getRootElement(), errorMsg ) 
  
function drawErrorMsg ( ) 
    dxDrawText ( errorMsg, screenWidth - (screenWidth /4), screenHeight - (screenHeight/2), screenWidth, screenHeight, tocolor ( 255, 255, 255, 255 ), 1 ) 
end 

Link to comment
That won't work either.
errorMsg = "" 
  
function errorMsg ( errorStr ) 
    errorMsg = errorStr 
    addEventHandler("onClientRender", root, drawErrorMsg ) 
    setTimer ( 
        function ( ) 
            removeEventHandler("onClientRender", root, drawErrorMsg ) 
        end 
        ,5000, 1 
    ) 
end 
addEvent( "errorMsg", true ) 
addEventHandler( "errorMsg", getRootElement(), errorMsg ) 
  
function drawErrorMsg ( ) 
    dxDrawText ( errorMsg, screenWidth - (screenWidth /4), screenHeight - (screenHeight/2), screenWidth, screenHeight, tocolor ( 255, 255, 255, 255 ), 1 ) 
end 

Why create anonymous function if you can pass arguments to setTimer?

setTimer ( removeEventHandler, 5000, 1, "onClientRender", root, drawErrorMsg ) 

Link to comment

Ugh I hate to ask stupid questions but I hope this will be my last one! I'm getting a bad 'team' pointer on getTeamName. (trying to save the player teams and give them back when I restart my source)

for id, player in ipairs(getElementsByType("player")) do 
            local team = getTeamName ( getPlayerTeam ( player ) ) 
            local account = getPlayerAccount(player) 
            local teamEnd = getAccountData(account, "player-team", team) 
            setPlayerTeam(player, getTeamFromName( teamEnd ) ) 
        end  

Link to comment

I didn't understand what you trying to do, can you explain somehow better?

local teamEnd = getAccountData(account, "player-team", team) 
setPlayerTeam(player, getTeamFromName( teamEnd ) ) 

I am guess that you meant to use setAccountData not getAccountData or you forgot and put 3 arguments in getAccountData but it required 2 arguments only.

but still if you was meant setAccountData, teamEnd will be a bool and you can't get team from bool, team name must be string lol.

Link to comment
That won't work either.
errorMsg = "" 
  
function errorMsg ( errorStr ) 
    errorMsg = errorStr 
    addEventHandler("onClientRender", root, drawErrorMsg ) 
    setTimer ( 
        function ( ) 
            removeEventHandler("onClientRender", root, drawErrorMsg ) 
        end 
        ,5000, 1 
    ) 
end 
addEvent( "errorMsg", true ) 
addEventHandler( "errorMsg", getRootElement(), errorMsg ) 
  
function drawErrorMsg ( ) 
    dxDrawText ( errorMsg, screenWidth - (screenWidth /4), screenHeight - (screenHeight/2), screenWidth, screenHeight, tocolor ( 255, 255, 255, 255 ), 1 ) 
end 

Why create anonymous function if you can pass arguments to setTimer?

setTimer ( removeEventHandler, 5000, 1, "onClientRender", root, drawErrorMsg ) 

Last time I checked, it didn't work this way, haven't tested it since then.

Link to comment
I didn't understand what you trying to do, can you explain somehow better?
local teamEnd = getAccountData(account, "player-team", team) 
setPlayerTeam(player, getTeamFromName( teamEnd ) ) 

I am guess that you meant to use setAccountData not getAccountData or you forgot and put 3 arguments in getAccountData but it required 2 arguments only.

but still if you was meant setAccountData, teamEnd will be a bool and you can't get team from bool, team name must be string lol.

Thanks! works! :)

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