I've a problem, the timer won't delete player props:
function UProtect_CreateTimer( ply )
local delay = 10
timer.Create("UProtect_Timer"..ply:UniqueID(), delay, 1, UProtect_RemoveEntities, ply)
end
hook.Add( "PlayerDisconnected", "UProtect_CreateTimer_Hook", UProtect_CreateTimer )
function UProtect_DestroyTimer( ply )
local utimer = "UProtect_Timer"..ply:UniqueID()
if ( timer.IsTimer(utimer) ) then
timer.Destroy(utimer)
end
end
hook.Add( "PlayerInitialSpawn", "UProtect_DestroyTimer_Hook", UProtect_DestroyTimer )
function UProtect_RemoveEntities( ply )
local count = 0
local entities = ents.GetAll()
for _, ent in pairs( entities ) do
if( ent && ent:IsValid() && !ent:IsPlayer() && UProtect_IsOwner(ply, ent) ) then
ent:Remove()
count = count + 1
end
end
if ( ulx && count > 0 ) then
local message = "Deleting " .. ply:Nick() .. "'s " .. count
if ( count < 2 ) then ulx.logString( message .. " entity." )
else ulx.logString( message .. " entities." )
end
end
UProtect_DestroyTimer( ply )
end
//hook.Add( "PlayerDisconnected", "UProtect_RemoveEntities_Hook", UProtect_RemoveEntities )
(The hook at the last line is working if i enable it)
Can someone help me, i don't understand why it don't work :/. Since i started lua coding i haven't did a working timer lol.
Edit:solved