Is creating a timer that runs for 0 seconds and does the following okay?


function GM:PlayerDeath( ply, ent, att )

	timer.Simple( 0, function()
	
	if ply:IsValid() then
	
		ply:SetTeam( TEAM_SPECTATOR )
		ply:Spectate( OBS_MODE_ROAMING )
		
		if team.NumPlayers( TEAM_SPECTATOR ) == #player.GetAll() then
	
			PrintMessage( HUD_PRINTTALK, "The Squad Of Resistance Troops Has Been Eliminated. New Round Starting." )
			
			timer.Simple( 10, function() 
			
				MapChange( { "gm_construct", "gm_pvpbattle", "gm_builderinov2", "sv2_warehouse" } )
			
			end )
	
		end
		
	end
	end)
	
	ply:EmitSound( table.Random( deathsounds ), 75, 100 )
	
end


Is creating a timer that runs for 0 seconds and does the following okay? Note: MapChange is a defined function in the gamemode I’m making.

It’s okay, but pointless. Make sure that you use IsValid( ply ) in case ply is nil. Also, your emitsound is outside of your validity check

Pointless? Because of some of the errors I made, or it’s pointless in general?

[editline]15th May 2015[/editline]

I’m guessing because of some of the errors, noone would really say something is pointless then give you tips to improve upon the very same thing they called pointless

I’m saying the 0 second timer is pointless. What’s the purpose of it as opposed to running the function plain?

Oh. Well, I put the 0 second timer in so I wouldn’t have to create two extra functions for it. I could use it though, still, right? It would work. What would be a better way, though?

-snip, never knew about the 0-second timer hack, nevermind-

Oh, I worded that wrong. Oh well, well, using the 0 second timer would work, right? Do you mean that as opposed to my current code, I could use


function GM:PlayerDeath( ply, ent, att )
	
	if ply:IsValid() then
	
		ply:SetTeam( TEAM_SPECTATOR )
		ply:Spectate( OBS_MODE_ROAMING )
		
		if team.NumPlayers( TEAM_SPECTATOR ) == #player.GetAll() then
	
			PrintMessage( HUD_PRINTTALK, "The Squad Of Resistance Troops Has Been Eliminated. New Round Starting." )
			
			timer.Simple( 10, function() 
			
				MapChange( { "gm_construct", "gm_pvpbattle", "gm_builderinov2", "sv2_warehouse" } )
			
			end )
	
		end
		
	end
	
	ply:EmitSound( table.Random( deathsounds ), 75, 100 )
	
end


?

[editline]15th May 2015[/editline]

0-second timer hack? Even I’ve never heard of that. So, I guess that means having the timer is necessary?