Files
Hunter/scripts/CombatFeedback.client.luau
2026-11-29 15:49:17 +03:00

162 lines
5.8 KiB
Luau
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
--!strict
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local player = Players.LocalPlayer
local round = ReplicatedStorage:WaitForChild("ArenaRound")
local window = round:GetAttribute("StreakWindow") :: number
local hitRemote = ReplicatedStorage:WaitForChild("SniperHit") :: RemoteEvent
local effects = require(ReplicatedStorage:WaitForChild("SniperEffects"))
local UI = require(ReplicatedStorage:WaitForChild("HunterUI") :: ModuleScript)
local playerGui = player:WaitForChild("PlayerGui")
local reticle = playerGui:WaitForChild("Crosshair"):WaitForChild("Reticle") :: Frame
local gui = Instance.new("ScreenGui")
gui.Name = "CombatFeedback"
gui.ResetOnSpawn = false
gui.IgnoreGuiInset = true
gui.DisplayOrder = 24
gui.Enabled = false
gui.Parent = playerGui
local panel = UI.element("StreakArc", gui, UDim2.fromScale(.5, .5), nil)
local count = panel:WaitForChild("Multiplier") :: TextLabel
local scale = Instance.new("UIScale", panel)
local countScale = Instance.new("UIScale", count)
local cream = Color3.fromRGB(255, 248, 205)
local amber = Color3.fromRGB(242, 137, 41)
local arcs: {{Frame}} = {}
for section = 1, 2 do
local group = panel:WaitForChild("Segment" .. section)
local pieces: {Frame} = {}
for i = 1, 14 do
table.insert(pieces, group:WaitForChild("Piece" .. i) :: Frame)
end
table.insert(arcs, pieces)
end
local sparks: {Frame} = {}
for i = 1, 6 do
local spark = UI.frame("Spark" .. i, panel, UDim2.fromOffset(0, 0), UDim2.fromOffset(3, 3), cream)
spark.AnchorPoint = Vector2.new(.5, .5)
spark.Visible = false
table.insert(sparks, spark)
end
local function fit()
scale.Scale = if gui.AbsoluteSize.X < 560 then .75 else 1
end
gui:GetPropertyChangedSignal("AbsoluteSize"):Connect(fit)
fit()
local shownKills, expiresAt = 0, 0
local visibleFraction, refillAt, refillFrom = 0, 0, 0
local refillTime = .24
local countMotion: Tween? = nil
local lit = false
local function refresh()
local kills = (player:GetAttribute("StreakKills") :: number?) or 0
local untilTime = (player:GetAttribute("StreakUntil") :: number?) or 0
if player:GetAttribute("InArena") ~= true or kills <= 0 then
shownKills, visibleFraction, expiresAt = 0, 0, 0
return
end
if untilTime == expiresAt and kills == shownKills then return end
shownKills, expiresAt = kills, untilTime
count.Text = "×" .. kills
local now = workspace:GetServerTimeNow()
if expiresAt <= now then return end
refillFrom, refillAt = visibleFraction, now
if countMotion then countMotion:Cancel() end
countScale.Scale = 1.27
countMotion = TweenService:Create(countScale, TweenInfo.new(.29, Enum.EasingStyle.Quart), {Scale = 1})
countMotion:Play()
end
local deferred = false
local function deferRefresh()
if deferred then return end
deferred = true
task.defer(function()
deferred = false
refresh()
end)
end
for _, attribute in {"StreakKills", "StreakUntil", "InArena"} do
player:GetAttributeChangedSignal(attribute):Connect(deferRefresh)
end
refresh()
local heartbeat = RunService.Heartbeat:Connect(function()
local now = workspace:GetServerTimeNow()
local target = if expiresAt > 0 then math.clamp((expiresAt - now) / window, 0, 1) else 0
local tuner = playerGui:FindFirstChild("ViewmodelTuner")
gui.Enabled = reticle.Visible and not (tuner and tuner:IsA("ScreenGui") and tuner.Enabled)
if target == 0 then visibleFraction, expiresAt = 0, 0 end
if not gui.Enabled then return end
count.Visible = target > 0
if target == 0 then
if lit then
for index, pieces in arcs do
for _, piece in pieces do piece.BackgroundTransparency = if index == 1 then .94 else 1 end
end
for _, spark in sparks do spark.Visible = false end
lit = false
end
return
end
lit = true
local age = now - refillAt
local t = math.clamp(age / refillTime, 0, 1)
visibleFraction = refillFrom + (target - refillFrom) * (1 - (1 - t)^3)
for index, pieces in arcs do
local cursor = math.clamp(visibleFraction * 1.12 - (index - 1) * .071, 0, 1) * #pieces
for i, piece in pieces do
local amount = math.clamp(cursor - i + 1, 0, 1)
local leading = math.max(0, 1 - math.abs(cursor - i - .5) / 4)
local shine = leading * (.68 + .24 * math.sin(now * 12)) + .20 * i / #pieces
piece.BackgroundColor3 = amber:Lerp(cream, math.clamp(shine, 0, 1))
piece.BackgroundTransparency = .90 - amount * .87
end
end
local burst = math.clamp(age / .34, 0, 1)
local head = math.rad(76 - 69 * visibleFraction)
for i, spark in sparks do
spark.Visible = burst < 1
if spark.Visible then
local offset = (7 + 3 * i) * burst
local angle = head - (.04 + .055 * burst) * i
spark.Position = UDim2.fromOffset((85 + offset) * math.cos(angle), (77 + offset) * math.sin(angle))
spark.BackgroundTransparency = burst
spark.Rotation = 45 + burst * 90
end
end
end)
script.Destroying:Once(function() heartbeat:Disconnect() end)
local function playing(): boolean
local character = player.Character
local humanoid = character and character:FindFirstChildOfClass("Humanoid")
return player:GetAttribute("InArena") == true and humanoid ~= nil and humanoid.Health > 0
end
hitRemote.OnClientEvent:Connect(function(_position: unknown, _damage: unknown, zone: unknown, killed: unknown, _victim: unknown, streak: unknown)
if not playing() then return end
-- Every server-confirmed impact gets the original hitmarker, even a critical or a kill.
effects.sound("Hit", nil, if zone == "Head" or killed == true then .85 else 1)
if zone == "Head" then effects.sound("Critical") end
if killed == true then
effects.sound("Elimination")
if typeof(streak) == "number" and streak >= 1 then
local character = player.Character
task.delay(.14, function()
if player.Character == character and playing() then effects.sound("StreakAccent") end
end)
end
end
end)