Coding a Time Left timer for DarkRP Printer

Hey,

Basically what I’m trying to do here is code a custom printer, and I’ve had trouble creating the Time Left timer to display properly.

Here are some screenshots of the code/printer so far:

Image of the printer in game:

http://i.gyazo.com/9a8b5b06cce576ed22c8e68b916c0486.png

Image of the function handling the timer in cl_init.lua:

Image of where it is drawn onto the printer in cl_init.lua:

http://i.gyazo.com/41e1f7fba9a670f73b8ec338780c1e18.png

Any help would be really appreciated witht his, been stuck for ages.

Cheers.

Okay, you never mentioned what the actual problem was, but I see three noteworthy things in your code:

  1. You call PrintTimer() from withing PrintTimer(), without any condition. That should result in an infinite loop and cause the game to crash. Doesn’t it?
  2. The timer function doesn’t do anything, seemingly intentionally - wouldn’t you want it to print the money?
  3. PrintTimer() is global. Unless you have a good reason for it to be global, consider changing it to local.

[editline]7th March 2015[/editline]

Also if you have two printers at the same time, their timers would clash.

The problem was the two printers at the same time using the same time, sorry for not stating that. Any chance you would know how to make it affect them individually?

[lua]timer.Create( “PrintTimer” … printer:EntIndex(), 30, 0, function() --[[ do your stuff ]] end )[/lua]

Entity:EntIndex

Another option is to use

Entity:GetCreationID - this is guaranteed to be unique even if a printer has been removed and recreated. But this shouldn’t matter anyway :stuck_out_tongue:

If you’re using a timer for the simple reason to count times left / reps left or time-left before generating cash, you don’t need to use a timer…

Bind it to CurTime( ) or SpawnTime ( which you need to set to CurTime when the entity is spawned ) and then you simply calculate how much time is left…

https://dl.dropboxusercontent.com/u/26074909/tutoring/time/understanding_time%20and_basic_time_calculations.lua.html

You can use % 30 so the number will always be 0-30 ( and you can have it count-down by using max_time - ( SpawnTimed % 30 ) )…

Using a timer for that seems like a waste ( especially because timers are failing and aren’t as reliable as they used to be )

Why? In what way is this better or more convenient?
Using a timer is a lot more self-descriptive.