This commit is contained in:
listik committed 2026-11-29 15:49:17 +03:00
commit a85391509d
211 files changed
+28903

No files matched your search

+216
View File
@@ -0,0 +1,216 @@
--!strict
-- Draw occlusion outlines and the match's overhead health bars from this camera.
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local Workspace = game:GetService("Workspace")
local localPlayer = Players.LocalPlayer
local enemyColor = Color3.fromRGB(255, 55, 69)
local allyColor = Color3.fromRGB(73, 255, 100)
local barOffset = Vector3.new(0, 1.55, 0)
local barRange = 180
local barMotion = TweenInfo.new(0.14, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
local updateInterval = 0.08
local filter = RaycastParams.new()
filter.FilterType = Enum.RaycastFilterType.Exclude
filter.IgnoreWater = true
local folder = Instance.new("Folder")
folder.Name = "PlayerOcclusionOutlines"
folder.Parent = Workspace
local barFolder = Instance.new("Folder")
barFolder.Name = "ArenaHealthBars"
barFolder.Parent = localPlayer:WaitForChild("PlayerGui")
type HealthBar = {gui: BillboardGui, fill: Frame, fraction: number, tween: Tween?}
local bars: {[Player]: HealthBar} = {}
local outlines: {[Player]: Highlight} = {}
local exclusions: {Instance} = {}
local active: {[Player]: boolean} = {}
local barTargets: {[Player]: boolean} = {}
local function blocked(origin: Vector3, point: Vector3): boolean
local direction = point - origin
while true do
local hit = Workspace:Raycast(origin, direction, filter)
if not hit then return false end
local part = hit.Instance
if part == Workspace.Terrain then
return true
end
local opacity = (1 - part.Transparency) * (1 - part.LocalTransparencyModifier)
if opacity >= 0.35 then return true end
-- Ignore invisible helpers and glass, but keep looking for a wall behind them.
filter:AddToFilter(part)
end
end
local function inFrame(camera: Camera, root: BasePart, head: BasePart): boolean
local center = camera:WorldToViewportPoint(root.Position)
if center.Z <= 0 then return false end
local top = camera:WorldToViewportPoint(head.Position)
local margin = math.max(12, 2.5 * (Vector2.new(center.X, center.Y) - Vector2.new(top.X, top.Y)).Magnitude)
local viewport = camera.ViewportSize
return center.X >= -margin and center.X <= viewport.X + margin
and center.Y >= -margin and center.Y <= viewport.Y + margin
end
local function isHidden(character: Model, root: BasePart, head: BasePart, view: CFrame): boolean
local origin = view.Position
if not blocked(origin, head.Position) then return false end
if not blocked(origin, root.Position) then return false end
local side = view.RightVector * (math.min(head.Size.X, head.Size.Z) * 0.35)
if not blocked(origin, head.Position + side) or not blocked(origin, head.Position - side) then
return false
end
-- Check the rest of the body so that a visible arm or leg also clears the outline.
for _, bodyPart in character:GetChildren() do
if bodyPart:IsA("BasePart") and bodyPart ~= root and bodyPart ~= head and bodyPart.Transparency < 0.65 then
if not blocked(origin, bodyPart.Position) then return false end
end
end
return true
end
local function showOutline(other: Player, character: Model, color: Color3)
local outline = outlines[other]
if not outline then
outline = Instance.new("Highlight")
outline.Name = "OccludedPlayer"
outline.FillTransparency = 1
outline.OutlineTransparency = 0
outline.DepthMode = Enum.HighlightDepthMode.AlwaysOnTop
outlines[other] = outline
end
outline.OutlineColor = color
outline.Adornee = character
outline.Parent = folder
active[other] = true
end
local function clearBar(other: Player, bar: HealthBar)
if bar.tween then bar.tween:Cancel() end
bar.gui:Destroy()
bars[other] = nil
end
local function showBar(other: Player, head: BasePart, fraction: number, color: Color3)
local bar = bars[other]
if bar and bar.gui.Adornee ~= head then
clearBar(other, bar)
bar = nil
end
if not bar then
local gui = Instance.new("BillboardGui")
gui.Name = tostring(other.UserId)
gui.Adornee = head
gui.Size = UDim2.new(3.8, 0, 0, 7)
gui.StudsOffsetWorldSpace = barOffset
gui.MaxDistance = barRange
gui.AlwaysOnTop = true
gui.LightInfluence = 0
local track = Instance.new("Frame")
track.Name = "Track"
track.Size = UDim2.fromScale(1, 1)
track.BackgroundColor3 = Color3.fromRGB(9, 13, 22)
track.BorderSizePixel = 0
track.Parent = gui
local edge = Instance.new("UIStroke")
edge.Color = Color3.fromRGB(5, 7, 12)
edge.Transparency = 0.15
edge.Parent = track
local fill = Instance.new("Frame")
fill.Name = "Fill"
fill.Position = UDim2.fromOffset(1, 1)
fill.Size = UDim2.new(fraction, -2 * fraction, 1, -2)
fill.BorderSizePixel = 0
fill.Parent = track
bar = {gui = gui, fill = fill, fraction = fraction, tween = nil}
bars[other] = bar
gui.Parent = barFolder
elseif bar.fraction ~= fraction then
bar.fraction = fraction
if bar.tween then bar.tween:Cancel() end
local tween = TweenService:Create(bar.fill, barMotion, {Size = UDim2.new(fraction, -2 * fraction, 1, -2)})
bar.tween = tween
tween:Play()
end
bar.fill.BackgroundColor3 = color
bar.gui.Enabled = true
end
local function update()
table.clear(active)
table.clear(barTargets)
local camera = Workspace.CurrentCamera
if camera then
local players = Players:GetPlayers()
local view = camera:GetRenderCFrame()
table.clear(exclusions)
table.insert(exclusions, camera)
for _, player in players do
if player.Character then table.insert(exclusions, player.Character) end
end
filter.FilterDescendantsInstances = exclusions
local inArena = localPlayer:GetAttribute("InArena") == true
local mode = localPlayer:GetAttribute("ArenaMode")
for _, other in players do
local character = other.Character
if other == localPlayer or not character or not character:IsDescendantOf(Workspace) then continue end
local otherInArena = other:GetAttribute("InArena") == true
if otherInArena ~= inArena or (inArena and other:GetAttribute("ArenaMode") ~= mode) then continue end
local humanoid = character:FindFirstChildOfClass("Humanoid")
local root = character:FindFirstChild("HumanoidRootPart")
local head = character:FindFirstChild("Head")
local fraction = character:GetAttribute("ArenaHealthFraction")
if not humanoid or humanoid.Health <= 0 or fraction == 0 or not root or not root:IsA("BasePart")
or not head or not head:IsA("BasePart") then continue end
if inArena and typeof(fraction) == "number" then barTargets[other] = true end
local bar = bars[other]
if not inFrame(camera, root, head) then
if bar then bar.gui.Enabled = false end
continue
end
local sameTeam = localPlayer.Team ~= nil and localPlayer.Team == other.Team
and not localPlayer.Neutral and not other.Neutral
local color = if sameTeam then allyColor else enemyColor
if isHidden(character, root, head, view) then
showOutline(other, character, color)
elseif barTargets[other] and typeof(fraction) == "number" and (head.Position - view.Position).Magnitude <= barRange
and not blocked(view.Position, head.Position + barOffset) then
showBar(other, head, fraction, color)
continue
end
if bar then bar.gui.Enabled = false end
end
end
for other, outline in outlines do
if not active[other] then
outline:Destroy()
outlines[other] = nil
end
end
for other, bar in bars do
if not barTargets[other] then clearBar(other, bar) end
end
end
local elapsed = 0
local connection = RunService.Heartbeat:Connect(function(dt)
elapsed += dt
if elapsed < updateInterval then return end
elapsed %= updateInterval
update()
end)
script.Destroying:Once(function()
connection:Disconnect()
folder:Destroy()
barFolder:Destroy()
end)