• Darkrp money printer how to add print time bar?
    6 replies, posted
I have made a money printer and I want to know how I could write text in the cl_init.lua that would show the time left until next print. image of printer: [url]http://steamcommunity.com/sharedfiles/filedetails/?id=1111574610[/url] Heres the code in init.lua for the time located in function ENT:Think() interval = 10 if CurTime() > self.timer + interval then self.timer = CurTime() self:SetMoneyAmount(self:GetMoneyAmount() + 100) end
Due to the way you set it up it's slightly more complicated to get the time until it will print again. I would use: [code] local printTimer = 10 timer.Create( "Printing_TimeLeft", 1, 0, function() if printTimer == 0 then self:SetMoneyAmount( self:GetMoneyAmount() + 100 ) printTimer = 10 else printTimer = printTimer - 1 end end ) [/code] In this case the variable printTimer will output the amount of seconds it has left until printing again, then it will become 10 again. (Also use local for interval as it isn't quite a unique variable name and if you don't need it then why have it anyway :downs:) [B]TIP:[/B] [noparse]Use [code][/code] tags for pasting your code :)[/noparse]
Thank you, also I will use that next time!
[QUOTE=louiefox;52576559]Thank you, also I will use that next time![/QUOTE] Sorry let me be clear about CurTime() often being a better solution than timers. I just told you to use timers because it works better with things that keep track of time such as a countdown (afaik).
Add this instead of the think function you use. [CODE] local printTime = 10 local printDone = -1 function ENT:Think() if(printDone < 0) then printDone = CurTime() + printTime self:SetNWFloat("PrintDone", printDone) end if(CurTime() >= printDone ) then self:SetMoneyAmount(self:GetMoneyAmount() + 100) printDone = CurTime() + printTime self:SetNWFloat("PrintDone", printDone) end end [/CODE] To get the time left I'm pretty sure can just add this as a text. [CODE] self:GetNWFloat("PrintDone",0) - CurTime() [/CODE] This is untested.
galaxybeats, I couldn't get your solution to work. but outlawreaper, yours worked but when I spawned more than one printer, one would print money and all the others would stop until that finished and then alternate...
This is some code I used for a printer I made a while back. For shared lua file. [CODE] ENT.Type = "anim" ENT.Base = "base_gmodentity" ENT.PrintName = "Printer" ENT.Author = "Reaper" ENT.Spawnable = true function ENT:SetupDataTables() self:NetworkVar("Float",0,"NextPrint") self:NetworkVar("Int",0,"MoneyAmount") end [/CODE] Server side [CODE] local printTime = 10 function ENT:Initialize() self:SetModel("Your Model") self:PhysicsInit(SOLID_VPHYSICS) self:SetMoveType(MOVETYPE_VPHYSICS) self:SetSolid(SOLID_VPHYSICS) self:SetMoney(0) self:SetNextPrint(CurTime()+printTime ) self.IsPrinting = false end function ENT:Think() if(self:GetNextPrint() <= CurTime() and !self.IsPrinting) then self:Print() end end function ENT:Print() if(self.IsPrinting) then return end self.IsPrinting = true self:SetMoneyAmount(self:GetMoneyAmount()+100) self:SetNextPrint(CurTime()+printTime ) self.IsPrinting = false end [/CODE] For the client to get the time left [CODE] local timeLeft = math.Round(self:GetNextPrint()-CurTime()) [/CODE] This is also not tested.
Sorry, you need to Log In to post a reply to this thread.