
TOOL.ClientConVar[ "r" ] = 255
TOOL.ClientConVar[ "g" ] = 0
TOOL.ClientConVar[ "b" ] = 255
TOOL.ClientConVar[ "a" ] = 255
TOOL.ClientConVar[ "mode" ] = 0
TOOL.ClientConVar[ "fx" ] = 0

function TOOL:LeftClick( trace )

	if trace.Entity && 		// Hit an entity
	   trace.Entity:IsValid() && 	// And the entity is valid
	   trace.Entity:EntIndex() != 0 // And isn't worldspawn
	then

		if (CLIENT) then
			return true 
		end
	
		local r		= tonumber( self:GetClientInfo( "r" ) ) or 0
		local g		= tonumber( self:GetClientInfo( "g" ) ) or 0
		local b		= tonumber( self:GetClientInfo( "b" ) ) or 0
		local a		= tonumber( self:GetClientInfo( "a" ) ) or 0
		local mode	= tonumber( self:GetClientInfo( "mode" ) ) or 0
		local fx	= tonumber( self:GetClientInfo( "fx" ) ) or 0

		SetColour( self:GetOwner(), trace.Entity, r, g, b, a, mode, fx)

		return true
		
	end
	
end

function TOOL:RightClick( trace )

	if trace.Entity && 		// Hit an entity
	   trace.Entity:IsValid() && 	// And the entity is valid
	   trace.Entity:EntIndex() != 0 // And isn't worldspawn
	then

		trace.Entity:SetKeyValue("renderfx", 0)
		trace.Entity:SetRenderMode(0)
		trace.Entity:SetColor(255, 255, 255, 255)
		trace.Entity:GetTable().colour = nil
	
		return true
	
	end
	
end

function SetColour( pl, Ent, r,g,b,a, mode, fx )

	Ent:SetColor( r,g,b, a )
	Ent:SetRenderMode(mode)
	Ent:SetKeyValue("renderfx", fx)

	local etable = {
			r = r,
			g = g,
			b = b,
			a = a,
			mode = mode,
			fx = fx
			}

	Ent:GetTable().colour = etable

	return true
end
duplicator.RegisterEntityModifier( "colour", SetColour, "r","g","b","a", "mode", "fx" )
