101 lines
4.1 KiB
Luau
101 lines
4.1 KiB
Luau
--!strict
|
||
local rs=game:GetService("ReplicatedStorage")
|
||
local Players=game:GetService("Players")
|
||
local RunService=game:GetService("RunService")
|
||
local TweenService=game:GetService("TweenService")
|
||
local UI=require(rs:WaitForChild("HunterUI") :: ModuleScript)
|
||
local Kinds=require(rs.Hunter.EventKinds)
|
||
local Router=require(script.Parent.EventRouter)
|
||
local player=Players.LocalPlayer
|
||
local match=rs:WaitForChild("ArenaRound"):WaitForChild("Procedural")
|
||
local gui=Instance.new("ScreenGui")
|
||
gui.Name,gui.DisplayOrder,gui.ResetOnSpawn="TrophyCounter",23,false
|
||
gui.Parent=player:WaitForChild("PlayerGui")
|
||
local plate=UI.plate(gui,"Coins",UDim2.new(.5,0,1,-85),UDim2.fromOffset(106,48),UI.Gold)
|
||
plate.AnchorPoint=Vector2.new(.5,1)
|
||
local art=UI.element("GoldCoin",plate,UDim2.fromOffset(6,4),UDim2.fromOffset(40,40)) :: Frame
|
||
local rig=UI.bindCoin(art)
|
||
local label=UI.label(plate,"Count","×0",UDim2.fromOffset(47,0),UDim2.fromOffset(52,48),24,UI.Gold)
|
||
label.FontFace=UI.Display
|
||
local scale=Instance.new("UIScale",plate)
|
||
local bounce: Tween?=nil
|
||
local last=0
|
||
local function update()
|
||
local count=player:GetAttribute("ArenaTokens")
|
||
local n=if typeof(count)=="number" then count else 0
|
||
gui.Enabled=player:GetAttribute("InArena")==true and match:GetAttribute("Ruleset")=="TrophyHunt" and match:GetAttribute("Phase")=="Round"
|
||
label.Text="×"..n
|
||
if gui.Enabled and n>last then
|
||
if bounce then bounce:Cancel() end
|
||
scale.Scale=1.18
|
||
bounce=TweenService:Create(scale,TweenInfo.new(.32,Enum.EasingStyle.Back,Enum.EasingDirection.Out),{Scale=1})
|
||
bounce:Play()
|
||
end
|
||
last=n
|
||
end
|
||
local connections={player:GetAttributeChangedSignal("ArenaTokens"):Connect(update),player:GetAttributeChangedSignal("InArena"):Connect(update),
|
||
match:GetAttributeChangedSignal("Ruleset"):Connect(update),match:GetAttributeChangedSignal("Phase"):Connect(update)}
|
||
local tokens: {[BasePart]: boolean} = {}
|
||
local arena = workspace:WaitForChild("ProceduralArena")
|
||
local function add(item: Instance)
|
||
if item:IsA("BasePart") and item.Name == "Tokens" then tokens[item] = true end
|
||
end
|
||
for _, item in arena:GetDescendants() do add(item) end
|
||
local created = arena.DescendantAdded:Connect(add)
|
||
local removed = arena.DescendantRemoving:Connect(function(item)
|
||
if item:IsA("BasePart") then tokens[item] = nil end
|
||
end)
|
||
local draw=RunService.RenderStepped:Connect(function()
|
||
local now = workspace:GetServerTimeNow()
|
||
for token in tokens do
|
||
local deadline = token:GetAttribute("TokenExpiresAt")
|
||
local flashSeconds = token:GetAttribute("TokenFlashSeconds")
|
||
local flashing = typeof(deadline) == "number" and typeof(flashSeconds) == "number" and deadline - now <= flashSeconds
|
||
token.LocalTransparencyModifier = if flashing then .32 + .26 * math.sin(now * math.pi * 2 / .76) else 0
|
||
end
|
||
if not gui.Enabled then return end
|
||
local t=os.clock()
|
||
UI.spinCoin(rig,t*2,math.max(0,math.cos(t*2))*.55,t%1)
|
||
end)
|
||
|
||
local pool: {Part}={}
|
||
local motions: {[Part]: Tween}={}
|
||
for i=1,6 do
|
||
local coin=Instance.new("Part")
|
||
coin.Name="TrophySpark"
|
||
coin.Shape,coin.Material,coin.Color=Enum.PartType.Cylinder,Enum.Material.Neon,UI.Gold
|
||
coin.Size=Vector3.new(.12,.62,.62)
|
||
coin.Anchored,coin.CanCollide,coin.CanQuery,coin.CanTouch=true,false,false,false
|
||
coin.Transparency=1
|
||
coin.Parent=workspace
|
||
table.insert(pool,coin)
|
||
end
|
||
local off=Router.on(Kinds.TokenDropped,function(payload)
|
||
if not gui.Enabled or typeof(payload.at)~="Vector3" then return end
|
||
for i,coin in pool do
|
||
if motions[coin] then motions[coin]:Cancel() end
|
||
local a=i*math.pi/3
|
||
local from=payload.at+Vector3.yAxis*.7
|
||
coin.CFrame=CFrame.new(from)*CFrame.Angles(a,0,0)
|
||
coin.Transparency=.1
|
||
local tween=TweenService:Create(coin,TweenInfo.new(.55,Enum.EasingStyle.Quad,Enum.EasingDirection.Out),
|
||
{CFrame=CFrame.new(from+Vector3.new(math.cos(a)*4,2.4,math.sin(a)*4))*CFrame.Angles(a,1.7,1),Transparency=1})
|
||
motions[coin]=tween
|
||
tween:Play()
|
||
end
|
||
end)
|
||
update()
|
||
script.Destroying:Once(function()
|
||
draw:Disconnect()
|
||
created:Disconnect()
|
||
removed:Disconnect()
|
||
for token in tokens do token.LocalTransparencyModifier = 0 end
|
||
for _, cn in connections do cn:Disconnect() end
|
||
off()
|
||
for _, coin in pool do
|
||
if motions[coin] then motions[coin]:Cancel() end
|
||
coin:Destroy()
|
||
end
|
||
gui:Destroy()
|
||
end)
|