
TOOL.LeftClickAutomatic = true
TOOL.RightClickAutomatic = true
TOOL.RequiresTraceHit = true

TOOL.ClientConVar[ "decal" ] = "Blood"

function TOOL:LeftClick( trace )

	self:GetOwner():EmitSound("SprayCan.Paint")
	local decal	= self:GetClientInfo( "decal" )
	
	local normal = trace.StartPos - trace.HitPos
	normal:Normalize()
	local Pos1, Pos2 = trace.HitPos - normal, trace.HitPos + normal

	util.Decal( decal, Pos1, Pos2 )

	// Add to the entities table if entity is not the world
	local Ent = trace.Entity
	if Ent:IsValid() and Ent:GetClass() != "prop_ragdoll" then
		local decal = {decal, Ent:WorldToLocal(Pos1), Ent:WorldToLocal(Pos2)}

		if not	Ent:GetTable().decals then Ent:GetTable().decals = {} end

		table.insert( Ent:GetTable().decals, 1, decal )

		//Trim decal table so only 50 decals are saved
		if #Ent:GetTable().decals > 50 then
			Ent:GetTable().decals[51] = nil
		end
	end
	
	self:GetWeapon():SetNextPrimaryFire( CurTime() + 0.03 )
	
	return false
	
end

function TOOL:RightClick( trace )

	self:GetOwner():EmitSound("SprayCan.Paint")
	local decal	= self:GetClientInfo( "decal" )
	
	local normal = trace.StartPos - trace.HitPos
	normal:Normalize()
	local Pos1, Pos2 = trace.HitPos - normal, trace.HitPos + normal

	util.Decal( decal, Pos1, Pos2 )

	// Add to the entities table if entity is not the world
	local Ent = trace.Entity
	if Ent:IsValid() and Ent:GetClass() != "prop_ragdoll" then
		local decal = {decal, Ent:WorldToLocal(Pos1), Ent:WorldToLocal(Pos2)}

		if not	Ent:GetTable().decals then Ent:GetTable().decals = {} end

		table.insert( Ent:GetTable().decals, 1, decal )

		//Trim decal table so only 50 decals are saved
		if #Ent:GetTable().decals > 50 then
			Ent:GetTable().decals[51] = nil
		end
	end

	self:GetWeapon():SetNextSecondaryFire( CurTime() + 0.2 )

	// Don't make the shoot effects
	return false
	
end
