-- functions


local function Lerp(a, b, d) return a + (b - a) * d end

local function UpdateReticle()
	for _, reticle in pairs(MOUSE_GUI:GetChildren()) do
		reticle.Visible	= reticle.Name == MOUSE.Reticle
	end
end

local function UpdateScope()
	SCOPE_GUI.Visible	= scope and aiming
	MOUSE_GUI.Visible	= not SCOPE_GUI.Visible
end

local function Hitmarker(position, damage, armor, headshot)
	local position	= CAMERA:WorldToViewportPoint(position)
	
	local hitmarker	= script.Hitmarker:Clone()
		hitmarker.Position	= UDim2.new(0, position.X, 0, position.Y)
		hitmarker.Size		= UDim2.new(0.05, 0, 0.05, 0)
		hitmarker.Parent	= GUI
		
	if headshot then
		for _, frame in pairs(hitmarker:GetChildren()) do
			if frame.Name ~= "Shadow" then
				frame.BackgroundColor3	= Color3.new(1, 0.2, 0.2)
			end
		end
	end
		
	local infoB		= TweenInfo.new(0.05, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
	local tweenB	= TweenService:Create(hitmarker, infoB, {Size = UDim2.new(0.015, 0, 0.015, 0)})
	
	tweenB:Play()
	Debris:AddItem(hitmarker, 0.1)
	
	local damageLabel	= script.DamageLabel:Clone()
		damageLabel.Position	= UDim2.new(0, position.X, 0, position.Y)
		damageLabel.Size		= UDim2.new(0, 1, 0, 1)
		damageLabel.Text		= tostring(damage)
		damageLabel.TextColor3	= armor and Color3.fromRGB(248, 130, 33) or Color3.fromRGB(230, 230, 230)
		damageLabel.Parent		= GUI
		
	local offset	= math.random(-36, 36)
		
	local infoC		= TweenInfo.new(0.2, Enum.EasingStyle.Elastic, Enum.EasingDirection.Out)
	local tweenC	= TweenService:Create(damageLabel, infoC, {Size = UDim2.new(0, 36, 0, 36); Rotation = offset / 3; Position = UDim2.new(0, position.X + offset, 0, position.Y - 48)})
	local infoD		= TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
	local tweenD	= TweenService:Create(damageLabel, infoD, {TextTransparency = 1; TextStrokeTransparency = 1})
	
	tweenC:Play()
	tweenD:Play()
	Debris:AddItem(damageLabel, 1)
	
	script.HitmarkerSound:Play()
	
	if armor then
		script.ArmorSound:Play()
	end
	if headshot then
		script.HeadshotSound:Play()
	end
end
