90 lines
3.5 KiB
Luau
90 lines
3.5 KiB
Luau
--!strict
|
|
local Players=game:GetService("Players")
|
|
local rs=game:GetService("ReplicatedStorage")
|
|
local RunService=game:GetService("RunService")
|
|
local UI=require(rs:WaitForChild("HunterUI") :: ModuleScript)
|
|
local S=require(rs.Hunter.Strings).lifeHints
|
|
local player=Players.LocalPlayer
|
|
local pg=player:WaitForChild("PlayerGui")
|
|
local match=rs:WaitForChild("ArenaRound"):WaitForChild("Procedural")
|
|
local gui=Instance.new("ScreenGui")
|
|
gui.Name,gui.DisplayOrder,gui.ResetOnSpawn,gui.Enabled="OneLifeSpectator",23,false,false
|
|
gui.Parent=pg
|
|
local panel=UI.plate(gui,"Spectator",UDim2.fromScale(.5,.84),UDim2.new(.85,0,0,56),UI.Blue)
|
|
panel.AnchorPoint=Vector2.new(.5,.5)
|
|
Instance.new("UISizeConstraint",panel).MaxSize=Vector2.new(360,56)
|
|
local name=UI.label(panel,"Target","",UDim2.fromOffset(51,0),UDim2.new(1,-102,1,0),16,UI.Ink)
|
|
name.TextTruncate=Enum.TextTruncate.AtEnd
|
|
local targets: {Player}={}
|
|
local selected: Player?=nil
|
|
local control: Humanoid?=nil
|
|
|
|
local function assign()
|
|
local camera=workspace.CurrentCamera
|
|
local subject=selected and selected.Character and selected.Character:FindFirstChildOfClass("Humanoid")
|
|
if not camera or not subject then return end
|
|
control=subject
|
|
camera.CameraSubject=subject
|
|
name.Text=string.format(S.spectate, selected and selected.DisplayName or "")
|
|
end
|
|
|
|
for index, sign in {-1,1} do
|
|
local button=Instance.new("TextButton")
|
|
button.Name=if sign<0 then "Previous" else "Next"
|
|
button.AnchorPoint=Vector2.new(if sign<0 then 0 else 1,.5)
|
|
button.Position=UDim2.new(index-1,if sign<0 then 7 else -7,.5,0)
|
|
button.Size=UDim2.fromOffset(38,38)
|
|
button.BackgroundColor3=UI.Panel
|
|
button.TextColor3=UI.Ink
|
|
button.TextSize=22
|
|
button.Text=if sign<0 then "◀" else "▶"
|
|
button.Parent=panel
|
|
UI.bindButton(button, UI.Blue, true)
|
|
button.Activated:Connect(function()
|
|
if #targets<2 then return end
|
|
local current=table.find(targets,selected :: Player) or 1
|
|
selected=targets[(current+sign-1)%#targets+1]
|
|
assign()
|
|
end)
|
|
end
|
|
|
|
local function reset()
|
|
local camera=workspace.CurrentCamera
|
|
local human=player.Character and player.Character:FindFirstChildOfClass("Humanoid")
|
|
if camera and human and control and camera.CameraSubject==control then camera.CameraSubject=human end
|
|
control,selected=nil,nil
|
|
pg:SetAttribute("HunterSpectating",nil)
|
|
gui.Enabled=false
|
|
end
|
|
|
|
local elapsed=0
|
|
local step=RunService.Heartbeat:Connect(function(dt)
|
|
elapsed+=dt
|
|
if elapsed<.15 then return end
|
|
elapsed%=.15
|
|
local active=player:GetAttribute("InArena")==true and player:GetAttribute("ArenaWaiting")==true
|
|
and match:GetAttribute("Ruleset")=="OneLife" and match:GetAttribute("MiniRoundActive")==true
|
|
if not active then if control or gui.Enabled then reset() end; return end
|
|
local side=player:GetAttribute("ArenaTeam")
|
|
table.clear(targets)
|
|
for _, other in Players:GetPlayers() do
|
|
local human=other.Character and other.Character:FindFirstChildOfClass("Humanoid")
|
|
if other~=player and other:GetAttribute("ArenaTeam")==side and other:GetAttribute("InArena")==true
|
|
and other:GetAttribute("ArenaWaiting")~=true and human and human.Health>0 then
|
|
table.insert(targets,other)
|
|
end
|
|
end
|
|
if #targets==0 then reset(); return end
|
|
if not selected or not table.find(targets,selected) then selected=targets[1] end
|
|
assign()
|
|
local summary=pg:FindFirstChild("ArenaResults")
|
|
local blocked=summary and summary:GetAttribute("LiveScoreboardOpen")==true
|
|
gui.Enabled=not blocked
|
|
pg:SetAttribute("HunterSpectating",if gui.Enabled then true else nil)
|
|
end)
|
|
script.Destroying:Once(function()
|
|
step:Disconnect()
|
|
reset()
|
|
gui:Destroy()
|
|
end)
|