1
This commit is contained in:
commit
a85391509d
211 files changed
+28903
No files matched your search
@@ -0,0 +1,154 @@
|
||||
--!strict
|
||||
local Players = game:GetService("Players")
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local RunService = game:GetService("RunService")
|
||||
local effects = require(ReplicatedStorage:WaitForChild("SniperEffects") :: ModuleScript)
|
||||
local damageTaken = ReplicatedStorage:WaitForChild("DamageTaken") :: RemoteEvent
|
||||
local player = Players.LocalPlayer
|
||||
|
||||
local gui = Instance.new("ScreenGui")
|
||||
gui.Name = "DamageFeedback"
|
||||
gui.ResetOnSpawn = false
|
||||
gui.ScreenInsets = Enum.ScreenInsets.None
|
||||
gui.DisplayOrder = 1001
|
||||
gui.Parent = player:WaitForChild("PlayerGui")
|
||||
|
||||
type Edge = "Top" | "Right" | "Bottom" | "Left"
|
||||
type Strip = {frame: Frame, weight: number}
|
||||
type Impact = {direction: Vector3, at: number, strength: number}
|
||||
local sectorNames = {"Front", "FrontRight", "Right", "BackRight", "Back", "BackLeft", "Left", "FrontLeft"}
|
||||
local sectors: {{Strip}} = {}
|
||||
local impacts: {[number]: Impact} = {}
|
||||
local strengths = table.create(#sectorNames, 0)
|
||||
local rotations = {Top = 90, Right = 180, Bottom = 270, Left = 0}
|
||||
local duration = .55
|
||||
local fade = NumberSequence.new({
|
||||
NumberSequenceKeypoint.new(0, 0),
|
||||
NumberSequenceKeypoint.new(.11, .16),
|
||||
NumberSequenceKeypoint.new(.45, .6),
|
||||
NumberSequenceKeypoint.new(.77, .92),
|
||||
NumberSequenceKeypoint.new(1, 1),
|
||||
})
|
||||
local color = ColorSequence.new(Color3.fromRGB(255, 66, 75), Color3.fromRGB(165, 7, 29))
|
||||
|
||||
local function addEdge(sector: {Strip}, container: Frame, edge: Edge, center: number, size: number)
|
||||
for i = -1, 1 do
|
||||
local main = i == 0
|
||||
local along = center + i * .091 * size
|
||||
local length = (if main then .117 else .051) * size
|
||||
local depth = if main then .13 else .09
|
||||
local horizontal = edge == "Top" or edge == "Bottom"
|
||||
local strip = Instance.new("Frame")
|
||||
strip.Name = edge .. tostring(i + 2)
|
||||
strip.BackgroundColor3 = Color3.new(1, 1, 1)
|
||||
strip.BackgroundTransparency = 1
|
||||
strip.BorderSizePixel = 0
|
||||
strip.AnchorPoint = if horizontal then Vector2.new(.5, if edge == "Top" then 0 else 1)
|
||||
else Vector2.new(if edge == "Left" then 0 else 1, .5)
|
||||
strip.Position = if horizontal then UDim2.fromScale(along, if edge == "Top" then 0 else 1)
|
||||
else UDim2.fromScale(if edge == "Left" then 0 else 1, along)
|
||||
strip.Size = if horizontal then UDim2.fromScale(length, depth) else UDim2.fromScale(depth * .62, length)
|
||||
strip.Visible = false
|
||||
strip.Parent = container
|
||||
local gradient = Instance.new("UIGradient")
|
||||
gradient.Rotation = rotations[edge]
|
||||
gradient.Color = color
|
||||
gradient.Transparency = fade
|
||||
gradient.Parent = strip
|
||||
table.insert(sector, {frame = strip, weight = if main then 1 else .6})
|
||||
end
|
||||
end
|
||||
|
||||
for i, name in sectorNames do
|
||||
local container = Instance.new("Frame")
|
||||
container.Name = name
|
||||
container.BackgroundTransparency = 1
|
||||
container.Size = UDim2.fromScale(1, 1)
|
||||
container.Parent = gui
|
||||
sectors[i] = {}
|
||||
end
|
||||
local function edge(i: number, side: Edge, center: number, size: number)
|
||||
addEdge(sectors[i], gui:FindFirstChild(sectorNames[i]) :: Frame, side, center, size)
|
||||
end
|
||||
local nearCorner, farCorner, cornerSize = .14, .86, .72
|
||||
edge(1, "Top", .5, 1)
|
||||
edge(2, "Top", farCorner, cornerSize)
|
||||
edge(2, "Right", nearCorner, cornerSize)
|
||||
edge(3, "Right", .5, 1)
|
||||
edge(4, "Right", farCorner, cornerSize)
|
||||
edge(4, "Bottom", farCorner, cornerSize)
|
||||
edge(5, "Bottom", .5, 1)
|
||||
edge(6, "Bottom", nearCorner, cornerSize)
|
||||
edge(6, "Left", farCorner, cornerSize)
|
||||
edge(7, "Left", .5, 1)
|
||||
edge(8, "Left", nearCorner, cornerSize)
|
||||
edge(8, "Top", nearCorner, cornerSize)
|
||||
|
||||
local function sectorFor(camera: CFrame, direction: Vector3): number
|
||||
local horizontal = Vector2.new(direction.X, direction.Z)
|
||||
if horizontal.Magnitude < .015 then return if direction.Y >= 0 then 1 else 5 end
|
||||
local right = Vector2.new(camera.RightVector.X, camera.RightVector.Z)
|
||||
local forward = Vector2.new(right.Y, -right.X)
|
||||
local angle = math.atan2(horizontal:Dot(right), horizontal:Dot(forward))
|
||||
return math.floor(angle / (math.pi / 4) + .5) % #sectorNames + 1
|
||||
end
|
||||
|
||||
local lastSound = -math.huge
|
||||
local received = damageTaken.OnClientEvent:Connect(function(character: Model, direction: Vector3, damage: number)
|
||||
if player.Character ~= character or player:GetAttribute("InArena") ~= true then return end
|
||||
local camera = workspace.CurrentCamera
|
||||
if not camera then return end
|
||||
local now = os.clock()
|
||||
local humanoid = character:FindFirstChildOfClass("Humanoid")
|
||||
local ratio = math.clamp(damage / math.max(if humanoid then humanoid.MaxHealth else 100, 1), 0, 1)
|
||||
local source = if direction.Magnitude > .001 then direction.Unit else camera.CFrame.LookVector
|
||||
impacts[sectorFor(camera.CFrame, source)] = {direction = source, at = now, strength = .70 + math.min(.3, ratio * .85)}
|
||||
if now - lastSound >= .10 then
|
||||
lastSound = now
|
||||
effects.sound("Hurt")
|
||||
end
|
||||
end)
|
||||
|
||||
local step = RunService.RenderStepped:Connect(function()
|
||||
if not next(impacts) then return end
|
||||
local camera = workspace.CurrentCamera
|
||||
if not camera then return end
|
||||
local now = os.clock()
|
||||
for i = 1, #sectors do strengths[i] = 0 end
|
||||
for slot, impact in impacts do
|
||||
local age = now - impact.at
|
||||
if age >= duration then
|
||||
impacts[slot] = nil
|
||||
else
|
||||
local sector = sectorFor(camera.CFrame, impact.direction)
|
||||
local attack = .55 + .45 * math.clamp(age / .04, 0, 1)
|
||||
local decay = 1 - math.clamp((age - .075) / (duration - .075), 0, 1)
|
||||
strengths[sector] = math.max(strengths[sector], impact.strength * attack * decay ^ 2)
|
||||
end
|
||||
end
|
||||
for i, strips in sectors do
|
||||
local strength = strengths[i]
|
||||
for _, strip in strips do
|
||||
strip.frame.Visible = strength > .01
|
||||
strip.frame.BackgroundTransparency = 1 - strength * strip.weight
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
local function clear()
|
||||
table.clear(impacts)
|
||||
for _, strips in sectors do
|
||||
for _, strip in strips do strip.frame.Visible = false end
|
||||
end
|
||||
end
|
||||
local respawned = player.CharacterAdded:Connect(clear)
|
||||
local zone = player:GetAttributeChangedSignal("InArena"):Connect(function()
|
||||
if player:GetAttribute("InArena") ~= true then clear() end
|
||||
end)
|
||||
script.Destroying:Once(function()
|
||||
received:Disconnect()
|
||||
step:Disconnect()
|
||||
respawned:Disconnect()
|
||||
zone:Disconnect()
|
||||
gui:Destroy()
|
||||
end)
|
||||
Reference in new issue
Block a user