General > Developers Corner

How to make motd stay up for certain times??

(1/1)

Lalala:
I know how to create accept and decline buttons
I can't figure this out would love for someone to post the code I would need soon.
Thanks

krooks:
I'm not a lua coder by any means, but I ran across this bit of code in the sui scoreboard:


--- Code: ---timer.Simple( 1.5, function()
--your code
)
--- End code ---

Maybe it can help?

nathan736:
to do this you would need to create  a timer based accept button  that gets disabled when crated and starts a timer that reinables it but make sure any code that needs what is ran in the timer to be done first is in the function of the timer as well or it won't work
ps: i don't know gui lua code so take this with a  bag of salt

MrPresident:
Here's how I do it. I don't use the built in ULX MOTD though. This would take some modification to the base ULX code to make this work with their MOTD.


--- Code: ---/*--------------------------------
---------------TOS----------------
--------------------------------*/
local PANEL = {}

function PANEL:Init()
    self:SetPos((ScrW() / 2) - 400, 30)
    self:SetSize(800, 650)
    self:SetVisible(false)


self.time = SGS.tostime
self.nextthink = CurTime() + 1
self.bdisabled = true

self:DrawFrame()


end

function PANEL:Paint( w, h )

draw.RoundedBoxEx( 16, 0, 0, self:GetWide(), self:GetTall(), Color(80, 80, 80, 150), true, true, true, true )

end

function PANEL:DrawFrame()
HTMLPanel = vgui.Create("DPanel", self)
HTMLPanel:SetPos(8,64)
HTMLPanel:SetSize(782, 500)


HTMLTest = vgui.Create("HTML", HTMLPanel)
HTMLTest:SetPos(0,0)
HTMLTest:Dock( FILL )
HTMLTest:OpenURL("http://www.g4p.org/Stranded/TOS/")

TOSbutton = vgui.Create( "DButton", self )
TOSbutton:SetSize( 120, 40 )
TOSbutton:SetPos( 8, 572 )
TOSbutton:SetText( "Wait: " .. self.time )
TOSbutton:SetDisabled( true )
TOSbutton.DoClick = function( TOSbutton )
if TOSbutton:GetDisabled() then return end
SGS.accepttos = true
RunConsoleCommand("sgs_refreshmodelpanel")
RunConsoleCommand("sgs_tosaccept")
self:Remove()
end

TOSbutton2 = vgui.Create( "DButton", self )
TOSbutton2:SetSize( 120, 40 )
TOSbutton2:SetPos( 136, 572 )
TOSbutton2:SetText( "I DON'T ACCEPT" )
TOSbutton2.DoClick = function( TOSbutton2 )
RunConsoleCommand("disconnect")
end


end


function PANEL:Think()
if CurTime() < self.nextthink then return end
if self.bdisabled then
if self.time > 0 then
self.time = self.time - 1
TOSbutton:SetText( "Wait: " .. self.time )
TOSbutton:SetDisabled( true )
else
TOSbutton:SetText( "I ACCEPT" )
TOSbutton:SetDisabled( false )
self.bdisabled = false
end
end
self.nextthink = CurTime() + 1
end

vgui.Register("sgs_tospanel", PANEL, "Panel")

--- End code ---

Navigation

[0] Message Index

Go to full version