• Derma
    0 replies, posted
I was wondering if there was a way to call afunction to make a line then have it update on it's own? For example: Press button -> Make DLabel and says "You can enable this in 10 seconds" - Every second it decreases by 1 second -> Enables and stays at "0" seconds. At the moment I have: [lua] function PANEL:PerformLayout() PVPButton.DoClick = function() if PVPCanEnable == false then print( "PVP Will be disabled and enable-able again in " .. PVPCanEnableTime .. " seconds!" ) return end PVPEnableVal = PVPEnableVal or 1 PVPEnableVal = PVPEnableVal + 1 if PVPEnableVal % 2 == 0 then -- ON PVPEnabled = "Enabled" PVPEnableTog = true LocalPlayer():SetNWInt( "PvP_On", 1 ) print( "PvP is now enabled." ) PVPCanEnableTimeLeft = 0 elseif PVPEnableVal % 2 == 1 then -- OFF --Set text for "PvP: Enabled" PVPEnabled = "Disabled" PVPEnableTog = false --Making you not able to enable again for 10 seconds and disables pvp after PVPCanEnable = false timer.Create( "pvp_canenable", 10, 1, function() LocalPlayer():SetNWInt( "PvP_On", 0 ) PVPCanEnable = true end ) --DEBUG print( "PvP is now disabled." ) PVPCanEnableTime = CurTime() + 10 --PVPCanEnableTime = PVPCanEnableTime - CurTime() end GAMEMODE.MainMenu.PVPTab:DrawInformation() end PVPCanEnableTimeText = vgui.Create( "DLabel", self ) PVPCanEnableTimeText:SetText( "" ) end function PANEL:Thinkk() if PVPCanEnable == false then PVPCanEnableTimeLeft = PVPCanEnableTime - CurTime() if PVPCanEnableTimeLeft <= 0 then PVPCanEnableTimeLeft = 0 end PVPCanEnableTimeText:SetText( "PvP will disable in " .. PVPCanEnableTimeLeft .. " seconds." ) end end hook.Add( "Think", "ThinkForTime", PANEL:Thinkk() ) function PANEL:DrawInformation() PVPCanEnableTimeText:SetPos( 15, self:GetTall() - 15 ) PVPCanEnableTimeText:SetFont( "UiBold" ) PVPCanEnableTimeText:SetColor(clrDrakGray) PVPCanEnableTimeText:SetText( "PvP will disable in " .. PVPCanEnableTimeLeft .. " seconds. [N/A]" ) PVPCanEnableTimeText:SizeToContents() end [/lua] I know, I know. A lot of unnecessary variables, that's beside the point. Please just help me fix the updating crap, don't say anything bout the variables and "optimizing" it because I will do that after it's set up. I would think SetText would change what the text is, but apparently not.
Sorry, you need to Log In to post a reply to this thread.