• Will this work as a timer
    74 replies, posted
[QUOTE=sintwin;22045019]Try putting the think hook before all of the other derma stuff. [lua]hook.Add("Think", "UpdateTextHookName", function() if timeleft == "" then timeleft = 0 end if !LocalPlayer():Alive() then timeleft = math.Round( spawntime - CurTime()) or 0 else local spawntime = CurTime() +15 end end [/lua][/QUOTE] You left out a ")". Did you try what I posted earlier? [lua] local StartTime = CurTime() local RespawnTime = vgui.Create( "DLabel", CharacterCreation ) RespawnTime:SetFont( "BudgetLabel" ) RespawnTime:SetText( "You have to wait ".. ( (StartTime + 15 ) - CurTime() ) .." sec to spawn" ) RespawnTime:SizeToContents() RespawnTime:SetPos( 50, 20 ) RespawnTime:SetVisible( true ) [/lua] SNIP - Put it anywhere in the code above, doesn't matter aslong as its inside the function that creates the derma. And don't you have one too many ends?
[QUOTE=sintwins;22046769]You left out a ")". Did you try what I posted earlier? local StartTime = CurTime() local RespawnTime = vgui.Create( "DLabel", CharacterCreation ) RespawnTime:SetFont( "BudgetLabel" ) RespawnTime:SetText( "You have to wait ".. ( (StartTime + 15 ) - CurTime() ) .." sec to spawn" ) RespawnTime:SizeToContents() RespawnTime:SetPos( 50, 20 ) RespawnTime:SetVisible( true ) SNIP - Put it anywhere in the code above, doesn't matter aslong as its inside the function that creates the derma. And don't you ahve one too many ends?[/QUOTE] I'm going to try it again. No, yours just sticks on 15 seconds and does not count down. There's no errors, it just does not count down
[lua] local StartTime = CurTime() local RespawnTime = vgui.Create( "DLabel", CharacterCreation ) RespawnTime:SetFont( "BudgetLabel" ) RespawnTime:SetText( "You have to wait ".. ( (StartTime + 15 ) - CurTime() ) .." sec to spawn" ) RespawnTime:SizeToContents() RespawnTime:SetPos( 50, 20 ) RespawnTime:SetVisible( true ) RespawnTime.Think = function() RespawnTime:SetText( "You have to wait ".. ( (StartTime + 15 ) - CurTime() ) .." sec to spawn" ) end[/lua] wrote in reply box
[QUOTE=Tobba;22048114] local StartTime = CurTime() local RespawnTime = vgui.Create( "DLabel", CharacterCreation ) RespawnTime:SetFont( "BudgetLabel" ) RespawnTime:SetText( "You have to wait ".. ( (StartTime + 15 ) - CurTime() ) .." sec to spawn" ) RespawnTime:SizeToContents() RespawnTime:SetPos( 50, 20 ) RespawnTime:SetVisible( true ) RespawnTime.Think = function() RespawnTime:SetText( "You have to wait ".. ( (StartTime + 15 ) - CurTime() ) .." sec to spawn" ) end wrote in reply box[/QUOTE] Testing... It works, but is there any way to stop it printing it to about 10 decimal places and make it stop when it reaches 0? Fixed it not stopping at zero. Just need to know if i can stop it printing in decimals as well as whole numbers.
[lua] RespawnTime.Think = function() RespawnTime:SetText( "You have to wait ".. math.Round((StartTime + 15 ) - CurTime() ) .." sec to spawn" ) end [/lua]
[QUOTE=ralle105;22048962]RespawnTime.Think = function() RespawnTime:SetText( "You have to wait ".. math.Round((StartTime + 15 ) - CurTime() ) .." sec to spawn" ) end [/QUOTE] Thankyou. [editline]10:02PM[/editline] Hmm.. I thought I had fixed it going further than 0 with this [lua]RespawnTime.Think = function() RespawnTime:SetText( "You have to wait "..math.Round((StartTime + 15 ) - CurTime()).." secs to spawn" ) if RespawnTime:GetValue() == "You have to wait 0 secs to spawn" then RespawnTime:SetText( "You Can Spawn" ) CloseButton:SetVisible( true ) end end[/lua] But it sets the text to "You Can Spawn" for one second, and then carries on
if math.floor(StartTime + 15 - CurTime()) > 0 then
[QUOTE=|FlapJack|;22049283]if math.floor(StartTime + 15) - CurTime()) > 0 then[/QUOTE] Where the hell have you been Flapjack, this could have been resolved in a matter of seconds with you here :argh: [editline]10:09PM[/editline] Testing to see if it works
Just so you know, I accidentally added extra parenthesis. Fixed in above post.
Oh, btw yours only checks if the number is greater than zero, so it will always say "You can spawn" no matter what, so it should be [lua]math.floor((StartTime + 15) - CurTime()) <= 0 then[/lua] Btw you missed some parenthesis. just after math.floor
[QUOTE=|FlapJack|;22049432]Just so you know, I accidentally added extra parenthesis. Fixed in above post.[/QUOTE] :colbert:
I meant my code should replace if RespawnTime:GetValue() == "You have to wait 0 secs to spawn" then Below that if statement, set the text. In the elseif, set it to "You can spawn" Simple.
[QUOTE=|FlapJack|;22049538]I meant my code should replace if RespawnTime:GetValue() == "You have to wait 0 secs to spawn" then Below that if statement, set the text. In the elseif, set it to "You can spawn" Simple.[/QUOTE] I did replace it, but all it did was permanantly set the text to You can spawn
[lua]RespawnTime.OldThink = RespawnTime.Think RespawnTime.Think = function(...) if math.floor(StartTime + 15 - CurTime()) > 0 then then RespawnTime:SetText("You can spawn in "..math.floor(StartTime + 15 - CurTime()).." seconds") else RespawnTime:SetText( "You can Spawn" ) CloseButton:SetVisible( true ) end return RespawnTime.OldThink(...) end[/lua]
[QUOTE=|FlapJack|;22049704]RespawnTime.OldThink = RespawnTime.Think RespawnTime.Think = function(...) if math.floor(StartTime + 15 - CurTime()) > 0 then then RespawnTime:SetText("You can spawn in "..math.floor(StartTime + 15 - CurTime()).." seconds") else RespawnTime:SetText( "You can Spawn" ) CloseButton:SetVisible( true ) end return RespawnTime.OldThink(...) end[/QUOTE] I didn't need to do that, i just did this: [lua]RespawnTime.Think = function() RespawnTime:SetText( "You have to wait "..math.Round((StartTime + 15 ) - CurTime()).." secs to spawn" ) if math.floor((StartTime + 15) - CurTime()) < 0 then RespawnTime:SetText( "You Can Spawn" ) CloseButton:SetVisible( true ) end end[/lua] Works like a charm
Sorry, you need to Log In to post a reply to this thread.