390 lines
16 KiB
Luau
390 lines
16 KiB
Luau
--!strict
|
|
local Debris = game:GetService("Debris")
|
|
local Players = game:GetService("Players")
|
|
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
|
local RunService = game:GetService("RunService")
|
|
local TweenService = game:GetService("TweenService")
|
|
local Catalog = require(ReplicatedStorage:WaitForChild("PowerUpCatalog") :: ModuleScript)
|
|
local Magnet = require(ReplicatedStorage:WaitForChild("LootMagnet") :: ModuleScript)
|
|
local Sounds = require(ReplicatedStorage:WaitForChild("SniperEffects") :: ModuleScript)
|
|
local drops = ReplicatedStorage:WaitForChild("PowerUpDrops")
|
|
local collected = drops:WaitForChild("Collected") :: RemoteEvent
|
|
local player = Players.LocalPlayer
|
|
local life = drops:GetAttribute("Life") :: number
|
|
local airTime = drops:GetAttribute("AirTime") :: number
|
|
local white = Color3.fromRGB(242, 248, 255)
|
|
local ink = Color3.fromRGB(12, 17, 32)
|
|
local folder = Instance.new("Folder")
|
|
folder.Name = "LocalPowerUpDrops"
|
|
folder.Parent = workspace
|
|
|
|
-- Line paths on a 32 x 32 icon grid. The symbols also distinguish similar colors.
|
|
local symbols: {[string]: {{number}}} = {
|
|
Turbo = {{5,10,15,16,5,22},{16,8,27,16,16,24},{5,16,10,16}},
|
|
Spring = {{6,25,12,25,21,19,11,17,21,13,14,10},{21,6,25,3,29,7},{25,3,25,16}},
|
|
Double = {{6,16,16,6,26,16},{6,26,16,16,26,26}},
|
|
Feather = {{6,27,19,13},{9,24,7,16,13,9,25,5,26,14,21,21,16,24,9,24},{15,18,14,12},{19,14,23,14}},
|
|
Shield = {{16,4,26,8,25,19,21,25,16,28,11,25,7,19,6,8,16,4},{11,16,15,20,22,12}},
|
|
Heal = {{13,6,19,6,19,13,26,13,26,19,19,19,19,26,13,26,13,19,6,19,6,13,13,13,13,6}},
|
|
Magnet = {{7,7,7,19,11,25,21,25,25,19,25,7,19,7,19,18,16,21,13,18,13,7,7,7},{7,13,13,13},{19,13,25,13}},
|
|
Lucky = {{16,4,24,8,28,16,24,24,16,28,8,24,4,16,8,8,16,4},{16,9,16,23},{20,12,13,12,11,15,20,18,18,21,12,21}},
|
|
Reload = {{25,13,22,7,15,5,8,9,5,16,7,22,14,26,22,24,26,19},{25,6,25,13,18,13},{18,16,29,16}},
|
|
Ammo = {{10,6,23,6,23,18,19,25,9,27,6,24,10,17,10,6},{9,14,23,14},{9,21,17,19}},
|
|
Steady = {{16,4,16,11},{16,21,16,28},{4,16,11,16},{21,16,28,16},{12,12,20,12,20,20,12,20,12,12}},
|
|
Quiet = {{6,13,11,13,18,7,18,25,11,19,6,19,6,13},{22,12,28,20},{28,12,22,20}},
|
|
Phantom = {{7,26,7,13,10,7,16,5,22,7,25,13,25,26,21,23,16,27,12,23,7,26},{12,14,12,16},{20,14,20,16}},
|
|
Storm = {{17,4,7,18,15,18,13,28,26,13,18,13,17,4}},
|
|
Team = {{16,5,19,10,16,14,13,10,16,5},{7,13,10,18,7,22,4,18,7,13},{25,13,28,18,25,22,22,18,25,13},{8,26,16,20,24,26}},
|
|
}
|
|
local byId = {}
|
|
for _, def in Catalog do byId[def.id] = def end
|
|
|
|
local function icon(parent: GuiObject, key: string, tint: Color3)
|
|
for _, path in symbols[key] do
|
|
for i = 1, #path - 2, 2 do
|
|
local a = Vector2.new(path[i], path[i + 1])
|
|
local b = Vector2.new(path[i + 2], path[i + 3])
|
|
local middle = (a + b) / 2
|
|
local edge = b - a
|
|
local line = Instance.new("Frame")
|
|
line.BorderSizePixel = 0
|
|
line.BackgroundColor3 = tint
|
|
line.AnchorPoint = Vector2.new(.5, .5)
|
|
line.Position = UDim2.fromScale(middle.X / 32, middle.Y / 32)
|
|
line.Size = UDim2.fromScale((edge.Magnitude + 1.4) / 32, .058)
|
|
line.Rotation = math.deg(math.atan2(edge.Y, edge.X))
|
|
line.Parent = parent
|
|
end
|
|
end
|
|
end
|
|
|
|
local function ball(parent: Instance, name: string, size: number, tint: Color3, alpha: number, material: Enum.Material): Part
|
|
local p = Instance.new("Part")
|
|
p.Name, p.Shape = name, Enum.PartType.Ball
|
|
p.Material, p.Color, p.Transparency = material, tint, alpha
|
|
p.Size = Vector3.one * size
|
|
p.Anchored, p.CanCollide, p.CanQuery, p.CanTouch, p.CastShadow = true, false, false, false, false
|
|
p.Parent = parent
|
|
return p
|
|
end
|
|
|
|
local function textLabel(parent: Instance, name: string, text: string, size: number, color: Color3): TextLabel
|
|
local label = Instance.new("TextLabel")
|
|
label.Name, label.Text = name, text
|
|
label.TextSize, label.TextColor3 = size, color
|
|
label.Font = Enum.Font.GothamBlack
|
|
label.BackgroundTransparency = 1
|
|
label.TextStrokeColor3, label.TextStrokeTransparency = ink, .22
|
|
label.Parent = parent
|
|
return label
|
|
end
|
|
|
|
local function attach(part: BasePart, position: Vector3): Attachment
|
|
local origin = Instance.new("Attachment")
|
|
origin.Position = position
|
|
origin.Parent = part
|
|
return origin
|
|
end
|
|
|
|
local function stars(parent: Instance, tint: Color3): ParticleEmitter
|
|
local sparkle = Instance.new("ParticleEmitter")
|
|
sparkle.Name = "Stars"
|
|
sparkle.Texture = "rbxasset://textures/particles/sparkles_main.dds"
|
|
sparkle.Color = ColorSequence.new(white, tint)
|
|
sparkle.Rate = 7
|
|
sparkle.Lifetime = NumberRange.new(.28, .57)
|
|
sparkle.Rotation = NumberRange.new(0, 180)
|
|
sparkle.RotSpeed = NumberRange.new(-95, 95)
|
|
sparkle.Size = NumberSequence.new(.39, 0)
|
|
sparkle.Speed = NumberRange.new(1, 4)
|
|
sparkle.SpreadAngle = Vector2.new(180, 180)
|
|
sparkle.LightEmission = 1
|
|
sparkle.Parent = parent
|
|
return sparkle
|
|
end
|
|
|
|
type Orb = {
|
|
model: Model, shell: Part, halo: Beam, coreBeam: Beam, trail: Trail, badge: BillboardGui,
|
|
timer: TextLabel, fill: Frame, orbit: {Part}, inheritedPosition: Vector3?, shownSecond: number,
|
|
}
|
|
type Drop = {data: Configuration, key: string, origin: Vector3, rest: Vector3, born: number, expires: number, orb: Orb?}
|
|
local seen: {[Configuration]: Drop} = {}
|
|
|
|
local function orbFor(drop: Drop): Orb
|
|
local def = byId[drop.key]
|
|
local tint = def.color
|
|
local model = Instance.new("Model")
|
|
model.Name = "PowerSphere_" .. drop.key
|
|
local shell = ball(model, "Sphere", 2.65, tint, .48, Enum.Material.SmoothPlastic)
|
|
model.PrimaryPart = shell
|
|
local core = ball(model, "InnerLight", 1.84, tint, .73, Enum.Material.Neon)
|
|
local lamp = Instance.new("PointLight")
|
|
lamp.Color, lamp.Range, lamp.Brightness = tint, 8, .75
|
|
lamp.Parent = core
|
|
|
|
local logo = Instance.new("BillboardGui")
|
|
logo.Name = "InnerIcon"
|
|
logo.Size = UDim2.fromScale(1.76, 1.76)
|
|
logo.LightInfluence = 0
|
|
logo.MaxDistance = 88
|
|
logo.Parent = core
|
|
local iconCanvas = Instance.new("Frame")
|
|
iconCanvas.Size = UDim2.fromScale(1, 1)
|
|
iconCanvas.BackgroundTransparency = 1
|
|
iconCanvas.Parent = logo
|
|
local ring = Instance.new("UICorner")
|
|
ring.CornerRadius = UDim.new(.5, 0)
|
|
ring.Parent = iconCanvas
|
|
local outline = Instance.new("UIStroke")
|
|
outline.Color, outline.Transparency = tint:Lerp(white, .38), .45
|
|
outline.Thickness = 1.2
|
|
outline.Parent = iconCanvas
|
|
icon(iconCanvas, drop.key, white)
|
|
|
|
local beamBase = attach(shell, Vector3.yAxis * .65)
|
|
local beamTip = attach(shell, Vector3.yAxis * 19)
|
|
local beam = Instance.new("Beam")
|
|
beam.Name = "AuraBeam"
|
|
beam.Attachment0, beam.Attachment1 = beamBase, beamTip
|
|
beam.FaceCamera = true
|
|
beam.LightEmission, beam.Brightness = .92, 1.7
|
|
beam.Color = ColorSequence.new(tint:Lerp(white, .28), tint)
|
|
beam.Width0, beam.Width1 = 1.7, .22
|
|
beam.Transparency = NumberSequence.new({
|
|
NumberSequenceKeypoint.new(0, .36), NumberSequenceKeypoint.new(.55, .78), NumberSequenceKeypoint.new(1, 1),
|
|
})
|
|
beam.Parent = shell
|
|
local lightRay = beam:Clone()
|
|
lightRay.Name = "RayCore"
|
|
lightRay.Width0, lightRay.Width1 = .25, .04
|
|
lightRay.Transparency = NumberSequence.new(.08, 1)
|
|
lightRay.Parent = shell
|
|
|
|
local trail = Instance.new("Trail")
|
|
trail.Name = "FlightRibbon"
|
|
trail.Attachment0, trail.Attachment1 = attach(shell, Vector3.yAxis * .65), attach(shell, -Vector3.yAxis * .65)
|
|
trail.Color = ColorSequence.new(white, tint)
|
|
trail.Lifetime = .25
|
|
trail.LightEmission = 1
|
|
trail.WidthScale = NumberSequence.new(1, .05)
|
|
trail.Transparency = NumberSequence.new(.10, 1)
|
|
trail.FaceCamera, trail.Enabled = true, false
|
|
trail.Parent = shell
|
|
stars(core, tint)
|
|
local orbit: {Part} = {}
|
|
for i = 1, 3 do
|
|
local sprite = ball(model, "Orbit" .. i, .12, tint, 1, Enum.Material.Neon)
|
|
local badge = Instance.new("BillboardGui")
|
|
badge.Size = UDim2.fromScale(.62, .62)
|
|
badge.LightInfluence, badge.MaxDistance = 0, 88
|
|
badge.Parent = sprite
|
|
local frame = Instance.new("Frame")
|
|
frame.Size = UDim2.fromScale(1, 1)
|
|
frame.BackgroundTransparency = 1
|
|
frame.Parent = badge
|
|
for _, angle in {0, 90} do
|
|
local arm = Instance.new("Frame")
|
|
arm.AnchorPoint = Vector2.new(.5, .5)
|
|
arm.Position = UDim2.fromScale(.5, .5)
|
|
arm.Size = UDim2.fromScale(.19, 1)
|
|
arm.BackgroundColor3, arm.BorderSizePixel = tint:Lerp(white, .75), 0
|
|
arm.Rotation = angle
|
|
arm.Parent = frame
|
|
local fade = Instance.new("UIGradient")
|
|
fade.Rotation = 90
|
|
fade.Transparency = NumberSequence.new({
|
|
NumberSequenceKeypoint.new(0, 1), NumberSequenceKeypoint.new(.5, 0), NumberSequenceKeypoint.new(1, 1),
|
|
})
|
|
fade.Parent = arm
|
|
end
|
|
table.insert(orbit, sprite)
|
|
end
|
|
|
|
local badge = Instance.new("BillboardGui")
|
|
badge.Name = "PowerTimer"
|
|
badge.Size = UDim2.fromOffset(182, 48)
|
|
badge.StudsOffsetWorldSpace = Vector3.yAxis * 2.15
|
|
badge.LightInfluence, badge.MaxDistance = 0, 85
|
|
badge.Parent = shell
|
|
local name = textLabel(badge, "Name", def.title, 15, tint:Lerp(white, .50))
|
|
name.Size = UDim2.new(1, 0, 0, 22)
|
|
local backing = Instance.new("Frame")
|
|
backing.Name = "ClockPlate"
|
|
backing.AnchorPoint, backing.Position = Vector2.new(.5, 0), UDim2.new(.5, 0, 0, 22)
|
|
backing.Size, backing.BackgroundColor3 = UDim2.fromOffset(54, 17), ink
|
|
backing.BackgroundTransparency, backing.BorderSizePixel = .15, 0
|
|
backing.Parent = badge
|
|
local edge = Instance.new("UIStroke")
|
|
edge.Color, edge.Thickness, edge.Transparency = tint, 1, .28
|
|
edge.Parent = backing
|
|
local time = textLabel(backing, "Time", "1:00", 14, white)
|
|
time.Size = UDim2.fromScale(1, 1)
|
|
local rail = Instance.new("Frame")
|
|
rail.AnchorPoint, rail.Position = Vector2.new(.5, 0), UDim2.fromScale(.5, .87)
|
|
rail.Size, rail.BorderSizePixel = UDim2.fromOffset(64, 2), 0
|
|
rail.BackgroundColor3 = ink
|
|
rail.Parent = badge
|
|
local fill = Instance.new("Frame")
|
|
fill.Name, fill.BorderSizePixel = "Remaining", 0
|
|
fill.Size, fill.BackgroundColor3 = UDim2.fromScale(1, 1), tint
|
|
fill.Parent = rail
|
|
model:PivotTo(CFrame.new(drop.origin))
|
|
model.Parent = folder
|
|
return {model = model, shell = shell, halo = beam, coreBeam = lightRay, trail = trail,
|
|
badge = badge, timer = time, fill = fill, orbit = orbit, shownSecond = -1}
|
|
end
|
|
|
|
local function register(data: Instance)
|
|
if not data:IsA("Configuration") then return end
|
|
local key = data:GetAttribute("Kind")
|
|
local origin, rest = data:GetAttribute("Origin"), data:GetAttribute("Rest")
|
|
local born, expires = data:GetAttribute("Born"), data:GetAttribute("Expires")
|
|
if typeof(key) ~= "string" or not byId[key] or typeof(origin) ~= "Vector3" or typeof(rest) ~= "Vector3"
|
|
or typeof(born) ~= "number" or typeof(expires) ~= "number" then return end
|
|
seen[data] = {data = data, key = key, origin = origin, rest = rest, born = born, expires = expires}
|
|
end
|
|
|
|
local function hide(drop: Drop)
|
|
if drop.orb then drop.orb.model:Destroy() end
|
|
drop.orb = nil
|
|
end
|
|
|
|
for _, data in drops:GetChildren() do register(data) end
|
|
local added = drops.ChildAdded:Connect(register)
|
|
local removed = drops.ChildRemoved:Connect(function(data)
|
|
if not data:IsA("Configuration") then return end
|
|
local drop = seen[data]
|
|
if drop then hide(drop) end
|
|
seen[data] = nil
|
|
end)
|
|
|
|
local function update(drop: Drop, camera: Camera, now: number)
|
|
if now >= drop.expires or (camera.CFrame.Position - drop.rest).Magnitude > 132 then
|
|
hide(drop)
|
|
return
|
|
end
|
|
local orb = drop.orb or orbFor(drop)
|
|
drop.orb = orb
|
|
local age = math.max(0, now - drop.born)
|
|
local landing = math.clamp(age / airTime, 0, 1)
|
|
local launch = drop.data:GetAttribute("Launch")
|
|
local userId = drop.data:GetAttribute("Collector")
|
|
local position = drop.origin:Lerp(drop.rest, 1 - (1 - landing) ^ 1.5)
|
|
+ Vector3.yAxis * (math.sin(landing * math.pi) * 3.8 + .22 * math.sin(age * 3.3))
|
|
local progress = 0
|
|
local flying = typeof(launch) == "number" and now >= launch and typeof(userId) == "number"
|
|
if flying and typeof(launch) == "number" and typeof(userId) == "number" then
|
|
local owner = Players:GetPlayerByUserId(userId)
|
|
local target = owner and Magnet.catchPoint(owner.Character, if owner == player then camera else nil)
|
|
if target then
|
|
local takeoff = orb.inheritedPosition or position
|
|
orb.inheritedPosition = takeoff
|
|
position, progress = Magnet.curve(takeoff, target, now - launch, drop.born % 6.28)
|
|
end
|
|
else
|
|
orb.inheritedPosition = nil
|
|
end
|
|
local scale = if flying then 1 - .77 * math.clamp((progress - .38) / .62, 0, 1) else 1
|
|
if orb.model:GetScale() ~= scale then orb.model:ScaleTo(scale) end
|
|
orb.model:PivotTo(CFrame.new(position))
|
|
for i, sparkle in orb.orbit do
|
|
local angle = age * 3 + i * math.pi * 2 / 3
|
|
local r = 1.55 * scale
|
|
sparkle.Position = position + Vector3.new(math.cos(angle) * r, math.sin(angle * .8) * r * .50, math.sin(angle) * r)
|
|
end
|
|
orb.trail.Enabled = flying or landing < .88
|
|
orb.halo.Enabled = not flying and landing >= .92
|
|
orb.coreBeam.Enabled = orb.halo.Enabled
|
|
orb.halo.Width0 = 1.55 + .28 * math.sin(age * 4)
|
|
orb.badge.Enabled = not flying and landing >= .84
|
|
local remaining = math.max(0, drop.expires - now)
|
|
local whole = math.ceil(remaining)
|
|
if whole ~= orb.shownSecond then
|
|
orb.shownSecond = whole
|
|
orb.timer.Text = string.format("%d:%02d", whole // 60, whole % 60)
|
|
orb.timer.TextColor3 = if whole <= 5 then Color3.fromRGB(255, 145, 116) else white
|
|
end
|
|
orb.fill.Size = UDim2.fromScale(remaining / life, 1)
|
|
orb.shell.Transparency = if remaining <= 4 then .50 + .14 * math.sin(now * 8) else .47
|
|
end
|
|
|
|
local gui = Instance.new("ScreenGui")
|
|
gui.Name = "PowerUpPickup"
|
|
gui.ResetOnSpawn = false
|
|
gui.DisplayOrder = 22
|
|
gui.Parent = player:WaitForChild("PlayerGui")
|
|
local notification = Instance.new("Frame")
|
|
notification.Name = "Acquired"
|
|
notification.Position = UDim2.new(0, 20, .5, 0)
|
|
notification.Size = UDim2.fromOffset(290, 64)
|
|
notification.BackgroundColor3 = ink
|
|
notification.BackgroundTransparency = .15
|
|
notification.BorderSizePixel = 0
|
|
notification.Visible = false
|
|
notification.Parent = gui
|
|
local rim = Instance.new("UIStroke", notification)
|
|
rim.Thickness = 1.5
|
|
local iconSlot = Instance.new("Frame")
|
|
iconSlot.Position, iconSlot.Size = UDim2.fromOffset(11, 12), UDim2.fromOffset(40, 40)
|
|
iconSlot.BackgroundTransparency = 1
|
|
iconSlot.Parent = notification
|
|
local title = textLabel(notification, "Title", "", 19, white)
|
|
title.Position, title.Size = UDim2.fromOffset(57, 6), UDim2.fromOffset(225, 26)
|
|
title.TextXAlignment = Enum.TextXAlignment.Left
|
|
local detail = textLabel(notification, "Detail", "", 12, white)
|
|
detail.Position, detail.Size = UDim2.fromOffset(57, 31), UDim2.fromOffset(225, 27)
|
|
detail.TextWrapped = true
|
|
detail.TextXAlignment = Enum.TextXAlignment.Left
|
|
local animation: Tween? = nil
|
|
local serial = 0
|
|
local receive = collected.OnClientEvent:Connect(function(key: string)
|
|
local def = byId[key]
|
|
if not def or player:GetAttribute("InArena") ~= true then return end
|
|
Sounds.sound("StreakAccent")
|
|
local position = Magnet.catchPoint(player.Character, workspace.CurrentCamera)
|
|
if position then
|
|
local flash = ball(folder, "PickupFlash", .1, def.color, 1, Enum.Material.Neon)
|
|
flash.Position = position
|
|
local burst = stars(flash, def.color)
|
|
burst.Rate = 0
|
|
burst.Speed = NumberRange.new(4, 10)
|
|
burst:Emit(22)
|
|
Debris:AddItem(flash, .7)
|
|
end
|
|
if animation then animation:Cancel() end
|
|
iconSlot:ClearAllChildren()
|
|
icon(iconSlot, key, def.color:Lerp(white, .4))
|
|
rim.Color, title.TextColor3 = def.color, def.color:Lerp(white, .35)
|
|
title.Text, detail.Text = def.title, def.detail
|
|
notification.Position = UDim2.new(0, -295, .5, 0)
|
|
notification.Visible = true
|
|
animation = TweenService:Create(notification, TweenInfo.new(.23, Enum.EasingStyle.Quint), {Position = UDim2.new(0, 20, .5, 0)})
|
|
animation:Play()
|
|
serial += 1
|
|
local version = serial
|
|
task.delay(2.5, function()
|
|
if serial == version and notification.Parent then notification.Visible = false end
|
|
end)
|
|
end)
|
|
|
|
local step = RunService.RenderStepped:Connect(function()
|
|
local camera = workspace.CurrentCamera
|
|
if not camera or player:GetAttribute("InArena") ~= true then return end
|
|
local now = workspace:GetServerTimeNow()
|
|
for _, drop in seen do update(drop, camera, now) end
|
|
end)
|
|
local zone = player:GetAttributeChangedSignal("InArena"):Connect(function()
|
|
if player:GetAttribute("InArena") == true then return end
|
|
for _, drop in seen do hide(drop) end
|
|
notification.Visible = false
|
|
end)
|
|
script.Destroying:Once(function()
|
|
step:Disconnect()
|
|
zone:Disconnect()
|
|
receive:Disconnect()
|
|
added:Disconnect()
|
|
removed:Disconnect()
|
|
folder:Destroy()
|
|
gui:Destroy()
|
|
end)
|