
local meta = FindMetaTable( "Player" );

function meta:SayLocalOOCChat( text )

	local tbl = ents.FindInSphere( self:GetPos(), 180 );
	
	local rec = RecipientFilter();
	
	for k, v in pairs( tbl ) do
	
		if( v:IsPlayer() ) then
		
			rec:AddPlayer( v );
			v:PrintMessage( 2, self:GetRPName() .. ": " .. text );
		
		end
	
	end

	umsg.Start( "LocalOOCChat", rec );
		umsg.String( self:GetRPName() );
		umsg.String( text );
	umsg.End();	

end

function meta:VortLocalChat( text )

	if( not self:Alive() or not self:GetPlayerConscious() ) then
		return;
	end

	local tbl = ents.FindInSphere( self:GetPos(), 180 );
	
	local rec = RecipientFilter();
	
	for k, v in pairs( tbl ) do
	
		if( v:IsPlayer() and v:IsVort() ) then
		
			rec:AddPlayer( v );
			v:PrintMessage( 2, self:GetRPName() .. ": [Vortigese] " .. text );
		
		end
		
		if( v:IsItem() ) then
		
			if( v:GetTable().ItemData.PlayerChat ) then
				
				v:GetTable().ItemData.PlayerChat( v:GetTable().ItemData, self, v, text, ( v:GetPos() - self:EyePos() ):Length(), 1 );
				
			end

		end
	
	end

	umsg.Start( "ChVortigese", rec );
		umsg.String( self:GetRPName() );
		umsg.String( text );
	umsg.End();

end

function meta:SayICAction( text )

	if( not self:Alive() or not self:GetPlayerConscious() ) then
		return;
	end

	if( string.len( text ) < 1 ) then return; end
	if( string.gsub( text, " ", "" ) == "" ) then return; end

	local tbl = ents.FindInSphere( self:GetPos(), 180 );
	
	local rec = RecipientFilter();
	
	for k, v in pairs( tbl ) do
	
		if( v:IsPlayer() ) then
		
			rec:AddPlayer( v );
			v:PrintMessage( 2, "(" .. self:GetRPName() .. ") " .. text );
		
		end
	
	end

	umsg.Start( "SayICAction", rec );
		umsg.String( string.sub( text, 2 ) );
	umsg.End();	
	

end

function meta:DoICAction( text )

	if( not self:Alive() or not self:GetPlayerConscious() ) then
		return;
	end

	if( string.len( text ) < 1 ) then return; end
	if( string.gsub( text, " ", "" ) == "" ) then return; end

	local tbl = ents.FindInSphere( self:GetPos(), 180 );
	
	local rec = RecipientFilter();
	
	for k, v in pairs( tbl ) do
	
		if( v:IsPlayer() ) then
		
			rec:AddPlayer( v );
			v:PrintMessage( 2, self:GetRPName() .. text );
		
		end
	
	end

	umsg.Start( "ICAction", rec );
		umsg.String( "** " .. self:GetRPName() );
		umsg.String( text );
	umsg.End();	

end

function meta:WhisperLocalChat( text )

	if( not self:Alive() or not self:GetPlayerConscious() ) then
		return;
	end

	local tbl = ents.FindInSphere( self:GetPos(), 90 );
	
	local rec = RecipientFilter();
	
	for k, v in pairs( tbl ) do
	
		if( v:IsPlayer() ) then
		
			rec:AddPlayer( v );
			v:PrintMessage( 2, self:GetRPName() .. ": [WHISPER] " .. text );
		
		end
		
		if( v:IsItem() ) then
		
			if( v:GetTable().ItemData.PlayerChat ) then
				
				v:GetTable().ItemData.PlayerChat( v:GetTable().ItemData, self, v, text, ( v:GetPos() - self:EyePos() ):Length(), 1 );
				
			end

		end
	
	end

	umsg.Start( "WhisperICChat", rec );
		umsg.String( self:GetRPName() );
		umsg.String( text );
	umsg.End();

end


function meta:YellLocalChat( text )

	if( not self:Alive() or not self:GetPlayerConscious() ) then
		return;
	end

	local tbl = ents.FindInSphere( self:GetPos(), 600 );
	
	local rec = RecipientFilter();
	
	for k, v in pairs( tbl ) do
	
		if( v:IsPlayer() ) then
		
			rec:AddPlayer( v );
			v:PrintMessage( 2, self:GetRPName() .. ": [YELL] " .. text );
		
		end
	
		if( v:IsItem() ) then
		
			if( v:GetTable().ItemData.PlayerChat ) then
				
				v:GetTable().ItemData.PlayerChat( v:GetTable().ItemData, self, v, text, ( v:GetPos() - self:EyePos() ):Length(), 3 );
				
			end

		end
	
	end

	umsg.Start( "YellICChat", rec );
		umsg.String( self:GetRPName() );
		umsg.String( text );
	umsg.End();

end

function meta:SayLocalChat( text )

	if( not self:Alive() or not self:GetPlayerConscious() ) then
		return;
	end

	local tbl = ents.FindInSphere( self:GetPos(), 180 );
	
	local rec = RecipientFilter();
	
	for k, v in pairs( tbl ) do
	
		if( v:IsPlayer() ) then
		
			rec:AddPlayer( v );
			v:PrintMessage( 2, self:GetRPName() .. ": " .. text );
		
		end
		
		if( v:IsItem() ) then
		
			if( v:GetTable().ItemData.PlayerChat ) then
				
				v:GetTable().ItemData.PlayerChat( v:GetTable().ItemData, self, v, text, ( v:GetPos() - self:EyePos() ):Length(), 2 );
				
			end
		
		end
	
	end

	umsg.Start( "ICChat", rec );
		umsg.String( self:GetRPName() );
		umsg.String( text );
	umsg.End();

end

function meta:SayGlobalChat( text )

	umsg.Start( "OOCChat" );
		umsg.String( self:GetRPName() );
		umsg.Short( self:Team() );
		umsg.String( text );
	umsg.End();
	
	return "[OOC] " .. text;

end

if( not meta.OrigPrintMessage ) then
	meta.OrigPrintMessage = meta.PrintMessage;
end

function meta:PrintMessage( type, msg )

	if( type == 2 ) then
	
		meta.OrigPrintMessage( self, type, msg );
	
	else

		umsg.Start( "PrintBlueMessage", self );
			umsg.String( msg );
		umsg.End();
		
	end

end