LUA Rainbow Coloured Entity

Hey, I’m VERY VERY new to LUA so sorry if I sound stupid and sloppy in this but I have 0 education with LUA.

I want to make my VIP printers for DarkRP a multi-coloured (rainbow) colour but I can’t seem to get it to work.
In the printer’s .lua where the colour option is, I wrote

ENT.PrinterColor   = Color(random(255), random(255), random(255), 255)

which seems to give me no error until I spawn it in and makes the whole map all glitchy and see-through and my gravity gun’s glow outside the viewmodel…

Also how would I set its material?


This is how I do it.

ColorPrinter = function(ent)
	if not IsValid(ent) then return end
	local col = HSVToColor( CurTime() % 6 * 60, 1, 1 )
	ent:SetColor( Color( col.r, col.g, col.b, 255 ) )

It’s not the smoothest transition but it is what it is.

How would I go about putting this in my own code?

Either in ENT:Think or something. Also that speed isn’t really the best way to do it.
Should be RealTime()*speed60, replace speed with whatever.

timer.Create( "colorprinter", 0.35, 0, function() ColorPrinter(self) end)

@ Initialize

I’m so dumb… I can’t tell you how sorry I am. I don’t know what that means with the ENT:Think and what not :ohno:

Think is one of the entity hooks that can be found here:

Does this look right to you? :confused:

If you’re going to be using notepad++ to edit/create lua files at least download the glua notepad++ plugin as it’ll make your life easier. If you want to know if it’ll work why don’t you test it? I’ve given you everything you need to know to make it work.

I tried it and it didn’t work. I just wanted some feedback

The self you’re referencing doesn’t exist in a timer the way you have it set up. You’ll have to either lookup the entity in the timer, or put it in an entity think hook. Or like he said above, put the timer in the entity initialize function, assuming it’s a custom entity.

What entity are you trying to rainbow?

Or just put it in Initialize like I said. >:(

o shit just saw your edit, or maybe I misread.

It’s a money printer for DarkRP. It’s one that’s already in Garry’s Mod: “models/props_c17/consolebox01a.mdl”

I mean, you could just put it in a think hook, do a lookup for all ents by that money printer’s class, and then loop through those and set the color. Not the best way but probably the easiest without editing those core files.

Okay so where would I put the think hook, how, and what format do I put it in? Do I need to put it in a certain order? I feel so dumb.

See example one, and use it server side

Here’s how you’ll find the money printers

function """"""ENT:Initialize()""""""""
	self.damage = 100
	self.IsMoneyPrinter = true
	timer.Simple(180, function() PrintMore(self) end)
	self.sound = CreateSound(self, Sound("ambient/levels/labs/equipment_printer_loop1.wav"))
	self.sound:PlayEx(1, 100)
	""""""""""""timer.Create( "colorprinter", 0.35, 0, function() ColorPrinter(self) end)"""""""""""

I’ve created a new money printer base for the VIP version since I don’t want the regular money printers to be colourful.

I’ve put that in, so now what do I put in my actual money printer’s code? This?

Put it in Think, its bad to abuse timers like that and they will get overwritten every entity created.

Would I be able to add you on steam to talk about it in more detail? I’m really confused how Think works even when reading the Garry’s Mod Wiki