How to break timer on wep after cleanup?

Hi again.

One thing. After map is cleaned up with:


function RoundEnd()    local count = #player.GetAll()
    if count < 2 then
        timer.Simple( 30, function() game.CleanUpMap() RoundPrepare() end )
    else
        timer.Simple( 5, function() game.CleanUpMap() RoundPrepare() end )
    end
end

And the weapon is cannon which shoots CRT monitors and delete them after 6 seconds.


timer.Simple( 6, function() ent:Remove() end )

And that’s the problem. After map clean up it will clean props and after that there is error:


[ERROR] gamemodes/smash/entities/weapons/cannon.lua:119: Tried to use a NULL entity!  1. Remove - [C]:-1
   2. unknown - gamemodes/smash/entities/weapons/cannon.lua:119


Any ideas, how to fix this bug?

There is also count for number of players. It’s not the best solution, but it kept me respawning while I’m alone on the server.

You can either add a check if the entity is NULL inside the timer ( preferred method ):


timer.Simple( 6, function() if ( IsValid(ent) ) then ent:Remove() end end )

or you have to use timer.Create in order to be able to stop a timer:



timer.Create("MyUniqueTimerName", 1, 1, function() /*dostuff*/ end ) -- create timer
timer.Destroy("MyUniqueTimerName")--destroy it

Thank you very much :slight_smile: