• Temporary draw.RoundedBox() & How to make it "move in"?
    8 replies, posted
Hello, I wanted to know how I'd temporary draw on the hud like for five seconds with a function like this: [CODE] function tellhud(text, seconds) -- code here end[/CODE] and that function would draw the text for the given seconds on the hud? plus, I wanted to make the text "fade/slide" in from the side(which could be a third function argument) but I dont know either how to do that, something like in MrCosmicSeagulls video.
Use Derma/vgui instead of a 'HUD'
you can for example make a variable increase: local x = 0; in the hook do x = x + 1, and in the position of text, use the x variable for x positioning but the HUD is different fast on different computers so you could use CurTime() + 0.005 for example and increase the x only then, or a timer.Create once x == what you want, then stop increasing it
[QUOTE=NiandraLades;47841221]Use Derma/vgui instead of a 'HUD'[/QUOTE] Explain that further? Like, I shall add a DPanel, with a timer.simple running like the DPanel:Close() after 5 seconds? but whats the function again to make it like counting to hud, and not "clickable" or so?
I'm not sure if Close() is a thing, but Remove() is and using a timer to remove it is perfectly fine, as well You'd wanna use DFrame as the base vgui component and use stuff like SetDraggable(false) - as long as you don't enable the mouse cursor when it opens, it most likely won't be clickable
VGUI or Derma. I personally define my own vgui and call it. [B]Server[/B] [lua] local ADVERT = CORE.ADVERT local hook = hook local table = table local string = string local chat = chat local pairs = pairs local util = util local colors = { Color(26, 188, 156), Color(46, 204, 113), Color(52, 152, 219), Color(155, 89, 182), Color(241, 196, 15), Color(230, 126, 34), Color(231, 76, 60), } local color = table.FindNext(colors, #colors) local advert util.AddNetworkString("advert_display") hook.Add("Initialize", "GetAdvertss", function() mysql:DoQuery("SELECT * FROM `adverts`", function(data) if data then ADVERT.Adverts = data advert = table.FindNext(ADVERT.Adverts, #ADVERT.Adverts) end end) end) hook.Add("Think", "DisplayAdvertss", function() if !ADVERT.LastThink or ADVERT.LastThink <= CurTime() then if ADVERT.Adverts then color = table.Random(colors) advert = table.FindNext(ADVERT.Adverts, advert) net.Start("advert_display") net.WriteFloat(color.r) net.WriteFloat(color.g) net.WriteFloat(color.b) net.WriteString(advert['ad']) net.Broadcast() ADVERT.LastThink = CurTime() + 60 end end end) [/lua] [B]Shared[/B] [lua] if !CORE.ADVERT then CORE.ADVERT = {} end [/lua] [B]Client[/B] [lua]local ADVERT = CORE.ADVERT local net = net local tonumber = tonumber net.Receive("advert_display", function( len ) local color, text = Color(tonumber(net.ReadFloat()), tonumber(net.ReadFloat()), tonumber(net.ReadFloat())), net.ReadString() ADVERT:AddHistory(color, text) end) [/lua] [lua] local ADVERT = CORE.ADVERT local surface = surface local hook = hook local math = math local gui = gui local os = os local string = string local vgui = vgui local player = player local chat = chat local type = type local pairs = pairs local tonumber = tonumber local tostring = tostring if !ADVERT.History then ADVERT.History = {} end function ADVERT:AddHistory(color, text) ADVERT.History[#ADVERT.History + 1] = { color = color, text = text, added = false } CORE.ADVERT.Adverts:Refresh() end hook.Add("InitPostEntity", "ADVERT.InitPostEntity", function() CORE.ADVERT.Adverts = vgui.Create("Adverts") CORE.ADVERT.Adverts:Init() CORE.ADVERT.Adverts:Hide() end) [/lua] [lua] local ADVERT = CORE.ADVERT local PANEL = {} function PANEL:Init() self:SetZPos(-99999) self:SetPos(-20, -26) self:SetSize(ScrW() + 40, 26) self.Paint = function() surface.DrawBox(0, 0, self:GetWide(), self:GetTall(), Color(30, 30, 30, 200)) end self.Refresh = function() self:MoveTo(-20, 0, 2, 0, 1, function() for k, v in pairs(ADVERT.History, true) do if !v.added then ADVERT.History[k].added = true surface.SetFont("qmd") local w, h = surface.GetTextSize(v.text) local DPanel = vgui.Create("DPanel", self) DPanel:SetPos(ScrW() + 2, 2) DPanel:SetSize(w + 4, h) DPanel.Paint = function() surface.DrawSentence("qmd", Color(0, 0, 0), -1, 1, v.text) surface.DrawSentence("qmd", Color(0, 0, 0), 1, -1, v.text) surface.DrawSentence("qmd", v.color, 0, 0, v.text) end DPanel:MoveTo(-w, 0, 30, 0, 1, function() self:MoveTo(-20, -26, 2, 0, 1) end) end end end) end end function PANEL:Hide() self:SetPos(-20, -26) end vgui.Register("Adverts", PANEL, "DPanel") [/lua] As seen in the top of this video. [media]https://www.youtube.com/watch?v=g2_alMyiVt0[/media]
[QUOTE=NiandraLades;47841316]I'm not sure if Close() is a thing, but Remove() is and using a timer to remove it is perfectly fine, as well You'd wanna use DFrame as the base vgui component and use stuff like SetDraggable(false) - as long as you don't enable the mouse cursor when it opens, it most likely won't be clickable[/QUOTE] You mean about the mouse course the Panel:KillFocus? ( [url]http://wiki.garrysmod.com/page/Panel/KillFocus[/url] ) or what? I only want it displayed like a normal hud box.
this is a very old bit of code which i slightly adapted as an example so not sure if it will even work with latest garrysmod (though looking over the methods all are valid in the current version) and probably not the best way to do it, but it should display text in the top middle of the screen. could give you a basis for knowing what your options are: [code] net.Receive("TestTxt", function() hook.Add("HUDPaint", "Test", CreateText()) timer.Simple(5, function() hook.Remove("HUDPaint", "Test") end) end) function CreateText() local txt = "123" surface.SetFont( "Default" ) surface.SetTextColor( Color( 255, 0, 0, 100 + (math.sin( CurTime() * 20 ) * 80) ) ) local w = surface.GetTextSize( txt ) draw.RoundedBox( 10, ( ScrW() / 2 ) - w / 2 -20, 190, w + 40, 60, Color( 50,50,50, 255 )) surface.SetTextPos( ( ScrW() / 2 ) - w / 2, 200 ) surface.DrawText( txt ) end[/code] didnt bother including the serverside code as im sure you understand how to send a net message to the client.
[QUOTE=Cushie;47842141]this is a very old bit of code which i slightly adapted as an example so not sure if it will even work with latest garrysmod (though looking over the methods all are valid in the current version) and probably not the best way to do it, but it should display text in the top middle of the screen. could give you a basis for knowing what your options are: [code] net.Receive("TestTxt", function() hook.Add("HUDPaint", "Test", CreateText()) timer.Simple(5, function() hook.Remove("HUDPaint", "Test") end) end) function CreateText() local txt = "123" surface.SetFont( "Default" ) surface.SetTextColor( Color( 255, 0, 0, 100 + (math.sin( CurTime() * 20 ) * 80) ) ) local w = surface.GetTextSize( txt ) draw.RoundedBox( 10, ( ScrW() / 2 ) - w / 2 -20, 190, w + 40, 60, Color( 50,50,50, 255 )) surface.SetTextPos( ( ScrW() / 2 ) - w / 2, 200 ) surface.DrawText( txt ) end[/code] didnt bother including the serverside code as im sure you understand how to send a net message to the client.[/QUOTE] I will try this, had a "similair" solution in brain, thanks, couldn't code over the few days because of irl stuff, sorry that I didnt respond. [editline]2nd June 2015[/editline] Okay, Cushie's way works, I actually dont need to use net library, since I will only call this clientside for now. Thanks c:
Sorry, you need to Log In to post a reply to this thread.