• Will this work as a timer
    74 replies, posted
[lua]local spawntimertime = 15 local NextSpawn = math.Round( 0 - ( CurTime() - spawntimertime ) local Spawntimer = math.Round(NextSpawn)*359/spawntimertime[/lua] And then calling it in a derma panel using [lua]RespawnTime:SetText( "You have to wait "..Spawntimer.." sec to spawn" )[/lua] (RespawnTime is the name of a DLabel )
Why dont you just test it? o.O
I just want peoples opinions on how ( if it is possible ) to clean it up and perfect it so it has less chance of glitching and bugging,. And no it doesn't work, it just gives me a random number instead of a countdown :( [editline]05:19PM[/editline] Anyone?
Okay, can I ask you why you multiplied 15 with 359 and then divided with 15 again?
[QUOTE=Busymonkey;22023480]Okay, can I ask you why you multiplied 15 with 359 and then divided with 15 again?[/QUOTE] I don't know, I just looked at how the guy did it with Sledbuild.
I would do something like that. [LUA]local spawntime = CurTime() +15 local timeleft = math.Round( spawntime - CurTime()) RespawnTime:SetText( "You have to wait "..timeleft.." sec to spawn" ) [/LUA]
thankyou sintwin, it works properly, but does not countdown, instead it stays at 15 seconds.
Could I see the derma stuff please :)?
Which part? or do you want all of it?
I suppose it wouldn't hurt saying it all, depends how big it is.
[lua]local RespawnTime = vgui.Create( "DLabel", CharacterCreation ) RespawnTime:SetFont( "BudgetLabel" ) RespawnTime:SetText( "You have to wait "..timeleft.." sec to spawn" ) RespawnTime:SizeToContents() RespawnTime:SetPos( 50, 20 ) RespawnTime:SetVisible( true )[/lua] Respawn stuff [editline]05:51PM[/editline] And of course yours [lua]local spawntime = CurTime() +15 local timeleft = math.Round( spawntime - CurTime()) [/lua]
Where did you put the other code? Did you put a condition before the local spawntime = CurTime() + 15? If you didn't then that is your problem as it will be constantly making it the current time +15 so it will always result in it saying 15. You need some conditioning to when it defines the variable.
Crap, I blame you sinwtwin :argh: Wait, it's already in a function, because the whole derma panel is a function, because I neeeded to send a usermessage for whenever a player dies [editline]05:56PM[/editline] [lua]function CharacterCreationMenu( ply )[/lua] Is the function it is in
:'( I was only correcting the part you sent above, I hope we can kiss and make up. P.S How do you make emoticons.
Seriously, why the multiplying and dividing, lol :P [editline]awr[/editline] Press "reply" and see what he wrote.
You need to update the DLabel text.
[QUOTE=MakeR;22024044]You need to update the DLabel text.[/QUOTE] I thought it could either be that or that there is no conditioning, it could be both lol.
[lua] hook.Add("Think", "UpdateTextHookName", function() RespawnTime:SetText("You have to wait "..timeleft.." sec to spawn") end) [/lua] Try that. SNIP - Oh wait. Try this first. [lua] 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 ) local StartTime = CurTime() [/lua]
Try [lua] local RespawnTime = vgui.Create( "DLabel", CharacterCreation ) RespawnTime:SetFont( "BudgetLabel" ) RespawnTime:SetText( " " ) RespawnTime.Paint = function() surface.SetTextColor( 200, 200, 200, 255 ) surface.SetTextPos( 0, 0 ) surface.DrawText( "You have to wait "..timeleft.." sec to spawn" ) end RespawnTime:SizeToContents() RespawnTime:SetPos( 50, 20 ) RespawnTime:SetVisible( true ) [/lua] That code should update automatically, if I'm correct. DLabel's don't.
[QUOTE=HeavyMtl123;22023497]I don't know, I just looked at how the guy did it with Sledbuild.[/QUOTE] How did you take code that was working and make it not work?
[QUOTE=sintwins;22024095][lua] hook.Add("Think", "UpdateTextHookName", function() RespawnTime:SetText("You have to wait "..timeleft.." sec to spawn") end) [/lua] Try that.[/QUOTE] It's better to use Panel.Think, in my opinion, you're calling that when the frame is closed to, there is no need to do that. [url]http://wiki.garrysmod.com/?title=Panel.Think[/url]
[QUOTE=|King Flawless|;22024138]How did you take code that was working and make it not work?[/QUOTE] All you ever do is go in threads with HeavyMT in and troll him. Is it your new hobby other than flame people who are new at Lua?
[QUOTE=|King Flawless|;22024138]How did you take code that was working and make it not work?[/QUOTE] Because it's just too easy to make it still work, it's more of a challenge to make it not work.
[QUOTE=sintwins;22024156]All you ever do is go in threads with HeavyMT in and troll him. Is it your new hobby other than flame people who are new at Lua?[/QUOTE] He is not new he has been coding for 6 months or so I hear [editline]06:32PM[/editline] [QUOTE=sintwin;22024265]Because it's just too easy to make it still work, it's more of a challenge to make it not work.[/QUOTE] Think you got that mixed up tbh
[QUOTE=|King Flawless|;22024573]He is not new he has been coding for 6 months or so I hear [editline]06:32PM[/editline] Think you got that mixed up tbh[/QUOTE] 6 months is pretty new, and i've been on and off with coding stuff, so there have been time gaps between the times have been coding. So i don't really care whether i know a lot or not. [editline]07:18PM[/editline] Also, one other question to all the other people reading this, i'm having trouble using surface.SetTexture and surface.DrawTexturedRect, because all it does is make a rectangle, but gives it the purple and black checkered effect Code: [lua]function DrawSprite(spritename, x, y, width, height, r, g, b, a) surface.SetTexture("HUDMaterial/new_compass") surface.DrawTexturedRect(ScrW()/2-70, ScrH()-130, 140, 160) end hook.Add("HUDPaint","DrawTheCompass",DrawSprite)[/lua]
[QUOTE=HeavyMtl123;22024903]6 months is pretty new, and i've been on and off with coding stuff, so there have been time gaps between the times have been coding. So i don't really care whether i know a lot or not. [editline]07:18PM[/editline] Also, one other question to all the other people reading this, i'm having trouble using surface.SetTexture and surface.DrawTexturedRect, because all it does is make a rectangle, but gives it the purple and black checkered effect Code: [lua]function DrawSprite(spritename, x, y, width, height, r, g, b, a) surface.SetTexture("HUDMaterial/new_compass") surface.DrawTexturedRect(ScrW()/2-70, ScrH()-130, 140, 160) end hook.Add("HUDPaint","DrawTheCompass",DrawSprite)[/lua][/QUOTE] I think this is because you have to put the texture ID in SetTexture and not the file path. So it is just defaulting to the glitchy purple and black effect. Use this to find its ID. local textureyayay = surface.GetTextureID("HUDMaterial/new_compass") then do surface.SetTexture(textureyayay) instead. And at [QUOTE=|King Flawless|;22024573] Think you got that mixed up tbh[/QUOTE] No, I didn't get mixed up go troll some where else.
[QUOTE=sintwin;22025574]I think this is because you have to put the texture ID in SetTexture and not the file path. So it is just defaulting to the glitchy purple and black effect. Use this to find its ID. local textureyayay = surface.GetTextureID("HUDMaterial/new_compass") then do surface.SetTexture(textureyayay) instead. And at No, I didn't get mixed up go troll some where else.[/QUOTE] Thankyou sintwin, will test it. [editline]08:34PM[/editline] [img]http://i47.tinypic.com/rqzzfn.jpg[/img] This is what I get even if I use your way sintwin. [editline]09:11PM[/editline] Anyone? [editline]09:43PM[/editline] No-one?
Bump
Are you trying to put respawn time into a derma menu? im unsure from all the banter. But if its in a derma menu, then the derma needs to be refreshed to update any numbers.
Yeah, but I think his main issue now is the texture. I am unsure why that is happening, you sure that it is a valid texture? Wait till someone awesome comes and solves it like maker or flapjack lol.
Sorry, you need to Log In to post a reply to this thread.