Darkrp money printer how to add print time bar?

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: http://steamcommunity.com/sharedfiles/filedetails/?id=1111574610

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)


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:

local printTimer = 10
timer.Create( "Printing_TimeLeft", 1, 0, function()
	if printTimer == 0 then
		self:SetMoneyAmount( self:GetMoneyAmount() + 100 )
		printTimer = 10
		printTimer = printTimer - 1
end )

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:)

TIP: [noparse]Use

tags for pasting your code :)[/noparse]

Thank you, also I will use that next time!

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.

local printTime = 10
local printDone = -1
function ENT:Think()
	if(printDone < 0) then
		printDone = CurTime() + printTime
		self:SetNWFloat("PrintDone", printDone)
	if(CurTime() >= printDone ) then
		self:SetMoneyAmount(self:GetMoneyAmount() + 100)
		printDone = CurTime() + printTime
		self:SetNWFloat("PrintDone", printDone)

To get the time left I’m pretty sure can just add this as a text.

self:GetNWFloat("PrintDone",0) - CurTime()

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.

ENT.Type = "anim"
ENT.Base = "base_gmodentity"
ENT.PrintName = "Printer"
ENT.Author = "Reaper"
ENT.Spawnable = true

function ENT:SetupDataTables()

Server side

local printTime = 10
function ENT:Initialize()
  self:SetModel("Your Model")

  self:SetNextPrint(CurTime()+printTime )
  self.IsPrinting = false

function ENT:Think()
  if(self:GetNextPrint() <= CurTime() and !self.IsPrinting) then

function ENT:Print()
  if(self.IsPrinting) then return end
  self.IsPrinting = true
  self:SetNextPrint(CurTime()+printTime )
  self.IsPrinting = false

For the client to get the time left

local timeLeft = math.Round(self:GetNextPrint()-CurTime())

This is also not tested.