
local meta = FindMetaTable( "Player" )


// This is totally in the wrong place. 
function player.GetByUniqueID( ID )

	for _, pl in pairs( player.GetAll() ) do

		if ( pl:IsValid() && pl:IsPlayer() && pl:UniqueID() == ID )	then
			return pl
		end
		
	end

	return false
end


// Return if there's nothing to add on to
if (!meta) then return end


/*---------------------------------------------------------
   Name:	DebugInfo
   Params: 	
   Desc:	Prints debug information for the player
			( this is just an example )
---------------------------------------------------------*/  
function meta:DebugInfo()

	Msg( "Name: " .. self:Name() .. "\n" )
	Msg( "Pos: " .. tostring( self:GetPos() ) .. "\n" )

end

// Helpful aliases
meta.GetName 	= meta.Nick
meta.Name 		= meta.Nick



/*---------------------------------------------------------
   Name:	ConCommand
   Params: 	
   Desc:	Overrides the default ConCommand function
---------------------------------------------------------*/ 
if ( CLIENT ) then

	local SendConCommand = meta.ConCommand
	local CommandList = nil
	
	function meta:ConCommand( command, bSkipQueue )
		
		if ( bSkipQueue ) then
			SendConCommand( self, command )
		else
			CommandList = CommandList or {}
			table.insert( CommandList, command )
		end
		
	end
	
	local function SendQueuedConsoleCommands()
	
		if (!CommandList) then return end
		
		local BytesSent = 0
		
		for k, v in pairs( CommandList ) do
		
			SendConCommand( LocalPlayer(), v )
			CommandList[ k ] = nil
			
			// Only send x bytes per tick
			BytesSent = BytesSent + v:len()
			if ( BytesSent > 128 ) then
				break
			end
		
		end
		
		// Turn the table into a nil so we can return easy
		if ( table.Count( CommandList ) == 0 ) then 
		
			CommandList = nil
			
		end
	
	end
	
	hook.Add( "Tick", "SendQueuedConsoleCommands", SendQueuedConsoleCommands )

end
