• Showing HUD elements for set amount of time?
    5 replies, posted
Hey again everyone. In my gamemode, I have a function that checks if a player is new, or has already been on the server before. In the case that a player is new, I want a welcome message to display in the center of the screen. [I]Example:[/I] [IMG]http://i.imgur.com/cgAgmTO.jpg[/IMG] It works all fine... But I want it to disappear again. How would I do that? [I]My code:[/I] [CODE] hook.Add("HUDPaint", "welcomeMessage", function() draw.DrawText( "Welcome to MTech!", "welcomeMessageFont", ScrW() * 0.5, ScrH() * 0.25, Color( 156, 42, 42, 255 ), TEXT_ALIGN_CENTER ) end) [/CODE] Any help is appreciated as always :D - Fillipuster
Make a timer and remove it using hook.Remove("HUDPaint", "welcomeMessage")
[QUOTE=ms333;47006935]Make a timer and remove it using hook.Remove("HUDPaint", "welcomeMessage")[/QUOTE] This doesn't work :/ [I]Code:[/I] [CODE] net.Receive("registratorComplete", function(length, client) hook.Add("HUDPaint", "welcomeMessage", function() draw.DrawText( "Welcome to MTech!", "welcomeMessageFont", ScrW() * 0.5, ScrH() * 0.25, Color( 156, 42, 42, 255 ), TEXT_ALIGN_CENTER ) end) timer.Create("welcomeMessageKiller", 5, 1, function() hook.Remove("HUDPaint", "welcomeMessage") end) timer.Start("welcomeMessageKiller") end) [/CODE]
I have a few examples; some require a net-message to be sent to the client, others use HUDPaint ( and they start the counter when LocalPlayer becomes valid ): [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/vgui/display_something_on_initial_spawn.lua.html[/url] [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/vgui/display_something_on_initial_spawn_teams.lua.html[/url] [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/vgui/display_vgui_on_initial_spawn.lua.html[/url] Remove .html to view .lua... If you're using my dev-base you could simple use hook.AddTemp ( or a few helpers such as render.This or draw.This ) which adds a hook for a specific duration before removing it.
[QUOTE=Fillipuster;47007121]This doesn't work :/ [I]Code:[/I] [CODE] net.Receive("registratorComplete", function(length, client) hook.Add("HUDPaint", "welcomeMessage", function() draw.DrawText( "Welcome to MTech!", "welcomeMessageFont", ScrW() * 0.5, ScrH() * 0.25, Color( 156, 42, 42, 255 ), TEXT_ALIGN_CENTER ) end) timer.Create("welcomeMessageKiller", 5, 1, function() hook.Remove("HUDPaint", "welcomeMessage") end) timer.Start("welcomeMessageKiller") end) [/CODE][/QUOTE] Try removing the timer.Start line, it's not necessary.
Just use timer.Simple
Sorry, you need to Log In to post a reply to this thread.