Timer cleanup?

hello, i would like to cleanup the disconnected player entities 10 minutes after the player disconnect, so, the player’ll keep his prop after a crash or something like that.
here is the code [lua]hook.Add(“PlayerDisconnected”, “CleanUpWhenDisconnect”,
function( ply )
timer.Create(“atimer”, function(ply)
cleanup.CC_Cleanup( ply, “gmod_cleanup”, {} )
end)
end
)[/lua]
but the timer don’t seems to run when the player is disconnected.
Thanks in advance

It doesn’t look like you’ve set it to 10 minutes anywhere in the script.

timer.Simple(600, function(pl) – do cleanup stuff end , pl )

oh sorry i forgot the time here, the code i used was [lua]hook.Add(“PlayerDisconnected”, “CleanUpWhenDisconnect”,
function( ply )
timer.Create(“atimer”, 600, 0, function(ply)
cleanup.CC_Cleanup( ply, “gmod_cleanup”, {} )
end)
end
)[/lua]

You aren’t passing the player into the timer.

so, [lua]function myfunction(ply)
timer.Simple(600, function(ply)
cleanup.CC_Cleanup( ply, “gmod_cleanup”, {} )
end, ply)
end
hook.Add(“PlayerDisconnected”, “CleanUpWhenDisconnect”, myfunction)[/lua]
will work?

Only problem there is that the player has since left the game when the timer runs. So the player is nil.

[editline]01:30PM[/editline]

You need to define which props are owned by the player’s SteamID, then remove all props owned by the SteamID that left.

how can i do that?
did i need to use SetOwner() for all props spawned by the player or something like that?
Edit:
or something like this[lua]function myfunction(ply)
SID = ply:SteamID()
timer.Simple(20, function(ply)
cleanup.CC_Cleanup( SID, “gmod_cleanup”, {} )
end, SID)
end
hook.Add(“PlayerDisconnected”, “CleanUpWhenDisconnect”, myfunction)
[/lua]
i don’t know how cleanup function work because its not explained in the gmod wiki

Not setowner - that disables collisions with the player. Just add a string to each prop when spawned.

[lua]ent.Owner = pl:SteamID()[/lua]

I’m totaly lost in this code :smiley:
dose this’ll work?[lua]function myfunction(ply)
for k, v in ipairs (ents.GetAll())
if v:Owner == ply:SteamID() then
timer.Simple(600, function()
v:Remove()
end)
end
end
end
hook.Add(“PlayerDisconnected”, “CleanUpWhenDisconnect”, myfunction)
function SetOwner(ply, ent)
ent.Owner = ply:SteamID()
end
hook.Add( “PlayerSpawnProp”, “SetOwner”, SetOwner)[/lua]

[lua]function myfunction(ply)
for k, v in ipairs (ents.GetAll()) do
if v.Owner == ply:SteamID() then
timer.Simple(600, function(ent)
ent:Remove()
end , v)
end
end
end
hook.Add(“PlayerDisconnected”, “CleanUpWhenDisconnect”, myfunction)

function SetOwner(ply, ent)
ent.Owner = ply:SteamID()
end
hook.Add( “PlayerSpawnProp”, “SetOwner”, SetOwner)[/lua]

this don’t seem to work and its hard to debug because its called when i disconnect

Do you really need to create possibly dozens of timers?

No. Had to write that code quickly - was busy.