timer.Simple troubles.

I am experimenting some with a timer.Simple and timer.Create.

I’ve been testing an entity that when used, activates Godmode by activator:GodEnable, removes itself then initiate a timer that when called disables the Godmode. The GodEnable works just perfectly fine, although the timer doesn’t seem to initiate.

Here is my current code in the init.lua

function ENT:Use(activator, caller) 
	timer.Simple( 5, GodDisable )

the function GodDisable (I have put up in shared.lua, since it didn’t work in init.lua, and it doesn’t seem to work in shared.lua either. :P) gets called after 5 seconds.

ENT.Type = "anim"
ENT.Base = "base_gmodentity"
ENT.PrintName = "Adrenaline"
ENT.Author = "Test"
ENT.Category = "Chemical"
ENT.Spawnable = true
ENT.AdminSpawnable = true

function GodDisable(ply)

I have tried numerous things, All doomed to fail.

Could anyone point me in the good direction? I’d be very thankful.

Have to add the player entity.
This should work.
timer.Simple( 5, GodDisable, activator )

Doesn’t seem to work. The entity spawns, but it can’t be used.

[lua]timer.Simple( 5, function(ply) ply:GodDisable(true) end )[/lua]

Ok, just do this, it should work.

function ENT:Use( activator, caller )
if ( activator:IsPlayer() ) then
timer.Simple( 5, function() activator:GodDisable() end, activator );

Thank you Ronon Dex, and Chewgum for helping me out. It’s working now. :slight_smile:

You don’t need to write self.Entity just self works now.