Make a prop undo after 15 seconds

Hello all,

I’ve got a (probably) very simple question for you guys today. Ok, so this is the case:

[LUA]
ent:SetPos( self.Owner:EyePos() + ( self.Owner:GetAimVector() * 16 ) )
ent:SetAngles( self.Owner:EyeAngles() )
ent:Spawn()[/LUA]

After the ent:Spawn ( in this case it spawns a baby doll prop ) I want to make it (the prop) delete after 15 seconds.
I have tried something with a timer, but couldn’t figure it out.

Maybe you guys know how to do this…?

Thanks in advance.

timer.simple(15, function() ent:Remove() end)

Where should I place this?

Whenever you want to trigger it getting removed after 15 seconds…

[LUA] function SWEP:PrimaryAttack()

self.Weapon:SetNextPrimaryFire( CurTime() + 2.5 )	
self:ThrowMonitor( "models/props_lab/monitor02.mdl" )
    timer.simple(15, function() ent:Remove() end)

end[/LUA]

I want it to get triggered when PrimaryAttack is pressed, but when I add the code, nothing happens.

because it’s timer.Simple not timer.simple… did you not read the error message from console?

`

Yeah, got this error code:
[ERROR] addons/prop gun/lua/weapons/weapon_prop/shared.lua:122: attempt to call field ‘simple’ (a nil value)

  1. ThrowMonitor - addons/prop gun/lua/weapons/weapon_prop/shared.lua:122
  2. unknown - addons/prop gun/lua/weapons/weapon_prop/shared.lua:71

He clearly just stated you need to use timer.Simple not timer.simple

change timer.simple(15, function() ent:Remove() end)

to timer.Simple(15, function() ent:Remove() end)

Sorry, my fault, pasted wrong error. This is the new error, it works, but I want to get rid of the errors:

[ERROR] addons/prop gun/lua/weapons/weapon_prop/shared.lua:57: attempt to index global ‘ent’ (a nil value)

  1. unknown - addons/prop gun/lua/weapons/weapon_prop/shared.lua:57

Timer Failed! [Simple][@addons/prop gun/lua/weapons/weapon_prop/shared.lua (line 57)]

[ERROR] addons/prop gun/lua/weapons/weapon_prop/shared.lua:57: attempt to index global ‘ent’ (a nil value)

  1. unknown - addons/prop gun/lua/weapons/weapon_prop/shared.lua:57

Timer Failed! [Simple][@addons/prop gun/lua/weapons/weapon_prop/shared.lua (line 57)]

Have self:ThrowMonitor() return the entity being created and in PrimaryAttack locally index that value to ent.

How to locally index the value to ent? Like this?
[LUA]local index = ent( “models/props_lab/monitor02.mdl” ) [/LUA]

In your ThrowMonitor method, at the bottom type

[LUA]return ent[/LUA]

And in your PrimaryAttack, replace the call to ThrowMonitor with this:

[LUA]
local ent = self:ThrowMonitor( “models/props_lab/monitor02.mdl” )
[/LUA]

Awh, got another error…

Timer Failed! [Simple][@lua/weapons/weapon_prop/shared.lua (line 72)]

[prop gun] lua/weapons/weapon_prop/shared.lua:57: Tried to use a NULL entity!

  1. Remove - [C]:-1
  2. unknown - lua/weapons/weapon_prop/shared.lua:57

Timer Failed! [Simple][@lua/weapons/weapon_prop/shared.lua (line 57)]

Call the timer in the end of your ThrowMonitor function. And you might wanna show us that function is you expect us to help you.