• HUD Text Appearing Then Disappearing
    4 replies, posted
Hello, I am trying to make text appear when a player gains experience then disappear after a few seconds or so. I know how to detect a player EXP gain, but I was wondering what's the method for doing it. Should I create a timer, set the color alpha so it's visible then after a few seconds set the alpha to invisible? If there is an easier way please tell me or if this is the best way to do it. Thanks!
I create my own element. Then spawn it when necessary, maybe this will help you. [lua]     local Error = {}     function Error:Init()         timer.Simple(2, function() if IsValid(self) then self:Remove() end end)     end     function Error:Paint( w, h )         draw.RoundedBox( 0, 0, 0, w, h, Color(40, 40, 40, 200) )         surface.SetFont("TheDefaultSettingsBig")         local width, height = surface.GetTextSize( self.Msg )         draw.SimpleTextOutlined( self.Msg, "TheDefaultSettingsBig", (self:GetWide()*0.5)-(width*0.5), (self:GetTall()*0.5)-(height*0.5), Color(200, 200, 200, 255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP, 1, Color(40, 40, 40, 255))     end     function Error:OnMousePressed()         self:Remove()     end     function Error:OnMouseReleased()     end     vgui.Register( "rts_error", Error, "Panel" ) if SERVER then     util.AddNetworkString("Error_Message")     function SendError(client, error, bool)         net.Start("Error_Message")             net.WriteString(error)             if bool == 2 then                 net.WriteFloat(2)             end         net.Send(client)     end else     net.Receive("Error_Message", function(len, pl)         local msg = net.ReadString()         local Bool = net.ReadFloat()         Display_Error(msg)         if Bool == 2 then             if IsValid(Teams_Menu) then                 Teams_Menu:Remove()                 gui.EnableScreenClicker( false )             end         end     end)     function Display_Error(msg)         surface.SetFont("TheDefaultSettingsBig")         local width, height = surface.GetTextSize( msg )         if IsValid(err) then             err:Remove()         end         err = vgui.Create( "rts_error" )         err.Msg = msg         err:SetSize(width+16, height+16)         err:SetPos((ScrW()*0.5)-(err:GetWide()*0.5), (ScrH()*0.5)-(err:GetTall()*0.5))         err:SetVisible( true )     end end [/lua]
Interesting method, thank you
If you want something simpler that requires the use of a single function and fades away instead of just disappearing: local XP = {} XP.alpha = 0 XP.XPnotification = function(gain)     XP.alpha = 595     XP.gain = gain     hook.Add("HUDPaint", "draw_xp_gain", XP.drawXPnotification) end XP.drawXPnotification = function()     if not (XP.alpha > 0) then hook.Remove("HUDPaint", "draw_xp_gain") return end     draw.SimpleText("+" .. XP.gain, "ChatFont", 20, 20, Color(230, 230, 230, XP.alpha))     XP.alpha = XP.alpha - 15 * FrameTime() * 10 end
Wow that's easier! Thanks man!
Sorry, you need to Log In to post a reply to this thread.