1
This commit is contained in:
commit
a85391509d
211 files changed
+28903
No files matched your search
@@ -0,0 +1,94 @@
|
||||
--!strict
|
||||
-- Local environmental profile so the arena and the lobby can use different lighting.
|
||||
local Lighting = game:GetService("Lighting")
|
||||
local Players = game:GetService("Players")
|
||||
local TweenService = game:GetService("TweenService")
|
||||
|
||||
local player = Players.LocalPlayer
|
||||
local atmosphere = Lighting:FindFirstChildOfClass("Atmosphere")
|
||||
local bloom = Lighting:FindFirstChildOfClass("BloomEffect")
|
||||
local sunRays = Lighting:FindFirstChildOfClass("SunRaysEffect")
|
||||
local motion = TweenInfo.new(.55, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut)
|
||||
|
||||
local day = {
|
||||
ClockTime = Lighting.ClockTime,
|
||||
Brightness = Lighting.Brightness,
|
||||
EnvironmentDiffuseScale = Lighting.EnvironmentDiffuseScale,
|
||||
EnvironmentSpecularScale = Lighting.EnvironmentSpecularScale,
|
||||
}
|
||||
local dusk = {
|
||||
ClockTime = 17.86,
|
||||
Brightness = 1.36,
|
||||
EnvironmentDiffuseScale = .84,
|
||||
EnvironmentSpecularScale = .82,
|
||||
}
|
||||
local clearAir = if atmosphere then {
|
||||
Density = atmosphere.Density, Offset = atmosphere.Offset, Haze = atmosphere.Haze,
|
||||
Color = atmosphere.Color, Decay = atmosphere.Decay, Glare = atmosphere.Glare,
|
||||
} else nil
|
||||
local duskAir = {
|
||||
Density = .25, Offset = .14, Haze = 1.26, Glare = .08,
|
||||
Color = Color3.fromRGB(186, 188, 228), Decay = Color3.fromRGB(107, 111, 161),
|
||||
}
|
||||
local daytimeBloom = if bloom then {Intensity = bloom.Intensity, Threshold = bloom.Threshold, Size = bloom.Size} else nil
|
||||
local showSunRays = sunRays ~= nil and sunRays.Enabled
|
||||
|
||||
local grade = Instance.new("ColorCorrectionEffect")
|
||||
grade.Name = "ArenaDuskGrade"
|
||||
grade.Brightness = .006
|
||||
grade.Contrast = -.014
|
||||
grade.Saturation = -.12
|
||||
grade.TintColor = Color3.fromRGB(231, 237, 255)
|
||||
grade.Enabled = false
|
||||
grade.Parent = Lighting
|
||||
|
||||
local goggles: ColorCorrectionEffect? = nil
|
||||
local gogglesSignal: RBXScriptConnection? = nil
|
||||
local inArena = false
|
||||
local tweens: {Tween} = {}
|
||||
|
||||
local function showGrade()
|
||||
grade.Enabled = inArena and not (goggles and goggles.Enabled)
|
||||
end
|
||||
|
||||
local function registerGoggles(effect: Instance)
|
||||
if effect.Name ~= "GogglesColor" or not effect:IsA("ColorCorrectionEffect") then return end
|
||||
if gogglesSignal then gogglesSignal:Disconnect() end
|
||||
goggles = effect
|
||||
gogglesSignal = effect:GetPropertyChangedSignal("Enabled"):Connect(showGrade)
|
||||
showGrade()
|
||||
end
|
||||
local added = Lighting.ChildAdded:Connect(registerGoggles)
|
||||
local current = Lighting:FindFirstChild("GogglesColor")
|
||||
if current then registerGoggles(current) end
|
||||
|
||||
local function blend(instance: Instance, props: {[string]: any})
|
||||
local tween = TweenService:Create(instance, motion, props)
|
||||
table.insert(tweens, tween)
|
||||
tween:Play()
|
||||
end
|
||||
|
||||
local function update()
|
||||
local arena = player:GetAttribute("InArena") == true
|
||||
if arena == inArena then return end
|
||||
inArena = arena
|
||||
for _, tween in tweens do tween:Cancel() end
|
||||
table.clear(tweens)
|
||||
blend(Lighting, if arena then dusk else day)
|
||||
if atmosphere and clearAir then blend(atmosphere, if arena then duskAir else clearAir) end
|
||||
if bloom and daytimeBloom then
|
||||
blend(bloom, if arena then {Intensity = .63, Threshold = 1.52, Size = 23} else daytimeBloom)
|
||||
end
|
||||
if sunRays then sunRays.Enabled = showSunRays and not arena end
|
||||
showGrade()
|
||||
end
|
||||
local zoneSignal = player:GetAttributeChangedSignal("InArena"):Connect(update)
|
||||
update()
|
||||
|
||||
script.Destroying:Once(function()
|
||||
added:Disconnect()
|
||||
zoneSignal:Disconnect()
|
||||
if gogglesSignal then gogglesSignal:Disconnect() end
|
||||
for _, tween in tweens do tween:Cancel() end
|
||||
grade:Destroy()
|
||||
end)
|
||||
@@ -0,0 +1,58 @@
|
||||
--!strict
|
||||
local CollectionService = game:GetService("CollectionService")
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local Mobility = {
|
||||
BoostMultiplier = 1.48,
|
||||
BoostDuration = 2,
|
||||
JumpRise = 48,
|
||||
JumpRadius = 4.8,
|
||||
ProceduralRuneTag = "HunterProceduralRune",
|
||||
}
|
||||
|
||||
function Mobility.watchRunes(add: (Instance, string) -> (), remove: (Instance, string) -> ()): () -> ()
|
||||
local Modes = require(ReplicatedStorage:WaitForChild("ArenaModes") :: ModuleScript)
|
||||
local tag = Mobility.ProceduralRuneTag
|
||||
local closed = false
|
||||
local function register(rune: Instance)
|
||||
-- Let an atomic rune model finish replicating before reading its origin and art groups.
|
||||
task.defer(function()
|
||||
if closed then return end
|
||||
if rune:IsDescendantOf(workspace) and CollectionService:HasTag(rune, tag) then
|
||||
add(rune, Modes.Procedural)
|
||||
end
|
||||
end)
|
||||
end
|
||||
local proceduralAdded = CollectionService:GetInstanceAddedSignal(tag):Connect(register)
|
||||
local proceduralRemoved = CollectionService:GetInstanceRemovedSignal(tag):Connect(function(rune) remove(rune, Modes.Procedural) end)
|
||||
for _, rune in CollectionService:GetTagged(tag) do register(rune) end
|
||||
return function()
|
||||
closed = true
|
||||
proceduralAdded:Disconnect()
|
||||
proceduralRemoved:Disconnect()
|
||||
end
|
||||
end
|
||||
|
||||
function Mobility.active(character: Model?, key: string, now: number): boolean
|
||||
local expires = character and character:GetAttribute("Loot" .. key .. "Until")
|
||||
return typeof(expires) == "number" and expires > now
|
||||
end
|
||||
|
||||
function Mobility.walkMultiplier(character: Model, now: number): number
|
||||
local rampExpiry = character:GetAttribute("ArenaBoostUntil")
|
||||
local ramp = if typeof(rampExpiry) == "number" and rampExpiry > now then Mobility.BoostMultiplier else 1
|
||||
local loot = if Mobility.active(character, "Turbo", now) then 1.30 elseif Mobility.active(character, "Team", now) then 1.20 else 1
|
||||
return math.max(ramp, loot) * (if Mobility.active(character, "Slow", now) then .65 else 1)
|
||||
end
|
||||
|
||||
function Mobility.groundReach(root: BasePart, humanoid: Humanoid): number
|
||||
return math.max(3, humanoid.HipHeight + root.Size.Y * .5) + .85
|
||||
end
|
||||
|
||||
function Mobility.hop(root: BasePart, humanoid: Humanoid)
|
||||
local upSpeed = math.sqrt(2 * workspace.Gravity * Mobility.JumpRise)
|
||||
local deltaSpeed = upSpeed - root.AssemblyLinearVelocity.Y
|
||||
humanoid:ChangeState(Enum.HumanoidStateType.Freefall)
|
||||
root:ApplyImpulse(Vector3.yAxis * deltaSpeed * root.AssemblyMass)
|
||||
end
|
||||
|
||||
return table.freeze(Mobility)
|
||||
@@ -0,0 +1,166 @@
|
||||
--!strict
|
||||
local Players = game:GetService("Players")
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local RunService = game:GetService("RunService")
|
||||
local StarterPlayer = game:GetService("StarterPlayer")
|
||||
local Mobility = require(ReplicatedStorage:WaitForChild("ArenaMobility") :: ModuleScript)
|
||||
local Modes = require(ReplicatedStorage:WaitForChild("ArenaModes") :: ModuleScript)
|
||||
local round = ReplicatedStorage:WaitForChild("ArenaRound")
|
||||
local hopUsed = Instance.new("RemoteEvent")
|
||||
hopUsed.Name = "JumpRuneUsed"
|
||||
hopUsed.Parent = round
|
||||
|
||||
type Pad = {
|
||||
model: Model, frame: CFrame, halfWidth: number, halfLength: number,
|
||||
forward: Vector3, searchRadius: number,
|
||||
}
|
||||
type Boost = {character: Model, humanoid: Humanoid, untilTime: number}
|
||||
type JumpPad = {origin: BasePart, mode: string}
|
||||
local pads: {[string]: {[Instance]: Pad}} = {[Modes.Procedural] = {}}
|
||||
local jumpOrigins: {[Instance]: JumpPad} = {}
|
||||
local lastHop: {[Player]: number} = {}
|
||||
local boosts: {[Player]: Boost} = {}
|
||||
local standing: {[Player]: Pad} = {}
|
||||
local horizontalMask = Vector3.new(1, 0, 1)
|
||||
|
||||
local stopWatching = Mobility.watchRunes(function(model, mode)
|
||||
if not model:IsA("Model") or not model.PrimaryPart then return end
|
||||
local kind = model:GetAttribute("Kind")
|
||||
if kind == "Jump" then
|
||||
jumpOrigins[model] = {origin = model.PrimaryPart, mode = mode}
|
||||
return
|
||||
end
|
||||
if kind ~= "Boost" then return end
|
||||
local frame = model.PrimaryPart.CFrame
|
||||
local halfWidth = (model:GetAttribute("HalfWidth") :: number?) or 4.8
|
||||
local halfLength = (model:GetAttribute("HalfLength") :: number?) or 4.8
|
||||
pads[mode][model] = {
|
||||
model = model, frame = frame, halfWidth = halfWidth, halfLength = halfLength,
|
||||
forward = (frame.LookVector * horizontalMask).Unit,
|
||||
searchRadius = math.sqrt(halfWidth ^ 2 + halfLength ^ 2) + 6,
|
||||
}
|
||||
end, function(model, mode)
|
||||
pads[mode][model] = nil
|
||||
jumpOrigins[model] = nil
|
||||
end)
|
||||
|
||||
local function baseSpeed(): number
|
||||
return (workspace:GetAttribute("HunterWalkSpeed") :: number?) or StarterPlayer.CharacterWalkSpeed
|
||||
end
|
||||
|
||||
local function clearBoost(player: Player)
|
||||
local boost = boosts[player]
|
||||
if not boost then return end
|
||||
boosts[player] = nil
|
||||
boost.character:SetAttribute("ArenaBoostUntil", nil)
|
||||
if boost.humanoid.Parent and boost.humanoid.Health > 0 then
|
||||
boost.humanoid.WalkSpeed = baseSpeed() * Mobility.walkMultiplier(boost.character, workspace:GetServerTimeNow())
|
||||
end
|
||||
end
|
||||
|
||||
local function contains(pad: Pad, x: number, z: number): boolean
|
||||
return math.abs(x) < pad.halfWidth and math.abs(z) < pad.halfLength
|
||||
end
|
||||
|
||||
local function padAt(root: BasePart, humanoid: Humanoid, speed: number, mode: string): Pad?
|
||||
local floor: RaycastResult? = nil
|
||||
local reach = Mobility.groundReach(root, humanoid)
|
||||
for _, pad in pads[mode] do
|
||||
if (root.Position - pad.frame.Position).Magnitude > pad.searchRadius then continue end
|
||||
if not floor then
|
||||
floor = workspace:Raycast(root.Position, -Vector3.yAxis * reach, Modes.collision(mode))
|
||||
if not floor then return nil end
|
||||
end
|
||||
local delta = pad.frame:PointToObjectSpace(floor.Position)
|
||||
if math.abs(delta.Y) > .45 or not contains(pad, delta.X, delta.Z) then continue end
|
||||
-- Reject characters just beginning to jump or still falling toward the ramp.
|
||||
local normalSpeed = root.AssemblyLinearVelocity:Dot(floor.Normal)
|
||||
if math.abs(normalSpeed) <= math.max(11, speed * .15) then return pad end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
local onHop = hopUsed.OnServerEvent:Connect(function(player: Player, model: unknown)
|
||||
if typeof(model) ~= "Instance" then return end
|
||||
local pad = jumpOrigins[model]
|
||||
if not pad or Modes.of(player) ~= pad.mode then return end
|
||||
local origin = pad.origin
|
||||
local now = workspace:GetServerTimeNow()
|
||||
if now - (lastHop[player] or 0) < .45 or player:GetAttribute("InArena") ~= true or not Modes.open(round, pad.mode, now) then return end
|
||||
local character = player.Character
|
||||
local humanoid = character and character:FindFirstChildOfClass("Humanoid")
|
||||
local root = character and character:FindFirstChild("HumanoidRootPart")
|
||||
if not humanoid or humanoid.Health <= 0 or humanoid.Sit or not root or not root:IsA("BasePart") or root.Anchored then return end
|
||||
local offset = root.Position - origin.Position
|
||||
local isOwner = root:GetNetworkOwner() == player
|
||||
local allowedDistance = Mobility.JumpRadius + (if isOwner then 10 else 1)
|
||||
if (offset * horizontalMask).Magnitude > allowedDistance or offset.Y < .5
|
||||
or offset.Y > Mobility.JumpRise + Mobility.groundReach(root, humanoid) then return end
|
||||
if not isOwner then
|
||||
local reach = Mobility.groundReach(root, humanoid)
|
||||
local floor = workspace:Raycast(root.Position, -Vector3.yAxis * reach, Modes.collision(pad.mode))
|
||||
local velocity = root.AssemblyLinearVelocity
|
||||
if not floor or math.abs(floor.Position.Y - origin.Position.Y) > .45 or math.abs(velocity.Y) > 11
|
||||
or (velocity * horizontalMask).Magnitude < .6 then return end
|
||||
Mobility.hop(root, humanoid)
|
||||
end
|
||||
lastHop[player] = now
|
||||
model:SetAttribute("PulseAt", now)
|
||||
end)
|
||||
|
||||
local accumulator = 0
|
||||
local step = RunService.Heartbeat:Connect(function(dt)
|
||||
accumulator += dt
|
||||
if accumulator < 1 / 30 then return end
|
||||
accumulator %= 1 / 30
|
||||
local now = workspace:GetServerTimeNow()
|
||||
local active = Modes.open(round, Modes.Procedural, now)
|
||||
for _, player in Players:GetPlayers() do
|
||||
local mode = Modes.of(player)
|
||||
local character = player.Character
|
||||
local humanoid = character and character:FindFirstChildOfClass("Humanoid")
|
||||
local root = character and character:FindFirstChild("HumanoidRootPart")
|
||||
if not active or player:GetAttribute("InArena") ~= true
|
||||
or not character or not humanoid or humanoid.Health <= 0
|
||||
or not root or not root:IsA("BasePart") or root.Anchored or humanoid.Sit then
|
||||
standing[player] = nil
|
||||
clearBoost(player)
|
||||
continue
|
||||
end
|
||||
local boost = boosts[player]
|
||||
if boost and (now >= boost.untilTime or boost.character ~= character) then clearBoost(player) end
|
||||
local velocity = root.AssemblyLinearVelocity
|
||||
local horizontal = velocity * horizontalMask
|
||||
local speed = horizontal.Magnitude
|
||||
local previous = standing[player]
|
||||
if previous and pads[mode][previous.model] == previous then
|
||||
-- Project vertically onto the slope so crossing just above it still counts as one pass.
|
||||
local relative = root.Position - previous.frame.Position
|
||||
local normal = previous.frame.UpVector
|
||||
local point = root.Position - Vector3.yAxis * (relative:Dot(normal) / normal.Y)
|
||||
local delta = previous.frame:PointToObjectSpace(point)
|
||||
if contains(previous, delta.X, delta.Z) then continue end
|
||||
end
|
||||
standing[player] = nil
|
||||
if speed < .6 then continue end
|
||||
local pad = padAt(root, humanoid, speed, mode)
|
||||
if not pad or horizontal:Dot(pad.forward) < speed * .35 then continue end
|
||||
local expiry = now + Mobility.BoostDuration
|
||||
boosts[player] = {character = character, humanoid = humanoid, untilTime = expiry}
|
||||
character:SetAttribute("ArenaBoostUntil", expiry)
|
||||
humanoid.WalkSpeed = baseSpeed() * Mobility.walkMultiplier(character, now)
|
||||
standing[player] = pad
|
||||
pad.model:SetAttribute("PulseAt", now)
|
||||
end
|
||||
end)
|
||||
|
||||
local removing = Players.PlayerRemoving:Connect(function(player)
|
||||
standing[player], lastHop[player] = nil, nil
|
||||
clearBoost(player)
|
||||
end)
|
||||
script.Destroying:Once(function()
|
||||
step:Disconnect()
|
||||
onHop:Disconnect()
|
||||
removing:Disconnect()
|
||||
stopWatching()
|
||||
end)
|
||||
@@ -0,0 +1,199 @@
|
||||
--!strict
|
||||
-- Client-only overlays for the local player's rune activations.
|
||||
local ArenaMobilityScreen = {}
|
||||
|
||||
type Streak = {halo: Frame, core: Frame, direction: Vector2, offset: number, speed: number, length: number}
|
||||
type Sigil = {root: Frame, scale: UIScale, diamond: UIStroke, stars: {Frame}, side: number, index: number}
|
||||
type Spark = {frame: Frame, side: number, offset: number, x: number, lift: number, bend: number, size: number}
|
||||
|
||||
local gold = Color3.fromRGB(255, 199, 100)
|
||||
local coral = Color3.fromRGB(255, 123, 172)
|
||||
local violet = Color3.fromRGB(157, 102, 255)
|
||||
local lilac = Color3.fromRGB(230, 210, 255)
|
||||
local white = Color3.fromRGB(255, 247, 240)
|
||||
local streakShape = NumberSequence.new({
|
||||
NumberSequenceKeypoint.new(0, 1),
|
||||
NumberSequenceKeypoint.new(.32, .62),
|
||||
NumberSequenceKeypoint.new(.83, 0),
|
||||
NumberSequenceKeypoint.new(1, .2),
|
||||
})
|
||||
local edgeShape = NumberSequence.new({
|
||||
NumberSequenceKeypoint.new(0, 0),
|
||||
NumberSequenceKeypoint.new(.34, .59),
|
||||
NumberSequenceKeypoint.new(1, 1),
|
||||
})
|
||||
local jumpDuration = 1.05
|
||||
|
||||
local function frame(name: string, parent: Instance, color: Color3?): Frame
|
||||
local item = Instance.new("Frame")
|
||||
item.Name = name
|
||||
item.BorderSizePixel = 0
|
||||
item.BackgroundTransparency = 1
|
||||
item.AnchorPoint = Vector2.new(.5, .5)
|
||||
if color then item.BackgroundColor3 = color end
|
||||
item.Parent = parent
|
||||
return item
|
||||
end
|
||||
|
||||
local function gradient(parent: Frame, transparency: NumberSequence, rotation: number, color: ColorSequence?)
|
||||
local effect = Instance.new("UIGradient")
|
||||
effect.Transparency = transparency
|
||||
effect.Rotation = rotation
|
||||
if color then effect.Color = color end
|
||||
effect.Parent = parent
|
||||
end
|
||||
|
||||
function ArenaMobilityScreen.new(parent: PlayerGui)
|
||||
local gui = Instance.new("ScreenGui")
|
||||
gui.Name = "ArenaMobilityScreen"
|
||||
gui.ResetOnSpawn = false
|
||||
gui.ScreenInsets = Enum.ScreenInsets.None
|
||||
gui.DisplayOrder = 8
|
||||
gui.Enabled = false
|
||||
|
||||
local speedLayer = frame("Speed", gui)
|
||||
speedLayer.Position = UDim2.fromScale(.5, .5)
|
||||
speedLayer.Size = UDim2.fromScale(1, 1)
|
||||
local jumpLayer = frame("JumpMagic", gui)
|
||||
jumpLayer.Position = speedLayer.Position
|
||||
jumpLayer.Size = speedLayer.Size
|
||||
local random = Random.new(606)
|
||||
|
||||
local streaks: {Streak} = {}
|
||||
for i = 1, 32 do
|
||||
local angle = (i + random:NextNumber(-.35, .35)) * math.pi / 16
|
||||
local tint = gold:Lerp(coral, random:NextNumber(0, .76))
|
||||
local halo = frame("SpeedStreak", speedLayer, tint)
|
||||
local stroke = frame("Core", halo, white)
|
||||
stroke.Position = UDim2.fromScale(.5, .5)
|
||||
stroke.Size = UDim2.fromScale(1, .32)
|
||||
gradient(halo, streakShape, 0)
|
||||
gradient(stroke, streakShape, 0, ColorSequence.new(tint, white))
|
||||
table.insert(streaks, {
|
||||
halo = halo, core = stroke, direction = Vector2.new(math.cos(angle), math.sin(angle)),
|
||||
offset = random:NextNumber(), speed = random:NextNumber(.78, 1.50), length = random:NextNumber(.65, 1.46),
|
||||
})
|
||||
end
|
||||
|
||||
local glows: {Frame} = {}
|
||||
local sigils: {Sigil} = {}
|
||||
local sparks: {Spark} = {}
|
||||
for _, side in {-1, 1} do
|
||||
local glow = frame("SideAura", jumpLayer, violet)
|
||||
glow.AnchorPoint = Vector2.new(if side == -1 then 0 else 1, .5)
|
||||
glow.Position = UDim2.fromScale(if side == -1 then 0 else 1, .5)
|
||||
glow.Size = UDim2.fromScale(.25, 1)
|
||||
gradient(glow, edgeShape, if side == -1 then 0 else 180, ColorSequence.new(white, lilac))
|
||||
table.insert(glows, glow)
|
||||
for i = 1, 6 do
|
||||
local root = frame("Sigil", jumpLayer)
|
||||
root.Size = UDim2.fromOffset(34, 34)
|
||||
local scale = Instance.new("UIScale")
|
||||
scale.Parent = root
|
||||
local diamond = frame("Diamond", root)
|
||||
diamond.Position = UDim2.fromScale(.5, .5)
|
||||
diamond.Size = UDim2.fromScale(.44, .44)
|
||||
diamond.Rotation = 45
|
||||
local outline = Instance.new("UIStroke")
|
||||
outline.ApplyStrokeMode = Enum.ApplyStrokeMode.Border
|
||||
outline.Color = if i % 2 == 0 then violet else lilac
|
||||
outline.Thickness = 1.4
|
||||
outline.Parent = diamond
|
||||
local stars: {Frame} = {}
|
||||
for j = -1, 1 do
|
||||
local star = frame("Star", root, if j == 0 then white else lilac)
|
||||
star.Position = UDim2.fromScale(.5, .5 + j * .33)
|
||||
star.Size = if j == 0 then UDim2.fromOffset(5, 5) else UDim2.fromOffset(3, 3)
|
||||
star.Rotation = 45
|
||||
table.insert(stars, star)
|
||||
end
|
||||
table.insert(sigils, {root = root, scale = scale, diamond = outline, stars = stars, side = side, index = i})
|
||||
end
|
||||
for i = 1, 15 do
|
||||
local spark = frame("Spark", jumpLayer, violet:Lerp(lilac, random:NextNumber(.3, 1)))
|
||||
table.insert(sparks, {
|
||||
frame = spark, side = side, offset = random:NextNumber() * .48, x = random:NextNumber(.033, .24),
|
||||
lift = random:NextNumber(.25, .66), bend = random:NextNumber(-.045, .045), size = random:NextNumber(2, 7),
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
gui.Parent = parent
|
||||
local boostBegan, boostEnds, jumpBegan = 0, 0, 0
|
||||
local function boost(now: number, expiry: number)
|
||||
boostBegan, boostEnds = now, expiry
|
||||
end
|
||||
local function jump(now: number)
|
||||
jumpBegan = now
|
||||
end
|
||||
local function reset()
|
||||
boostBegan, boostEnds, jumpBegan = 0, 0, 0
|
||||
gui.Enabled = false
|
||||
end
|
||||
|
||||
local function render(now: number, aiming: boolean)
|
||||
local boosted = boostEnds > 0 and now < boostEnds + .21
|
||||
local airborne = jumpBegan > 0 and now - jumpBegan < jumpDuration
|
||||
gui.Enabled = boosted or airborne
|
||||
if not gui.Enabled then return end
|
||||
local subdued = if aiming then .28 else 1
|
||||
local size = gui.AbsoluteSize
|
||||
speedLayer.Visible = boosted
|
||||
jumpLayer.Visible = airborne
|
||||
|
||||
if boosted then
|
||||
local age = now - boostBegan
|
||||
local attack = math.clamp((age + .025) / .16, 0, 1)
|
||||
local release = math.clamp((boostEnds + .21 - now) / .33, 0, 1)
|
||||
local intensity = attack * release * subdued
|
||||
for _, streak in streaks do
|
||||
local t = (age * streak.speed + streak.offset) % 1
|
||||
local dx, dy = streak.direction.X, streak.direction.Y
|
||||
local edge = math.max(math.abs(dx), math.abs(dy))
|
||||
local distance = (.67 + .42 * t) / edge
|
||||
local length = size.Y * (.027 + .079 * t) * streak.length
|
||||
local visibility = math.sin(math.pi * t) ^ .6 * intensity
|
||||
streak.halo.Position = UDim2.fromScale(.5 + .5 * dx * distance, .5 + .5 * dy * distance)
|
||||
streak.halo.Size = UDim2.fromOffset(length, math.max(3, 5.4 * streak.length))
|
||||
streak.halo.Rotation = math.deg(math.atan2(dy * size.Y, dx * size.X))
|
||||
streak.halo.BackgroundTransparency = 1 - visibility * .30
|
||||
streak.core.BackgroundTransparency = 1 - visibility * .86
|
||||
end
|
||||
end
|
||||
|
||||
if airborne then
|
||||
local age = now - jumpBegan
|
||||
local t = math.clamp(age / jumpDuration, 0, 1)
|
||||
local flare = (1 - t) ^ 2 * math.clamp((age + .025) / .09, 0, 1) * subdued
|
||||
for _, glow in glows do glow.BackgroundTransparency = 1 - flare * .34 end
|
||||
for _, sigil in sigils do
|
||||
local lift = (sigil.index - 1) / 5
|
||||
local phase = math.clamp((age - lift * .10) / .82, 0, 1)
|
||||
local fade = math.sin(phase * math.pi) ^ 1.25 * subdued
|
||||
local x = .5 + sigil.side * (.405 - .055 * math.sin(lift * math.pi) + .045 * phase)
|
||||
local y = .92 - lift * .49 - .26 * phase
|
||||
sigil.root.Position = UDim2.fromScale(x, y)
|
||||
sigil.root.Rotation = sigil.side * (25 - lift * 40 + phase * 36)
|
||||
sigil.scale.Scale = .75 + .42 * math.sin(math.pi * phase) + lift * .23
|
||||
sigil.diamond.Transparency = 1 - fade * .85
|
||||
for _, star in sigil.stars do star.BackgroundTransparency = 1 - fade * .96 end
|
||||
end
|
||||
for _, spark in sparks do
|
||||
local p = math.clamp((age - spark.offset) / .50, 0, 1)
|
||||
local x = .5 + spark.side * (.5 - spark.x + spark.bend * p)
|
||||
spark.frame.Position = UDim2.fromScale(x, .98 - spark.lift * p - spark.offset * .32)
|
||||
spark.frame.Rotation = 45 + spark.side * 95 * p
|
||||
local size = spark.size * (1 - .48 * p)
|
||||
spark.frame.Size = UDim2.fromOffset(size, size)
|
||||
spark.frame.BackgroundTransparency = 1 - math.sin(p * math.pi) * .85 * subdued
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return {
|
||||
boost = boost, jump = jump, render = render, reset = reset,
|
||||
destroy = function() gui:Destroy() end,
|
||||
}
|
||||
end
|
||||
|
||||
return ArenaMobilityScreen
|
||||
@@ -0,0 +1,40 @@
|
||||
--!strict
|
||||
local ArenaModes = {Procedural = "Procedural"}
|
||||
local trace: RaycastParams? = nil
|
||||
|
||||
function ArenaModes.of(_player: Player): string
|
||||
return ArenaModes.Procedural
|
||||
end
|
||||
|
||||
function ArenaModes.state(root: Instance, _mode: string): Instance
|
||||
return root:WaitForChild(ArenaModes.Procedural)
|
||||
end
|
||||
|
||||
function ArenaModes.open(root: Instance, mode: string, now: number): boolean
|
||||
if mode ~= ArenaModes.Procedural then return false end
|
||||
local state = ArenaModes.state(root, mode)
|
||||
local deadline = state:GetAttribute("EndsAt")
|
||||
return state:GetAttribute("Phase") == "Round" and typeof(deadline) == "number" and now < deadline
|
||||
end
|
||||
|
||||
function ArenaModes.geometry(_mode: string): Model
|
||||
return workspace:WaitForChild("ProceduralArena") :: Model
|
||||
end
|
||||
|
||||
function ArenaModes.same(player: Player, other: Player): boolean
|
||||
return player:GetAttribute("ArenaMode") == other:GetAttribute("ArenaMode")
|
||||
end
|
||||
|
||||
function ArenaModes.collision(mode: string): RaycastParams
|
||||
local cached = trace
|
||||
if cached then return cached end
|
||||
local params = RaycastParams.new()
|
||||
params.FilterType = Enum.RaycastFilterType.Include
|
||||
params.FilterDescendantsInstances = {ArenaModes.geometry(mode)}
|
||||
params.IgnoreWater = true
|
||||
params.RespectCanCollide = true
|
||||
trace = params
|
||||
return params
|
||||
end
|
||||
|
||||
return table.freeze(ArenaModes)
|
||||
@@ -0,0 +1,91 @@
|
||||
--!strict
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local Modes = require(ReplicatedStorage:WaitForChild("ArenaModes") :: ModuleScript)
|
||||
|
||||
local Sites = {}
|
||||
export type Site = {name: string, position: Vector3}
|
||||
export type Map = {blue: Vector3, orange: Vector3, ground: Site, gallery: Site, roof: Site, west: Site, east: Site}
|
||||
|
||||
local level = 32.51785
|
||||
|
||||
function Sites.resolve(id: string): Map
|
||||
local origin = Modes.geometry(id):GetPivot().Position
|
||||
local geometry = Modes.collision(id)
|
||||
local function sample(point: Vector3): Vector3?
|
||||
local floor = workspace:Raycast(point + Vector3.yAxis * 2, -Vector3.yAxis * 5, geometry)
|
||||
if not floor or floor.Normal.Y < .95 or math.abs(floor.Position.Y - point.Y) > 1.6 then return nil end
|
||||
if workspace:Raycast(floor.Position + Vector3.yAxis * .15, Vector3.yAxis * 6, geometry) then return nil end
|
||||
return floor.Position
|
||||
end
|
||||
local function find(name: string, candidates: {Vector3}): Site
|
||||
for _, candidate in candidates do
|
||||
local at = origin + candidate
|
||||
local center = sample(at)
|
||||
if center and sample(at + Vector3.xAxis * 4) and sample(at - Vector3.xAxis * 4)
|
||||
and sample(at + Vector3.zAxis * 4) and sample(at - Vector3.zAxis * 4) then
|
||||
return {name = name, position = center}
|
||||
end
|
||||
end
|
||||
error("No walkable match objective: " .. id .. " / " .. name)
|
||||
end
|
||||
local base = Vector3.new(0, 0, 205)
|
||||
local gallery = {Vector3.new(0, level, 44), Vector3.new(0, level, -44)}
|
||||
local roof = {Vector3.yAxis * level * 2, Vector3.new(0, level * 2, 12)}
|
||||
return {
|
||||
blue = find("База синих", {-base}).position,
|
||||
orange = find("База оранжевых", {base}).position,
|
||||
ground = find("Нижний проход", {Vector3.zero, Vector3.new(0, 0, 6)}),
|
||||
gallery = find("Средняя галерея", gallery),
|
||||
roof = find("Крыша цитадели", roof),
|
||||
west = find("Западный фланг", {Vector3.new(-162.6, 0, 0), Vector3.new(-145, 0, 0), Vector3.new(-120, 0, 0)}),
|
||||
east = find("Восточный фланг", {Vector3.new(162.6, 0, 0), Vector3.new(145, 0, 0), Vector3.new(120, 0, 0)}),
|
||||
}
|
||||
end
|
||||
|
||||
function Sites.hotPath(id: string, map: Map, radius: number): {Site}
|
||||
local origin = Modes.geometry(id):GetPivot().Position
|
||||
local geometry = Modes.collision(id)
|
||||
local function fits(center: Vector3): boolean
|
||||
for index = 0, 15 do
|
||||
local angle = index * math.pi / 8
|
||||
local offset = Vector3.new(math.cos(angle), 0, math.sin(angle)) * (radius + .4)
|
||||
for _, distance in {0.5, 1} do
|
||||
local at = center + offset * distance
|
||||
local floor = workspace:Raycast(at + Vector3.yAxis * 1.2, -Vector3.yAxis * 2.4, geometry)
|
||||
if not floor or floor.Normal.Y < .95 or math.abs(floor.Position.Y - center.Y) > .35 then return false end
|
||||
if workspace:Raycast(at + Vector3.yAxis * .25, Vector3.yAxis * 9, geometry) then return false end
|
||||
end
|
||||
for _, height in {1, 4, 8} do
|
||||
if workspace:Raycast(center + Vector3.yAxis * height, offset, geometry) then return false end
|
||||
end
|
||||
end
|
||||
return workspace:Raycast(center + Vector3.yAxis * .25, Vector3.yAxis * 9, geometry) == nil
|
||||
end
|
||||
local path: {Site} = {}
|
||||
local function insert(site: Site, alternatives: {Vector3})
|
||||
local candidates = {site.position}
|
||||
for _, offset in alternatives do table.insert(candidates, origin + offset) end
|
||||
for _, candidate in candidates do
|
||||
local floor = workspace:Raycast(candidate + Vector3.yAxis * 1.2, -Vector3.yAxis * 2.4, geometry)
|
||||
if floor and floor.Normal.Y >= .95 and math.abs(floor.Position.Y - candidate.Y) <= .35 and fits(floor.Position) then
|
||||
table.insert(path, {name = site.name, position = floor.Position})
|
||||
return
|
||||
end
|
||||
end
|
||||
error("No room for Hot Point: " .. site.name)
|
||||
end
|
||||
insert(map.ground, {Vector3.new(18, 0, 0), Vector3.new(-18, 0, 0)})
|
||||
insert(map.west, {Vector3.new(-151, 0, 0), Vector3.new(-176, 0, 0), Vector3.new(-189, 0, 0)})
|
||||
insert(map.roof, {Vector3.new(0, 2 * level, 24), Vector3.new(0, 2 * level, -24)})
|
||||
insert(map.east, {Vector3.new(151, 0, 0), Vector3.new(176, 0, 0), Vector3.new(189, 0, 0)})
|
||||
local galleries = {Vector3.new(0, level, 0)}
|
||||
for _, x in {36, -36, 45, -45, 18, -18} do
|
||||
for _, z in {0, 27, -27, 34, -34} do
|
||||
table.insert(galleries, Vector3.new(x, level, z))
|
||||
end
|
||||
end
|
||||
insert(map.gallery, galleries)
|
||||
return path
|
||||
end
|
||||
|
||||
return Sites
|
||||
@@ -0,0 +1,581 @@
|
||||
--!strict
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local Modes = require(ReplicatedStorage:WaitForChild("ArenaModes") :: ModuleScript)
|
||||
local Sites = require(script.Parent:WaitForChild("ArenaObjectiveSites") :: ModuleScript)
|
||||
local HotPoint = require(script.Parent:WaitForChild("HotPoint") :: ModuleScript)
|
||||
local SiegeConfig = require(ReplicatedStorage:WaitForChild("CitadelAssaultConfig") :: ModuleScript)
|
||||
local Capture = require(script.Parent:WaitForChild("CitadelCaptureService") :: ModuleScript)
|
||||
local Score = require(script.Parent:WaitForChild("CitadelScoreService") :: ModuleScript)
|
||||
local SiegeSpawn = require(script.Parent:WaitForChild("CitadelSpawnService") :: ModuleScript)
|
||||
local CollectionService = game:GetService("CollectionService")
|
||||
|
||||
type Side = "Blue" | "Orange"
|
||||
type Fighter = HotPoint.Fighter
|
||||
type Marker = HotPoint.Marker
|
||||
type Zone = {site: Sites.Site, marker: Marker, owner: Side?, claiming: Side?, progress: number}
|
||||
type Flag = {side: Side, marker: Marker, carrier: Player?, droppedUntil: number}
|
||||
type Drop = {marker: Marker, amount: number, expires: number}
|
||||
type Config = {arena: string, rule: string, state: Instance, now: number, duration: number,
|
||||
members: () -> {Player}, bench: (Player) -> (), deploy: (Player) -> (), balanceWaiting: () -> ()}
|
||||
export type Match = {
|
||||
step: (number) -> boolean, kill: (Player, Player, Vector3, number) -> (),
|
||||
hit: ((Player, number, boolean) -> ())?,
|
||||
death: (Player, Vector3?, number) -> (), leaving: (Player, Vector3?, number) -> (),
|
||||
winner: () -> string, destroy: () -> (),
|
||||
}
|
||||
|
||||
local active: {[string]: Match} = {}
|
||||
local Objectives = {}
|
||||
local sides: {Side} = {"Blue", "Orange"}
|
||||
local blue = Color3.fromRGB(67, 216, 255)
|
||||
local orange = Color3.fromRGB(255, 150, 68)
|
||||
local gold = Color3.fromRGB(255, 220, 96)
|
||||
local neutral = Color3.fromRGB(188, 150, 255)
|
||||
local rng = Random.new()
|
||||
|
||||
local function opposite(side: Side): Side
|
||||
return if side == "Blue" then "Orange" else "Blue"
|
||||
end
|
||||
|
||||
local function color(side: Side?): Color3
|
||||
return if side == "Blue" then blue elseif side == "Orange" then orange else neutral
|
||||
end
|
||||
|
||||
local function sideOf(player: Player): Side?
|
||||
local side = player:GetAttribute("ArenaTeam")
|
||||
return if side == "Blue" then "Blue" elseif side == "Orange" then "Orange" else nil
|
||||
end
|
||||
|
||||
local function boundsAt(position: Vector3, target: Vector3, radius: number, height: number): boolean
|
||||
local delta = position - target
|
||||
return math.abs(delta.Y) < height and delta.X * delta.X + delta.Z * delta.Z <= radius * radius
|
||||
end
|
||||
|
||||
local function label(adornee: BasePart, name: string, tint: Color3, offset: number, waypoint: boolean?): TextLabel
|
||||
local gui = Instance.new("BillboardGui")
|
||||
gui.Name = "ObjectiveLabel"
|
||||
gui.Size = UDim2.fromOffset(220, 26)
|
||||
gui.StudsOffsetWorldSpace = Vector3.yAxis * offset
|
||||
gui.MaxDistance = if waypoint then 710 else 170
|
||||
gui.AlwaysOnTop = waypoint == true
|
||||
gui.LightInfluence = 0
|
||||
gui.Parent = adornee
|
||||
local text = Instance.new("TextLabel")
|
||||
text.Size = UDim2.fromScale(1, 1)
|
||||
text.BackgroundTransparency = 1
|
||||
text.Font = Enum.Font.GothamBlack
|
||||
text.TextSize = 15
|
||||
text.Text, text.TextColor3 = name, tint
|
||||
text.TextStrokeColor3, text.TextStrokeTransparency = Color3.fromRGB(9, 13, 25), .14
|
||||
text.Parent = gui
|
||||
return text
|
||||
end
|
||||
|
||||
local function marker(parent: Instance, id: string, name: string, at: Vector3, tint: Color3, diameter: number, tall: boolean?): Marker
|
||||
local part = Instance.new("Part")
|
||||
part.Name = id
|
||||
part.Shape = if tall then Enum.PartType.Ball else Enum.PartType.Cylinder
|
||||
part.Size = if tall then Vector3.new(diameter, diameter, diameter) else Vector3.new(.16, diameter, diameter)
|
||||
part.CFrame = CFrame.new(at + Vector3.yAxis * (if tall then 2.4 else .12)) * CFrame.Angles(0, 0, math.pi / 2)
|
||||
part.Anchored, part.CanCollide, part.CanQuery, part.CanTouch, part.CastShadow = true, false, false, false, false
|
||||
part.Material, part.Color = Enum.Material.Neon, tint
|
||||
part.Transparency = if tall then .04 else .76
|
||||
local aura = Instance.new("PointLight")
|
||||
aura.Range, aura.Brightness, aura.Color = if tall then 13 else 9, .7, tint
|
||||
aura.Parent = part
|
||||
part.Parent = parent
|
||||
return {body = part, label = label(part, name, tint, if tall then 2.1 else 4, id ~= "Tokens"), origin = at}
|
||||
end
|
||||
|
||||
local function paint(mark: Marker, tint: Color3)
|
||||
if mark.body.Color == tint then return end
|
||||
mark.body.Color = tint
|
||||
mark.label.TextColor3 = tint
|
||||
local aura = mark.body:FindFirstChildOfClass("PointLight")
|
||||
if aura then aura.Color = tint end
|
||||
end
|
||||
|
||||
local function visibleAt(fighter: Fighter, at: Vector3, geometry: RaycastParams): boolean
|
||||
return workspace:Raycast(fighter.root.Position, at - fighter.root.Position, geometry) == nil
|
||||
end
|
||||
|
||||
local function presence(fighters: {Fighter}, zone: Zone, geometry: RaycastParams): (boolean, boolean)
|
||||
local b, o = false, false
|
||||
-- Separate vertically stacked objectives by avatar foot height.
|
||||
for _, fighter in fighters do
|
||||
if boundsAt(fighter.root.Position, zone.site.position, 11, 8)
|
||||
and visibleAt(fighter, zone.site.position + Vector3.yAxis * 2.7, geometry) then
|
||||
if fighter.side == "Blue" then b = true else o = true end
|
||||
end
|
||||
end
|
||||
return b, o
|
||||
end
|
||||
|
||||
function Objectives.current(arena: string): Match?
|
||||
return active[arena]
|
||||
end
|
||||
|
||||
function Objectives.start(config: Config): Match
|
||||
local rule, state, arena = config.rule, config.state, config.arena
|
||||
local world = Modes.geometry(arena)
|
||||
local geometry = Modes.collision(arena)
|
||||
local map = if rule == "TeamDeathmatch" or rule == "HuntLeader" then nil else Sites.resolve(arena)
|
||||
local hotPath = if rule == "HotPoint" and map then Sites.hotPath(arena, map, HotPoint.Radius) else nil
|
||||
local folder = Instance.new("Folder")
|
||||
folder.Name = "MatchObjectives"
|
||||
folder.Parent = world
|
||||
local blueScore, orangeScore = 0, 0
|
||||
local function add(side: Side, points: number)
|
||||
if side == "Blue" then blueScore += points else orangeScore += points end
|
||||
state:SetAttribute(side .. "Score", if side == "Blue" then blueScore else orangeScore)
|
||||
end
|
||||
local function status(text: string)
|
||||
if state:GetAttribute("ObjectiveStatus") ~= text then state:SetAttribute("ObjectiveStatus", text) end
|
||||
end
|
||||
state:SetAttribute("BlueScore", 0)
|
||||
state:SetAttribute("OrangeScore", 0)
|
||||
state:SetAttribute("ObjectiveStatus", "")
|
||||
local function collect(members: {Player}): {Fighter}
|
||||
local found: {Fighter} = {}
|
||||
for _, p in members do
|
||||
local side = sideOf(p)
|
||||
local c = p.Character
|
||||
local h = c and c:FindFirstChildOfClass("Humanoid")
|
||||
local r = c and c:FindFirstChild("HumanoidRootPart")
|
||||
if side and h and h.Health > 0 and r and r:IsA("BasePart") and p:GetAttribute("InArena") == true then
|
||||
table.insert(found, {player = p, side = side, root = r})
|
||||
end
|
||||
end
|
||||
return found
|
||||
end
|
||||
local function makeZone(site: Sites.Site, name: string): Zone
|
||||
return {site = site, marker = marker(folder, name, site.name, site.position, neutral, 22), owner = nil, claiming = nil, progress = 0}
|
||||
end
|
||||
local zones: {Zone} = {}
|
||||
local hotPoint = if hotPath then HotPoint.start({
|
||||
state = state, geometry = geometry, sites = hotPath, startedAt = config.now,
|
||||
marker = function(site: Sites.Site): Marker
|
||||
return marker(folder, "HotPoint", "ГОРЯЧАЯ ТОЧКА", site.position, neutral, HotPoint.Radius * 2)
|
||||
end,
|
||||
score = add, status = status,
|
||||
}) else nil
|
||||
local flags: {[Side]: Flag} = {}
|
||||
local tokens: {Drop} = {}
|
||||
local carried: {[Player]: number} = {}
|
||||
local leaders: {[Side]: Player} = {}
|
||||
local previousLeader: {[Side]: Player} = {}
|
||||
local leaderLabels: {[Player]: BillboardGui} = {}
|
||||
local siegeTimes: Score.Ledger = {Blue = {}, Orange = {}}
|
||||
local siegeSide: Side = if SiegeConfig.FIRST_ATTACKER == "Orange" then "Orange" else "Blue"
|
||||
local siegeIndex, siegeProgress = 1, 0
|
||||
local hadSiegeSwap = false
|
||||
local siegeState: Folder? = nil
|
||||
local lifeActive, miniNumber = false, 0
|
||||
local lifeEnds, nextMini = math.huge, config.now + 2
|
||||
local lastStep, nextScore = config.now, config.now + 1
|
||||
local match: Match
|
||||
|
||||
if map then
|
||||
if rule == "Domination" then
|
||||
for i, site in {map.west, map.gallery, map.east} do
|
||||
local key = string.char(64 + i)
|
||||
local zone = makeZone(site, key)
|
||||
zone.marker.label.Text = key .. " · " .. site.name
|
||||
table.insert(zones, zone)
|
||||
end
|
||||
elseif rule == "CaptureFlag" or rule == "TrophyHunt" then
|
||||
for _, side in sides do
|
||||
local at = if side == "Blue" then map.blue else map.orange
|
||||
local name = if side == "Blue" then "БАЗА СИНИХ" else "БАЗА ОРАНЖЕВЫХ"
|
||||
marker(folder, side .. "Base", name, at, color(side), 15)
|
||||
if rule == "CaptureFlag" then
|
||||
local flag = marker(folder, side .. "Flag", "ФЛАГ", at, color(side), 2.6, true)
|
||||
flag.body.Transparency = 1
|
||||
flag.body.CFrame = CFrame.new(flag.body.Position)
|
||||
local function attach(name: string, size: Vector3, offset: Vector3, tint: Color3)
|
||||
local part = Instance.new("Part")
|
||||
part.Name, part.Size, part.Color = name, size, tint
|
||||
part.CFrame = flag.body.CFrame + offset
|
||||
part.Material = Enum.Material.Neon
|
||||
part.Massless, part.CanCollide, part.CanTouch, part.CanQuery = true, false, false, false
|
||||
part.Parent = flag.body
|
||||
local weld = Instance.new("WeldConstraint")
|
||||
weld.Part0, weld.Part1, weld.Parent = flag.body, part, part
|
||||
end
|
||||
attach("Pole", Vector3.new(.17, 4.5, .17), Vector3.new(0, 0, 0), Color3.fromRGB(203, 221, 238))
|
||||
attach("Banner", Vector3.new(2.65, 1.48, .15), Vector3.new(1.35, 1.45, 0), color(side))
|
||||
flags[side] = {side = side, marker = flag, carrier = nil, droppedUntil = 0}
|
||||
end
|
||||
end
|
||||
elseif rule == "Siege" then
|
||||
local data = Instance.new("Folder")
|
||||
data.Name = "CitadelMatchState"
|
||||
data.Parent = state
|
||||
siegeState = data
|
||||
local sites: {Sites.Site} = {map.ground, map.gallery, map.roof}
|
||||
for _, point in CollectionService:GetTagged("CitadelPoint") do
|
||||
if not point:IsA("BasePart") or not point:IsDescendantOf(world) then continue end
|
||||
local index = point:GetAttribute("Index")
|
||||
if typeof(index) == "number" and index % 1 == 0 and sites[index] then
|
||||
sites[index] = {name = sites[index].name, position = point.Position}
|
||||
end
|
||||
end
|
||||
for i, site in sites do
|
||||
local zone = makeZone(site, "Checkpoint" .. i)
|
||||
zone.marker.body:SetAttribute("Index", i)
|
||||
zone.marker.body.Parent = nil
|
||||
table.insert(zones, zone)
|
||||
end
|
||||
zones[1].marker.body.Parent = folder
|
||||
end
|
||||
end
|
||||
|
||||
local function putFlag(flag: Flag, at: Vector3)
|
||||
flag.marker.body.CFrame = CFrame.new(at + Vector3.yAxis * 2.4)
|
||||
end
|
||||
local function sendHome(flag: Flag)
|
||||
if flag.carrier then flag.carrier:SetAttribute("ArenaFlag", nil) end
|
||||
flag.carrier, flag.droppedUntil = nil, 0
|
||||
putFlag(flag, flag.marker.origin)
|
||||
end
|
||||
local function floorAt(at: Vector3): Vector3
|
||||
local hit = workspace:Raycast(at + Vector3.yAxis * .3, -Vector3.yAxis * 50, geometry)
|
||||
return if hit then hit.Position else (if map then map.ground.position else at)
|
||||
end
|
||||
local function tokenDrop(at: Vector3, amount: number, now: number)
|
||||
local floor = floorAt(at)
|
||||
for _, existing in tokens do
|
||||
if boundsAt(existing.marker.origin, floor, 3.5, 3) then
|
||||
existing.amount += amount
|
||||
existing.expires = now + 42
|
||||
existing.marker.label.Text = "ЖЕТОНЫ ×" .. existing.amount
|
||||
return
|
||||
end
|
||||
end
|
||||
if #tokens >= 60 then
|
||||
local old = table.remove(tokens, 1)
|
||||
old.marker.body:Destroy()
|
||||
end
|
||||
table.insert(tokens, {marker = marker(folder, "Tokens", "ЖЕТОНЫ ×" .. amount, floor, gold, 1.55, true), amount = amount, expires = now + 42})
|
||||
end
|
||||
local function dropCarried(player: Player, at: Vector3?, now: number)
|
||||
for _, flag in flags do
|
||||
if flag.carrier ~= player then continue end
|
||||
if at then
|
||||
flag.carrier, flag.droppedUntil = nil, now + 20
|
||||
putFlag(flag, floorAt(at))
|
||||
else
|
||||
sendHome(flag)
|
||||
end
|
||||
player:SetAttribute("ArenaFlag", nil)
|
||||
end
|
||||
local amount = carried[player]
|
||||
if amount then
|
||||
carried[player] = nil
|
||||
player:SetAttribute("ArenaTokens", nil)
|
||||
if at then tokenDrop(at, amount, now) end
|
||||
end
|
||||
end
|
||||
local function clearLeader(side: Side)
|
||||
local p = leaders[side]
|
||||
if not p then return end
|
||||
previousLeader[side] = p
|
||||
leaders[side] = nil
|
||||
p:SetAttribute("ArenaLeader", nil)
|
||||
local badge = leaderLabels[p]
|
||||
if badge then badge:Destroy() end
|
||||
leaderLabels[p] = nil
|
||||
end
|
||||
local function updateLeaders(fighters: {Fighter})
|
||||
for _, side in sides do
|
||||
local roster: {Fighter} = {}
|
||||
local present = false
|
||||
for _, f in fighters do
|
||||
if f.side ~= side then continue end
|
||||
table.insert(roster, f)
|
||||
if f.player == leaders[side] then present = true end
|
||||
end
|
||||
if present then continue end
|
||||
clearLeader(side)
|
||||
if #roster == 0 then continue end
|
||||
local pick = rng:NextInteger(1, #roster)
|
||||
if #roster > 1 and roster[pick].player == previousLeader[side] then pick = pick % #roster + 1 end
|
||||
local p = roster[pick].player
|
||||
local head = p.Character and p.Character:FindFirstChild("Head")
|
||||
if not head or not head:IsA("BasePart") then continue end
|
||||
leaders[side] = p
|
||||
p:SetAttribute("ArenaLeader", true)
|
||||
leaderLabels[p] = label(head, "ЛИДЕР", gold, 2.7).Parent :: BillboardGui
|
||||
end
|
||||
local a, b = leaders.Blue, leaders.Orange
|
||||
status("Лидеры · " .. (if a then a.DisplayName else "—") .. " / " .. (if b then b.DisplayName else "—"))
|
||||
end
|
||||
local function runFlags(fighters: {Fighter}, now: number)
|
||||
for _, side in sides do
|
||||
local flag = flags[side]
|
||||
local carrier = flag.carrier
|
||||
if carrier and carrier.Character and carrier.Character.PrimaryPart then
|
||||
flag.marker.body.CFrame = CFrame.new(carrier.Character.PrimaryPart.Position + Vector3.yAxis * 3.1)
|
||||
elseif carrier or (flag.droppedUntil > 0 and now >= flag.droppedUntil) then
|
||||
sendHome(flag)
|
||||
end
|
||||
if flag.carrier then continue end
|
||||
for _, f in fighters do
|
||||
if not boundsAt(f.root.Position, flag.marker.body.Position, 5.5, 6.5) or not visibleAt(f, flag.marker.body.Position, geometry) then continue end
|
||||
if f.side == side then
|
||||
if flag.droppedUntil > 0 then sendHome(flag) end
|
||||
else
|
||||
flag.carrier = f.player
|
||||
flag.droppedUntil = 0
|
||||
f.player:SetAttribute("ArenaFlag", side)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
for _, fighter in fighters do
|
||||
local own, enemy = flags[fighter.side], flags[opposite(fighter.side)]
|
||||
if enemy.carrier == fighter.player and not own.carrier and own.droppedUntil == 0
|
||||
and boundsAt(fighter.root.Position, own.marker.origin, 7, 7) then
|
||||
add(fighter.side, 1)
|
||||
sendHome(enemy)
|
||||
end
|
||||
end
|
||||
local function stateOf(flag: Flag): string
|
||||
return if flag.carrier then "украден" elseif flag.droppedUntil > 0 then "на земле" else "на базе"
|
||||
end
|
||||
status("Флаг синих: " .. stateOf(flags.Blue) .. " · Флаг оранжевых: " .. stateOf(flags.Orange))
|
||||
end
|
||||
local function runTrophies(fighters: {Fighter}, now: number)
|
||||
if not map then return end
|
||||
for i = #tokens, 1, -1 do
|
||||
local token = tokens[i]
|
||||
local collector: Fighter? = nil
|
||||
if now < token.expires then
|
||||
for _, f in fighters do
|
||||
if boundsAt(f.root.Position, token.marker.origin, 5, 6) and visibleAt(f, token.marker.body.Position, geometry) then collector = f; break end
|
||||
end
|
||||
if not collector then continue end
|
||||
local p = collector.player
|
||||
carried[p] = (carried[p] or 0) + token.amount
|
||||
p:SetAttribute("ArenaTokens", carried[p])
|
||||
end
|
||||
token.marker.body:Destroy()
|
||||
table.remove(tokens, i)
|
||||
end
|
||||
for _, f in fighters do
|
||||
local amount = carried[f.player]
|
||||
if amount and boundsAt(f.root.Position, if f.side == "Blue" then map.blue else map.orange, 8, 7) then
|
||||
add(f.side, amount)
|
||||
carried[f.player] = nil
|
||||
f.player:SetAttribute("ArenaTokens", nil)
|
||||
end
|
||||
end
|
||||
status("Сдавайте собранные жетоны на своей базе")
|
||||
end
|
||||
local function runSiege(members: {Player}, fighters: {Fighter}, now: number, dt: number): boolean
|
||||
local data = assert(siegeState)
|
||||
local half = SiegeConfig.ATTACK_DURATION
|
||||
local elapsed = now - config.now
|
||||
if elapsed >= half and not hadSiegeSwap then
|
||||
hadSiegeSwap = true
|
||||
for _, z in zones do z.marker.body.Parent = nil end
|
||||
siegeSide, siegeIndex, siegeProgress = opposite(siegeSide), 1, 0
|
||||
local arenaSites = assert(map)
|
||||
local ordinals = {Blue = 0, Orange = 0}
|
||||
for _, p in members do
|
||||
config.deploy(p)
|
||||
local side, character = sideOf(p), p.Character
|
||||
if not side or not character or not character.PrimaryPart then continue end
|
||||
local attack = side == siegeSide
|
||||
ordinals[side] += 1
|
||||
local at = SiegeSpawn.position(world, attack, if attack then arenaSites.blue else arenaSites.orange, ordinals[side])
|
||||
character:PivotTo(CFrame.new(at + Vector3.yAxis * 4))
|
||||
end
|
||||
end
|
||||
local swap = elapsed >= half and elapsed < half + SiegeConfig.SWAP_FREEZE
|
||||
local attackStart = if hadSiegeSwap then half + SiegeConfig.SWAP_FREEZE else 0
|
||||
data:SetAttribute("Phase", if swap then "RoleSwap" elseif hadSiegeSwap then "Attack2" else "Attack1")
|
||||
data:SetAttribute("Attacker", siegeSide)
|
||||
data:SetAttribute("Seconds", math.clamp(math.ceil(half - (elapsed - attackStart)), 0, half))
|
||||
if swap then
|
||||
data:SetAttribute("Progress", 0)
|
||||
data:SetAttribute("Status", "Idle")
|
||||
status("СМЕНА РОЛЕЙ")
|
||||
return false
|
||||
end
|
||||
local attacker = if siegeSide == "Blue" then "Синие" else "Оранжевые"
|
||||
local zone = zones[siegeIndex]
|
||||
data:SetAttribute("Index", siegeIndex)
|
||||
if not zone then
|
||||
data:SetAttribute("Point", nil)
|
||||
data:SetAttribute("NextPoint", nil)
|
||||
status("Все рубежи взяты!")
|
||||
return true
|
||||
end
|
||||
zone.marker.body.Parent = folder
|
||||
local attack, defense = false, false
|
||||
for _, fighter in fighters do
|
||||
local delta = fighter.root.Position - zone.site.position
|
||||
local reason = "Outside"
|
||||
if delta.X * delta.X + delta.Z * delta.Z <= SiegeConfig.CAPTURE_RADIUS ^ 2 then
|
||||
if math.abs(delta.Y) > SiegeConfig.HEIGHT_TOLERANCE then reason = "Height"
|
||||
elseif not visibleAt(fighter, zone.site.position + Vector3.yAxis * SiegeConfig.SIGHT_HEIGHT, geometry) then reason = "Blocked"
|
||||
else
|
||||
reason = "Inside"
|
||||
if fighter.side == siegeSide then attack = true else defense = true end
|
||||
end
|
||||
end
|
||||
fighter.player:SetAttribute("CitadelZone", reason)
|
||||
end
|
||||
local progress, phase = Capture.advance(siegeProgress, math.min(dt, math.max(0, elapsed - attackStart)), attack, defense,
|
||||
SiegeConfig.CAPTURE_TIME, SiegeConfig.DECAY_MULTIPLIER)
|
||||
siegeProgress = progress
|
||||
data:SetAttribute("Progress", progress)
|
||||
data:SetAttribute("Status", phase)
|
||||
data:SetAttribute("Point", zone.site.position)
|
||||
data:SetAttribute("PointName", zone.site.name)
|
||||
local nextZone = zones[siegeIndex + 1]
|
||||
data:SetAttribute("NextPoint", if nextZone then nextZone.site.position else nil)
|
||||
local percent = math.floor(progress / SiegeConfig.HUD_PROGRESS_STEP + 1e-8) * SiegeConfig.HUD_PROGRESS_STEP * 100
|
||||
local reason = if phase == "Contested" then "Зона оспаривается!" elseif phase == "Decaying" then "Захват откатывается"
|
||||
elseif phase == "Capturing" then "Захват идёт" else "Двигайтесь к синему кругу"
|
||||
status(string.format("%s · Рубеж %d/%d · %d%% · %s", attacker, siegeIndex, #zones, percent, reason))
|
||||
paint(zone.marker, if phase == "Contested" then orange else blue)
|
||||
if phase ~= "Captured" or not Score.record(siegeTimes, siegeSide, siegeIndex, elapsed - attackStart) then return false end
|
||||
add(siegeSide, SiegeConfig.POINTS_PER_OBJECTIVE)
|
||||
data:SetAttribute(siegeSide .. "Time" .. siegeIndex, elapsed - attackStart)
|
||||
zone.marker.body.Parent = nil
|
||||
siegeIndex += 1
|
||||
siegeProgress = 0
|
||||
return siegeIndex > #zones
|
||||
end
|
||||
local function runOneLife(members: {Player}, fighters: {Fighter}, now: number): boolean
|
||||
if lifeActive then
|
||||
local b, o = 0, 0
|
||||
for _, f in fighters do if f.side == "Blue" then b += 1 else o += 1 end end
|
||||
if (b > 0 and o > 0) and now < lifeEnds then
|
||||
status(string.format("Мини-раунд %d · Живы %d / %d · %d с", miniNumber, b, o, math.ceil(lifeEnds - now)))
|
||||
return false
|
||||
end
|
||||
if b ~= o then add(if b > o then "Blue" else "Orange", 1) end
|
||||
if blueScore >= 3 or orangeScore >= 3 then return true end
|
||||
for _, p in members do config.bench(p) end
|
||||
lifeActive, nextMini = false, now + 4
|
||||
end
|
||||
if now >= nextMini then config.balanceWaiting() end
|
||||
local ready: {Player} = {}
|
||||
local b, o = false, false
|
||||
for _, p in members do
|
||||
local c = p.Character
|
||||
local h = c and c:FindFirstChildOfClass("Humanoid")
|
||||
if not c or not c.PrimaryPart or not h or h.Health <= 0 then continue end
|
||||
table.insert(ready, p)
|
||||
if sideOf(p) == "Blue" then b = true else o = true end
|
||||
end
|
||||
if b and o and now >= nextMini then
|
||||
for _, p in ready do config.deploy(p) end
|
||||
miniNumber += 1
|
||||
lifeActive, lifeEnds = true, now + 45
|
||||
status("Мини-раунд " .. miniNumber)
|
||||
elseif not b or not o then
|
||||
status("Ожидаем игроков с обеих сторон")
|
||||
else
|
||||
status("Следующий мини-раунд через " .. math.ceil(nextMini - now) .. " с")
|
||||
end
|
||||
return false
|
||||
end
|
||||
local function step(now: number): boolean
|
||||
if rule == "TeamDeathmatch" then return false end
|
||||
local elapsed = math.max(0, now - lastStep)
|
||||
local dt = math.min(elapsed, .5)
|
||||
lastStep = now
|
||||
local members = config.members()
|
||||
local fighters = collect(members)
|
||||
if rule == "OneLife" then return runOneLife(members, fighters, now) end
|
||||
if rule == "HuntLeader" then updateLeaders(fighters); return false end
|
||||
if rule == "CaptureFlag" then runFlags(fighters, now); return false end
|
||||
if rule == "TrophyHunt" then runTrophies(fighters, now); return false end
|
||||
if rule == "Siege" then return runSiege(members, fighters, now, dt) end
|
||||
if hotPoint then hotPoint.step(fighters, now, elapsed); return false end
|
||||
|
||||
local scoreNow = now >= nextScore
|
||||
if scoreNow then nextScore = now + 1 end
|
||||
local ownedBlue, ownedOrange = 0, 0
|
||||
for _, zone in zones do
|
||||
local b, o = presence(fighters, zone, geometry)
|
||||
local side: Side? = if b == o then nil elseif b then "Blue" else "Orange"
|
||||
if side and side ~= zone.owner then
|
||||
if zone.claiming ~= side then zone.claiming, zone.progress = side, 0 end
|
||||
zone.progress += dt
|
||||
if zone.progress >= 3 then zone.owner, zone.progress = side, 0 end
|
||||
else
|
||||
zone.claiming, zone.progress = nil, 0
|
||||
end
|
||||
paint(zone.marker, color(zone.owner))
|
||||
if zone.owner == "Blue" then ownedBlue += 1 elseif zone.owner == "Orange" then ownedOrange += 1 end
|
||||
end
|
||||
if scoreNow then
|
||||
if ownedBlue > 0 then add("Blue", ownedBlue) end
|
||||
if ownedOrange > 0 then add("Orange", ownedOrange) end
|
||||
end
|
||||
status(string.format("Точки под контролем · %d / %d", ownedBlue, ownedOrange))
|
||||
return false
|
||||
end
|
||||
|
||||
match = {
|
||||
step = step,
|
||||
hit = if hotPoint then hotPoint.hit else nil,
|
||||
kill = function(player, victim, at, now)
|
||||
local side = sideOf(player)
|
||||
if not side then return end
|
||||
if rule == "TeamDeathmatch" then
|
||||
add(side, 1)
|
||||
elseif rule == "HuntLeader" then
|
||||
local target = opposite(side)
|
||||
local bonus = leaders[target] == victim
|
||||
add(side, if bonus then 3 else 1)
|
||||
if bonus then clearLeader(target) end
|
||||
elseif rule == "TrophyHunt" then
|
||||
tokenDrop(at, 1, now)
|
||||
end
|
||||
end,
|
||||
death = function(player, at, now)
|
||||
if hotPoint then hotPoint.death(player) end
|
||||
dropCarried(player, at, now)
|
||||
if rule == "OneLife" then config.bench(player) end
|
||||
end,
|
||||
leaving = function(player, at, now)
|
||||
if hotPoint then hotPoint.death(player) end
|
||||
dropCarried(player, at, now)
|
||||
local side = sideOf(player)
|
||||
if side and leaders[side] == player then clearLeader(side) end
|
||||
end,
|
||||
winner = function()
|
||||
if rule == "Siege" then
|
||||
local winner, reason = Score.winner(siegeTimes, SiegeConfig.TIE_EPSILON)
|
||||
state:SetAttribute("CitadelResultReason", reason)
|
||||
return winner
|
||||
end
|
||||
if blueScore ~= orangeScore then return if blueScore > orangeScore then "Blue" else "Orange" end
|
||||
return "Draw"
|
||||
end,
|
||||
destroy = function()
|
||||
if siegeState then
|
||||
siegeState:Destroy()
|
||||
for _, p in config.members() do p:SetAttribute("CitadelZone", nil) end
|
||||
end
|
||||
if active[arena] == match then active[arena] = nil end
|
||||
if hotPoint then hotPoint.destroy() end
|
||||
for _, side in sides do clearLeader(side) end
|
||||
for p in carried do p:SetAttribute("ArenaTokens", nil) end
|
||||
for _, flag in flags do if flag.carrier then flag.carrier:SetAttribute("ArenaFlag", nil) end end
|
||||
for _, z in zones do z.marker.body:Destroy() end
|
||||
folder:Destroy()
|
||||
status("")
|
||||
end,
|
||||
}
|
||||
active[arena] = match
|
||||
return match
|
||||
end
|
||||
|
||||
return Objectives
|
||||
@@ -0,0 +1,950 @@
|
||||
--!strict
|
||||
local ContextActionService = game:GetService("ContextActionService")
|
||||
local Players = game:GetService("Players")
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local RunService = game:GetService("RunService")
|
||||
local StarterGui = game:GetService("StarterGui")
|
||||
local TweenService = game:GetService("TweenService")
|
||||
local UserInputService = game:GetService("UserInputService")
|
||||
local UI = require(ReplicatedStorage:WaitForChild("HunterUI") :: ModuleScript)
|
||||
local Modes = require(ReplicatedStorage:WaitForChild("ArenaModes") :: ModuleScript)
|
||||
local Rules = require(ReplicatedStorage:WaitForChild("MatchRules") :: ModuleScript)
|
||||
local Sounds = require(ReplicatedStorage:WaitForChild("SniperEffects") :: ModuleScript)
|
||||
|
||||
local player = Players.LocalPlayer
|
||||
local playerGui = player:WaitForChild("PlayerGui")
|
||||
local state = ReplicatedStorage:WaitForChild("ArenaRound")
|
||||
local results = state:WaitForChild("RoundResults") :: RemoteEvent
|
||||
local limit = state:GetAttribute("TeamLimit") :: number
|
||||
local modeIds = {Modes.Procedural}
|
||||
local function currentMode(): string
|
||||
return Modes.Procedural
|
||||
end
|
||||
local function activeState(): Instance
|
||||
return Modes.state(state, currentMode())
|
||||
end
|
||||
|
||||
local ink, muted, panelColor = UI.Ink, UI.Muted, UI.Panel
|
||||
local blue, orange = UI.Blue, UI.Orange
|
||||
local blueDark = Color3.fromRGB(15, 55, 75)
|
||||
local orangeDark = Color3.fromRGB(99, 48, 35)
|
||||
|
||||
local gui = Instance.new("ScreenGui")
|
||||
gui.Name = "ArenaRoundHud"
|
||||
gui.ResetOnSpawn = false
|
||||
gui.DisplayOrder = 25
|
||||
gui.Parent = playerGui
|
||||
|
||||
local function frame(name: string, parent: Instance, position: UDim2, size: UDim2, color: Color3): Frame
|
||||
local item = Instance.new("Frame")
|
||||
item.Name = name
|
||||
item.Position = position
|
||||
item.Size = size
|
||||
item.BackgroundColor3 = color
|
||||
item.BorderSizePixel = 0
|
||||
item.Parent = parent
|
||||
return item
|
||||
end
|
||||
|
||||
local function corners(item: GuiObject, radius: number)
|
||||
Instance.new("UICorner", item).CornerRadius = UDim.new(0, radius)
|
||||
end
|
||||
|
||||
|
||||
local function gradient(item: GuiObject, light: Color3, dark: Color3, angle: number)
|
||||
item.BackgroundColor3 = Color3.new(1, 1, 1)
|
||||
local tint = Instance.new("UIGradient")
|
||||
tint.Color = ColorSequence.new(light, dark)
|
||||
tint.Rotation = angle
|
||||
tint.Parent = item
|
||||
return tint
|
||||
end
|
||||
|
||||
local function label(parent: Instance, text: string, position: UDim2, size: UDim2, fontSize: number, color: Color3): TextLabel
|
||||
local item = Instance.new("TextLabel")
|
||||
item.BackgroundTransparency = 1
|
||||
item.Text = text
|
||||
item.TextColor3 = color
|
||||
item.TextSize = fontSize
|
||||
item.Font = Enum.Font.GothamMedium
|
||||
item.Position = position
|
||||
item.Size = size
|
||||
item.Parent = parent
|
||||
return item
|
||||
end
|
||||
|
||||
local portraitCache: {[number]: {url: string?, waiting: {[ImageLabel]: boolean}}} = {}
|
||||
|
||||
local function portrait(parent: Instance, position: UDim2, size: number, accent: Color3): ImageLabel
|
||||
local image = UI.portrait(parent, position, size, accent)
|
||||
local initial = image:WaitForChild("Initial") :: TextLabel
|
||||
initial.TextSize = math.floor(size * .48)
|
||||
image:GetPropertyChangedSignal("IsLoaded"):Connect(function()
|
||||
initial.Visible = image.Image == "" or not image.IsLoaded
|
||||
end)
|
||||
return image
|
||||
end
|
||||
|
||||
local function setPortrait(image: ImageLabel, userId: number?, displayName: string?)
|
||||
image.Visible = userId ~= nil
|
||||
if image:GetAttribute("UserId") == userId then return end
|
||||
image:SetAttribute("UserId", userId)
|
||||
image.Image = ""
|
||||
local initial = image.Initial :: TextLabel
|
||||
initial.Visible = true
|
||||
local name = displayName or ""
|
||||
initial.Text = name:sub(1, (utf8.offset(name, 2) or (#name + 1)) - 1):upper()
|
||||
if not userId or userId <= 0 then return end
|
||||
local cached = portraitCache[userId]
|
||||
if cached then
|
||||
if cached.url then
|
||||
image.Image = cached.url
|
||||
initial.Visible = not image.IsLoaded
|
||||
else
|
||||
cached.waiting[image] = true
|
||||
end
|
||||
return
|
||||
end
|
||||
local entry: {url: string?, waiting: {[ImageLabel]: boolean}} = {url = nil, waiting = {[image] = true}}
|
||||
portraitCache[userId] = entry
|
||||
task.spawn(function()
|
||||
for attempt = 1, 3 do
|
||||
local ok, url, ready = pcall(Players.GetUserThumbnailAsync, Players, userId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size100x100)
|
||||
if ok and ready then
|
||||
entry.url = url
|
||||
for target in entry.waiting do
|
||||
if target.Parent and target:GetAttribute("UserId") == userId then
|
||||
target.Image = url
|
||||
local fallback = target.Initial :: TextLabel
|
||||
fallback.Visible = not target.IsLoaded
|
||||
end
|
||||
end
|
||||
break
|
||||
end
|
||||
if attempt < 3 then task.wait(attempt * .75) end
|
||||
end
|
||||
table.clear(entry.waiting)
|
||||
if not entry.url then portraitCache[userId] = nil end
|
||||
end)
|
||||
end
|
||||
|
||||
local hudLayout = frame("MatchHUD", gui, UDim2.fromScale(0, 0), UDim2.fromScale(1, 1), panelColor)
|
||||
hudLayout.BackgroundTransparency = 1
|
||||
local widthOfCard = 373
|
||||
local objective = UI.plate(hudLayout, "Objective", UDim2.fromOffset(15, 75), UDim2.fromOffset(widthOfCard, 62), UI.Blue)
|
||||
local objectiveContour = UI.contour(objective, blue)
|
||||
local objectiveScale = Instance.new("UIScale", objective)
|
||||
objective.Visible = false
|
||||
local objectiveTitle = UI.label(objective, "Rule", "", UDim2.fromOffset(16, 7), UDim2.new(1, -32, 0, 21), 18, ink)
|
||||
objectiveTitle.FontFace = UI.Display
|
||||
objectiveTitle.TextXAlignment = Enum.TextXAlignment.Left
|
||||
local objectiveText = UI.label(objective, "Instructions", "", UDim2.fromOffset(16, 29), UDim2.new(1, -32, 0, 31), 14, ink)
|
||||
objectiveText.Font = Enum.Font.GothamMedium
|
||||
objectiveText.TextWrapped = true
|
||||
objectiveText.TextXAlignment = Enum.TextXAlignment.Left
|
||||
objectiveText.TextYAlignment = Enum.TextYAlignment.Top
|
||||
local objectiveStatus = UI.label(objective, "Status", "", UDim2.fromOffset(16, 60), UDim2.new(1, -32, 0, 25), 12, blue)
|
||||
local siegeBar = Instance.new("Frame")
|
||||
siegeBar.Position = UDim2.fromOffset(16, 88)
|
||||
siegeBar.Size = UDim2.new(1, -32, 0, 5)
|
||||
siegeBar.BackgroundColor3 = Color3.fromRGB(34, 45, 65)
|
||||
siegeBar.BorderSizePixel = 0
|
||||
siegeBar.Visible = false
|
||||
siegeBar.Parent = objective
|
||||
local siegeSegments: {Frame} = {}
|
||||
for i = 1, 10 do
|
||||
local segment = Instance.new("Frame")
|
||||
segment.Position = UDim2.fromScale((i - 1) / 10, 0)
|
||||
segment.Size = UDim2.new(.1, -2, 1, 0)
|
||||
segment.BackgroundColor3 = blue
|
||||
segment.BorderSizePixel = 0
|
||||
segment.Parent = siegeBar
|
||||
siegeSegments[i] = segment
|
||||
end
|
||||
objectiveStatus.TextWrapped = true
|
||||
objectiveStatus.TextXAlignment = Enum.TextXAlignment.Left
|
||||
objectiveStatus.TextYAlignment = Enum.TextYAlignment.Top
|
||||
|
||||
local strip = UI.plate(hudLayout, "Timer", UDim2.fromOffset(15, 7), UDim2.fromOffset(widthOfCard, 63), UI.Outline)
|
||||
UI.contour(strip, blue)
|
||||
local scoreScale = Instance.new("UIScale", strip)
|
||||
|
||||
local function scoreCard(id: string, x: number, accent: Color3): TextLabel
|
||||
local tile = UI.element("ScoreChip", strip, UDim2.fromOffset(x, 9), UDim2.fromOffset(88, 45))
|
||||
tile.Name = id .. "Card"
|
||||
UI.tintPlate(tile, accent:Lerp(ink, .19), accent)
|
||||
local score = label(tile, "0", UDim2.fromScale(.5, .5), UDim2.new(1, 0, 0, 38), 31, panelColor)
|
||||
score.AnchorPoint = Vector2.new(.5, .5)
|
||||
score.Name = "Score"
|
||||
score.FontFace = UI.Display
|
||||
return score
|
||||
end
|
||||
|
||||
local blueScore = scoreCard("Blue", 178, blue)
|
||||
local orangeScore = scoreCard("Orange", 274, orange)
|
||||
local center = frame("Center", strip, UDim2.fromOffset(20, 0), UDim2.fromOffset(150, 61), panelColor)
|
||||
center.BackgroundTransparency = 1
|
||||
local separator = frame("Divider", strip, UDim2.fromOffset(161, 15), UDim2.fromOffset(1, 33), UI.Outline)
|
||||
separator.Rotation = 10
|
||||
local mode = label(center, "", UDim2.fromOffset(1, 4), UDim2.new(1, 0, 0, 12), 10, muted)
|
||||
mode.Name = "PhaseLabel"
|
||||
mode.Font = Enum.Font.GothamBold
|
||||
mode.TextXAlignment = Enum.TextXAlignment.Left
|
||||
local clock = label(center, "", UDim2.fromOffset(0, 6), UDim2.new(1, 0, 0, 46), 40, ink)
|
||||
clock.Name = "Clock"
|
||||
clock.FontFace = UI.Display
|
||||
clock.TextXAlignment = Enum.TextXAlignment.Left
|
||||
local roundLine = UI.element("ProgressBar", strip, UDim2.fromOffset(20, 55), UDim2.fromOffset(126, 2))
|
||||
roundLine.Name = "RoundProgress"
|
||||
local roundFill = roundLine:WaitForChild("Fill") :: Frame
|
||||
roundFill.BackgroundColor3 = blue
|
||||
UI.sheen(roundFill)
|
||||
|
||||
local countdown = frame("RoundCountdown", hudLayout, UDim2.new(.5, 0, 0, 12), UDim2.fromOffset(148, 106), panelColor)
|
||||
countdown.AnchorPoint = Vector2.new(.5, 0)
|
||||
countdown.BackgroundTransparency = 1
|
||||
countdown.Visible = false
|
||||
|
||||
local allyCapture = Color3.fromRGB(90, 247, 170)
|
||||
local enemyCapture = Color3.fromRGB(255, 79, 105)
|
||||
local captureHud = UI.plate(hudLayout, "HotPointCapture", UDim2.new(.5, 0, 0, 10), UDim2.fromOffset(384, 52), UI.Outline)
|
||||
captureHud.AnchorPoint, captureHud.Visible = Vector2.new(.5, 0), false
|
||||
local captureArc = UI.contour(captureHud, allyCapture)
|
||||
local captureLabel = UI.label(captureHud, "Status", "", UDim2.fromOffset(14, 5), UDim2.new(1, -77, 0, 24), 15, ink)
|
||||
captureLabel.FontFace = UI.Display
|
||||
captureLabel.TextXAlignment = Enum.TextXAlignment.Left
|
||||
local captureValue = UI.label(captureHud, "Percent", "", UDim2.new(1, -62, 0, 5), UDim2.fromOffset(48, 24), 15, ink)
|
||||
captureValue.FontFace = UI.Display
|
||||
captureValue.TextXAlignment = Enum.TextXAlignment.Right
|
||||
local captureTrack = UI.element("ProgressBar", captureHud, UDim2.fromOffset(14, 34), UDim2.new(1, -28, 0, 8))
|
||||
captureTrack.Name = "CaptureProgress"
|
||||
local captureFill = captureTrack:WaitForChild("Fill") :: Frame
|
||||
captureFill.Size = UDim2.fromScale(0, 1)
|
||||
UI.sheen(captureFill)
|
||||
local captureTween: Tween? = nil
|
||||
local captureTeam: string? = nil
|
||||
local capturePercent = 0
|
||||
local captureCueTeam: string? = nil
|
||||
local captureCuePhase: string? = nil
|
||||
|
||||
local function countdownDigit(name: string, color: Color3, depth: number): TextLabel
|
||||
local digit = label(countdown, "", UDim2.fromScale(.5, .5), UDim2.fromScale(1, 1), 92, color)
|
||||
digit.Name = name
|
||||
digit.AnchorPoint = Vector2.new(.5, .5)
|
||||
digit.FontFace = UI.Display
|
||||
digit.ZIndex = depth
|
||||
return digit
|
||||
end
|
||||
|
||||
local countdownText = countdownDigit("Digit", Color3.fromRGB(255, 62, 79), 14)
|
||||
local countdownOutline = Instance.new("UIStroke", countdownText)
|
||||
countdownOutline.Color = Color3.fromRGB(33, 4, 13)
|
||||
countdownOutline.Thickness = 4
|
||||
local digitScale = Instance.new("UIScale", countdownText)
|
||||
local echo = countdownDigit("Pulse", Color3.fromRGB(255, 60, 76), 13)
|
||||
local echoScale = Instance.new("UIScale", echo)
|
||||
local digitMotion: Tween? = nil
|
||||
local echoMotion: Tween? = nil
|
||||
local echoFade: Tween? = nil
|
||||
local countdownSound: Sound? = nil
|
||||
|
||||
local function clearCountdownBeat()
|
||||
if digitMotion then digitMotion:Cancel() end
|
||||
if echoMotion then echoMotion:Cancel() end
|
||||
if echoFade then echoFade:Cancel() end
|
||||
if countdownSound then
|
||||
countdownSound:Destroy()
|
||||
countdownSound = nil
|
||||
end
|
||||
end
|
||||
|
||||
local function showCountdownBeat(seconds: number)
|
||||
clearCountdownBeat()
|
||||
local value = tostring(seconds)
|
||||
countdownText.Text = value
|
||||
echo.Text = value
|
||||
digitScale.Scale = .76
|
||||
echoScale.Scale = .96
|
||||
echo.TextTransparency = .5
|
||||
countdown.Visible = true
|
||||
|
||||
digitMotion = TweenService:Create(digitScale, TweenInfo.new(.28, Enum.EasingStyle.Back, Enum.EasingDirection.Out), {Scale = 1})
|
||||
local echoTime = TweenInfo.new(.5, Enum.EasingStyle.Quart, Enum.EasingDirection.Out)
|
||||
echoMotion = TweenService:Create(echoScale, echoTime, {Scale = 1.35})
|
||||
echoFade = TweenService:Create(echo, echoTime, {TextTransparency = 1})
|
||||
digitMotion:Play()
|
||||
echoMotion:Play()
|
||||
echoFade:Play()
|
||||
countdownSound = Sounds.sound("RoundCountdown")
|
||||
end
|
||||
|
||||
local teamStats = UI.plate(hudLayout, "TeamKillStats", UDim2.fromOffset(15, 74), UDim2.fromOffset(widthOfCard, 55), UI.Outline)
|
||||
local teamContour = UI.contour(teamStats, blue)
|
||||
teamStats.Visible = false
|
||||
local statsScale = Instance.new("UIScale", teamStats)
|
||||
local badges = frame("Badges", teamStats, UDim2.fromOffset(10, 5), UDim2.new(1, -19, 1, -9), panelColor)
|
||||
badges.BackgroundTransparency = 1
|
||||
local grid = Instance.new("UIGridLayout")
|
||||
grid.CellSize = UDim2.fromOffset(79, 45)
|
||||
grid.CellPadding = UDim2.fromOffset(4, 4)
|
||||
grid.FillDirectionMaxCells = 5
|
||||
grid.SortOrder = Enum.SortOrder.LayoutOrder
|
||||
grid.Parent = badges
|
||||
|
||||
type KillBadge = {card: Frame, avatar: ImageLabel, kills: TextLabel, killSize: UITextSizeConstraint, teamLine: Frame}
|
||||
local killBadges: {KillBadge} = {}
|
||||
for i = 1, limit do
|
||||
local card = frame("Member" .. i, badges, UDim2.fromOffset(0, 0), UDim2.fromOffset(79, 45), panelColor)
|
||||
card.LayoutOrder = i
|
||||
card.Visible = false
|
||||
card.BackgroundTransparency = 1
|
||||
UI.hoverRow(card, muted)
|
||||
local avatar = portrait(card, UDim2.fromOffset(10, 3), 38, muted)
|
||||
local kills = label(card, "", UDim2.new(0, 51, .5, -16), UDim2.fromOffset(26, 32), 23, ink)
|
||||
kills.Name = "Kills"
|
||||
kills.FontFace = UI.Display
|
||||
kills.TextXAlignment = Enum.TextXAlignment.Left
|
||||
kills.TextScaled = true
|
||||
local killSize = Instance.new("UITextSizeConstraint", kills)
|
||||
local teamLine = frame("Accent", card, UDim2.new(0, 4, .5, -10), UDim2.fromOffset(3, 20), blue)
|
||||
teamLine.Rotation = 17
|
||||
corners(teamLine, 2)
|
||||
UI.sheen(teamLine)
|
||||
killBadges[i] = {card = card, avatar = avatar, kills = kills, killSize = killSize, teamLine = teamLine}
|
||||
end
|
||||
|
||||
local shownMembers = 0
|
||||
local function fitHud()
|
||||
local width = hudLayout.AbsoluteSize.X
|
||||
if width <= 0 then return end
|
||||
scoreScale.Scale = math.clamp((width - 30) / widthOfCard, .46, if width < 540 then .71 else 1)
|
||||
statsScale.Scale = scoreScale.Scale
|
||||
objectiveScale.Scale = scoreScale.Scale
|
||||
local top = 12 + math.round(63 * scoreScale.Scale)
|
||||
objective.Position = UDim2.fromOffset(15, top)
|
||||
if objective.Visible then
|
||||
top += 5 + math.round(objective.Size.Y.Offset * scoreScale.Scale)
|
||||
end
|
||||
teamStats.Position = UDim2.fromOffset(15, top)
|
||||
local packed = shownMembers > 3
|
||||
local columns = if packed then 5 else 3
|
||||
local cellW, cellH = if packed then 62 else 79, if packed then 37 else 45
|
||||
grid.CellSize = UDim2.fromOffset(cellW, cellH)
|
||||
grid.FillDirectionMaxCells = columns
|
||||
local rowCount = math.ceil(shownMembers / columns)
|
||||
local height = 7 + rowCount * (cellH + 4)
|
||||
teamStats.Size = UDim2.fromOffset(18 + (cellW + 4) * math.max(1, math.min(columns, shownMembers)), height)
|
||||
for _, badge in killBadges do
|
||||
local size = if packed then 28 else 38
|
||||
local countX = badge.avatar.Position.X.Offset + size + 3
|
||||
badge.avatar.Size = UDim2.fromOffset(size, size)
|
||||
badge.kills.Size = UDim2.fromOffset(cellW - countX - 2, 32)
|
||||
badge.kills.Position = UDim2.new(0, countX, .5, -16)
|
||||
badge.killSize.MaxTextSize = if packed then 17 else 23
|
||||
end
|
||||
local bottom = top + (if rowCount > 0 then height * scoreScale.Scale else 0)
|
||||
local minimumTop = if countdown.Visible then 119 else 10
|
||||
local captureTop = if width >= 1200 then minimumTop else math.max(minimumTop, bottom + 8)
|
||||
captureHud.Position = UDim2.new(.5, 0, 0, captureTop)
|
||||
captureHud.Size = UDim2.fromOffset(math.floor(math.min(384, width - 24)), 52)
|
||||
gui:SetAttribute("ContentBottom", if width >= 700 then 4 else bottom)
|
||||
end
|
||||
hudLayout:GetPropertyChangedSignal("AbsoluteSize"):Connect(fitHud)
|
||||
fitHud()
|
||||
|
||||
local function refreshCapture()
|
||||
local match = activeState()
|
||||
local phase = match:GetAttribute("HotPointPhase") :: string?
|
||||
local team = player:GetAttribute("ArenaTeam")
|
||||
if not phase or (team ~= "Blue" and team ~= "Orange") or match:GetAttribute("Phase") ~= "Round"
|
||||
or match:GetAttribute("Ruleset") ~= "HotPoint" then
|
||||
if captureTween then captureTween:Cancel(); captureTween = nil end
|
||||
captureHud.Visible, captureTeam, capturePercent = false, nil, 0
|
||||
captureCueTeam, captureCuePhase = nil, nil
|
||||
captureFill.Size = UDim2.fromScale(0, 1)
|
||||
return
|
||||
end
|
||||
local side = match:GetAttribute("HotPointTeam") :: string?
|
||||
local allied = side == team
|
||||
if phase == "Captured" and captureCuePhase ~= "Captured" then
|
||||
Sounds.sound("HotPointCaptured")
|
||||
elseif phase == "Capturing" and allied and side ~= captureCueTeam then
|
||||
Sounds.sound("HotPointStart")
|
||||
end
|
||||
captureCueTeam, captureCuePhase = if phase == "Captured" then nil else side, phase
|
||||
local accent = if not side then UI.Gold elseif allied then allyCapture else enemyCapture
|
||||
captureHud.Visible = true
|
||||
captureLabel.Text = if phase == "Captured" then "ТОЧКА ЗАХВАЧЕНА · +1"
|
||||
elseif phase == "Contested" then "ТОЧКА ОСПАРИВАЕТСЯ"
|
||||
elseif phase == "UnderFire" then (if allied then "ВАШ ЗАХВАТ ТЕРЯЕТСЯ" else "ЗАХВАТ СОПЕРНИКОВ ПАДАЕТ")
|
||||
elseif allied then "ВАША КОМАНДА ЗАХВАТЫВАЕТ" else "СОПЕРНИКИ ЗАХВАТЫВАЮТ"
|
||||
local percent = math.clamp((match:GetAttribute("HotPointProgress") :: number?) or 0, 0, 100)
|
||||
captureValue.Text, captureValue.TextColor3 = string.format("%d%%", percent), accent
|
||||
captureArc:SetAttribute("Accent", accent)
|
||||
captureFill.BackgroundColor3 = accent
|
||||
if percent == capturePercent and side == captureTeam then return end
|
||||
if captureTween then captureTween:Cancel() end
|
||||
local size = UDim2.fromScale(percent / 100, 1)
|
||||
if percent == 0 or side ~= captureTeam then
|
||||
captureFill.Size = size
|
||||
else
|
||||
captureTween = TweenService:Create(captureFill, TweenInfo.new(.17, Enum.EasingStyle.Linear), {Size = size})
|
||||
captureTween:Play()
|
||||
end
|
||||
captureTeam, capturePercent = side, percent
|
||||
end
|
||||
|
||||
local function refreshObjective()
|
||||
local match = activeState()
|
||||
local visible = player:GetAttribute("InArena") == true and match:GetAttribute("Phase") == "Round"
|
||||
local needsLayout = visible ~= objective.Visible
|
||||
objective.Visible = visible
|
||||
siegeBar.Visible = false
|
||||
if visible then
|
||||
local rule = Rules.get(match:GetAttribute("Ruleset"))
|
||||
local accent = if player:GetAttribute("ArenaTeam") == "Orange" then orange else blue
|
||||
objectiveTitle.Text = rule.title
|
||||
objectiveTitle.TextColor3 = accent
|
||||
objectiveText.Text = rule.detail
|
||||
objectiveContour:SetAttribute("Accent", accent)
|
||||
local text = (match:GetAttribute("ObjectiveStatus") :: string?) or ""
|
||||
local siege = match:FindFirstChild("CitadelMatchState")
|
||||
if rule.id == "Siege" and siege then
|
||||
local phase = siege:GetAttribute("Phase")
|
||||
local attacker = siege:GetAttribute("Attacker")
|
||||
local seconds = (siege:GetAttribute("Seconds") :: number?) or 0
|
||||
local zone = player:GetAttribute("CitadelZone")
|
||||
local role = if attacker == player:GetAttribute("ArenaTeam") then "Вы атакуете" else "Вы защищаете"
|
||||
local point = (siege:GetAttribute("PointName") :: string?) or ""
|
||||
objectiveTitle.Text = if phase == "RoleSwap" then "СМЕНА РОЛЕЙ" else string.format("АТАКА %d/2 · %d:%02d",
|
||||
if phase == "Attack2" then 2 else 1, math.floor(seconds / 60), seconds % 60)
|
||||
objectiveText.Text = role .. " · " .. point
|
||||
if phase ~= "RoleSwap" and siege:GetAttribute("Point") then
|
||||
if zone == "Height" then text = "Найдите нужный этаж"
|
||||
elseif zone == "Blocked" then text = "Нет прямой видимости центра"
|
||||
elseif zone == "Inside" and role == "Вы защищаете" then text = "Вы блокируете захват. Оставайтесь в круге!" end
|
||||
siegeBar.Visible = true
|
||||
local progress = (siege:GetAttribute("Progress") :: number?) or 0
|
||||
for i, segment in siegeSegments do
|
||||
segment.Visible = progress + 1e-8 >= i / #siegeSegments
|
||||
segment.BackgroundColor3 = if siege:GetAttribute("Status") == "Contested" then orange else blue
|
||||
end
|
||||
end
|
||||
end
|
||||
local tokens = (player:GetAttribute("ArenaTokens") :: number?) or 0
|
||||
if player:GetAttribute("ArenaFlag") then text = "У вас флаг · Несите его на свою базу"
|
||||
elseif tokens > 0 then text = "Жетонов у вас: " .. tokens .. " · Вернитесь на базу"
|
||||
elseif player:GetAttribute("ArenaLeader") then text = "Вы лидер · За вас дают 3 очка"
|
||||
elseif rule.id == "TrophyHunt" then text = "" end
|
||||
objectiveStatus.Visible = text ~= ""
|
||||
objectiveStatus.Text = text
|
||||
objectiveStatus.TextColor3 = accent:Lerp(ink, .3)
|
||||
local height = if siegeBar.Visible then 101 elseif objectiveStatus.Visible then 88 else 62
|
||||
if height ~= objective.Size.Y.Offset then
|
||||
objective.Size = UDim2.fromOffset(widthOfCard, height)
|
||||
needsLayout = true
|
||||
end
|
||||
end
|
||||
if needsLayout then fitHud() end
|
||||
end
|
||||
|
||||
type ResultPlayer = {userId: number, displayName: string, kills: number, deaths: number}
|
||||
type RoundResult = {mode: string, ruleset: string, winner: string, endsAt: number, duration: number, blueScore: number, orangeScore: number,
|
||||
blue: {ResultPlayer}, orange: {ResultPlayer}, allowModeChange: boolean?, siegeReason: string?}
|
||||
type ResultRow = {body: Frame, avatar: ImageLabel, name: TextLabel, kills: TextLabel, deaths: TextLabel}
|
||||
type ResultTeam = {card: Frame, score: TextLabel, empty: TextLabel, accent: Color3, rows: {ResultRow}}
|
||||
type SummaryView = "Live" | "Final"
|
||||
|
||||
local resultsGui = Instance.new("ScreenGui")
|
||||
resultsGui.Name = "ArenaResults"
|
||||
resultsGui.ResetOnSpawn = false
|
||||
resultsGui.IgnoreGuiInset = true
|
||||
resultsGui.DisplayOrder = 35
|
||||
resultsGui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
|
||||
resultsGui.Parent = playerGui
|
||||
local resultsShade = frame("RoundResults", resultsGui, UDim2.fromScale(0, 0), UDim2.fromScale(1, 1), Color3.fromRGB(5, 9, 18))
|
||||
resultsShade.Active = true
|
||||
resultsShade.Visible = false
|
||||
local resultsPanel = UI.plate(resultsShade, "Summary", UDim2.fromScale(.5, .5), UDim2.fromOffset(960, 630), UI.Outline, Color3.fromRGB(13, 19, 29))
|
||||
resultsPanel.AnchorPoint = Vector2.new(.5, .5)
|
||||
local resultsScale = Instance.new("UIScale", resultsPanel)
|
||||
local function fitResults()
|
||||
local size = resultsShade.AbsoluteSize
|
||||
resultsScale.Scale = math.clamp(math.min((size.X - 26) / 960, (size.Y - 26) / resultsPanel.Size.Y.Offset), .01, 1)
|
||||
end
|
||||
resultsShade:GetPropertyChangedSignal("AbsoluteSize"):Connect(fitResults)
|
||||
fitResults()
|
||||
local resultArc = UI.contour(resultsPanel, blue)
|
||||
local resultTitle = UI.label(resultsPanel, "Title", "ИТОГИ РАУНДА", UDim2.fromOffset(26, 17), UDim2.fromOffset(510, 42), 31, ink)
|
||||
resultTitle.FontFace = UI.Display
|
||||
resultTitle.TextXAlignment = Enum.TextXAlignment.Left
|
||||
local resultWinner = UI.label(resultsPanel, "Winner", "", UDim2.fromOffset(27, 60), UDim2.fromOffset(510, 25), 17, UI.Gold)
|
||||
resultWinner.TextXAlignment = Enum.TextXAlignment.Left
|
||||
local resultMode = UI.label(resultsPanel, "Mode", "", UDim2.fromOffset(566, 30), UDim2.fromOffset(368, 31), 15, muted)
|
||||
resultMode.TextXAlignment = Enum.TextXAlignment.Right
|
||||
|
||||
local outcomeShade = frame("CitadelOutcome", resultsShade, UDim2.fromScale(0, 0), UDim2.fromScale(1, 1), Color3.fromRGB(5, 9, 18))
|
||||
outcomeShade.ZIndex = 20
|
||||
outcomeShade.Visible = false
|
||||
local outcome = UI.label(outcomeShade, "Outcome", "", UDim2.fromScale(.5, .5), UDim2.fromScale(.78, .18), 76, ink)
|
||||
outcome.AnchorPoint = Vector2.new(.5, .5)
|
||||
outcome.FontFace = UI.Display
|
||||
outcome.TextScaled = true
|
||||
local outcomeLimit = Instance.new("UITextSizeConstraint", outcome)
|
||||
outcomeLimit.MaxTextSize = 104
|
||||
local outcomeScale = Instance.new("UIScale", outcome)
|
||||
local outcomeLine = frame("Light", outcomeShade, UDim2.fromScale(.5, .61), UDim2.fromScale(0, .004), UI.Gold)
|
||||
outcomeLine.AnchorPoint = Vector2.new(.5, .5)
|
||||
local outcomeTweens: {Tween} = {}
|
||||
local outcomeVersion = 0
|
||||
local function clearOutcome()
|
||||
outcomeVersion += 1
|
||||
for _, tween in outcomeTweens do tween:Cancel() end
|
||||
table.clear(outcomeTweens)
|
||||
outcomeShade.Visible = false
|
||||
end
|
||||
|
||||
local function showOutcome(text: string, accent: Color3)
|
||||
clearOutcome()
|
||||
outcome.Text, outcome.TextColor3, outcome.TextTransparency = text, accent, 1
|
||||
outcomeScale.Scale = .72
|
||||
outcomeShade.BackgroundTransparency = .12
|
||||
outcomeLine.BackgroundColor3, outcomeLine.BackgroundTransparency = accent, 0
|
||||
outcomeLine.Size = UDim2.fromScale(0, .004)
|
||||
outcomeShade.Visible = true
|
||||
local version = outcomeVersion
|
||||
local function play(target: Instance, info: TweenInfo, goal: {[string]: any}): Tween
|
||||
local tween = TweenService:Create(target, info, goal)
|
||||
table.insert(outcomeTweens, tween)
|
||||
tween:Play()
|
||||
return tween
|
||||
end
|
||||
play(outcomeScale, TweenInfo.new(.55, Enum.EasingStyle.Back), {Scale = 1})
|
||||
play(outcome, TweenInfo.new(.3), {TextTransparency = 0})
|
||||
play(outcomeLine, TweenInfo.new(.55, Enum.EasingStyle.Quint), {Size = UDim2.fromScale(.38, .004)})
|
||||
task.delay(2, function()
|
||||
if version ~= outcomeVersion then return end
|
||||
local fade = TweenInfo.new(.35, Enum.EasingStyle.Quad)
|
||||
play(outcomeShade, fade, {BackgroundTransparency = 1})
|
||||
play(outcomeLine, fade, {BackgroundTransparency = 1})
|
||||
play(outcome, fade, {TextTransparency = 1}).Completed:Once(function()
|
||||
if version == outcomeVersion then outcomeShade.Visible = false end
|
||||
end)
|
||||
end)
|
||||
end
|
||||
|
||||
local function resultTeam(id: string, x: number, name: string, color: Color3, dark: Color3): ResultTeam
|
||||
local card = UI.plate(resultsPanel, id, UDim2.fromOffset(x, 97), UDim2.fromOffset(446, 467), color:Lerp(panelColor, .35), panelColor:Lerp(dark, .28))
|
||||
local header = frame("Header", card, UDim2.fromOffset(5, 7), UDim2.new(1, -10, 0, 61), dark)
|
||||
gradient(header, dark:Lerp(color, .35), dark, 8)
|
||||
UI.sheen(header)
|
||||
local titleText = UI.label(card, "TeamName", name, UDim2.fromOffset(18, 14), UDim2.fromOffset(324, 48), 23, ink)
|
||||
titleText.FontFace = UI.Display
|
||||
titleText.TextXAlignment = Enum.TextXAlignment.Left
|
||||
local chip = UI.element("ScoreChip", card, UDim2.fromOffset(352, 12), UDim2.fromOffset(80, 50))
|
||||
UI.tintPlate(chip, color:Lerp(ink, .2), color)
|
||||
local score = UI.label(chip, "Score", "0", UDim2.fromScale(0, 0), UDim2.fromScale(1, 1), 32, panelColor)
|
||||
score.FontFace = UI.Display
|
||||
local head = frame("Columns", card, UDim2.fromOffset(12, 73), UDim2.fromOffset(422, 25), panelColor)
|
||||
head.BackgroundTransparency = 1
|
||||
local playerHeader = UI.label(head, "Player", "ИГРОК", UDim2.fromOffset(8, 0), UDim2.fromOffset(200, 25), 12, muted)
|
||||
playerHeader.TextXAlignment = Enum.TextXAlignment.Left
|
||||
UI.label(head, "Kills", "УБИЙСТВА", UDim2.fromOffset(241, 0), UDim2.fromOffset(93, 25), 12, muted)
|
||||
UI.label(head, "Deaths", "СМЕРТИ", UDim2.fromOffset(334, 0), UDim2.fromOffset(86, 25), 12, muted)
|
||||
local rows: {ResultRow} = {}
|
||||
for i = 1, limit do
|
||||
local row = UI.element("PlayerRow", card, UDim2.fromOffset(12, 102 + (i - 1) * 35), UDim2.fromOffset(422, 32))
|
||||
row.Name = "Player" .. i
|
||||
UI.hoverRow(row, color)
|
||||
local avatar = portrait(row, UDim2.fromOffset(5, 3), 26, color)
|
||||
local nameLabel = UI.label(row, "DisplayName", "", UDim2.fromOffset(40, 0), UDim2.fromOffset(196, 32), 15, ink)
|
||||
nameLabel.TextXAlignment = Enum.TextXAlignment.Left
|
||||
nameLabel.TextTruncate = Enum.TextTruncate.AtEnd
|
||||
local kills = UI.label(row, "Kills", "", UDim2.fromOffset(241, 0), UDim2.fromOffset(93, 32), 18, color)
|
||||
local deaths = UI.label(row, "Deaths", "", UDim2.fromOffset(334, 0), UDim2.fromOffset(86, 32), 16, muted)
|
||||
kills.FontFace = UI.Display
|
||||
rows[i] = {body = row, avatar = avatar, name = nameLabel, kills = kills, deaths = deaths}
|
||||
end
|
||||
local empty = UI.label(card, "Empty", "В команде не было игроков", UDim2.fromOffset(12, 105), UDim2.fromOffset(422, 54), 15, muted)
|
||||
return {card = card, score = score, empty = empty, accent = color, rows = rows}
|
||||
end
|
||||
|
||||
local blueResult = resultTeam("Blue", 23, "СИНИЕ", blue, blueDark)
|
||||
local orangeResult = resultTeam("Orange", 491, "ОРАНЖЕВЫЕ", orange, orangeDark)
|
||||
local nextRound = UI.label(resultsPanel, "NextRound", "", UDim2.fromOffset(25, 573), UDim2.fromOffset(910, 31), 16, ink)
|
||||
local resultTrack = UI.element("ProgressBar", resultsPanel, UDim2.fromOffset(25, 609), UDim2.fromOffset(910, 3))
|
||||
local resultFill = resultTrack:WaitForChild("Fill") :: Frame
|
||||
UI.sheen(resultFill)
|
||||
local resultEndsAt = 0
|
||||
local lastResultSecond = -1
|
||||
local resultsCountdown = "ГОЛОСОВАНИЕ ЧЕРЕЗ %d С"
|
||||
local summaryView: SummaryView? = nil
|
||||
local resultSlide: Tween? = nil
|
||||
local resultFade: Tween? = nil
|
||||
local resultDrain: Tween? = nil
|
||||
|
||||
local function populateResults(team: ResultTeam, score: number, players: {ResultPlayer})
|
||||
team.score.Text = tostring(score)
|
||||
team.empty.Visible = #players == 0
|
||||
team.empty.Text = if summaryView == "Live" then "В команде пока нет игроков" else "В команде не было игроков"
|
||||
for i, row in team.rows do
|
||||
local member = players[i]
|
||||
row.body.Visible = member ~= nil
|
||||
row.body.Interactable = member ~= nil
|
||||
setPortrait(row.avatar, member and member.userId, member and member.displayName)
|
||||
if member then
|
||||
local self = member.userId == player.UserId
|
||||
row.name.Text = (if self then "Вы · " else "") .. member.displayName
|
||||
row.kills.Text = tostring(member.kills)
|
||||
row.deaths.Text = tostring(member.deaths)
|
||||
row.body.BackgroundColor3 = panelColor:Lerp(team.accent, if self then .34 elseif i % 2 == 0 then .08 else .15)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function setSummaryTeams(bluePlayers: {ResultPlayer}, orangePlayers: {ResultPlayer}, blueTotal: number, orangeTotal: number)
|
||||
populateResults(blueResult, blueTotal, bluePlayers)
|
||||
populateResults(orangeResult, orangeTotal, orangePlayers)
|
||||
local rowSpace = 35 * math.max(3, #bluePlayers, #orangePlayers)
|
||||
local height = 280 + rowSpace
|
||||
if resultsPanel.Size.Y.Offset == height then return end
|
||||
resultsPanel.Size = UDim2.fromOffset(960, height)
|
||||
blueResult.card.Size = UDim2.fromOffset(446, 117 + rowSpace)
|
||||
orangeResult.card.Size = blueResult.card.Size
|
||||
nextRound.Position = UDim2.fromOffset(25, height - 57)
|
||||
resultTrack.Position = UDim2.fromOffset(25, height - 21)
|
||||
fitResults()
|
||||
end
|
||||
|
||||
local function startSummary(view: SummaryView, ruleId: unknown)
|
||||
summaryView = view
|
||||
resultTitle.Text = if view == "Live" then "СТАТИСТИКА МАТЧА" else "ИТОГИ РАУНДА"
|
||||
local rule = Rules.get(ruleId)
|
||||
resultMode.Text = rule.title .. " · Динамическая арена"
|
||||
if view == "Live" then
|
||||
resultWinner.Text = "СЧЁТ · " .. rule.score
|
||||
resultWinner.TextColor3 = muted
|
||||
end
|
||||
resultsPanel.Position = UDim2.fromScale(.5, .53)
|
||||
resultsShade.BackgroundTransparency = 1
|
||||
resultsShade.Visible = true
|
||||
local arrival = TweenInfo.new(.25, Enum.EasingStyle.Quart, Enum.EasingDirection.Out)
|
||||
resultSlide = TweenService:Create(resultsPanel, arrival, {Position = UDim2.fromScale(.5, .5)})
|
||||
resultFade = TweenService:Create(resultsShade, arrival, {BackgroundTransparency = if view == "Live" then .32 else .14})
|
||||
resultSlide:Play()
|
||||
resultFade:Play()
|
||||
end
|
||||
|
||||
local function hideResults()
|
||||
clearOutcome()
|
||||
summaryView = nil
|
||||
resultsShade.Visible = false
|
||||
if resultSlide then resultSlide:Cancel() end
|
||||
if resultFade then resultFade:Cancel() end
|
||||
if resultDrain then resultDrain:Cancel() end
|
||||
end
|
||||
|
||||
local connections: {[Player]: {RBXScriptConnection}} = {}
|
||||
|
||||
local function killsFor(member: Player): number
|
||||
return (member:GetAttribute("RoundKills") :: number?) or 0
|
||||
end
|
||||
|
||||
local function refreshLiveStats()
|
||||
if summaryView ~= "Live" then return end
|
||||
local items: {[string]: {ResultPlayer}} = {Blue = {}, Orange = {}}
|
||||
local arenaMode = currentMode()
|
||||
for member in connections do
|
||||
local side = member:GetAttribute("ArenaTeam")
|
||||
if (side == "Blue" or side == "Orange") and Modes.of(member) == arenaMode then
|
||||
table.insert(items[side], {
|
||||
userId = member.UserId,
|
||||
displayName = member.DisplayName,
|
||||
kills = killsFor(member),
|
||||
deaths = (member:GetAttribute("RoundDeaths") :: number?) or 0,
|
||||
})
|
||||
end
|
||||
end
|
||||
local function byPerformance(a: ResultPlayer, b: ResultPlayer): boolean
|
||||
if a.kills ~= b.kills then return a.kills > b.kills end
|
||||
if a.deaths ~= b.deaths then return a.deaths < b.deaths end
|
||||
return a.userId < b.userId
|
||||
end
|
||||
table.sort(items.Blue, byPerformance)
|
||||
table.sort(items.Orange, byPerformance)
|
||||
local match = activeState()
|
||||
setSummaryTeams(items.Blue, items.Orange, (match:GetAttribute("BlueScore") :: number?) or 0,
|
||||
(match:GetAttribute("OrangeScore") :: number?) or 0)
|
||||
end
|
||||
|
||||
local function scoreUpdater(score: TextLabel, attribute: string)
|
||||
local scale = Instance.new("UIScale", score)
|
||||
local motion: Tween? = nil
|
||||
local function refresh(animated: boolean)
|
||||
local value = (activeState():GetAttribute(attribute) :: number?) or 0
|
||||
if animated and value > (tonumber(score.Text) or 0) then
|
||||
if motion then motion:Cancel() end
|
||||
scale.Scale = 1.17
|
||||
motion = TweenService:Create(scale, TweenInfo.new(.23, Enum.EasingStyle.Quart), {Scale = 1})
|
||||
motion:Play()
|
||||
end
|
||||
score.Text = tostring(value)
|
||||
end
|
||||
for _, id in modeIds do
|
||||
Modes.state(state, id):GetAttributeChangedSignal(attribute):Connect(function()
|
||||
if currentMode() == id then refresh(true) end
|
||||
end)
|
||||
end
|
||||
refresh(false)
|
||||
return refresh
|
||||
end
|
||||
local refreshBlue = scoreUpdater(blueScore, "BlueScore")
|
||||
local refreshOrange = scoreUpdater(orangeScore, "OrangeScore")
|
||||
|
||||
local function remaining(): number
|
||||
local deadline = (activeState():GetAttribute("EndsAt") :: number?) or 0
|
||||
return math.max(0, math.ceil(deadline - workspace:GetServerTimeNow()))
|
||||
end
|
||||
|
||||
local function updateLiveClock(seconds: number, phase: string, duration: number)
|
||||
local remainingText = if phase == "Round" then "ДО КОНЦА РАУНДА" else "ДО СЛЕДУЮЩЕГО РАУНДА"
|
||||
nextRound.Text = string.format("%s %02d:%02d · ОТПУСТИТЕ TAB, ЧТОБЫ ЗАКРЫТЬ", remainingText, seconds // 60, seconds % 60)
|
||||
if resultDrain then resultDrain:Cancel() end
|
||||
resultDrain = TweenService:Create(resultFill, TweenInfo.new(.22, Enum.EasingStyle.Linear), {
|
||||
Size = UDim2.fromScale(math.clamp(seconds / math.max(duration, 1), 0, 1), 1),
|
||||
})
|
||||
resultDrain:Play()
|
||||
end
|
||||
|
||||
local function refreshControls()
|
||||
gui:SetAttribute("LobbyAvailable", player:GetAttribute("ArenaTeam") == nil
|
||||
and not resultsShade.Visible and playerGui:GetAttribute("HunterVoting") ~= true)
|
||||
end
|
||||
|
||||
local function refreshRoster()
|
||||
local members: {[string]: {Player}} = {Blue = {}, Orange = {}}
|
||||
local arenaMode = currentMode()
|
||||
for participant in connections do
|
||||
local id = participant:GetAttribute("ArenaTeam")
|
||||
if (id == "Blue" or id == "Orange") and Modes.of(participant) == arenaMode then
|
||||
table.insert(members[id], participant)
|
||||
end
|
||||
end
|
||||
local team = player:GetAttribute("ArenaTeam")
|
||||
local allies = if team == "Blue" or team == "Orange" then members[team] else {}
|
||||
table.sort(allies, function(a, b)
|
||||
local aKills, bKills = killsFor(a), killsFor(b)
|
||||
if aKills ~= bKills then return aKills > bKills end
|
||||
return a.Name:lower() < b.Name:lower()
|
||||
end)
|
||||
shownMembers = #allies
|
||||
teamStats.Visible = shownMembers > 0
|
||||
fitHud()
|
||||
local accent = if team == "Orange" then orange else blue
|
||||
teamContour:SetAttribute("Accent", accent)
|
||||
for i, badge in killBadges do
|
||||
local member = allies[i]
|
||||
badge.card.Visible = member ~= nil
|
||||
setPortrait(badge.avatar, member and member.UserId, member and member.DisplayName)
|
||||
if member then
|
||||
badge.card:SetAttribute("DisplayName", member.DisplayName)
|
||||
badge.kills.TextColor3 = if member == player then accent else ink
|
||||
local edge = badge.avatar:FindFirstChildOfClass("UIStroke")
|
||||
if edge then edge.Color = accent end
|
||||
badge.kills.Text = tostring(killsFor(member))
|
||||
badge.teamLine.BackgroundColor3 = accent
|
||||
end
|
||||
end
|
||||
refreshLiveStats()
|
||||
refreshObjective()
|
||||
refreshCapture()
|
||||
refreshControls()
|
||||
end
|
||||
|
||||
local function watch(participant: Player)
|
||||
if connections[participant] then return end
|
||||
connections[participant] = {
|
||||
participant:GetAttributeChangedSignal("ArenaTeam"):Connect(refreshRoster),
|
||||
participant:GetAttributeChangedSignal("ArenaMode"):Connect(refreshRoster),
|
||||
participant:GetAttributeChangedSignal("RoundKills"):Connect(refreshRoster),
|
||||
participant:GetAttributeChangedSignal("RoundDeaths"):Connect(refreshLiveStats),
|
||||
}
|
||||
refreshRoster()
|
||||
end
|
||||
|
||||
Players.PlayerAdded:Connect(watch)
|
||||
Players.PlayerRemoving:Connect(function(participant)
|
||||
for _, connection in connections[participant] or {} do connection:Disconnect() end
|
||||
connections[participant] = nil
|
||||
refreshRoster()
|
||||
end)
|
||||
for _, participant in Players:GetPlayers() do watch(participant) end
|
||||
|
||||
player:GetAttributeChangedSignal("InArena"):Connect(function()
|
||||
if summaryView == "Live" or (summaryView == "Final" and player:GetAttribute("InArena") == true) then hideResults() end
|
||||
refreshRoster()
|
||||
refreshBlue(false)
|
||||
refreshOrange(false)
|
||||
end)
|
||||
results.OnClientEvent:Connect(function(result: RoundResult, participantSide: string?)
|
||||
local left = result.endsAt - workspace:GetServerTimeNow()
|
||||
if left <= 0 then return end
|
||||
if resultsShade.Visible then hideResults() end
|
||||
startSummary("Final", result.ruleset)
|
||||
setSummaryTeams(result.blue, result.orange, result.blueScore, result.orangeScore)
|
||||
local winnerColor = if result.winner == "Blue" then blue elseif result.winner == "Orange" then orange else UI.Gold
|
||||
resultWinner.Text = if result.winner == "Blue" then "СИНИЕ ПОБЕДИЛИ"
|
||||
elseif result.winner == "Orange" then "ОРАНЖЕВЫЕ ПОБЕДИЛИ" else "НИЧЬЯ"
|
||||
if result.siegeReason then resultWinner.Text = result.siegeReason end
|
||||
if result.ruleset == "Siege" and (participantSide == "Blue" or participantSide == "Orange") then
|
||||
if result.winner == "Draw" then
|
||||
showOutcome("НИЧЬЯ", ink)
|
||||
elseif result.winner == participantSide then
|
||||
showOutcome("ПОБЕДА", UI.Gold)
|
||||
else
|
||||
showOutcome("ПОРАЖЕНИЕ", Color3.fromRGB(255, 105, 111))
|
||||
end
|
||||
end
|
||||
resultWinner.TextColor3 = winnerColor
|
||||
resultArc:SetAttribute("Accent", winnerColor)
|
||||
resultFill.BackgroundColor3 = winnerColor
|
||||
resultFill.Size = UDim2.fromScale(math.clamp(left / result.duration, 0, 1), 1)
|
||||
resultEndsAt = result.endsAt
|
||||
lastResultSecond = math.ceil(left)
|
||||
resultsCountdown = if result.allowModeChange == false then "СЛЕДУЮЩИЙ РАУНД ЧЕРЕЗ %d С" else "ГОЛОСОВАНИЕ ЧЕРЕЗ %d С"
|
||||
nextRound.Text = string.format(resultsCountdown, lastResultSecond)
|
||||
resultDrain = TweenService:Create(resultFill, TweenInfo.new(left, Enum.EasingStyle.Linear), {Size = UDim2.fromScale(0, 1)})
|
||||
resultDrain:Play()
|
||||
refreshRoster()
|
||||
refreshBlue(false)
|
||||
refreshOrange(false)
|
||||
end)
|
||||
local scoreConnections: {RBXScriptConnection} = {}
|
||||
for _, id in modeIds do
|
||||
local match = Modes.state(state, id)
|
||||
match:GetAttributeChangedSignal("Phase"):Connect(function()
|
||||
if currentMode() ~= id then return end
|
||||
refreshControls()
|
||||
end)
|
||||
for _, attribute in {"BlueScore", "OrangeScore"} do
|
||||
table.insert(scoreConnections, match:GetAttributeChangedSignal(attribute):Connect(function()
|
||||
if currentMode() == id then refreshLiveStats() end
|
||||
end))
|
||||
end
|
||||
for _, attribute in {"ObjectiveStatus", "Ruleset", "Phase"} do
|
||||
table.insert(scoreConnections, match:GetAttributeChangedSignal(attribute):Connect(function()
|
||||
if currentMode() ~= id then return end
|
||||
refreshObjective()
|
||||
if attribute ~= "ObjectiveStatus" then refreshCapture() end
|
||||
if attribute == "Ruleset" then refreshControls() end
|
||||
end))
|
||||
end
|
||||
for _, attribute in {"HotPointProgress", "HotPointTeam", "HotPointPhase"} do
|
||||
table.insert(scoreConnections, match:GetAttributeChangedSignal(attribute):Connect(refreshCapture))
|
||||
end
|
||||
end
|
||||
for _, attribute in {"ArenaTokens", "ArenaFlag", "ArenaLeader"} do
|
||||
table.insert(scoreConnections, player:GetAttributeChangedSignal(attribute):Connect(refreshObjective))
|
||||
end
|
||||
local votingChanged = playerGui:GetAttributeChangedSignal("HunterVoting"):Connect(function()
|
||||
if playerGui:GetAttribute("HunterVoting") == true then
|
||||
if summaryView == "Live" then hideResults() end
|
||||
end
|
||||
refreshControls()
|
||||
end)
|
||||
|
||||
local nativePlayerList = StarterGui:GetCoreGuiEnabled(Enum.CoreGuiType.PlayerList)
|
||||
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)
|
||||
local scoreboardAction = "HunterScoreboard"
|
||||
local function closeLiveScoreboard()
|
||||
if summaryView ~= "Live" then return end
|
||||
hideResults()
|
||||
refreshControls()
|
||||
end
|
||||
local scoreboardFocus = UserInputService.WindowFocusReleased:Connect(closeLiveScoreboard)
|
||||
ContextActionService:BindActionAtPriority(scoreboardAction, function(_, inputState)
|
||||
if inputState == Enum.UserInputState.End or inputState == Enum.UserInputState.Cancel then closeLiveScoreboard() end
|
||||
if UserInputService:GetFocusedTextBox() then return Enum.ContextActionResult.Pass end
|
||||
if inputState == Enum.UserInputState.Begin and summaryView == nil and playerGui:GetAttribute("HunterVoting") ~= true
|
||||
and playerGui:GetAttribute("HunterArenaCreator") ~= true then
|
||||
local match = activeState()
|
||||
startSummary("Live", match:GetAttribute("Ruleset"))
|
||||
resultArc:SetAttribute("Accent", blue)
|
||||
resultFill.BackgroundColor3 = blue
|
||||
resultFill.Size = UDim2.fromScale(0, 1)
|
||||
refreshLiveStats()
|
||||
updateLiveClock(remaining(), (match:GetAttribute("Phase") :: string?) or "Round", (match:GetAttribute("PhaseDuration") :: number?) or 1)
|
||||
refreshControls()
|
||||
end
|
||||
return Enum.ContextActionResult.Sink
|
||||
end, false, Enum.ContextActionPriority.High.Value, Enum.KeyCode.Tab)
|
||||
|
||||
local lastSecond = -1
|
||||
local lastPhase = ""
|
||||
local lastTeam: string? = nil
|
||||
local lastMode = ""
|
||||
local lastInArena = false
|
||||
local clockMotion: Tween? = nil
|
||||
local function updateClock()
|
||||
if summaryView == "Final" then
|
||||
local left = math.ceil(resultEndsAt - workspace:GetServerTimeNow())
|
||||
if left <= 0 then
|
||||
hideResults()
|
||||
refreshControls()
|
||||
elseif left ~= lastResultSecond then
|
||||
lastResultSecond = left
|
||||
nextRound.Text = string.format(resultsCountdown, left)
|
||||
end
|
||||
end
|
||||
local seconds = remaining()
|
||||
local phase = activeState():GetAttribute("Phase") :: string
|
||||
local team = player:GetAttribute("ArenaTeam") :: string?
|
||||
local arenaMode = currentMode()
|
||||
local inArena = player:GetAttribute("InArena") == true
|
||||
if seconds == lastSecond and phase == lastPhase and team == lastTeam and arenaMode == lastMode and inArena == lastInArena then return end
|
||||
local finishing = inArena and phase == "Round" and seconds > 0 and seconds <= 5
|
||||
local hadCountdown = countdown.Visible
|
||||
if finishing then
|
||||
if not countdown.Visible or seconds ~= lastSecond or arenaMode ~= lastMode then showCountdownBeat(seconds) end
|
||||
elseif countdown.Visible then
|
||||
countdown.Visible = false
|
||||
clearCountdownBeat()
|
||||
end
|
||||
if captureHud.Visible and hadCountdown ~= countdown.Visible then fitHud() end
|
||||
lastSecond, lastPhase, lastTeam, lastMode, lastInArena = seconds, phase, team, arenaMode, inArena
|
||||
local rule = Rules.get(activeState():GetAttribute("Ruleset"))
|
||||
if rule.id == "Siege" and inArena then refreshObjective() end
|
||||
mode.Visible = true
|
||||
mode.Text = if phase == "Vote" then "ГОЛОСОВАНИЕ" elseif phase == "Reveal" then "ДО НАЧАЛА РАУНДА"
|
||||
elseif phase == "Break" then (if activeState():GetAttribute("AllowModeChange") == false then "ДО НАЧАЛА РАУНДА" else "ДО ГОЛОСОВАНИЯ")
|
||||
elseif phase == "Round" then (if inArena then "ДО КОНЦА РАУНДА" else rule.title)
|
||||
else "ПОДГОТОВКА АРЕНЫ"
|
||||
clock.Position = UDim2.fromOffset(0, 14)
|
||||
clock.TextSize = 32
|
||||
clock.Text = string.format("%02d:%02d", seconds // 60, seconds % 60)
|
||||
clock.TextColor3 = if seconds <= 15 and phase == "Round" then Color3.fromRGB(255, 218, 148) else ink
|
||||
mode.TextColor3 = if team == "Blue" then blue elseif team == "Orange" then orange else muted
|
||||
roundFill.BackgroundColor3 = if seconds <= 15 and phase == "Round" then orange else mode.TextColor3:Lerp(blue, .32)
|
||||
if clockMotion then clockMotion:Cancel() end
|
||||
local duration = (activeState():GetAttribute("PhaseDuration") :: number?) or math.max(seconds, 1)
|
||||
if summaryView == "Live" then updateLiveClock(seconds, phase, duration) end
|
||||
clockMotion = TweenService:Create(roundFill, TweenInfo.new(.8, Enum.EasingStyle.Linear), {
|
||||
Size = UDim2.fromScale(math.clamp(seconds / duration, 0, 1), 1),
|
||||
})
|
||||
clockMotion:Play()
|
||||
refreshControls()
|
||||
end
|
||||
local timerConnection = RunService.Heartbeat:Connect(updateClock)
|
||||
script.Destroying:Once(function()
|
||||
timerConnection:Disconnect()
|
||||
votingChanged:Disconnect()
|
||||
scoreboardFocus:Disconnect()
|
||||
ContextActionService:UnbindAction(scoreboardAction)
|
||||
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, nativePlayerList)
|
||||
for _, connection in scoreConnections do connection:Disconnect() end
|
||||
if captureTween then captureTween:Cancel() end
|
||||
clearCountdownBeat()
|
||||
hideResults()
|
||||
resultsGui:Destroy()
|
||||
end)
|
||||
updateClock()
|
||||
@@ -0,0 +1,726 @@
|
||||
--!strict
|
||||
local Players = game:GetService("Players")
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local Teams = game:GetService("Teams")
|
||||
local Modes = require(ReplicatedStorage:WaitForChild("ArenaModes") :: ModuleScript)
|
||||
local Rules = require(ReplicatedStorage:WaitForChild("MatchRules") :: ModuleScript)
|
||||
local Hosting = require(ReplicatedStorage:WaitForChild("HostedArena") :: ModuleScript)
|
||||
local Objectives = require(script.Parent:WaitForChild("ArenaObjectives") :: ModuleScript)
|
||||
local SiegeConfig = require(ReplicatedStorage:WaitForChild("CitadelAssaultConfig") :: ModuleScript)
|
||||
|
||||
local ArenaSpawns = require(script.Parent:WaitForChild("ArenaSpawns"))
|
||||
local SkinCatalog = require(ReplicatedStorage:WaitForChild("RifleSkinCatalog") :: ModuleScript)
|
||||
local lobbySpawn = workspace:WaitForChild("HunterLobby"):WaitForChild("Arrival Spawn") :: SpawnLocation
|
||||
local rifleTemplate = ReplicatedStorage:WaitForChild("ArenaEquipment"):WaitForChild("SniperRifle") :: Tool
|
||||
|
||||
local ROUND_SECONDS = 300
|
||||
local BREAK_SECONDS = 15
|
||||
local VOTE_SECONDS = 15
|
||||
local TEAM_REVEAL_SECONDS = 1.05
|
||||
local TEAM_LIMIT = Hosting.MaxPlayers // 2
|
||||
local hosted = Hosting.isReserved()
|
||||
local modeRandom = Random.new()
|
||||
|
||||
local function makeTeam(name: string, color: BrickColor): Team
|
||||
local team = Instance.new("Team")
|
||||
team.Name = name
|
||||
team.TeamColor = color
|
||||
team.AutoAssignable = false
|
||||
team.Parent = Teams
|
||||
return team
|
||||
end
|
||||
|
||||
local roster: {[Player]: Team} = {}
|
||||
local joinOrder: {[Player]: number} = {}
|
||||
local placedCharacter: {[Player]: Model} = {}
|
||||
local lastCountedDeath: {[Player]: Model} = {}
|
||||
local lastRequest: {[Player]: number} = {}
|
||||
local lastSkinCycle: {[Player]: number} = {}
|
||||
local lastVote: {[Player]: number} = {}
|
||||
local admitted: {[Player]: boolean} = {}
|
||||
|
||||
local state = Instance.new("Folder")
|
||||
state.Name = "ArenaRound"
|
||||
state:SetAttribute("TeamLimit", TEAM_LIMIT)
|
||||
state:SetAttribute("IsHosted", hosted)
|
||||
state:SetAttribute("StreakWindow", 13)
|
||||
local randomState = Instance.new("Folder")
|
||||
randomState.Name = "Procedural"
|
||||
randomState.Parent = state
|
||||
|
||||
type Side = Hosting.Side
|
||||
type Match = {id: string, state: Folder, blue: Team, orange: Team, phase: string, endsAt: number, order: number,
|
||||
rule: string, allowModeChange: boolean, engine: Objectives.Match?, eligible: {[Player]: Side}, ballots: {[Player]: string}}
|
||||
type PendingJoin = {match: Match, side: Side, endsAt: number}
|
||||
local pendingJoins: {[Player]: PendingJoin} = {}
|
||||
local matches: {[string]: Match} = {
|
||||
[Modes.Procedural] = {
|
||||
id = Modes.Procedural, state = randomState,
|
||||
blue = makeTeam("Синие", BrickColor.new("Cyan")),
|
||||
orange = makeTeam("Оранжевые", BrickColor.new("Deep orange")),
|
||||
phase = "Setup", endsAt = 0, order = 0, rule = Rules.Default, allowModeChange = true, eligible = {}, ballots = {},
|
||||
},
|
||||
}
|
||||
local join = Instance.new("RemoteEvent")
|
||||
join.Name = "JoinTeam"
|
||||
join.Parent = state
|
||||
local cycleSkin = Instance.new("RemoteEvent")
|
||||
cycleSkin.Name = "CycleRifleSkin"
|
||||
cycleSkin.Parent = state
|
||||
local results = Instance.new("RemoteEvent")
|
||||
results.Name = "RoundResults"
|
||||
results.Parent = state
|
||||
local vote = Instance.new("RemoteEvent")
|
||||
vote.Name = "ModeVote"
|
||||
vote.Parent = state
|
||||
|
||||
local function setTeam(player: Player, match: Match, side: Side)
|
||||
local team = if side == "Blue" then match.blue else match.orange
|
||||
roster[player] = team
|
||||
player.Team = team
|
||||
player.Neutral = false
|
||||
player:SetAttribute("ArenaMode", match.id)
|
||||
player:SetAttribute("ArenaTeam", side)
|
||||
end
|
||||
|
||||
local function assignTeam(player: Player, match: Match, side: Side)
|
||||
match.order += 1
|
||||
joinOrder[player] = match.order
|
||||
player:SetAttribute("HostedArenaTeamNotice", nil)
|
||||
setTeam(player, match, side)
|
||||
end
|
||||
|
||||
local function countPlayers(match: Match): (number, number)
|
||||
local blueCount, orangeCount = 0, 0
|
||||
for _, team in roster do
|
||||
if team == match.blue then blueCount += 1 elseif team == match.orange then orangeCount += 1 end
|
||||
end
|
||||
return blueCount, orangeCount
|
||||
end
|
||||
|
||||
local function countSeats(match: Match): (number, number)
|
||||
local blue, orange = countPlayers(match)
|
||||
for _, pending in pendingJoins do
|
||||
if pending.match == match and pending.endsAt == match.endsAt then
|
||||
if pending.side == "Blue" then blue += 1 else orange += 1 end
|
||||
end
|
||||
end
|
||||
return blue, orange
|
||||
end
|
||||
|
||||
local function latestOn(team: Team): Player?
|
||||
local latest: Player? = nil
|
||||
local latestOrder = 0
|
||||
for player, assigned in roster do
|
||||
local order = joinOrder[player]
|
||||
if assigned == team and order > latestOrder then latest, latestOrder = player, order end
|
||||
end
|
||||
return latest
|
||||
end
|
||||
|
||||
local function balanceWaiting(match: Match)
|
||||
while true do
|
||||
local blue, orange = countPlayers(match)
|
||||
if math.abs(blue - orange) <= 1 then return end
|
||||
local player = latestOn(if blue > orange then match.blue else match.orange)
|
||||
if not player then return end
|
||||
setTeam(player, match, if blue > orange then "Orange" else "Blue")
|
||||
end
|
||||
end
|
||||
|
||||
local function arm(player: Player, character: Model, humanoid: Humanoid)
|
||||
local backpack = player:FindFirstChildOfClass("Backpack")
|
||||
if not backpack or character:FindFirstChild("SniperRifle") then return end
|
||||
local rifle = backpack:FindFirstChild("SniperRifle")
|
||||
if not rifle then
|
||||
local clone = rifleTemplate:Clone()
|
||||
clone.CanBeDropped = false
|
||||
clone:SetAttribute("Skin", SkinCatalog.get(player:GetAttribute("RifleSkin")).id)
|
||||
clone.Parent = backpack
|
||||
rifle = clone
|
||||
end
|
||||
if rifle:IsA("Tool") then humanoid:EquipTool(rifle) end
|
||||
end
|
||||
|
||||
local function clearTools(container: Instance?)
|
||||
if not container then return end
|
||||
for _, child in container:GetChildren() do
|
||||
if child:IsA("Tool") then child:Destroy() end
|
||||
end
|
||||
end
|
||||
|
||||
local function guardInventory(player: Player, container: Instance)
|
||||
container.ChildAdded:Connect(function(child)
|
||||
if player:GetAttribute("InArena") ~= true and child:IsA("Tool") then child:Destroy() end
|
||||
end)
|
||||
if player:GetAttribute("InArena") ~= true then clearTools(container) end
|
||||
end
|
||||
|
||||
local function resetStreak(player: Player)
|
||||
player:SetAttribute("StreakKills", 0)
|
||||
player:SetAttribute("StreakUntil", nil)
|
||||
end
|
||||
|
||||
local function recordDeath(player: Player, character: Model)
|
||||
if not roster[player] or placedCharacter[player] ~= character or lastCountedDeath[player] == character then return end
|
||||
lastCountedDeath[player] = character
|
||||
player:SetAttribute("RoundDeaths", ((player:GetAttribute("RoundDeaths") :: number?) or 0) + 1)
|
||||
end
|
||||
|
||||
local function moveToLobby(player: Player)
|
||||
placedCharacter[player] = nil
|
||||
player:SetAttribute("InArena", false)
|
||||
player.RespawnLocation = lobbySpawn
|
||||
local character = player.Character
|
||||
local backpack = player:FindFirstChildOfClass("Backpack")
|
||||
clearTools(character)
|
||||
clearTools(backpack)
|
||||
clearTools(player:FindFirstChild("StarterGear"))
|
||||
local humanoid = character and character:FindFirstChildOfClass("Humanoid")
|
||||
if character and humanoid and humanoid.Health > 0 then
|
||||
ArenaSpawns.place(character, lobbySpawn)
|
||||
end
|
||||
end
|
||||
|
||||
local function bench(player: Player)
|
||||
if not roster[player] then return end
|
||||
player:SetAttribute("ArenaWaiting", true)
|
||||
moveToLobby(player)
|
||||
end
|
||||
|
||||
local function sendToLobby(player: Player)
|
||||
roster[player] = nil
|
||||
joinOrder[player] = nil
|
||||
lastCountedDeath[player] = nil
|
||||
moveToLobby(player)
|
||||
player:SetAttribute("ArenaWaiting", nil)
|
||||
player:SetAttribute("ArenaMode", nil)
|
||||
player:SetAttribute("ArenaTeam", nil)
|
||||
player:SetAttribute("RoundKills", 0)
|
||||
player:SetAttribute("RoundDeaths", 0)
|
||||
resetStreak(player)
|
||||
player.Team = nil
|
||||
player.Neutral = true
|
||||
end
|
||||
|
||||
local function destinationFor(player: Player): SpawnLocation
|
||||
return ArenaSpawns.choose(player)
|
||||
end
|
||||
|
||||
local function enterArena(player: Player, character: Model, humanoid: Humanoid)
|
||||
if placedCharacter[player] == character or humanoid.Health <= 0 then return end
|
||||
placedCharacter[player] = character
|
||||
humanoid.Health = humanoid.MaxHealth
|
||||
local destination = destinationFor(player)
|
||||
player.RespawnLocation = destination
|
||||
ArenaSpawns.place(character, destination)
|
||||
arm(player, character, humanoid)
|
||||
end
|
||||
|
||||
local function deploy(player: Player)
|
||||
if not roster[player] then return end
|
||||
placedCharacter[player] = nil
|
||||
player:SetAttribute("ArenaWaiting", nil)
|
||||
player:SetAttribute("InArena", true)
|
||||
local character = player.Character
|
||||
local humanoid = character and character:FindFirstChildOfClass("Humanoid")
|
||||
if character and humanoid and humanoid.Health > 0 and character.PrimaryPart then
|
||||
enterArena(player, character, humanoid)
|
||||
else
|
||||
player.RespawnLocation = destinationFor(player)
|
||||
end
|
||||
end
|
||||
|
||||
local function enterRound(player: Player, match: Match)
|
||||
if match.rule == "OneLife" then bench(player) else deploy(player) end
|
||||
end
|
||||
|
||||
local function onCharacter(player: Player, character: Model)
|
||||
local root = character:WaitForChild("HumanoidRootPart", 10)
|
||||
local humanoid = character:WaitForChild("Humanoid", 10)
|
||||
player:WaitForChild("Backpack", 5)
|
||||
if not root or not humanoid or not humanoid:IsA("Humanoid") or player.Character ~= character then return end
|
||||
local function replicateHealth()
|
||||
local fraction = if humanoid.MaxHealth > 0 then humanoid.Health / humanoid.MaxHealth else 0
|
||||
character:SetAttribute("ArenaHealthFraction", math.clamp(fraction, 0, 1))
|
||||
end
|
||||
humanoid.HealthDisplayType = Enum.HumanoidHealthDisplayType.AlwaysOff
|
||||
humanoid.HealthChanged:Connect(replicateHealth)
|
||||
replicateHealth()
|
||||
humanoid.Died:Once(function()
|
||||
local match = matches[Modes.of(player)]
|
||||
local engine = match.engine
|
||||
local wasFighting = roster[player] ~= nil and placedCharacter[player] == character
|
||||
recordDeath(player, character)
|
||||
if player.Character == character then resetStreak(player) end
|
||||
if wasFighting and engine and match.phase == "Round" then
|
||||
local position = if root:IsA("BasePart") then root.Position else nil
|
||||
local now = workspace:GetServerTimeNow()
|
||||
task.defer(function()
|
||||
if match.engine == engine and roster[player] and placedCharacter[player] == character then engine.death(player, position, now) end
|
||||
end)
|
||||
end
|
||||
end)
|
||||
if roster[player] and player:GetAttribute("InArena") == true then
|
||||
enterArena(player, character, humanoid)
|
||||
else
|
||||
ArenaSpawns.place(character, lobbySpawn)
|
||||
end
|
||||
end
|
||||
|
||||
local function onPlayer(player: Player)
|
||||
sendToLobby(player)
|
||||
player.ChildAdded:Connect(function(child)
|
||||
if child:IsA("Backpack") or child:IsA("StarterGear") then guardInventory(player, child) end
|
||||
end)
|
||||
for _, child in player:GetChildren() do
|
||||
if child:IsA("Backpack") or child:IsA("StarterGear") then guardInventory(player, child) end
|
||||
end
|
||||
player.CharacterAdded:Connect(function(character)
|
||||
guardInventory(player, character)
|
||||
onCharacter(player, character)
|
||||
end)
|
||||
if player.Character then
|
||||
guardInventory(player, player.Character)
|
||||
task.spawn(onCharacter, player, player.Character)
|
||||
end
|
||||
end
|
||||
|
||||
Players.PlayerAdded:Connect(onPlayer)
|
||||
for _, player in Players:GetPlayers() do onPlayer(player) end
|
||||
|
||||
local function voteTotals(match: Match): ({[string]: number}, number)
|
||||
local counts: {[string]: number} = {}
|
||||
local total = 0
|
||||
for _, id in match.ballots do
|
||||
counts[id] = (counts[id] or 0) + 1
|
||||
total += 1
|
||||
end
|
||||
return counts, total
|
||||
end
|
||||
|
||||
local function votingOpen(match: Match, now: number): boolean
|
||||
return match.allowModeChange and match.phase == "Vote" and now < match.endsAt - Rules.VoteLockSeconds
|
||||
end
|
||||
|
||||
local function broadcastVotes(match: Match)
|
||||
local counts, total = voteTotals(match)
|
||||
for player in match.eligible do
|
||||
if player.Parent == Players and not roster[player] then
|
||||
vote:FireClient(player, match.id, match.endsAt, counts, total, match.ballots[player])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Players.PlayerRemoving:Connect(function(player)
|
||||
local wasPlaying = roster[player] ~= nil
|
||||
local match = matches[Modes.of(player)]
|
||||
local engine = match.engine
|
||||
local root = player.Character and player.Character.PrimaryPart
|
||||
if wasPlaying and engine then engine.leaving(player, root and root.Position, workspace:GetServerTimeNow()) end
|
||||
roster[player] = nil
|
||||
joinOrder[player] = nil
|
||||
placedCharacter[player] = nil
|
||||
lastCountedDeath[player] = nil
|
||||
lastRequest[player] = nil
|
||||
lastSkinCycle[player] = nil
|
||||
lastVote[player] = nil
|
||||
admitted[player] = nil
|
||||
pendingJoins[player] = nil
|
||||
local now = workspace:GetServerTimeNow()
|
||||
for _, arenaMatch in matches do
|
||||
arenaMatch.eligible[player] = nil
|
||||
if votingOpen(arenaMatch, now) and arenaMatch.ballots[player] then
|
||||
arenaMatch.ballots[player] = nil
|
||||
broadcastVotes(arenaMatch)
|
||||
end
|
||||
end
|
||||
if not wasPlaying or match.phase ~= "Round" or workspace:GetServerTimeNow() >= match.endsAt then return end
|
||||
if match.rule == "OneLife" then return end
|
||||
|
||||
local blueCount, orangeCount = countPlayers(match)
|
||||
if math.abs(blueCount - orangeCount) <= 1 then return end
|
||||
-- A departure can leave a two-player gap. Move the latest arrival from the larger side.
|
||||
local larger = if blueCount > orangeCount then match.blue else match.orange
|
||||
local latest = latestOn(larger)
|
||||
if latest then
|
||||
local previousRoot = latest.Character and latest.Character.PrimaryPart
|
||||
if engine then engine.leaving(latest, previousRoot and previousRoot.Position, workspace:GetServerTimeNow()) end
|
||||
setTeam(latest, match, if larger == match.blue then "Orange" else "Blue")
|
||||
local character = latest.Character
|
||||
local humanoid = character and character:FindFirstChildOfClass("Humanoid")
|
||||
if character and humanoid and humanoid.Health > 0 then
|
||||
local destination = destinationFor(latest)
|
||||
latest.RespawnLocation = destination
|
||||
ArenaSpawns.place(character, destination)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
local function joinError(player: Player, match: Match, side: Side, now: number): string?
|
||||
if roster[player] then return "AlreadyPlaying" end
|
||||
if match.phase ~= "Round" or now >= match.endsAt then return "BetweenRounds" end
|
||||
|
||||
local blueCount, orangeCount = countSeats(match)
|
||||
local own, other = blueCount, orangeCount
|
||||
if side == "Orange" then own, other = orangeCount, blueCount end
|
||||
local unavailable = Hosting.teamJoinError(own, other)
|
||||
if unavailable then return unavailable end
|
||||
|
||||
local character = player.Character
|
||||
local humanoid = character and character:FindFirstChildOfClass("Humanoid")
|
||||
if not character or not humanoid or humanoid.Health <= 0 or not character.PrimaryPart
|
||||
or not player:FindFirstChildOfClass("Backpack") then
|
||||
return "Spawning"
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
local function tryJoin(player: Player, match: Match, side: Side, now: number): string
|
||||
local issue = joinError(player, match, side, now)
|
||||
if issue then return issue end
|
||||
assignTeam(player, match, side)
|
||||
enterRound(player, match)
|
||||
return "Joined"
|
||||
end
|
||||
|
||||
join.OnServerEvent:Connect(function(player: Player, id: unknown, requestedMode: unknown, preference: unknown)
|
||||
if id ~= "Blue" and id ~= "Orange" and id ~= "Auto" and id ~= "AutoPreview" then return end
|
||||
if preference ~= nil and preference ~= "Blue" and preference ~= "Orange" then return end
|
||||
if pendingJoins[player] then return end
|
||||
local mode = if requestedMode == nil then Modes.Procedural else requestedMode
|
||||
if typeof(mode) ~= "string" or not matches[mode] then return end
|
||||
local now = workspace:GetServerTimeNow()
|
||||
if now - (lastRequest[player] or -math.huge) < .3 then return end
|
||||
lastRequest[player] = now
|
||||
if hosted and not admitted[player] then
|
||||
join:FireClient(player, if player:GetAttribute("HostedArenaFull") then "Full" else "AwaitingAdmission")
|
||||
return
|
||||
end
|
||||
local match = matches[mode]
|
||||
local side: Side
|
||||
if id == "AutoPreview" and (preference == "Blue" or preference == "Orange") then
|
||||
side = preference
|
||||
elseif id == "Auto" or id == "AutoPreview" then
|
||||
local blueCount, orangeCount = countSeats(match)
|
||||
side = if blueCount <= orangeCount then "Blue" else "Orange"
|
||||
else
|
||||
side = id
|
||||
end
|
||||
if id ~= "AutoPreview" then
|
||||
join:FireClient(player, tryJoin(player, match, side, now))
|
||||
return
|
||||
end
|
||||
|
||||
local issue = joinError(player, match, side, now)
|
||||
if issue or now + TEAM_REVEAL_SECONDS >= match.endsAt then
|
||||
join:FireClient(player, issue or "BetweenRounds")
|
||||
return
|
||||
end
|
||||
local pending = {match = match, side = side, endsAt = match.endsAt}
|
||||
pendingJoins[player] = pending
|
||||
join:FireClient(player, "TeamSelected", side)
|
||||
task.delay(TEAM_REVEAL_SECONDS, function()
|
||||
if pendingJoins[player] ~= pending then return end
|
||||
pendingJoins[player] = nil
|
||||
if player.Parent ~= Players then return end
|
||||
local result = if match.endsAt ~= pending.endsAt then "BetweenRounds"
|
||||
else tryJoin(player, match, side, workspace:GetServerTimeNow())
|
||||
join:FireClient(player, result)
|
||||
end)
|
||||
end)
|
||||
|
||||
if hosted then
|
||||
local admission = Instance.new("BindableEvent")
|
||||
admission.Name = "HostedArenaAdmission"
|
||||
admission.Event:Connect(function(player: Player, preference: Side?)
|
||||
if player.Parent ~= Players or admitted[player] then return end
|
||||
admitted[player] = true
|
||||
local match = matches[Modes.Procedural]
|
||||
local untilTime = workspace:GetServerTimeNow() + 50
|
||||
repeat
|
||||
if player.Parent ~= Players then return end
|
||||
if not pendingJoins[player] then
|
||||
local blueCount, orangeCount = countSeats(match)
|
||||
local side = preference or (if blueCount <= orangeCount then "Blue" else "Orange")
|
||||
local result = tryJoin(player, match, side, workspace:GetServerTimeNow())
|
||||
if result == "Joined" or result == "AlreadyPlaying" then return end
|
||||
if preference and (result == "Balance" or result == "Full") then
|
||||
player:SetAttribute("HostedArenaTeamNotice", result)
|
||||
return
|
||||
end
|
||||
end
|
||||
task.wait(.25)
|
||||
until workspace:GetServerTimeNow() >= untilTime
|
||||
end)
|
||||
admission.Parent = script
|
||||
end
|
||||
|
||||
vote.OnServerEvent:Connect(function(player: Player, arena: unknown, id: unknown)
|
||||
if typeof(arena) ~= "string" then return end
|
||||
local match, rule = matches[arena], Rules.find(id)
|
||||
if not match or not rule or not match.eligible[player] or roster[player] then return end
|
||||
local now = workspace:GetServerTimeNow()
|
||||
if not votingOpen(match, now) or now - (lastVote[player] or -math.huge) < .18 or match.ballots[player] == rule.id then return end
|
||||
lastVote[player] = now
|
||||
match.ballots[player] = rule.id
|
||||
broadcastVotes(match)
|
||||
end)
|
||||
|
||||
cycleSkin.OnServerEvent:Connect(function(player: Player)
|
||||
local now = workspace:GetServerTimeNow()
|
||||
if now - (lastSkinCycle[player] or -math.huge) < .18 then return end
|
||||
lastSkinCycle[player] = now
|
||||
local match = matches[Modes.of(player)]
|
||||
if match.phase ~= "Round" or now >= match.endsAt or not roster[player] or player:GetAttribute("InArena") ~= true then return end
|
||||
local character = player.Character
|
||||
local humanoid = character and character:FindFirstChildOfClass("Humanoid")
|
||||
local rifle = character and character:FindFirstChild("SniperRifle")
|
||||
if not humanoid or humanoid.Health <= 0 or not rifle or not rifle:IsA("Tool") then return end
|
||||
local selected = SkinCatalog.next(rifle:GetAttribute("Skin"))
|
||||
player:SetAttribute("RifleSkin", selected.id)
|
||||
rifle:SetAttribute("Skin", selected.id)
|
||||
end)
|
||||
|
||||
local function publish(match: Match)
|
||||
local duration = if match.phase == "Round" then ROUND_SECONDS elseif match.phase == "Vote" then VOTE_SECONDS
|
||||
elseif match.phase == "Reveal" then Rules.VoteRevealSeconds else BREAK_SECONDS
|
||||
match.state:SetAttribute("PhaseDuration", duration)
|
||||
match.state:SetAttribute("EndsAt", match.endsAt)
|
||||
match.state:SetAttribute("Phase", match.phase)
|
||||
end
|
||||
|
||||
for _, match in matches do
|
||||
match.state:SetAttribute("BlueKills", 0)
|
||||
match.state:SetAttribute("OrangeKills", 0)
|
||||
match.state:SetAttribute("BlueScore", 0)
|
||||
match.state:SetAttribute("OrangeScore", 0)
|
||||
match.state:SetAttribute("Ruleset", match.rule)
|
||||
match.state:SetAttribute("AllowModeChange", match.allowModeChange)
|
||||
publish(match)
|
||||
end
|
||||
state.Parent = ReplicatedStorage
|
||||
|
||||
local function returnVoters(match: Match)
|
||||
local returning: {Player} = {}
|
||||
for _, player in Players:GetPlayers() do
|
||||
local previousSide = match.eligible[player]
|
||||
if previousSide and match.ballots[player] and not roster[player] then
|
||||
assignTeam(player, match, previousSide)
|
||||
table.insert(returning, player)
|
||||
end
|
||||
end
|
||||
table.clear(match.eligible)
|
||||
table.clear(match.ballots)
|
||||
if #returning == 0 then return end
|
||||
|
||||
balanceWaiting(match)
|
||||
for _, player in returning do enterRound(player, match) end
|
||||
end
|
||||
|
||||
local function startRound(match: Match)
|
||||
local arena = Modes.geometry(match.id)
|
||||
local ready, result = pcall(function()
|
||||
local generator = require(script.Parent:WaitForChild("ProceduralArena") :: ModuleScript)
|
||||
local previous = arena:FindFirstChild("GeneratedLayout")
|
||||
local seed = generator.regenerate()
|
||||
local current = arena:FindFirstChild("GeneratedLayout")
|
||||
assert(current and current ~= previous and seed == arena:GetAttribute("Seed"),
|
||||
"The new match requires a fresh arena layout")
|
||||
return seed
|
||||
end)
|
||||
if not ready then
|
||||
warn("Procedural arena generation failed: ", result)
|
||||
match.endsAt = workspace:GetServerTimeNow() + BREAK_SECONDS
|
||||
publish(match)
|
||||
return
|
||||
end
|
||||
match.state:SetAttribute("MapSeed", result)
|
||||
match.state:SetAttribute("MapGeneration", arena:GetAttribute("Generation"))
|
||||
match.state:SetAttribute("MapLayout", arena:GetAttribute("LayoutVariant"))
|
||||
local now = workspace:GetServerTimeNow()
|
||||
local ok, engine = pcall(Objectives.start, {
|
||||
arena = match.id, rule = match.rule, state = match.state, now = now, duration = ROUND_SECONDS,
|
||||
bench = bench, deploy = deploy,
|
||||
balanceWaiting = function() balanceWaiting(match) end,
|
||||
members = function(): {Player}
|
||||
local found: {Player} = {}
|
||||
for p, team in roster do if team == match.blue or team == match.orange then table.insert(found, p) end end
|
||||
return found
|
||||
end,
|
||||
})
|
||||
if not ok then
|
||||
warn("Unable to start match: ", engine)
|
||||
match.phase, match.endsAt = "Setup", now + BREAK_SECONDS
|
||||
publish(match)
|
||||
return
|
||||
end
|
||||
match.engine = engine
|
||||
local roundDuration = if match.rule == "Siege" then SiegeConfig.MATCH_DURATION + SiegeConfig.SWAP_FREEZE else ROUND_SECONDS
|
||||
match.phase, match.endsAt = "Round", now + roundDuration
|
||||
match.state:SetAttribute("Ruleset", match.rule)
|
||||
match.state:SetAttribute("BlueKills", 0)
|
||||
match.state:SetAttribute("OrangeKills", 0)
|
||||
publish(match)
|
||||
returnVoters(match)
|
||||
end
|
||||
|
||||
type ResultPlayer = {userId: number, displayName: string, kills: number, deaths: number}
|
||||
|
||||
local function finishRound(match: Match)
|
||||
local bluePlayers: {ResultPlayer} = {}
|
||||
local orangePlayers: {ResultPlayer} = {}
|
||||
local participants: {{player: Player, side: Side}} = {}
|
||||
for _, player in Players:GetPlayers() do
|
||||
local team = roster[player]
|
||||
if team ~= match.blue and team ~= match.orange then continue end
|
||||
local character = player.Character
|
||||
local humanoid = character and character:FindFirstChildOfClass("Humanoid")
|
||||
if character and humanoid and humanoid.Health <= 0 then recordDeath(player, character) end
|
||||
table.insert(participants, {player = player, side = if team == match.blue then "Blue" else "Orange"})
|
||||
table.insert(if team == match.blue then bluePlayers else orangePlayers, {
|
||||
userId = player.UserId,
|
||||
displayName = player.DisplayName,
|
||||
kills = (player:GetAttribute("RoundKills") :: number?) or 0,
|
||||
deaths = (player:GetAttribute("RoundDeaths") :: number?) or 0,
|
||||
})
|
||||
end
|
||||
local function byPerformance(a: ResultPlayer, b: ResultPlayer): boolean
|
||||
if a.kills ~= b.kills then return a.kills > b.kills end
|
||||
if a.deaths ~= b.deaths then return a.deaths < b.deaths end
|
||||
return a.userId < b.userId
|
||||
end
|
||||
table.sort(bluePlayers, byPerformance)
|
||||
table.sort(orangePlayers, byPerformance)
|
||||
|
||||
match.phase = "Break"
|
||||
match.endsAt = workspace:GetServerTimeNow() + BREAK_SECONDS
|
||||
match.order = 0
|
||||
table.clear(match.eligible)
|
||||
table.clear(match.ballots)
|
||||
local engine = match.engine
|
||||
local winner = if engine then engine.winner() else "Draw"
|
||||
local siegeState = match.state:FindFirstChild("CitadelMatchState")
|
||||
local siegeTimes = if siegeState then siegeState:GetAttributes() else nil
|
||||
local snapshot = {
|
||||
mode = match.id,
|
||||
ruleset = match.rule,
|
||||
allowModeChange = match.allowModeChange,
|
||||
winner = winner,
|
||||
siegeReason = if siegeState then match.state:GetAttribute("CitadelResultReason") else nil,
|
||||
siegeTimes = siegeTimes,
|
||||
endsAt = match.endsAt,
|
||||
duration = BREAK_SECONDS,
|
||||
blueScore = (match.state:GetAttribute("BlueScore") :: number?) or 0,
|
||||
orangeScore = (match.state:GetAttribute("OrangeScore") :: number?) or 0,
|
||||
blue = bluePlayers,
|
||||
orange = orangePlayers,
|
||||
}
|
||||
publish(match)
|
||||
for _, entry in participants do
|
||||
local player = entry.player
|
||||
sendToLobby(player)
|
||||
match.eligible[player] = entry.side
|
||||
results:FireClient(player, snapshot, entry.side)
|
||||
end
|
||||
if engine then engine.destroy() end
|
||||
match.engine = nil
|
||||
end
|
||||
|
||||
local function finishVote(match: Match, now: number)
|
||||
local counts, total = voteTotals(match)
|
||||
if total > 0 then
|
||||
local highest = 0
|
||||
local choices: {string} = {}
|
||||
for _, rule in Rules.All do
|
||||
local count = counts[rule.id] or 0
|
||||
if count > highest then
|
||||
highest = count
|
||||
table.clear(choices)
|
||||
end
|
||||
if count == highest and count > 0 then table.insert(choices, rule.id) end
|
||||
end
|
||||
match.rule = choices[modeRandom:NextInteger(1, #choices)]
|
||||
end
|
||||
if next(match.eligible) then
|
||||
local ballotDeadline = match.endsAt
|
||||
match.phase, match.endsAt = "Reveal", now + Rules.VoteRevealSeconds
|
||||
match.state:SetAttribute("Ruleset", match.rule)
|
||||
publish(match)
|
||||
local outcome = {winner = match.rule, endsAt = match.endsAt}
|
||||
for player in match.eligible do
|
||||
if player.Parent == Players and not roster[player] then
|
||||
vote:FireClient(player, match.id, ballotDeadline, counts, total, match.ballots[player], outcome)
|
||||
end
|
||||
end
|
||||
end
|
||||
if match.phase == "Reveal" then return end
|
||||
match.phase = "Setup"
|
||||
startRound(match)
|
||||
end
|
||||
|
||||
local function runMatch(match: Match)
|
||||
while true do
|
||||
local now = workspace:GetServerTimeNow()
|
||||
local remaining = match.endsAt - now
|
||||
if match.phase == "Round" then
|
||||
local engine = match.engine
|
||||
if remaining <= 0 and next(roster) == nil then
|
||||
if engine then engine.destroy() end
|
||||
match.engine, match.phase, match.order = nil, "Setup", 0
|
||||
if match.allowModeChange then
|
||||
local choices: {string} = {}
|
||||
for _, rule in Rules.All do
|
||||
if rule.id ~= match.rule then table.insert(choices, rule.id) end
|
||||
end
|
||||
match.rule = choices[modeRandom:NextInteger(1, #choices)]
|
||||
end
|
||||
startRound(match)
|
||||
elseif remaining <= 0 or (engine and engine.step(now)) then finishRound(match)
|
||||
else task.wait(math.min(remaining, if match.rule == "Siege" then SiegeConfig.CHECK_INTERVAL else .2)) end
|
||||
elseif remaining > 0 then
|
||||
task.wait(remaining)
|
||||
elseif match.phase == "Break" and match.allowModeChange then
|
||||
match.phase, match.endsAt = "Vote", now + VOTE_SECONDS
|
||||
publish(match)
|
||||
broadcastVotes(match)
|
||||
elseif match.phase == "Vote" then
|
||||
finishVote(match, now)
|
||||
else
|
||||
match.phase = "Setup"
|
||||
startRound(match)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local proceduralMatch = matches[Modes.Procedural]
|
||||
local configured = false
|
||||
local configure = Instance.new("BindableFunction")
|
||||
configure.Name = "HostedArenaConfigure"
|
||||
configure.OnInvoke = function(value: unknown): boolean
|
||||
local options = Hosting.readRoundOptions(value)
|
||||
if not options then return false end
|
||||
local match = proceduralMatch
|
||||
if hosted then
|
||||
if configured then return false end
|
||||
elseif match.phase ~= "Round" or next(roster) or next(pendingJoins) then
|
||||
return false
|
||||
end
|
||||
|
||||
configured = true
|
||||
match.phase, match.endsAt = "Setup", 0
|
||||
match.rule, match.allowModeChange = options.initialMode, options.allowModeChange
|
||||
match.state:SetAttribute("Ruleset", match.rule)
|
||||
match.state:SetAttribute("AllowModeChange", match.allowModeChange)
|
||||
publish(match)
|
||||
if match.engine then
|
||||
match.engine.destroy()
|
||||
match.engine = nil
|
||||
end
|
||||
-- A reserved arena waits for its server-side session settings before generating its first round.
|
||||
if hosted then task.defer(runMatch, match) end
|
||||
return true
|
||||
end
|
||||
configure.Parent = script
|
||||
|
||||
if not hosted then task.spawn(runMatch, proceduralMatch) end
|
||||
@@ -0,0 +1,248 @@
|
||||
--!strict
|
||||
local Players = game:GetService("Players")
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local RunService = game:GetService("RunService")
|
||||
local Mobility = require(ReplicatedStorage:WaitForChild("ArenaMobility") :: ModuleScript)
|
||||
local Modes = require(ReplicatedStorage:WaitForChild("ArenaModes") :: ModuleScript)
|
||||
local MobilityScreen = require(ReplicatedStorage:WaitForChild("ArenaMobilityScreen") :: ModuleScript)
|
||||
local effects = require(ReplicatedStorage:WaitForChild("SniperEffects") :: ModuleScript)
|
||||
local player = Players.LocalPlayer
|
||||
local screen = MobilityScreen.new(player:WaitForChild("PlayerGui") :: PlayerGui)
|
||||
local viewmodel = player:WaitForChild("PlayerScripts"):WaitForChild("SniperViewmodel")
|
||||
local round = ReplicatedStorage:WaitForChild("ArenaRound")
|
||||
local hopUsed = round:WaitForChild("JumpRuneUsed") :: RemoteEvent
|
||||
|
||||
type Group = {model: Model, offset: CFrame, motion: string, sequence: number, strokes: {BasePart}}
|
||||
type Rune = {
|
||||
origin: BasePart, mode: string, kind: string, phase: number, groups: {Group}, halfLength: number,
|
||||
light: PointLight?, sparks: ParticleEmitter?, ring: Group?, lastPulse: number, localPulse: number,
|
||||
}
|
||||
type Wave = {model: Model, strokes: {BasePart}, pose: CFrame, startedAt: number}
|
||||
|
||||
local visibleRunes: {[Model]: Rune} = {}
|
||||
local jumps: {[Model]: Rune} = {}
|
||||
local waves: {Wave} = {}
|
||||
local visualEffects = Instance.new("Folder")
|
||||
visualEffects.Name = "LocalRuneEffects"
|
||||
visualEffects.Parent = workspace
|
||||
local boostPink = Color3.fromRGB(255, 55, 168)
|
||||
local boostCoral = Color3.fromRGB(255, 129, 123)
|
||||
local boostGold = Color3.fromRGB(255, 231, 112)
|
||||
|
||||
local function strokesOf(model: Model): {BasePart}
|
||||
local strokes = {}
|
||||
for _, child in model:GetChildren() do
|
||||
if child:IsA("BasePart") then table.insert(strokes, child) end
|
||||
end
|
||||
return strokes
|
||||
end
|
||||
|
||||
local function register(model: Instance, mode: string)
|
||||
if not model:IsA("Model") then return end
|
||||
local origin = model.PrimaryPart
|
||||
local kind = model:GetAttribute("Kind")
|
||||
if not origin or typeof(kind) ~= "string" then return end
|
||||
local groups: {Group} = {}
|
||||
local ring: Group? = nil
|
||||
for _, child in model:GetChildren() do
|
||||
if not child:IsA("Model") then continue end
|
||||
local motion = child:GetAttribute("Motion")
|
||||
if typeof(motion) ~= "string" then continue end
|
||||
local group = {
|
||||
model = child, offset = origin.CFrame:ToObjectSpace(child:GetPivot()), motion = motion,
|
||||
sequence = (child:GetAttribute("Sequence") :: number?) or 0, strokes = strokesOf(child),
|
||||
}
|
||||
table.insert(groups, group)
|
||||
if motion == "OuterRing" then ring = group end
|
||||
end
|
||||
local sparks = origin:FindFirstChild("RuneSparks", true)
|
||||
local rune: Rune = {
|
||||
origin = origin, mode = mode, kind = kind, phase = (model:GetAttribute("Phase") :: number?) or 0, groups = groups,
|
||||
halfLength = (model:GetAttribute("HalfLength") :: number?) or 0,
|
||||
light = origin:FindFirstChildOfClass("PointLight"), sparks = if sparks and sparks:IsA("ParticleEmitter") then sparks else nil,
|
||||
ring = ring, lastPulse = 0, localPulse = 0,
|
||||
}
|
||||
visibleRunes[model] = rune
|
||||
if kind == "Jump" then jumps[model] = rune end
|
||||
end
|
||||
|
||||
local function flash(rune: Rune, now: number)
|
||||
local isJump = rune.kind == "Jump"
|
||||
if rune.sparks then rune.sparks:Emit(if isJump then 30 else 19) end
|
||||
local ring = rune.ring
|
||||
if not ring then return end
|
||||
local wave = ring.model:Clone()
|
||||
wave.Name = "RuneWave"
|
||||
wave.Parent = visualEffects
|
||||
local pose = ring.model:GetPivot() + Vector3.yAxis * .12
|
||||
table.insert(waves, {model = wave, strokes = strokesOf(wave), pose = pose, startedAt = now})
|
||||
end
|
||||
|
||||
local function animate(rune: Rune, now: number, pulse: number)
|
||||
local phase = now + rune.phase
|
||||
if rune.light then rune.light.Brightness = .65 + math.sin(phase * 3) * .19 + pulse * 2.1 end
|
||||
local frame = rune.origin.CFrame
|
||||
-- Leave space for the tips and tails of the chevrons at each end of the ramp strip.
|
||||
local travel = rune.halfLength * 1.7
|
||||
for _, group in rune.groups do
|
||||
local pose = frame * group.offset
|
||||
local motion = group.motion
|
||||
local transparency
|
||||
if motion == "BoostChase" and travel > 0 then
|
||||
local initialZ = group.offset.Position.Z
|
||||
local progress = (phase * 12 / travel + .5 - initialZ / (rune.halfLength * 2)) % 1
|
||||
group.model:PivotTo(pose + frame.LookVector * ((progress - .5) * travel + initialZ))
|
||||
local edge = math.clamp(math.min(progress, 1 - progress) / .12, 0, 1)
|
||||
local fade = edge * edge * (3 - 2 * edge)
|
||||
transparency = 1 - (.84 + pulse * .14) * fade
|
||||
local tint = if progress < .5 then boostPink:Lerp(boostCoral, progress * 2)
|
||||
else boostCoral:Lerp(boostGold, progress * 2 - 1)
|
||||
for _, stroke in group.strokes do stroke.Color = tint end
|
||||
elseif motion == "Chase" then
|
||||
local sweep = (phase * 1.05 - (group.sequence - 1) * .22) % 1
|
||||
local glow = (0.5 + 0.5 * math.cos(sweep * 2 * math.pi)) ^ 4
|
||||
transparency = .57 - .52 * math.max(glow, pulse)
|
||||
elseif motion == "Lift" then
|
||||
local rise = (phase * .75 + group.sequence * .5) % 1
|
||||
group.model:PivotTo(pose + Vector3.yAxis * (rise * .9))
|
||||
transparency = .76 - .70 * math.sin(rise * math.pi)
|
||||
else
|
||||
local spin = if motion == "OuterRing" then .72 else -.94
|
||||
group.model:PivotTo(pose * CFrame.Angles(0, (phase * spin) % (2 * math.pi), 0))
|
||||
transparency = math.max(.04, .22 + .12 * math.sin(phase * 3) - pulse * .24)
|
||||
end
|
||||
for _, stroke in group.strokes do stroke.Transparency = transparency end
|
||||
end
|
||||
end
|
||||
|
||||
local stopWatching = Mobility.watchRunes(register, function(model)
|
||||
if model:IsA("Model") then visibleRunes[model], jumps[model] = nil, nil end
|
||||
end)
|
||||
|
||||
local boostChanged: RBXScriptConnection? = nil
|
||||
local boostSound: Sound? = nil
|
||||
local jumpSound: Sound? = nil
|
||||
local function stopBoostSound()
|
||||
if not boostSound then return end
|
||||
boostSound:Destroy()
|
||||
boostSound = nil
|
||||
end
|
||||
|
||||
local function stopMobilitySounds()
|
||||
stopBoostSound()
|
||||
if jumpSound then
|
||||
jumpSound:Destroy()
|
||||
jumpSound = nil
|
||||
end
|
||||
end
|
||||
|
||||
local function watchBoost(character: Model)
|
||||
if boostChanged then boostChanged:Disconnect() end
|
||||
stopMobilitySounds()
|
||||
screen.reset()
|
||||
local function playBoostSound()
|
||||
local expiry = character:GetAttribute("ArenaBoostUntil")
|
||||
if character ~= player.Character or player:GetAttribute("InArena") ~= true
|
||||
or typeof(expiry) ~= "number" or expiry <= workspace:GetServerTimeNow() then return end
|
||||
stopBoostSound()
|
||||
boostSound = effects.sound("BoostRune")
|
||||
screen.boost(workspace:GetServerTimeNow(), expiry)
|
||||
end
|
||||
boostChanged = character:GetAttributeChangedSignal("ArenaBoostUntil"):Connect(playBoostSound)
|
||||
playBoostSound()
|
||||
end
|
||||
|
||||
local respawned = player.CharacterAdded:Connect(watchBoost)
|
||||
if player.Character then watchBoost(player.Character) end
|
||||
local zone = player:GetAttributeChangedSignal("InArena"):Connect(function()
|
||||
if player:GetAttribute("InArena") ~= true then
|
||||
stopMobilitySounds()
|
||||
screen.reset()
|
||||
end
|
||||
end)
|
||||
|
||||
local horizontalMask = Vector3.new(1, 0, 1)
|
||||
local lastCharacter: Model? = nil
|
||||
local lastJump: Rune? = nil
|
||||
-- The character's simulation owner adds lift before the next physics step, keeping normal air control.
|
||||
local hop = RunService.PreSimulation:Connect(function()
|
||||
local character = player.Character
|
||||
if character ~= lastCharacter or player:GetAttribute("InArena") ~= true then lastJump = nil end
|
||||
lastCharacter = character
|
||||
if not character or player:GetAttribute("InArena") ~= true then return end
|
||||
local mode = Modes.of(player)
|
||||
local now = workspace:GetServerTimeNow()
|
||||
if not Modes.open(round, mode, now) then return end
|
||||
local humanoid = character:FindFirstChildOfClass("Humanoid")
|
||||
local root = character:FindFirstChild("HumanoidRootPart")
|
||||
if not humanoid or humanoid.Health <= 0 or humanoid.Sit or not root or not root:IsA("BasePart") or root.Anchored then return end
|
||||
local position = root.Position
|
||||
if lastJump then
|
||||
if lastJump.mode == mode and lastJump.origin:IsDescendantOf(workspace)
|
||||
and ((position - lastJump.origin.Position) * horizontalMask).Magnitude < Mobility.JumpRadius + .65 then return end
|
||||
lastJump = nil
|
||||
end
|
||||
local velocity = root.AssemblyLinearVelocity
|
||||
if math.abs(velocity.Y) > 11 or (velocity * horizontalMask).Magnitude < .6 then return end
|
||||
local reach = Mobility.groundReach(root, humanoid)
|
||||
for model, rune in jumps do
|
||||
if rune.mode ~= mode then continue end
|
||||
local offset = position - rune.origin.Position
|
||||
if offset.Y <= .5 or offset.Y > reach + .4 or (offset * horizontalMask).Magnitude >= Mobility.JumpRadius then continue end
|
||||
local floor = workspace:Raycast(position, -Vector3.yAxis * reach, Modes.collision(mode))
|
||||
if not floor or math.abs(floor.Position.Y - rune.origin.Position.Y) > .45 then continue end
|
||||
lastJump = rune
|
||||
Mobility.hop(root, humanoid)
|
||||
if jumpSound then jumpSound:Destroy() end
|
||||
jumpSound = effects.sound("JumpRune")
|
||||
screen.jump(now)
|
||||
rune.localPulse = now
|
||||
flash(rune, now)
|
||||
hopUsed:FireServer(model)
|
||||
return
|
||||
end
|
||||
end)
|
||||
|
||||
local elapsed = 0
|
||||
local step = RunService.RenderStepped:Connect(function(dt)
|
||||
elapsed += dt
|
||||
if elapsed < 1 / 60 then return end
|
||||
elapsed %= 1 / 60
|
||||
local camera = workspace.CurrentCamera
|
||||
if not camera then return end
|
||||
local now = workspace:GetServerTimeNow()
|
||||
screen.render(now, viewmodel:GetAttribute("Aiming") == true)
|
||||
for model, rune in visibleRunes do
|
||||
if (camera.CFrame.Position - rune.origin.Position).Magnitude > 152 then continue end
|
||||
local trigger = (model:GetAttribute("PulseAt") :: number?) or 0
|
||||
local age = math.max(0, now - math.max(trigger, rune.localPulse))
|
||||
if trigger > rune.lastPulse then
|
||||
rune.lastPulse = trigger
|
||||
if now - trigger < .5 and math.abs(trigger - rune.localPulse) > .6 then flash(rune, now) end
|
||||
end
|
||||
animate(rune, now, math.max(0, 1 - age / .52) ^ 2)
|
||||
end
|
||||
for i = #waves, 1, -1 do
|
||||
local wave = waves[i]
|
||||
local t = (now - wave.startedAt) / .55
|
||||
if t >= 1 then
|
||||
wave.model:Destroy()
|
||||
table.remove(waves, i)
|
||||
else
|
||||
wave.model:ScaleTo(1 + .78 * (1 - (1 - t) ^ 2))
|
||||
wave.model:PivotTo(wave.pose + Vector3.yAxis * (.3 * t))
|
||||
for _, stroke in wave.strokes do stroke.Transparency = .18 + .82 * t end
|
||||
end
|
||||
end
|
||||
end)
|
||||
script.Destroying:Once(function()
|
||||
step:Disconnect()
|
||||
hop:Disconnect()
|
||||
stopWatching()
|
||||
respawned:Disconnect()
|
||||
zone:Disconnect()
|
||||
if boostChanged then boostChanged:Disconnect() end
|
||||
stopMobilitySounds()
|
||||
screen.destroy()
|
||||
visualEffects:Destroy()
|
||||
end)
|
||||
@@ -0,0 +1,52 @@
|
||||
--!strict
|
||||
-- ModuleScript in ServerScriptService. Spawn markers belong to the player's arena.
|
||||
local Players = game:GetService("Players")
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local Modes = require(ReplicatedStorage:WaitForChild("ArenaModes") :: ModuleScript)
|
||||
local random = Random.new()
|
||||
local ArenaSpawns = {}
|
||||
|
||||
function ArenaSpawns.choose(player: Player): SpawnLocation
|
||||
local arena = Modes.geometry(Modes.of(player))
|
||||
local folder = arena:WaitForChild("PlayerSpawns")
|
||||
local side = player:GetAttribute("ArenaTeam")
|
||||
local choices: {SpawnLocation} = {}
|
||||
for _, marker in folder:GetChildren() do
|
||||
local group = marker:GetAttribute("ArenaTeam")
|
||||
if marker:IsA("SpawnLocation") and marker.Enabled and (group == nil or group == side) then
|
||||
table.insert(choices, marker)
|
||||
end
|
||||
end
|
||||
assert(#choices > 0, arena.Name .. " has no enabled spawns for this team")
|
||||
local best = choices[random:NextInteger(1, #choices)]
|
||||
local bestDistance = -1
|
||||
for _, marker in choices do
|
||||
local nearest = 1000
|
||||
for _, other in Players:GetPlayers() do
|
||||
local character = other.Character
|
||||
local root = character and character:FindFirstChild("HumanoidRootPart")
|
||||
local humanoid = character and character:FindFirstChildOfClass("Humanoid")
|
||||
if other ~= player and other:GetAttribute("InArena") == true and Modes.same(player, other)
|
||||
and root and root:IsA("BasePart") and humanoid and humanoid.Health > 0 then
|
||||
nearest = math.min(nearest, (root.Position - marker.Position).Magnitude)
|
||||
end
|
||||
end
|
||||
local score = nearest + random:NextNumber(0, 24)
|
||||
if score > bestDistance then
|
||||
bestDistance = score
|
||||
best = marker
|
||||
end
|
||||
end
|
||||
return best
|
||||
end
|
||||
|
||||
function ArenaSpawns.place(character: Model, marker: SpawnLocation)
|
||||
character:PivotTo(marker.CFrame + Vector3.new(0, 4, 0))
|
||||
local root = character:FindFirstChild("HumanoidRootPart")
|
||||
if root and root:IsA("BasePart") then
|
||||
root.AssemblyLinearVelocity = Vector3.zero
|
||||
root.AssemblyAngularVelocity = Vector3.zero
|
||||
end
|
||||
end
|
||||
|
||||
return ArenaSpawns
|
||||
@@ -0,0 +1,25 @@
|
||||
--!strict
|
||||
return table.freeze({
|
||||
MATCH_DURATION = 300,
|
||||
ATTACK_DURATION = 150,
|
||||
CAPTURE_TIME = 4,
|
||||
CAPTURE_RADIUS = 11,
|
||||
DECAY_MULTIPLIER = 0.5,
|
||||
HEIGHT_TOLERANCE = 7,
|
||||
POINTS_PER_OBJECTIVE = 1,
|
||||
MAX_OBJECTIVES = 3,
|
||||
HUD_PROGRESS_STEP = 0.1,
|
||||
FIRST_ATTACKER = "Blue",
|
||||
CHECK_INTERVAL = 0.1,
|
||||
INTERMISSION_BEFORE_SWAP = 5,
|
||||
SWAP_FREEZE = 3,
|
||||
EMPTY_TIMEOUT = 30,
|
||||
TIE_EPSILON = 0.05,
|
||||
SIGHT_HEIGHT = 2,
|
||||
HINT_COOLDOWN = 3,
|
||||
HintsEnabled = true,
|
||||
Debug = false,
|
||||
-- Пустые ID отключают пользовательский ассет.
|
||||
SoundIds = table.freeze({Start = "", Enter = "", Charge = "", Tick = "", Blocked = "", Decay = "", Capture = "", Victory = "", Countdown = "", Swap = "", Results = ""}),
|
||||
EffectIds = table.freeze({Energy = "", Confetti = "", Shockwave = ""}),
|
||||
})
|
||||
@@ -0,0 +1,14 @@
|
||||
--!strict
|
||||
local Capture = {}
|
||||
export type Status = "Idle" | "Capturing" | "Contested" | "Decaying" | "Captured"
|
||||
|
||||
function Capture.advance(progress: number, dt: number, attack: boolean, defense: boolean, seconds: number, decay: number): (number, Status)
|
||||
local grows = attack and not defense
|
||||
local nextProgress = math.clamp(progress + dt * (if grows then 1 else -decay) / seconds, 0, 1)
|
||||
if nextProgress >= 1 - 1e-9 then return 1, "Captured" end
|
||||
if defense then return nextProgress, "Contested" end
|
||||
if grows then return nextProgress, "Capturing" end
|
||||
return nextProgress, if progress > 0 then "Decaying" else "Idle"
|
||||
end
|
||||
|
||||
return Capture
|
||||
@@ -0,0 +1,28 @@
|
||||
--!strict
|
||||
local Score = {}
|
||||
export type Side = "Blue" | "Orange"
|
||||
export type Ledger = {[Side]: {number}}
|
||||
|
||||
function Score.record(ledger: Ledger, side: Side, index: number, elapsed: number): boolean
|
||||
if index ~= #ledger[side] + 1 then return false end
|
||||
ledger[side][index] = elapsed
|
||||
return true
|
||||
end
|
||||
|
||||
function Score.winner(ledger: Ledger, epsilon: number): (string, string)
|
||||
local b, o = #ledger.Blue, #ledger.Orange
|
||||
if b ~= o then
|
||||
local side = if b > o then "Blue" else "Orange"
|
||||
return side, side .. " взяли больше рубежей"
|
||||
end
|
||||
if b == 0 then return "Draw", "Ничья: обе команды без захватов" end
|
||||
local blue, orange = ledger.Blue[b], ledger.Orange[o]
|
||||
if math.abs(blue - orange) <= epsilon then return "Draw", "Ничья: время захвата совпало" end
|
||||
local side = if blue < orange then "Blue" else "Orange"
|
||||
local function clock(t: number): string
|
||||
return string.format("%d:%05.2f", math.floor(t / 60), t % 60)
|
||||
end
|
||||
return side, string.format("Победа по скорости: %s, рубеж %d (Blue %s, Orange %s)", side, b, clock(blue), clock(orange))
|
||||
end
|
||||
|
||||
return Score
|
||||
@@ -0,0 +1,14 @@
|
||||
--!strict
|
||||
local CollectionService = game:GetService("CollectionService")
|
||||
local Spawn = {}
|
||||
|
||||
function Spawn.position(world: Instance, attack: boolean, fallback: Vector3, ordinal: number): Vector3
|
||||
local points: {BasePart} = {}
|
||||
for _, point in CollectionService:GetTagged(if attack then "AttackerSpawn" else "DefenderSpawn") do
|
||||
if point:IsA("BasePart") and point:IsDescendantOf(world) then table.insert(points, point) end
|
||||
end
|
||||
if #points > 0 then return points[(ordinal - 1) % #points + 1].Position end
|
||||
return fallback + Vector3.xAxis * ((ordinal - 1) % 5 - 2) * 3 + Vector3.zAxis * (math.floor((ordinal - 1) / 5) * 3)
|
||||
end
|
||||
|
||||
return Spawn
|
||||
@@ -0,0 +1,161 @@
|
||||
--!strict
|
||||
local Players = game:GetService("Players")
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local RunService = game:GetService("RunService")
|
||||
local TweenService = game:GetService("TweenService")
|
||||
|
||||
local player = Players.LocalPlayer
|
||||
local round = ReplicatedStorage:WaitForChild("ArenaRound")
|
||||
local window = round:GetAttribute("StreakWindow") :: number
|
||||
local hitRemote = ReplicatedStorage:WaitForChild("SniperHit") :: RemoteEvent
|
||||
local effects = require(ReplicatedStorage:WaitForChild("SniperEffects"))
|
||||
|
||||
local UI = require(ReplicatedStorage:WaitForChild("HunterUI") :: ModuleScript)
|
||||
local playerGui = player:WaitForChild("PlayerGui")
|
||||
local reticle = playerGui:WaitForChild("Crosshair"):WaitForChild("Reticle") :: Frame
|
||||
|
||||
local gui = Instance.new("ScreenGui")
|
||||
gui.Name = "CombatFeedback"
|
||||
gui.ResetOnSpawn = false
|
||||
gui.IgnoreGuiInset = true
|
||||
gui.DisplayOrder = 24
|
||||
gui.Enabled = false
|
||||
gui.Parent = playerGui
|
||||
|
||||
local panel = UI.element("StreakArc", gui, UDim2.fromScale(.5, .5), nil)
|
||||
local count = panel:WaitForChild("Multiplier") :: TextLabel
|
||||
local scale = Instance.new("UIScale", panel)
|
||||
local countScale = Instance.new("UIScale", count)
|
||||
local cream = Color3.fromRGB(255, 248, 205)
|
||||
local amber = Color3.fromRGB(242, 137, 41)
|
||||
|
||||
local arcs: {{Frame}} = {}
|
||||
for section = 1, 2 do
|
||||
local group = panel:WaitForChild("Segment" .. section)
|
||||
local pieces: {Frame} = {}
|
||||
for i = 1, 14 do
|
||||
table.insert(pieces, group:WaitForChild("Piece" .. i) :: Frame)
|
||||
end
|
||||
table.insert(arcs, pieces)
|
||||
end
|
||||
local sparks: {Frame} = {}
|
||||
for i = 1, 6 do
|
||||
local spark = UI.frame("Spark" .. i, panel, UDim2.fromOffset(0, 0), UDim2.fromOffset(3, 3), cream)
|
||||
spark.AnchorPoint = Vector2.new(.5, .5)
|
||||
spark.Visible = false
|
||||
table.insert(sparks, spark)
|
||||
end
|
||||
|
||||
local function fit()
|
||||
scale.Scale = if gui.AbsoluteSize.X < 560 then .75 else 1
|
||||
end
|
||||
gui:GetPropertyChangedSignal("AbsoluteSize"):Connect(fit)
|
||||
fit()
|
||||
|
||||
local shownKills, expiresAt = 0, 0
|
||||
local visibleFraction, refillAt, refillFrom = 0, 0, 0
|
||||
local refillTime = .24
|
||||
local countMotion: Tween? = nil
|
||||
local lit = false
|
||||
local function refresh()
|
||||
local kills = (player:GetAttribute("StreakKills") :: number?) or 0
|
||||
local untilTime = (player:GetAttribute("StreakUntil") :: number?) or 0
|
||||
if player:GetAttribute("InArena") ~= true or kills <= 0 then
|
||||
shownKills, visibleFraction, expiresAt = 0, 0, 0
|
||||
return
|
||||
end
|
||||
if untilTime == expiresAt and kills == shownKills then return end
|
||||
shownKills, expiresAt = kills, untilTime
|
||||
count.Text = "×" .. kills
|
||||
local now = workspace:GetServerTimeNow()
|
||||
if expiresAt <= now then return end
|
||||
refillFrom, refillAt = visibleFraction, now
|
||||
if countMotion then countMotion:Cancel() end
|
||||
countScale.Scale = 1.27
|
||||
countMotion = TweenService:Create(countScale, TweenInfo.new(.29, Enum.EasingStyle.Quart), {Scale = 1})
|
||||
countMotion:Play()
|
||||
end
|
||||
|
||||
local deferred = false
|
||||
local function deferRefresh()
|
||||
if deferred then return end
|
||||
deferred = true
|
||||
task.defer(function()
|
||||
deferred = false
|
||||
refresh()
|
||||
end)
|
||||
end
|
||||
for _, attribute in {"StreakKills", "StreakUntil", "InArena"} do
|
||||
player:GetAttributeChangedSignal(attribute):Connect(deferRefresh)
|
||||
end
|
||||
refresh()
|
||||
|
||||
local heartbeat = RunService.Heartbeat:Connect(function()
|
||||
local now = workspace:GetServerTimeNow()
|
||||
local target = if expiresAt > 0 then math.clamp((expiresAt - now) / window, 0, 1) else 0
|
||||
local tuner = playerGui:FindFirstChild("ViewmodelTuner")
|
||||
gui.Enabled = reticle.Visible and not (tuner and tuner:IsA("ScreenGui") and tuner.Enabled)
|
||||
if target == 0 then visibleFraction, expiresAt = 0, 0 end
|
||||
if not gui.Enabled then return end
|
||||
count.Visible = target > 0
|
||||
if target == 0 then
|
||||
if lit then
|
||||
for index, pieces in arcs do
|
||||
for _, piece in pieces do piece.BackgroundTransparency = if index == 1 then .94 else 1 end
|
||||
end
|
||||
for _, spark in sparks do spark.Visible = false end
|
||||
lit = false
|
||||
end
|
||||
return
|
||||
end
|
||||
lit = true
|
||||
|
||||
local age = now - refillAt
|
||||
local t = math.clamp(age / refillTime, 0, 1)
|
||||
visibleFraction = refillFrom + (target - refillFrom) * (1 - (1 - t)^3)
|
||||
for index, pieces in arcs do
|
||||
local cursor = math.clamp(visibleFraction * 1.12 - (index - 1) * .071, 0, 1) * #pieces
|
||||
for i, piece in pieces do
|
||||
local amount = math.clamp(cursor - i + 1, 0, 1)
|
||||
local leading = math.max(0, 1 - math.abs(cursor - i - .5) / 4)
|
||||
local shine = leading * (.68 + .24 * math.sin(now * 12)) + .20 * i / #pieces
|
||||
piece.BackgroundColor3 = amber:Lerp(cream, math.clamp(shine, 0, 1))
|
||||
piece.BackgroundTransparency = .90 - amount * .87
|
||||
end
|
||||
end
|
||||
local burst = math.clamp(age / .34, 0, 1)
|
||||
local head = math.rad(76 - 69 * visibleFraction)
|
||||
for i, spark in sparks do
|
||||
spark.Visible = burst < 1
|
||||
if spark.Visible then
|
||||
local offset = (7 + 3 * i) * burst
|
||||
local angle = head - (.04 + .055 * burst) * i
|
||||
spark.Position = UDim2.fromOffset((85 + offset) * math.cos(angle), (77 + offset) * math.sin(angle))
|
||||
spark.BackgroundTransparency = burst
|
||||
spark.Rotation = 45 + burst * 90
|
||||
end
|
||||
end
|
||||
end)
|
||||
script.Destroying:Once(function() heartbeat:Disconnect() end)
|
||||
|
||||
local function playing(): boolean
|
||||
local character = player.Character
|
||||
local humanoid = character and character:FindFirstChildOfClass("Humanoid")
|
||||
return player:GetAttribute("InArena") == true and humanoid ~= nil and humanoid.Health > 0
|
||||
end
|
||||
|
||||
hitRemote.OnClientEvent:Connect(function(_position: unknown, _damage: unknown, zone: unknown, killed: unknown, _victim: unknown, streak: unknown)
|
||||
if not playing() then return end
|
||||
-- Every server-confirmed impact gets the original hitmarker, even a critical or a kill.
|
||||
effects.sound("Hit", nil, if zone == "Head" or killed == true then .85 else 1)
|
||||
if zone == "Head" then effects.sound("Critical") end
|
||||
if killed == true then
|
||||
effects.sound("Elimination")
|
||||
if typeof(streak) == "number" and streak >= 1 then
|
||||
local character = player.Character
|
||||
task.delay(.14, function()
|
||||
if player.Character == character and playing() then effects.sound("StreakAccent") end
|
||||
end)
|
||||
end
|
||||
end
|
||||
end)
|
||||
@@ -0,0 +1,141 @@
|
||||
--!strict
|
||||
-- Crosshair in the centre of the screen: four short white lines with a dark outline and a centre dot.
|
||||
-- Hidden while aiming down the sights. Hides the default mouse cursor while it is shown (the cursor comes back while the
|
||||
-- ViewmodelTuner panel is open, so its buttons can be clicked). Plus a hit marker on confirmed hits.
|
||||
|
||||
local Players = game:GetService("Players")
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local RunService = game:GetService("RunService")
|
||||
local UserInputService = game:GetService("UserInputService")
|
||||
local UI = require(ReplicatedStorage:WaitForChild("HunterUI") :: ModuleScript)
|
||||
|
||||
local GAP = 7 -- px from the centre to the start of each line
|
||||
local LENGTH = 9
|
||||
local THICK = 2
|
||||
local OUTLINE = Color3.new(0, 0, 0)
|
||||
local HIT_COLOR = Color3.fromRGB(255, 60, 50)
|
||||
|
||||
local player = Players.LocalPlayer
|
||||
local playerGui = player:WaitForChild("PlayerGui")
|
||||
|
||||
local gui = Instance.new("ScreenGui")
|
||||
gui.Name = "Crosshair"
|
||||
gui.IgnoreGuiInset = true -- true screen centre, matching the camera
|
||||
gui.ResetOnSpawn = false
|
||||
gui.DisplayOrder = 10
|
||||
gui.Parent = playerGui
|
||||
|
||||
local root = Instance.new("Frame")
|
||||
root.Name = "Reticle"
|
||||
root.AnchorPoint = Vector2.new(0.5, 0.5)
|
||||
root.Position = UDim2.fromScale(0.5, 0.5)
|
||||
root.Size = UDim2.fromOffset(0, 0)
|
||||
root.BackgroundTransparency = 1
|
||||
root.Parent = gui
|
||||
|
||||
local function bar(x: number, y: number, w: number, h: number): Frame
|
||||
return UI.element("CrosshairTick", root, UDim2.fromOffset(x, y), UDim2.fromOffset(w, h))
|
||||
end
|
||||
|
||||
local mid = GAP + LENGTH / 2
|
||||
local top = bar(0, -mid, THICK, LENGTH)
|
||||
local bottom = bar(0, mid, THICK, LENGTH)
|
||||
local left = bar(-mid, 0, LENGTH, THICK)
|
||||
local right = bar(mid, 0, LENGTH, THICK)
|
||||
bar(0, 0, THICK, THICK) -- centre dot
|
||||
|
||||
-- Hit marker: four short strokes on the diagonals (an "X" around the centre), shown on top of the
|
||||
-- crosshair for a moment after each confirmed hit, also while aiming. Body / limb: white and small;
|
||||
-- head or a kill: red and bigger. Pops in larger and fades out.
|
||||
local MARKER_TIME = 0.28
|
||||
type MarkerStyle = { color: Color3, radius: number, length: number, thick: number }
|
||||
local MARKER_HIT: MarkerStyle = { color = Color3.new(1, 1, 1), radius = 13, length = 8, thick = 2 }
|
||||
local MARKER_CRIT: MarkerStyle = { color = HIT_COLOR, radius = 17, length = 12, thick = 3 }
|
||||
|
||||
local marker = Instance.new("Frame")
|
||||
marker.AnchorPoint = Vector2.new(0.5, 0.5)
|
||||
marker.Position = UDim2.fromScale(0.5, 0.5)
|
||||
marker.Size = UDim2.fromOffset(0, 0)
|
||||
marker.BackgroundTransparency = 1
|
||||
marker.Visible = false
|
||||
marker.Parent = gui
|
||||
local markerScale = Instance.new("UIScale")
|
||||
markerScale.Parent = marker
|
||||
local strokes: { { frame: Frame, stroke: UIStroke, angle: number } } = {}
|
||||
for _, angle in { 45, 135, 225, 315 } do -- clockwise from straight up
|
||||
local f = Instance.new("Frame")
|
||||
f.AnchorPoint = Vector2.new(0.5, 0.5)
|
||||
f.BorderSizePixel = 0
|
||||
f.Rotation = angle -- a vertical stroke turned to lie along its diagonal
|
||||
local s = Instance.new("UIStroke")
|
||||
s.Color = OUTLINE
|
||||
s.Thickness = 1
|
||||
s.ApplyStrokeMode = Enum.ApplyStrokeMode.Border
|
||||
s.Parent = f
|
||||
f.Parent = marker
|
||||
table.insert(strokes, { frame = f, stroke = s, angle = angle })
|
||||
end
|
||||
local markerStart: number? = nil
|
||||
local markerBig = false
|
||||
|
||||
-- gap: how far the crosshair lines are open now (the marker sits outside them)
|
||||
local function updateMarker(gap: number)
|
||||
local start = markerStart
|
||||
local t = if start then os.clock() - start else math.huge
|
||||
if t > MARKER_TIME then
|
||||
marker.Visible = false
|
||||
return
|
||||
end
|
||||
marker.Visible = true
|
||||
local style = if markerBig then MARKER_CRIT else MARKER_HIT
|
||||
local radius = math.max(style.radius, gap - 2) + style.length / 2
|
||||
for _, s in strokes do
|
||||
local a = math.rad(s.angle)
|
||||
s.frame.Size = UDim2.fromOffset(style.thick, style.length)
|
||||
s.frame.Position = UDim2.fromOffset(math.sin(a) * radius, -math.cos(a) * radius)
|
||||
s.frame.BackgroundColor3 = style.color
|
||||
local fade = math.clamp((t - MARKER_TIME * 0.45) / (MARKER_TIME * 0.55), 0, 1)
|
||||
s.frame.BackgroundTransparency = fade
|
||||
s.stroke.Transparency = 0.35 + 0.65 * fade
|
||||
end
|
||||
markerScale.Scale = 1 + 0.5 * math.max(1 - t / 0.08, 0) -- pops in from 1.5x
|
||||
end
|
||||
|
||||
-- hidden while aiming down the sights (SniperViewmodel sets its "Aiming" attribute)
|
||||
local viewmodelScript = player:WaitForChild("PlayerScripts"):WaitForChild("SniperViewmodel")
|
||||
local renderName = "HunterCrosshair"
|
||||
RunService:BindToRenderStep(renderName, Enum.RenderPriority.Camera.Value + 2, function()
|
||||
local tuner = playerGui:FindFirstChild("ViewmodelTuner") :: ScreenGui?
|
||||
local menu = playerGui:FindFirstChild("MainMenu") :: ScreenGui?
|
||||
local tunerShown = tuner ~= nil and tuner.Enabled
|
||||
local menuShown = menu ~= nil and menu.Enabled
|
||||
local inArena = player:GetAttribute("InArena") == true
|
||||
UserInputService.MouseIconEnabled = not inArena or tunerShown or menuShown
|
||||
if not inArena and not UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton2) then
|
||||
UserInputService.MouseBehavior = Enum.MouseBehavior.Default
|
||||
end
|
||||
local character = player.Character
|
||||
local hasWeapon = character ~= nil and character:FindFirstChild("SniperRifle") ~= nil
|
||||
root.Visible = inArena and hasWeapon and not menuShown
|
||||
and viewmodelScript:GetAttribute("Aiming") ~= true
|
||||
and viewmodelScript:GetAttribute("ThirdPersonView") ~= true
|
||||
-- The gap follows the next shot's deflection angle from centre.
|
||||
local cam = workspace.CurrentCamera
|
||||
if not cam then return end
|
||||
local spread = (viewmodelScript:GetAttribute("SpreadDeg") :: number?) or 0
|
||||
local px = math.tan(math.rad(spread)) / math.tan(math.rad(cam.FieldOfView / 2)) * cam.ViewportSize.Y / 2
|
||||
local m = math.max(GAP, px) + LENGTH / 2
|
||||
top.Position = UDim2.fromOffset(0, -m)
|
||||
bottom.Position = UDim2.fromOffset(0, m)
|
||||
left.Position = UDim2.fromOffset(-m, 0)
|
||||
right.Position = UDim2.fromOffset(m, 0)
|
||||
if inArena then updateMarker(m) else marker.Visible = false end
|
||||
end)
|
||||
script.Destroying:Once(function() RunService:UnbindFromRenderStep(renderName) end)
|
||||
|
||||
-- the server confirms each own hit (SniperHit: position, damage, zone, killed)
|
||||
local hitRemote = ReplicatedStorage:WaitForChild("SniperHit") :: RemoteEvent
|
||||
hitRemote.OnClientEvent:Connect(function(_position: unknown, _damage: unknown, zone: unknown, killed: unknown)
|
||||
markerStart = os.clock()
|
||||
markerBig = zone == "Head" or killed == true
|
||||
end)
|
||||
@@ -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)
|
||||
@@ -0,0 +1,181 @@
|
||||
--!strict
|
||||
-- LocalScript in StarterPlayerScripts.
|
||||
-- Floating damage numbers for the shooter: the server confirms each hit
|
||||
-- (ReplicatedStorage.SniperHit: position, damage, zone, killed) and the number pops out where the
|
||||
-- bullet went, then floats up and fades. Head = big yellow number with a red "КРИТ" tag, body =
|
||||
-- white, arms / legs = smaller grey. Each number drifts a bit to the side, so a burst scatters.
|
||||
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local TweenService = game:GetService("TweenService")
|
||||
|
||||
local hitRemote = ReplicatedStorage:WaitForChild("SniperHit") :: RemoteEvent
|
||||
local SniperEffects = require(ReplicatedStorage:WaitForChild("SniperEffects")) :: any
|
||||
-- DmgNumSpread / DmgNumRise (SniperViewmodel attributes): how far the numbers fly to the side
|
||||
-- and up, 1 = normal. The hit sound also plays here (it is the shooter's confirm).
|
||||
|
||||
local LIFE = 0.9 -- seconds on screen
|
||||
type Style = { size: number, color: Color3, stroke: Color3 }
|
||||
local STYLES: { [string]: Style } = {
|
||||
Head = { size = 42, color = Color3.fromRGB(255, 214, 40), stroke = Color3.fromRGB(60, 25, 0) },
|
||||
Body = { size = 30, color = Color3.fromRGB(255, 255, 255), stroke = Color3.fromRGB(20, 20, 28) },
|
||||
Limb = { size = 24, color = Color3.fromRGB(205, 210, 222), stroke = Color3.fromRGB(20, 20, 28) },
|
||||
}
|
||||
local CRIT_COLOR = Color3.fromRGB(255, 45, 45)
|
||||
|
||||
local function textLabel(parent: Instance, text: string, size: number, color: Color3, stroke: Color3, strokeSize: number): TextLabel
|
||||
local l = Instance.new("TextLabel")
|
||||
l.BackgroundTransparency = 1
|
||||
l.Size = UDim2.fromScale(1, 0)
|
||||
l.AutomaticSize = Enum.AutomaticSize.Y
|
||||
l.Font = Enum.Font.FredokaOne
|
||||
l.Text = text
|
||||
l.TextSize = size
|
||||
l.TextColor3 = color
|
||||
local s = Instance.new("UIStroke")
|
||||
s.Color = stroke
|
||||
s.Thickness = strokeSize
|
||||
s.LineJoinMode = Enum.LineJoinMode.Round
|
||||
s.Parent = l
|
||||
l.Parent = parent
|
||||
return l
|
||||
end
|
||||
|
||||
local ICON = 64 -- px
|
||||
local TARGET_RED = Color3.fromRGB(230, 30, 30)
|
||||
local OUTLINE = Color3.fromRGB(20, 20, 28)
|
||||
|
||||
-- headshot kill: a red target (thick ring, a dot, four ticks crossing the ring)
|
||||
local function targetIcon(parent: Instance): Frame
|
||||
local icon = Instance.new("Frame")
|
||||
icon.Size = UDim2.fromOffset(ICON, ICON)
|
||||
icon.BackgroundTransparency = 1
|
||||
local ring = Instance.new("Frame")
|
||||
ring.AnchorPoint = Vector2.new(0.5, 0.5)
|
||||
ring.Position = UDim2.fromScale(0.5, 0.5)
|
||||
ring.Size = UDim2.fromOffset(ICON * 0.62, ICON * 0.62)
|
||||
ring.BackgroundTransparency = 1
|
||||
local rc = Instance.new("UICorner")
|
||||
rc.CornerRadius = UDim.new(1, 0)
|
||||
rc.Parent = ring
|
||||
local rs = Instance.new("UIStroke")
|
||||
rs.Color = TARGET_RED
|
||||
rs.Thickness = 7
|
||||
rs.Parent = ring
|
||||
ring.Parent = icon
|
||||
local function bar(x: number, y: number, w: number, h: number)
|
||||
local f = Instance.new("Frame")
|
||||
f.AnchorPoint = Vector2.new(0.5, 0.5)
|
||||
f.Position = UDim2.new(0.5, x, 0.5, y)
|
||||
f.Size = UDim2.fromOffset(w, h)
|
||||
f.BackgroundColor3 = TARGET_RED
|
||||
f.BorderSizePixel = 0
|
||||
local s = Instance.new("UIStroke")
|
||||
s.Color = OUTLINE
|
||||
s.Thickness = 1.5
|
||||
s.ApplyStrokeMode = Enum.ApplyStrokeMode.Border
|
||||
s.Parent = f
|
||||
f.Parent = icon
|
||||
end
|
||||
local r = ICON * 0.36
|
||||
bar(0, -r, 6, 18)
|
||||
bar(0, r, 6, 18)
|
||||
bar(-r, 0, 18, 6)
|
||||
bar(r, 0, 18, 6)
|
||||
bar(0, 0, 12, 12) -- the bullseye
|
||||
icon.Parent = parent
|
||||
return icon
|
||||
end
|
||||
|
||||
-- body kill: a skull
|
||||
local function skullIcon(parent: Instance): TextLabel
|
||||
local l = Instance.new("TextLabel")
|
||||
l.BackgroundTransparency = 1
|
||||
l.Size = UDim2.fromOffset(ICON, ICON)
|
||||
l.Text = "💀"
|
||||
l.TextSize = 52
|
||||
l.Parent = parent
|
||||
return l
|
||||
end
|
||||
|
||||
local function popup(position: Vector3, damage: number, zone: string, killed: boolean)
|
||||
local style = STYLES[zone] or STYLES.Body
|
||||
local anchor = Instance.new("Attachment")
|
||||
anchor.WorldPosition = position
|
||||
anchor.Parent = workspace.Terrain
|
||||
|
||||
local gui = Instance.new("BillboardGui")
|
||||
local height = if killed then 190 else 90 -- a kill also carries an icon and a caption
|
||||
gui.Size = UDim2.fromOffset(160, height)
|
||||
gui.AlwaysOnTop = true
|
||||
gui.LightInfluence = 0
|
||||
gui.MaxDistance = 1000
|
||||
gui.Adornee = anchor
|
||||
gui.Parent = anchor
|
||||
|
||||
local group = Instance.new("Frame") -- (a CanvasGroup does not draw inside a BillboardGui)
|
||||
group.BackgroundTransparency = 1
|
||||
group.Size = UDim2.fromScale(1, 1)
|
||||
group.Parent = gui
|
||||
local list = Instance.new("UIListLayout")
|
||||
list.HorizontalAlignment = Enum.HorizontalAlignment.Center
|
||||
list.VerticalAlignment = Enum.VerticalAlignment.Bottom
|
||||
list.Padding = UDim.new(0, -6)
|
||||
list.Parent = group
|
||||
local scale = Instance.new("UIScale")
|
||||
scale.Scale = 1.9
|
||||
scale.Parent = group
|
||||
|
||||
if killed then
|
||||
-- a kill: icon (a red target for the head, a skull otherwise), then the caption
|
||||
if zone == "Head" then
|
||||
targetIcon(group).LayoutOrder = 0
|
||||
else
|
||||
skullIcon(group).LayoutOrder = 0
|
||||
end
|
||||
local caption = textLabel(group, if zone == "Head" then "Хедшот!" else "Убит!", 22, Color3.new(1, 1, 1), Color3.fromRGB(20, 20, 28), 2.5)
|
||||
caption.Font = Enum.Font.GothamBlack
|
||||
caption.LayoutOrder = 1
|
||||
elseif zone == "Head" then
|
||||
local crit = textLabel(group, "КРИТ", 24, CRIT_COLOR, Color3.new(1, 1, 1), 2.5)
|
||||
crit.Rotation = -8
|
||||
crit.LayoutOrder = 1
|
||||
end
|
||||
textLabel(group, tostring(damage), style.size, style.color, style.stroke, 3).LayoutOrder = 3
|
||||
|
||||
-- pop in, then fly off to one side and up, fading at the end. SizeOffset is in units of the
|
||||
-- gui's own (pixel) size, so the flight is the same on screen near and far.
|
||||
local spread = SniperEffects.setting("DmgNumSpread", 1)
|
||||
local rise = SniperEffects.setting("DmgNumRise", 1)
|
||||
local side = (if math.random() < 0.5 then -1 else 1) * (0.7 + math.random() * 0.9) * spread -- 110..250 px at 1
|
||||
local up = (0.4 + math.random() * 0.6) * rise * 90 / height -- same flight in pixels for a taller gui
|
||||
local life = LIFE
|
||||
if killed then
|
||||
-- a kill flies straight up, high (about 200 px at 1), and stays a little longer
|
||||
side = (math.random() - 0.5) * 0.15
|
||||
up = (1.9 + math.random() * 0.4) * SniperEffects.setting("KillPopRise", 1) * 90 / height
|
||||
life = LIFE * 1.5
|
||||
end
|
||||
TweenService:Create(scale, TweenInfo.new(0.14, Enum.EasingStyle.Back, Enum.EasingDirection.Out), { Scale = 1 }):Play()
|
||||
TweenService:Create(gui, TweenInfo.new(life, Enum.EasingStyle.Quart, Enum.EasingDirection.Out), {
|
||||
SizeOffset = Vector2.new(side, up),
|
||||
}):Play()
|
||||
local fade = TweenInfo.new(0.35, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, life - 0.35)
|
||||
for _, d in group:GetDescendants() do
|
||||
if d:IsA("TextLabel") then
|
||||
TweenService:Create(d, fade, { TextTransparency = 1 }):Play()
|
||||
elseif d:IsA("UIStroke") then
|
||||
TweenService:Create(d, fade, { Transparency = 1 }):Play()
|
||||
elseif d:IsA("Frame") and d.BackgroundTransparency < 1 then -- the target icon's strokes
|
||||
TweenService:Create(d, fade, { BackgroundTransparency = 1 }):Play()
|
||||
end
|
||||
end
|
||||
task.delay(life, function()
|
||||
anchor:Destroy()
|
||||
end)
|
||||
end
|
||||
|
||||
hitRemote.OnClientEvent:Connect(function(position: unknown, damage: unknown, zone: unknown, killed: unknown)
|
||||
if typeof(position) == "Vector3" and typeof(damage) == "number" and typeof(zone) == "string" then
|
||||
popup(position, damage, zone, killed == true)
|
||||
end
|
||||
end)
|
||||
@@ -0,0 +1,339 @@
|
||||
--!strict
|
||||
-- LocalScript in StarterPlayer > StarterPlayerScripts.
|
||||
-- Goggles for the local player, off by default:
|
||||
-- N (gamepad Y, mobile "NV") - night vision: green, amplified light, scanlines, noise
|
||||
-- T (gamepad X, mobile "TH") - thermal: cold grey-blue world, living things glow white-hot
|
||||
-- Press the same key again to switch the goggles off; press the other key to switch mode.
|
||||
--
|
||||
-- Thermal shows every Model with a Humanoid (players, NPCs, animals) plus anything
|
||||
-- tagged "Hot" with CollectionService (campfires, engines...). Roblox draws at most
|
||||
-- 31 Highlights at once.
|
||||
|
||||
local CollectionService = game:GetService("CollectionService")
|
||||
local ContextActionService = game:GetService("ContextActionService")
|
||||
local Lighting = game:GetService("Lighting")
|
||||
local Players = game:GetService("Players")
|
||||
local RunService = game:GetService("RunService")
|
||||
|
||||
if not game:IsLoaded() then
|
||||
game.Loaded:Wait()
|
||||
end
|
||||
|
||||
local player = Players.LocalPlayer
|
||||
local playerGui = player:WaitForChild("PlayerGui") :: PlayerGui
|
||||
|
||||
---------------------------------------------------------------------
|
||||
-- Settings
|
||||
---------------------------------------------------------------------
|
||||
type ModeConfig = {
|
||||
ambient: Color3,
|
||||
outdoorAmbient: Color3,
|
||||
exposure: number,
|
||||
saturation: number,
|
||||
tint: Color3,
|
||||
contrast: number,
|
||||
brightness: number,
|
||||
labelText: string,
|
||||
labelColor: Color3,
|
||||
}
|
||||
|
||||
local NIGHT_VISION: ModeConfig = {
|
||||
ambient = Color3.fromRGB(105, 105, 105),
|
||||
outdoorAmbient = Color3.fromRGB(125, 125, 125),
|
||||
exposure = 1.2,
|
||||
saturation = -1, -- grayscale first...
|
||||
tint = Color3.fromRGB(90, 255, 110), -- ...then tint green
|
||||
contrast = 0.35,
|
||||
brightness = 0.05,
|
||||
labelText = "NV ●",
|
||||
labelColor = Color3.fromRGB(120, 255, 130),
|
||||
}
|
||||
|
||||
local THERMAL: ModeConfig = {
|
||||
ambient = Color3.fromRGB(130, 130, 130),
|
||||
outdoorAmbient = Color3.fromRGB(150, 150, 150),
|
||||
exposure = 1.2,
|
||||
saturation = -1,
|
||||
tint = Color3.fromRGB(150, 170, 215), -- cold background
|
||||
contrast = 0.1,
|
||||
brightness = -0.02,
|
||||
labelText = "THERMAL ●",
|
||||
labelColor = Color3.fromRGB(255, 170, 60),
|
||||
}
|
||||
|
||||
local HOT_TAG = "Hot"
|
||||
local HEAT_FILL = Color3.fromRGB(255, 245, 230)
|
||||
local HEAT_OUTLINE = Color3.fromRGB(255, 255, 255)
|
||||
|
||||
local NOISE_AMPLITUDE = 0.025 -- per-frame brightness flicker
|
||||
local POWER_UP_TIME = 0.35 -- seconds of white flash when switching on
|
||||
local POWER_UP_FLASH = 0.8
|
||||
|
||||
local SCANLINE_COUNT = 180
|
||||
local SCANLINE_TRANSPARENCY = 0.85
|
||||
|
||||
---------------------------------------------------------------------
|
||||
-- Post-processing effects (local to this client)
|
||||
---------------------------------------------------------------------
|
||||
local colorCorrection = Instance.new("ColorCorrectionEffect")
|
||||
colorCorrection.Name = "GogglesColor"
|
||||
colorCorrection.Enabled = false
|
||||
colorCorrection.Parent = Lighting
|
||||
|
||||
local bloom = Instance.new("BloomEffect")
|
||||
bloom.Name = "GogglesBloom"
|
||||
bloom.Intensity = 1.2
|
||||
bloom.Size = 30
|
||||
bloom.Threshold = 0.85
|
||||
bloom.Enabled = false
|
||||
bloom.Parent = Lighting
|
||||
|
||||
local blur = Instance.new("BlurEffect")
|
||||
blur.Name = "GogglesBlur"
|
||||
blur.Size = 2
|
||||
blur.Enabled = false
|
||||
blur.Parent = Lighting
|
||||
|
||||
---------------------------------------------------------------------
|
||||
-- Screen overlay: vignette, scanlines, label
|
||||
---------------------------------------------------------------------
|
||||
local overlay = Instance.new("ScreenGui")
|
||||
overlay.Name = "GogglesOverlay"
|
||||
overlay.IgnoreGuiInset = true
|
||||
overlay.ResetOnSpawn = false
|
||||
overlay.DisplayOrder = -10 -- under the rest of the HUD
|
||||
overlay.Enabled = false
|
||||
|
||||
local function makeVignetteEdge(size: UDim2, position: UDim2, rotation: number)
|
||||
local edge = Instance.new("Frame")
|
||||
edge.Size = size
|
||||
edge.Position = position
|
||||
edge.BackgroundColor3 = Color3.new(0, 0, 0)
|
||||
edge.BorderSizePixel = 0
|
||||
edge.Parent = overlay
|
||||
|
||||
local gradient = Instance.new("UIGradient")
|
||||
gradient.Rotation = rotation
|
||||
gradient.Transparency = NumberSequence.new({
|
||||
NumberSequenceKeypoint.new(0, 0.05),
|
||||
NumberSequenceKeypoint.new(0.6, 0.75),
|
||||
NumberSequenceKeypoint.new(1, 1),
|
||||
})
|
||||
gradient.Parent = edge
|
||||
end
|
||||
|
||||
makeVignetteEdge(UDim2.fromScale(0.25, 1), UDim2.fromScale(0, 0), 0) -- left
|
||||
makeVignetteEdge(UDim2.fromScale(0.25, 1), UDim2.fromScale(0.75, 0), 180) -- right
|
||||
makeVignetteEdge(UDim2.fromScale(1, 0.25), UDim2.fromScale(0, 0), 90) -- top
|
||||
makeVignetteEdge(UDim2.fromScale(1, 0.25), UDim2.fromScale(0, 0.75), 270) -- bottom
|
||||
|
||||
local scanlines = Instance.new("Frame")
|
||||
scanlines.Name = "Scanlines"
|
||||
scanlines.Size = UDim2.fromScale(1, 1)
|
||||
scanlines.BackgroundTransparency = 1
|
||||
scanlines.Parent = overlay
|
||||
|
||||
for i = 0, SCANLINE_COUNT - 1 do
|
||||
local line = Instance.new("Frame")
|
||||
line.Size = UDim2.new(1, 0, 0, 1)
|
||||
line.Position = UDim2.fromScale(0, i / SCANLINE_COUNT)
|
||||
line.BackgroundColor3 = Color3.new(0, 0, 0)
|
||||
line.BackgroundTransparency = SCANLINE_TRANSPARENCY
|
||||
line.BorderSizePixel = 0
|
||||
line.Parent = scanlines
|
||||
end
|
||||
|
||||
local label = Instance.new("TextLabel")
|
||||
label.Name = "Label"
|
||||
label.AnchorPoint = Vector2.new(1, 0)
|
||||
label.Position = UDim2.new(1, -24, 0, 48)
|
||||
label.Size = UDim2.fromOffset(160, 24)
|
||||
label.BackgroundTransparency = 1
|
||||
label.Font = Enum.Font.Code
|
||||
label.TextSize = 20
|
||||
label.TextXAlignment = Enum.TextXAlignment.Right
|
||||
label.Parent = overlay
|
||||
|
||||
overlay.Parent = playerGui
|
||||
|
||||
---------------------------------------------------------------------
|
||||
-- Thermal: highlight warm bodies
|
||||
---------------------------------------------------------------------
|
||||
local heatFolder = Instance.new("Folder")
|
||||
heatFolder.Name = "ThermalHighlights"
|
||||
heatFolder.Parent = workspace -- created by the client, so only this player sees it
|
||||
|
||||
local highlights: { [Instance]: Highlight } = {}
|
||||
local heatConnections: { RBXScriptConnection } = {}
|
||||
|
||||
local function removeHeat(target: Instance)
|
||||
local highlight = highlights[target]
|
||||
if highlight then
|
||||
highlights[target] = nil
|
||||
highlight:Destroy()
|
||||
end
|
||||
end
|
||||
|
||||
local function addHeat(target: Instance)
|
||||
if highlights[target] or target == player.Character then
|
||||
return
|
||||
end
|
||||
if not target:IsDescendantOf(workspace) then
|
||||
return
|
||||
end
|
||||
|
||||
local highlight = Instance.new("Highlight")
|
||||
highlight.Adornee = target
|
||||
highlight.FillColor = HEAT_FILL
|
||||
highlight.FillTransparency = 0
|
||||
highlight.OutlineColor = HEAT_OUTLINE
|
||||
highlight.OutlineTransparency = 0.2
|
||||
highlight.DepthMode = Enum.HighlightDepthMode.Occluded -- no seeing through walls
|
||||
highlight.Parent = heatFolder
|
||||
highlights[target] = highlight
|
||||
|
||||
local ancestryConnection: RBXScriptConnection
|
||||
ancestryConnection = target.AncestryChanged:Connect(function()
|
||||
if not target:IsDescendantOf(workspace) then
|
||||
ancestryConnection:Disconnect()
|
||||
removeHeat(target)
|
||||
end
|
||||
end)
|
||||
table.insert(heatConnections, ancestryConnection)
|
||||
end
|
||||
|
||||
local function onWorkspaceDescendant(descendant: Instance)
|
||||
if descendant:IsA("Humanoid") then
|
||||
local model = descendant.Parent
|
||||
if model and model:IsA("Model") then
|
||||
addHeat(model)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function startHeatTracking()
|
||||
for _, descendant in workspace:GetDescendants() do
|
||||
onWorkspaceDescendant(descendant)
|
||||
end
|
||||
for _, tagged in CollectionService:GetTagged(HOT_TAG) do
|
||||
addHeat(tagged)
|
||||
end
|
||||
table.insert(heatConnections, workspace.DescendantAdded:Connect(onWorkspaceDescendant))
|
||||
table.insert(heatConnections, CollectionService:GetInstanceAddedSignal(HOT_TAG):Connect(addHeat))
|
||||
table.insert(heatConnections, CollectionService:GetInstanceRemovedSignal(HOT_TAG):Connect(removeHeat))
|
||||
end
|
||||
|
||||
local function stopHeatTracking()
|
||||
for _, connection in heatConnections do
|
||||
connection:Disconnect()
|
||||
end
|
||||
table.clear(heatConnections)
|
||||
for target in highlights do
|
||||
removeHeat(target)
|
||||
end
|
||||
end
|
||||
|
||||
---------------------------------------------------------------------
|
||||
-- Mode switching
|
||||
---------------------------------------------------------------------
|
||||
type Mode = "Off" | "NightVision" | "Thermal"
|
||||
|
||||
type LightingSnapshot = {
|
||||
Ambient: Color3,
|
||||
OutdoorAmbient: Color3,
|
||||
ExposureCompensation: number,
|
||||
}
|
||||
|
||||
local mode: Mode = "Off"
|
||||
local baseBrightness = 0
|
||||
local enabledAt = 0
|
||||
local savedLighting: LightingSnapshot? = nil
|
||||
local renderConnection: RBXScriptConnection? = nil
|
||||
|
||||
local function onRenderStep()
|
||||
local flash = math.max(0, 1 - (os.clock() - enabledAt) / POWER_UP_TIME)
|
||||
local noise = (math.random() * 2 - 1) * NOISE_AMPLITUDE
|
||||
colorCorrection.Brightness = baseBrightness + flash * POWER_UP_FLASH + noise
|
||||
end
|
||||
|
||||
local function setMode(newMode: Mode)
|
||||
if newMode == mode then
|
||||
return
|
||||
end
|
||||
local oldMode = mode
|
||||
mode = newMode
|
||||
|
||||
if oldMode == "Thermal" then
|
||||
stopHeatTracking()
|
||||
end
|
||||
|
||||
if newMode == "Off" then
|
||||
if renderConnection then
|
||||
renderConnection:Disconnect()
|
||||
renderConnection = nil
|
||||
end
|
||||
local saved = savedLighting
|
||||
if saved then
|
||||
Lighting.Ambient = saved.Ambient
|
||||
Lighting.OutdoorAmbient = saved.OutdoorAmbient
|
||||
Lighting.ExposureCompensation = saved.ExposureCompensation
|
||||
savedLighting = nil
|
||||
end
|
||||
colorCorrection.Enabled = false
|
||||
bloom.Enabled = false
|
||||
blur.Enabled = false
|
||||
overlay.Enabled = false
|
||||
return
|
||||
end
|
||||
|
||||
if oldMode == "Off" then
|
||||
-- Remember the real night lighting so we can restore it.
|
||||
savedLighting = {
|
||||
Ambient = Lighting.Ambient,
|
||||
OutdoorAmbient = Lighting.OutdoorAmbient,
|
||||
ExposureCompensation = Lighting.ExposureCompensation,
|
||||
}
|
||||
renderConnection = RunService.RenderStepped:Connect(onRenderStep)
|
||||
end
|
||||
|
||||
local config = if newMode == "Thermal" then THERMAL else NIGHT_VISION
|
||||
-- Client-side Lighting changes only affect this player.
|
||||
Lighting.Ambient = config.ambient
|
||||
Lighting.OutdoorAmbient = config.outdoorAmbient
|
||||
Lighting.ExposureCompensation = config.exposure
|
||||
colorCorrection.Saturation = config.saturation
|
||||
colorCorrection.TintColor = config.tint
|
||||
colorCorrection.Contrast = config.contrast
|
||||
baseBrightness = config.brightness
|
||||
label.Text = config.labelText
|
||||
label.TextColor3 = config.labelColor
|
||||
enabledAt = os.clock()
|
||||
|
||||
colorCorrection.Enabled = true
|
||||
bloom.Enabled = true
|
||||
blur.Enabled = true
|
||||
overlay.Enabled = true
|
||||
|
||||
if newMode == "Thermal" then
|
||||
startHeatTracking()
|
||||
end
|
||||
end
|
||||
|
||||
local function bindModeKey(actionName: string, target: Mode, title: string, ...: Enum.KeyCode)
|
||||
ContextActionService:BindAction(
|
||||
actionName,
|
||||
function(_name: string, state: Enum.UserInputState, _input: InputObject): Enum.ContextActionResult?
|
||||
if state == Enum.UserInputState.Begin then
|
||||
setMode(if mode == target then "Off" else target)
|
||||
return Enum.ContextActionResult.Sink
|
||||
end
|
||||
return Enum.ContextActionResult.Pass
|
||||
end,
|
||||
true, -- on-screen button on mobile
|
||||
...
|
||||
)
|
||||
ContextActionService:SetTitle(actionName, title)
|
||||
end
|
||||
|
||||
bindModeKey("ToggleNightVision", "NightVision", "NV", Enum.KeyCode.N, Enum.KeyCode.ButtonY)
|
||||
bindModeKey("ToggleThermal", "Thermal", "TH", Enum.KeyCode.T, Enum.KeyCode.ButtonX)
|
||||
@@ -0,0 +1,119 @@
|
||||
--!strict
|
||||
local Players = game:GetService("Players")
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local StarterGui = game:GetService("StarterGui")
|
||||
local TweenService = game:GetService("TweenService")
|
||||
local UI = require(ReplicatedStorage:WaitForChild("HunterUI") :: ModuleScript)
|
||||
|
||||
local YELLOW = Color3.fromRGB(255, 194, 70)
|
||||
local RED = Color3.fromRGB(250, 80, 82)
|
||||
|
||||
local player = Players.LocalPlayer
|
||||
|
||||
task.spawn(function()
|
||||
for _ = 1, 20 do
|
||||
if pcall(StarterGui.SetCoreGuiEnabled, StarterGui, Enum.CoreGuiType.Health, false) then
|
||||
break
|
||||
end
|
||||
task.wait(0.5)
|
||||
end
|
||||
end)
|
||||
|
||||
local gui = Instance.new("ScreenGui")
|
||||
gui.Name = "HealthBar"
|
||||
gui.ResetOnSpawn = false
|
||||
gui.DisplayOrder = 10
|
||||
gui.Enabled = player:GetAttribute("InArena") == true
|
||||
gui.Parent = player:WaitForChild("PlayerGui")
|
||||
player:GetAttributeChangedSignal("InArena"):Connect(function()
|
||||
gui.Enabled = player:GetAttribute("InArena") == true
|
||||
end)
|
||||
|
||||
local plate = UI.plate(gui, "Health", UDim2.new(0, 15, 1, -16), UDim2.new(.46, 0, 0, 49), UI.Outline)
|
||||
local lightning = UI.contour(plate, UI.Mint)
|
||||
plate.AnchorPoint = Vector2.new(0, 1)
|
||||
local limit = Instance.new("UISizeConstraint", plate)
|
||||
limit.MaxSize = Vector2.new(350, 49)
|
||||
local function fit()
|
||||
local width = gui.AbsoluteSize.X
|
||||
if width > 0 then
|
||||
plate.Size = UDim2.fromOffset(math.max(120, math.min(width * .46, width - 221, 350)), 49)
|
||||
end
|
||||
end
|
||||
gui:GetPropertyChangedSignal("AbsoluteSize"):Connect(fit)
|
||||
fit()
|
||||
local shield = UI.element("Shield", plate, UDim2.fromOffset(14, 13), nil)
|
||||
Instance.new("UIScale", shield).Scale = 1.13
|
||||
local text = UI.label(plate, "Value", "100", UDim2.fromOffset(46, 0), UDim2.fromOffset(55, 49), 24, UI.Ink)
|
||||
text.FontFace = UI.Display
|
||||
text.TextXAlignment = Enum.TextXAlignment.Left
|
||||
local track = UI.element("ProgressBar", plate, UDim2.fromOffset(100, 17), UDim2.new(1, -117, 0, 15))
|
||||
local fill = track:WaitForChild("Fill") :: Frame
|
||||
local lag = UI.frame("DamageTrail", track, UDim2.fromScale(0, 0), UDim2.fromScale(1, 1), UI.Ink)
|
||||
lag.BackgroundTransparency = .37
|
||||
fill.ZIndex = 2
|
||||
UI.sheen(fill)
|
||||
|
||||
local function colorFor(r: number): Color3
|
||||
if r > 0.5 then
|
||||
return YELLOW:Lerp(UI.Mint, math.clamp((r - .5) / .31, 0, 1))
|
||||
end
|
||||
return RED:Lerp(YELLOW, r * 2)
|
||||
end
|
||||
|
||||
local lastHealth: number? = nil
|
||||
local fillTween: Tween? = nil
|
||||
local lagTween: Tween? = nil
|
||||
local conns: { RBXScriptConnection } = {}
|
||||
|
||||
local function update(humanoid: Humanoid)
|
||||
local max = math.max(humanoid.MaxHealth, 1)
|
||||
local hp = math.clamp(humanoid.Health, 0, max)
|
||||
local r = hp / max
|
||||
text.Text = tostring(math.ceil(hp))
|
||||
local tint = colorFor(r)
|
||||
lightning:SetAttribute("Accent", tint)
|
||||
if fillTween then fillTween:Cancel() end
|
||||
if lagTween then lagTween:Cancel() end
|
||||
if lastHealth then
|
||||
local damaged = hp < lastHealth
|
||||
if damaged then fill.BackgroundColor3 = UI.Ink end
|
||||
fillTween = TweenService:Create(fill, TweenInfo.new(.18, Enum.EasingStyle.Quart), {
|
||||
Size = UDim2.fromScale(r, 1), BackgroundColor3 = tint,
|
||||
})
|
||||
lagTween = TweenService:Create(lag, TweenInfo.new(.42, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false, if damaged then .18 else 0), {
|
||||
Size = UDim2.fromScale(r, 1),
|
||||
})
|
||||
fillTween:Play()
|
||||
lagTween:Play()
|
||||
else
|
||||
fill.Size = UDim2.fromScale(r, 1)
|
||||
fill.BackgroundColor3 = tint
|
||||
lag.Size = fill.Size
|
||||
end
|
||||
lastHealth = hp
|
||||
end
|
||||
|
||||
local function onCharacter(character: Model)
|
||||
local humanoid = character:WaitForChild("Humanoid", 10) :: Humanoid?
|
||||
if not humanoid then
|
||||
return
|
||||
end
|
||||
for _, cn in conns do
|
||||
cn:Disconnect()
|
||||
end
|
||||
table.clear(conns)
|
||||
lastHealth = nil
|
||||
update(humanoid)
|
||||
table.insert(conns, humanoid.HealthChanged:Connect(function()
|
||||
update(humanoid)
|
||||
end))
|
||||
table.insert(conns, humanoid:GetPropertyChangedSignal("MaxHealth"):Connect(function()
|
||||
update(humanoid)
|
||||
end))
|
||||
end
|
||||
|
||||
player.CharacterAdded:Connect(onCharacter)
|
||||
if player.Character then
|
||||
onCharacter(player.Character)
|
||||
end
|
||||
@@ -0,0 +1,32 @@
|
||||
--!strict
|
||||
local Rules = require(script.Parent:WaitForChild("MatchRules") :: ModuleScript)
|
||||
local HostedArena = {}
|
||||
|
||||
HostedArena.InviteSeconds = 35
|
||||
HostedArena.MaxPlayers = 20
|
||||
|
||||
export type Side = "Blue" | "Orange"
|
||||
export type RoundOptions = {initialMode: string, allowModeChange: boolean}
|
||||
export type Member = {userId: number, displayName: string}
|
||||
export type Listing = {id: string, hostId: number, hostName: string, players: number, ruleset: string}
|
||||
export type Details = {id: string, blue: {Member}, orange: {Member}, players: number}
|
||||
|
||||
function HostedArena.readRoundOptions(value: unknown): RoundOptions?
|
||||
if value == nil then return {initialMode = Rules.Default, allowModeChange = true} end
|
||||
if typeof(value) ~= "table" or typeof(value.allowModeChange) ~= "boolean" then return nil end
|
||||
local rule = Rules.find(value.initialMode)
|
||||
if not rule then return nil end
|
||||
return {initialMode = rule.id, allowModeChange = value.allowModeChange}
|
||||
end
|
||||
|
||||
function HostedArena.teamJoinError(own: number, other: number): string?
|
||||
if own >= HostedArena.MaxPlayers // 2 then return "Full" end
|
||||
if own > other then return "Balance" end
|
||||
return nil
|
||||
end
|
||||
|
||||
function HostedArena.isReserved(): boolean
|
||||
return game.PrivateServerId ~= "" and game.PrivateServerOwnerId == 0
|
||||
end
|
||||
|
||||
return table.freeze(HostedArena)
|
||||
@@ -0,0 +1,920 @@
|
||||
--!strict
|
||||
local GuiService = game:GetService("GuiService")
|
||||
local Players = game:GetService("Players")
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local RunService = game:GetService("RunService")
|
||||
local TweenService = game:GetService("TweenService")
|
||||
local UserInputService = game:GetService("UserInputService")
|
||||
local UI = require(ReplicatedStorage:WaitForChild("HunterUI") :: ModuleScript)
|
||||
local Hosting = require(ReplicatedStorage:WaitForChild("HostedArena") :: ModuleScript)
|
||||
local Modes = require(ReplicatedStorage:WaitForChild("ArenaModes") :: ModuleScript)
|
||||
local Rules = require(ReplicatedStorage:WaitForChild("MatchRules") :: ModuleScript)
|
||||
local ModeCard = require(ReplicatedStorage:WaitForChild("ModeCard") :: ModuleScript)
|
||||
local roundState = ReplicatedStorage:WaitForChild("ArenaRound")
|
||||
local join = roundState:WaitForChild("JoinTeam") :: RemoteEvent
|
||||
local remote = ReplicatedStorage:WaitForChild("HostedArenaRemote") :: RemoteEvent
|
||||
local hosted = remote:GetAttribute("IsHosted") == true
|
||||
local localPreview = remote:GetAttribute("LocalPublicPreview") == true
|
||||
local player = Players.LocalPlayer
|
||||
local pg = player:WaitForChild("PlayerGui")
|
||||
local roundHud = pg:WaitForChild("ArenaRoundHud")
|
||||
|
||||
type Invite = {id: string, hostId: number, hostName: string, hostUsername: string, expires: number}
|
||||
type Party = {accepted: number, pending: number, expires: number}
|
||||
type Listing = Hosting.Listing
|
||||
type Details = Hosting.Details
|
||||
type Side = Hosting.Side
|
||||
type Choice = {id: string, name: string, mode: string?, hostId: number?, players: number, ruleset: string}
|
||||
type ArenaCard = {choice: Choice, visual: ModeCard.Card, name: TextLabel}
|
||||
|
||||
local violet = Color3.fromRGB(178, 133, 255)
|
||||
local dark = Color3.fromRGB(17, 23, 38)
|
||||
local gui = Instance.new("ScreenGui")
|
||||
gui.Name = "HostedArenaHud"
|
||||
gui.ResetOnSpawn = false
|
||||
gui.DisplayOrder = 38
|
||||
gui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
|
||||
gui.Parent = pg
|
||||
|
||||
local function button(parent: Instance, name: string, value: string, position: UDim2, size: UDim2, accent: Color3, primary: boolean?): TextButton
|
||||
local item = Instance.new("TextButton")
|
||||
item.Name, item.Position, item.Size = name, position, size
|
||||
item.BackgroundColor3 = if primary then accent else dark:Lerp(accent, .17)
|
||||
item.BorderSizePixel = 0
|
||||
item.Text, item.TextSize = value, 15
|
||||
item.TextColor3 = if primary then dark else UI.Ink
|
||||
item.FontFace = UI.Display
|
||||
item.Parent = parent
|
||||
UI.bindButton(item, accent)
|
||||
return item
|
||||
end
|
||||
|
||||
local function leftLabel(parent: Instance, name: string, value: string, x: number, y: number, w: number, h: number, size: number, color: Color3): TextLabel
|
||||
local text = UI.label(parent, name, value, UDim2.fromOffset(x, y), UDim2.fromOffset(w, h), size, color)
|
||||
text.TextXAlignment = Enum.TextXAlignment.Left
|
||||
text.TextTruncate = Enum.TextTruncate.AtEnd
|
||||
return text
|
||||
end
|
||||
|
||||
local function showAvatar(image: ImageLabel, userId: number, name: string)
|
||||
local initial = image:FindFirstChild("Initial") :: TextLabel?
|
||||
if initial then
|
||||
initial.Text = if name == "" then "?" else name:sub(1, (utf8.offset(name, 2) or #name + 1) - 1)
|
||||
initial.Visible = true
|
||||
end
|
||||
image.Image = if userId > 0 then "rbxthumb://type=AvatarHeadShot&id=" .. userId .. "&w=150&h=150" else ""
|
||||
if initial then
|
||||
local function update() initial.Visible = image.Image == "" or not image.IsLoaded end
|
||||
if not image:GetAttribute("TracksLoading") then
|
||||
image:SetAttribute("TracksLoading", true)
|
||||
image:GetPropertyChangedSignal("IsLoaded"):Connect(update)
|
||||
end
|
||||
update()
|
||||
end
|
||||
end
|
||||
|
||||
local rowGap = 6
|
||||
local function makeList(parent: Instance, name: string, position: UDim2, size: UDim2, accent: Color3): ScrollingFrame
|
||||
local scroll = Instance.new("ScrollingFrame")
|
||||
scroll.Name, scroll.Position, scroll.Size = name, position, size
|
||||
scroll.BackgroundTransparency, scroll.BorderSizePixel = 1, 0
|
||||
scroll.ScrollBarThickness, scroll.ScrollBarImageColor3 = 5, accent
|
||||
scroll.ScrollingDirection = Enum.ScrollingDirection.Y
|
||||
scroll.CanvasSize, scroll.AutomaticCanvasSize = UDim2.new(), Enum.AutomaticSize.Y
|
||||
local layout = Instance.new("UIListLayout", scroll)
|
||||
layout.Padding, layout.SortOrder = UDim.new(0, rowGap), Enum.SortOrder.LayoutOrder
|
||||
scroll.Parent = parent
|
||||
return scroll
|
||||
end
|
||||
|
||||
local launch = button(gui, "OpenArenaCreator", if hosted then "‹ В ОБЩЕЕ ЛОББИ" else "+ СОЗДАТЬ АРЕНУ",
|
||||
UDim2.new(1, -24, 1, -42), UDim2.fromOffset(264, 52), violet, true)
|
||||
launch.AnchorPoint = Vector2.new(1, 1)
|
||||
launch.Modal = true
|
||||
|
||||
local browser = UI.plate(gui, "PublicArenas", UDim2.new(1, -24, 1, -104), UDim2.fromOffset(264, 432), UI.Blue, dark)
|
||||
browser.AnchorPoint = Vector2.new(1, 1)
|
||||
local browserTitle = leftLabel(browser, "Heading", if hosted then "АРЕНА СЕССИИ" else "ПУБЛИЧНЫЕ АРЕНЫ", 13, 7, 173, 34, 16, UI.Ink)
|
||||
browserTitle.FontFace = UI.Display
|
||||
local ownerLabel = leftLabel(browser, "Owner", "", 13, 38, 237, 21, 12, UI.Muted)
|
||||
ownerLabel.Visible = hosted
|
||||
local refreshDirectory = button(browser, "Refresh", "ОБНОВИТЬ", UDim2.fromOffset(191, 9), UDim2.fromOffset(61, 31), UI.Blue)
|
||||
refreshDirectory.TextSize = 10
|
||||
refreshDirectory.Visible = not hosted and not localPreview
|
||||
local listTop = if hosted then 64 else 47
|
||||
local cardHeight, moreHeight = 184, 37
|
||||
local browserChrome = listTop + 10
|
||||
local contentHeight = cardHeight
|
||||
local arenaList = makeList(browser, "List", UDim2.fromOffset(10, listTop), UDim2.new(0, 244, 1, -browserChrome), UI.Blue)
|
||||
local moreArenas = button(arenaList, "More", "ПОКАЗАТЬ ЕЩЁ", UDim2.new(), UDim2.new(1, -13, 0, moreHeight), UI.Blue)
|
||||
moreArenas.Visible = false
|
||||
|
||||
local shade = UI.frame("CreatorShade", gui, UDim2.fromScale(0, 0), UDim2.fromScale(1, 1), Color3.fromRGB(5, 10, 20))
|
||||
shade.BackgroundTransparency, shade.Active, shade.Visible = .2, true, false
|
||||
local dialogWidth, createHeight, detailsHeight = 642, 685, 461
|
||||
local currentHeight = createHeight
|
||||
local panel = UI.plate(shade, "Creator", UDim2.fromScale(.5, .5), UDim2.fromOffset(dialogWidth, createHeight), violet, dark)
|
||||
panel.AnchorPoint = Vector2.new(.5, .5)
|
||||
UI.contour(panel, violet)
|
||||
local panelScale = Instance.new("UIScale", panel)
|
||||
local function fit()
|
||||
local screen = shade.AbsoluteSize
|
||||
panelScale.Scale = math.clamp(math.min((screen.X - 24) / dialogWidth, (screen.Y - 24) / currentHeight), .05, 1)
|
||||
local maximum = math.clamp(screen.Y - 204, 210, 432)
|
||||
local desired = browserChrome + contentHeight
|
||||
browser.Size = UDim2.fromOffset(264, math.min(desired, maximum))
|
||||
local scrollable = desired > maximum
|
||||
arenaList.ScrollingEnabled = scrollable
|
||||
arenaList.ScrollBarImageTransparency = if scrollable then 0 else 1
|
||||
if not scrollable then arenaList.CanvasPosition = Vector2.zero end
|
||||
end
|
||||
shade:GetPropertyChangedSignal("AbsoluteSize"):Connect(fit)
|
||||
fit()
|
||||
|
||||
local header = leftLabel(panel, "Title", "СОЗДАНИЕ АРЕНЫ", 26, 15, 520, 45, 31, UI.Ink)
|
||||
header.FontFace = UI.Display
|
||||
local close = button(panel, "Close", "×", UDim2.fromOffset(568, 19), UDim2.fromOffset(48, 37), UI.Orange)
|
||||
close.TextSize, close.Modal = 23, true
|
||||
local public = button(panel, "Public", "ПУБЛИЧНАЯ", UDim2.fromOffset(26, 74), UDim2.fromOffset(284, 44), UI.Blue)
|
||||
local private = button(panel, "Private", "ПРИВАТНАЯ", UDim2.fromOffset(322, 74), UDim2.fromOffset(294, 44), violet)
|
||||
local explanation = leftLabel(panel, "Description", "", 26, 129, 590, 28, 14, UI.Muted)
|
||||
local modesHeading = leftLabel(panel, "ModesHeading", "СТАРТОВЫЙ РЕЖИМ", 26, 154, 590, 25, 15, UI.Ink)
|
||||
modesHeading.FontFace = UI.Display
|
||||
local modeChoices = UI.frame("InitialModeChoices", panel, UDim2.fromOffset(26, 184), UDim2.fromOffset(590, 174), dark)
|
||||
modeChoices.BackgroundTransparency = 1
|
||||
local modeCards: {[string]: ModeCard.Card} = {}
|
||||
for index, rule in Rules.All do
|
||||
local column, row = (index - 1) % 4, (index - 1) // 4
|
||||
local card = ModeCard.new(modeChoices, rule.id, UDim2.fromOffset(column * 149, row * 90), UDim2.fromOffset(143, 84), true)
|
||||
card.badgePanel.Visible = false
|
||||
card.title.Position = UDim2.new(0, 6, 1, -31)
|
||||
card.title.Size = UDim2.new(1, -12, 0, 25)
|
||||
card.art.Size = UDim2.new(1, -12, 1, -35)
|
||||
modeCards[rule.id] = card
|
||||
end
|
||||
local modeDescription = leftLabel(panel, "ModeDescription", "", 26, 361, 590, 24, 13, UI.Muted)
|
||||
local changeLabel = leftLabel(panel, "ModeChangeHeading", "Разрешить смену режимов", 26, 391, 375, 22, 16, UI.Ink)
|
||||
changeLabel.FontFace = UI.Display
|
||||
local changeHint = leftLabel(panel, "ModeChangeHint", "", 26, 413, 375, 20, 12, UI.Muted)
|
||||
local changeToggle = button(panel, "AllowModeChange", "", UDim2.fromOffset(430, 391), UDim2.fromOffset(186, 41), UI.Mint, true)
|
||||
local selectionCount = leftLabel(panel, "Selection", "", 26, 441, 590, 24, 13, violet)
|
||||
local list = makeList(panel, "ServerPlayers", UDim2.fromOffset(26, 471), UDim2.fromOffset(590, 123), violet)
|
||||
local status = leftLabel(panel, "Status", "", 26, 598, 590, 28, 14, UI.Muted)
|
||||
local action = button(panel, "Submit", "", UDim2.fromOffset(26, 626), UDim2.fromOffset(590, 42), violet, true)
|
||||
|
||||
local detailsPanel = UI.plate(shade, "ArenaDetails", UDim2.fromScale(.5, .5), UDim2.fromOffset(dialogWidth, detailsHeight), UI.Blue, dark)
|
||||
detailsPanel.AnchorPoint, detailsPanel.Visible = Vector2.new(.5, .5), false
|
||||
UI.contour(detailsPanel, UI.Blue)
|
||||
local detailsScale = Instance.new("UIScale", detailsPanel)
|
||||
local detailsTitle = leftLabel(detailsPanel, "Title", "", 26, 15, 520, 46, 27, UI.Ink)
|
||||
detailsTitle.FontFace = UI.Display
|
||||
local detailsClose = button(detailsPanel, "Close", "×", UDim2.fromOffset(568, 19), UDim2.fromOffset(48, 37), UI.Orange)
|
||||
detailsClose.TextSize, detailsClose.Modal = 23, true
|
||||
local detailsStatus = leftLabel(detailsPanel, "Status", "", 26, 357, 590, 32, 14, UI.Muted)
|
||||
local connect = button(detailsPanel, "Connect", "ПОДКЛЮЧИТЬСЯ ›", UDim2.fromOffset(26, 397), UDim2.fromOffset(590, 43), UI.Blue, true)
|
||||
|
||||
local function teamColumn(name: string, text: string, x: number, accent: Color3)
|
||||
local body = UI.plate(detailsPanel, name, UDim2.fromOffset(x + 144.5, 212), UDim2.fromOffset(289, 274), accent, dark:Lerp(accent, .08))
|
||||
body.AnchorPoint = Vector2.new(.5, .5)
|
||||
local zoom = Instance.new("UIScale", body)
|
||||
local glow = UI.frame("SelectionGlow", body, UDim2.fromOffset(3, 3), UDim2.new(1, -6, 1, -6), accent)
|
||||
glow.BackgroundTransparency = 1
|
||||
local shine = Instance.new("UIGradient", glow)
|
||||
shine.Rotation = 24
|
||||
shine.Transparency = NumberSequence.new({
|
||||
NumberSequenceKeypoint.new(0, .73),
|
||||
NumberSequenceKeypoint.new(.48, .18),
|
||||
NumberSequenceKeypoint.new(1, .83),
|
||||
})
|
||||
local border = UI.edge(body, accent, 0)
|
||||
local heading = leftLabel(body, "Heading", text, 12, 7, 173, 34, 17, accent)
|
||||
heading.FontFace = UI.Display
|
||||
local count = UI.label(body, "Count", "", UDim2.fromOffset(188, 8), UDim2.fromOffset(86, 31), 14, UI.Ink)
|
||||
local scroll = makeList(body, "Players", UDim2.fromOffset(9, 47), UDim2.fromOffset(271, 177), accent)
|
||||
local marker = UI.label(body, "ChoiceLabel", "ВЫБРАТЬ", UDim2.fromOffset(9, 232), UDim2.fromOffset(271, 32), 13, accent)
|
||||
marker.FontFace = UI.Display
|
||||
local dimmer = UI.frame("SelectionDimmer", body, UDim2.fromScale(0, 0), UDim2.fromScale(1, 1), dark)
|
||||
dimmer.BackgroundTransparency, dimmer.ZIndex = 1, 3
|
||||
local hit = Instance.new("TextButton")
|
||||
hit.Name = "Choose"
|
||||
hit.Size, hit.ZIndex = UDim2.new(1, -14, 1, 0), 4
|
||||
hit.Text, hit.BackgroundTransparency, hit.AutoButtonColor = "", 1, false
|
||||
hit.Selectable, hit.Parent = true, body
|
||||
return {count = count, scroll = scroll, accent = accent, stamp = nil :: string?,
|
||||
zoom = zoom, glow = glow, shine = shine, border = border, dimmer = dimmer, hit = hit, marker = marker,
|
||||
hovered = false, focused = false, pressed = false, feedbackTween = nil :: Tween?}
|
||||
end
|
||||
local blueTeam = teamColumn("Blue", "СИНИЕ", 26, UI.Blue)
|
||||
local orangeTeam = teamColumn("Orange", "ОРАНЖЕВЫЕ", 327, UI.Orange)
|
||||
type TeamColumn = typeof(blueTeam)
|
||||
local teamColumns: {[Side]: TeamColumn} = {Blue = blueTeam, Orange = orangeTeam}
|
||||
shade:GetPropertyChangedSignal("AbsoluteSize"):Connect(function()
|
||||
local screen = shade.AbsoluteSize
|
||||
detailsScale.Scale = math.clamp(math.min((screen.X - 24) / dialogWidth, (screen.Y - 24) / detailsHeight), .05, 1)
|
||||
end)
|
||||
local notice = UI.plate(gui, "Notice", UDim2.new(0, 24, 1, -108), UDim2.fromOffset(380, 44), violet, dark)
|
||||
notice.AnchorPoint, notice.Visible = Vector2.new(0, 1), false
|
||||
local noticeText = leftLabel(notice, "Text", "", 13, 0, 354, 44, 13, UI.Ink)
|
||||
noticeText.TextWrapped = true
|
||||
|
||||
local invitation = UI.plate(gui, "ArenaInvitation", UDim2.fromOffset(24, 163), UDim2.fromOffset(354, 166), violet, dark)
|
||||
invitation.Visible = false
|
||||
UI.contour(invitation, violet)
|
||||
local inviteTitle = leftLabel(invitation, "Title", "ПРИГЛАШЕНИЕ НА АРЕНУ", 14, 7, 282, 27, 17, UI.Ink)
|
||||
inviteTitle.FontFace = UI.Display
|
||||
local inviteTimer = UI.label(invitation, "Timer", "", UDim2.fromOffset(297, 7), UDim2.fromOffset(44, 27), 14, violet)
|
||||
local portrait = UI.portrait(invitation, UDim2.fromOffset(15, 43), 51, violet)
|
||||
portrait.Name = "CreatorPortrait"
|
||||
local hostLabel = leftLabel(invitation, "CreatorName", "", 78, 42, 261, 24, 17, UI.Ink)
|
||||
local hostAccount = leftLabel(invitation, "CreatorAccount", "", 78, 67, 261, 22, 13, UI.Muted)
|
||||
local accept = button(invitation, "Accept", "ПРИНЯТЬ [Y]", UDim2.fromOffset(14, 109), UDim2.fromOffset(156, 41), UI.Mint, true)
|
||||
local decline = button(invitation, "Decline", "ОТКЛОНИТЬ [U]", UDim2.fromOffset(181, 109), UDim2.fromOffset(159, 41), violet)
|
||||
|
||||
local isPrivate = false
|
||||
local roundOptions: Hosting.RoundOptions = {initialMode = Rules.Default, allowModeChange = true}
|
||||
local selected: {[number]: boolean} = {}
|
||||
local rows: {[number]: {button: TextButton, mark: TextLabel}} = {}
|
||||
local listings: {Listing} = {}
|
||||
local hasMore, listingPending, expandedList = false, false, false
|
||||
local lastListRequest, lastDetailRequest = -math.huge, -math.huge
|
||||
local arena: Choice? = nil
|
||||
local arenaDetails: Details? = nil
|
||||
local joinNote: string? = nil
|
||||
local preferredSide: Side? = nil
|
||||
local confirmedSide: Side? = nil
|
||||
local selectionTweens: {Tween} = {}
|
||||
local party: Party? = nil
|
||||
local currentInvite: Invite? = nil
|
||||
local accepted, sending, transferring = false, false, false
|
||||
local requestNumber, noticeNumber = 0, 0
|
||||
local opening: Tween? = nil
|
||||
local clockSecond = -1
|
||||
|
||||
local function resetTeamReveal()
|
||||
confirmedSide = nil
|
||||
for _, tween in selectionTweens do tween:Cancel() end
|
||||
table.clear(selectionTweens)
|
||||
for _, team in {blueTeam, orangeTeam} do
|
||||
if team.feedbackTween then team.feedbackTween:Cancel() end
|
||||
team.hit:SetAttribute("UIState", nil)
|
||||
team.pressed = false
|
||||
team.zoom.Scale = 1
|
||||
team.glow.BackgroundTransparency, team.dimmer.BackgroundTransparency = 1, 1
|
||||
team.border.Transparency, team.border.Thickness = 1, 1.2
|
||||
team.shine.Offset = Vector2.zero
|
||||
end
|
||||
detailsStatus.TextColor3, detailsStatus.TextTransparency = UI.Muted, 0
|
||||
end
|
||||
|
||||
local function showTeamFeedback(team: TeamColumn, side: Side)
|
||||
if confirmedSide then return end
|
||||
local chosen = preferredSide == side
|
||||
local state = if team.pressed then "Pressed" elseif chosen then "Selected"
|
||||
elseif not team.hit.Interactable then "Disabled" elseif team.hovered or team.focused then "Hover" else "Normal"
|
||||
if team.hit:GetAttribute("UIState") == state then return end
|
||||
team.hit:SetAttribute("UIState", state)
|
||||
if team.feedbackTween then team.feedbackTween:Cancel() end
|
||||
local opacity = if state == "Pressed" then .47 elseif state == "Selected" then .61 elseif state == "Hover" then .77 else 1
|
||||
team.border.Transparency = if state == "Selected" or state == "Pressed" then .22 elseif state == "Hover" then .57 else 1
|
||||
if GuiService.ReducedMotionEnabled then
|
||||
team.glow.BackgroundTransparency = opacity
|
||||
else
|
||||
team.feedbackTween = TweenService:Create(team.glow, TweenInfo.new(.14, Enum.EasingStyle.Quad),
|
||||
{BackgroundTransparency = opacity})
|
||||
team.feedbackTween:Play()
|
||||
end
|
||||
end
|
||||
|
||||
local function revealTeam(side: Side)
|
||||
resetTeamReveal()
|
||||
confirmedSide = side
|
||||
local chosen = if side == "Blue" then blueTeam else orangeTeam
|
||||
local other = if side == "Blue" then orangeTeam else blueTeam
|
||||
detailsStatus.TextColor3 = chosen.accent
|
||||
if GuiService.ReducedMotionEnabled then
|
||||
chosen.glow.BackgroundTransparency, chosen.border.Transparency = .65, .24
|
||||
other.dimmer.BackgroundTransparency = .54
|
||||
return
|
||||
end
|
||||
chosen.shine.Offset = Vector2.new(-.6, 0)
|
||||
detailsStatus.TextTransparency = .62
|
||||
local transition = TweenInfo.new(.29, Enum.EasingStyle.Quart, Enum.EasingDirection.Out)
|
||||
local settling = TweenInfo.new(.38, Enum.EasingStyle.Back, Enum.EasingDirection.Out)
|
||||
local sweep = TweenInfo.new(.57, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
|
||||
selectionTweens = {
|
||||
TweenService:Create(chosen.glow, transition, {BackgroundTransparency = .61}),
|
||||
TweenService:Create(chosen.border, transition, {Transparency = .18, Thickness = 2.2}),
|
||||
TweenService:Create(other.dimmer, transition, {BackgroundTransparency = .52}),
|
||||
TweenService:Create(chosen.zoom, settling, {Scale = 1.026}),
|
||||
TweenService:Create(chosen.shine, sweep, {Offset = Vector2.new(.48, 0)}),
|
||||
TweenService:Create(detailsStatus, transition, {TextTransparency = 0}),
|
||||
}
|
||||
for _, tween in selectionTweens do tween:Play() end
|
||||
end
|
||||
|
||||
local function refreshLaunch()
|
||||
launch.Visible = roundHud:GetAttribute("LobbyAvailable") == true and not shade.Visible and not transferring
|
||||
launch.Interactable = not sending
|
||||
browser.Visible = launch.Visible
|
||||
end
|
||||
|
||||
local function showNotice(text: string, sticky: boolean?)
|
||||
noticeNumber += 1
|
||||
local sequence = noticeNumber
|
||||
noticeText.Text, notice.Visible = text, text ~= ""
|
||||
if text ~= "" and not sticky then
|
||||
task.delay(5, function()
|
||||
if noticeNumber == sequence then notice.Visible = false end
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
local function refreshSelection()
|
||||
local busy = sending or party ~= nil
|
||||
for id, card in modeCards do
|
||||
ModeCard.setSelected(card, id == roundOptions.initialMode)
|
||||
local input = card.button
|
||||
if input then input.Interactable = not busy end
|
||||
end
|
||||
changeToggle.Interactable = not busy
|
||||
local count = 0
|
||||
for _ in selected do count += 1 end
|
||||
selectionCount.Text = string.format("ВЫБРАНО %d / %d", count, Hosting.MaxPlayers - 1)
|
||||
for id, row in rows do
|
||||
local active = selected[id] == true
|
||||
row.button.BackgroundColor3 = dark:Lerp(violet, if active then .45 else .15)
|
||||
row.button.Interactable = not sending and not party
|
||||
row.mark.Text, row.mark.TextColor3 = if active then "✓" else "+", if active then UI.Ink else violet
|
||||
end
|
||||
action.Interactable = not sending and (party ~= nil or not isPrivate or count > 0)
|
||||
action.BackgroundColor3 = if action.Interactable then violet else dark:Lerp(UI.Muted, .18)
|
||||
action.TextColor3 = if action.Interactable then dark else UI.Muted
|
||||
end
|
||||
|
||||
local function clearList(scroll: ScrollingFrame)
|
||||
for _, child in scroll:GetChildren() do
|
||||
if child:IsA("GuiObject") then child:Destroy() end
|
||||
end
|
||||
end
|
||||
|
||||
local function request(actionName: string, data: any?, extra: (Side | Hosting.RoundOptions)?)
|
||||
if sending or transferring then return end
|
||||
sending = true
|
||||
requestNumber += 1
|
||||
local sequence = requestNumber
|
||||
refreshSelection()
|
||||
refreshLaunch()
|
||||
if actionName == "LocalJoin" then join:FireServer("AutoPreview", data, extra) else remote:FireServer(actionName, data, extra) end
|
||||
task.delay(12, function()
|
||||
if sequence ~= requestNumber or not sending then return end
|
||||
sending = false
|
||||
refreshSelection()
|
||||
refreshLaunch()
|
||||
connect.Interactable = false
|
||||
detailsClose.Interactable = true
|
||||
resetTeamReveal()
|
||||
if shade.Visible then
|
||||
local message = "Ответ задержался. Попробуйте снова."
|
||||
if arena then joinNote, detailsStatus.Text = message, message else status.Text = message end
|
||||
else showNotice("Ответ задержался. Попробуйте снова.") end
|
||||
end)
|
||||
end
|
||||
|
||||
local function renderList()
|
||||
clearList(list)
|
||||
table.clear(rows)
|
||||
if not isPrivate then return end
|
||||
local available = Players:GetPlayers()
|
||||
table.sort(available, function(a, b) return a.DisplayName:lower() < b.DisplayName:lower() end)
|
||||
for index, candidate in available do
|
||||
if candidate == player then continue end
|
||||
local id = candidate.UserId
|
||||
local row = button(list, "Select_" .. id, "", UDim2.new(), UDim2.new(1, -10, 0, 46), violet)
|
||||
row.LayoutOrder = index
|
||||
showAvatar(UI.portrait(row, UDim2.fromOffset(8, 5), 36, violet), id, candidate.DisplayName)
|
||||
leftLabel(row, "PlayerName", candidate.DisplayName, 54, 1, 425, 24, 15, UI.Ink)
|
||||
leftLabel(row, "Account", "@" .. candidate.Name, 54, 23, 425, 20, 12, UI.Muted)
|
||||
local mark = UI.label(row, "SelectedMark", "", UDim2.fromOffset(522, 0), UDim2.fromOffset(46, 46), 24, violet)
|
||||
rows[id] = {button = row, mark = mark}
|
||||
row.Activated:Connect(function()
|
||||
if party or sending then return end
|
||||
if not selected[id] then
|
||||
local count = 0
|
||||
for _ in selected do count += 1 end
|
||||
if count >= Hosting.MaxPlayers - 1 then return end
|
||||
end
|
||||
selected[id] = if selected[id] then nil else true
|
||||
refreshSelection()
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
local function updatePanel()
|
||||
local busy = party ~= nil or sending
|
||||
local showPlayers = isPrivate and (#Players:GetPlayers() > 1 or party ~= nil)
|
||||
local compact = not showPlayers
|
||||
currentHeight = if compact then 530 else createHeight
|
||||
panel.Size = UDim2.fromOffset(dialogWidth, currentHeight)
|
||||
status.Position = UDim2.fromOffset(26, if compact then 443 else 598)
|
||||
action.Position = UDim2.fromOffset(26, if compact then 471 else 626)
|
||||
fit()
|
||||
refreshLaunch()
|
||||
public.Interactable, private.Interactable = not busy, not busy
|
||||
public.BackgroundColor3 = dark:Lerp(UI.Blue, if isPrivate then .17 else .58)
|
||||
private.BackgroundColor3 = dark:Lerp(violet, if isPrivate then .58 else .17)
|
||||
selectionCount.Visible, list.Visible = showPlayers, showPlayers
|
||||
modeDescription.Text = Rules.get(roundOptions.initialMode).detail
|
||||
changeToggle.Text = if roundOptions.allowModeChange then "ВКЛЮЧЕНО" else "ВЫКЛЮЧЕНО"
|
||||
changeToggle.BackgroundColor3 = if roundOptions.allowModeChange then UI.Mint else dark:Lerp(UI.Muted, .23)
|
||||
changeToggle.TextColor3 = if roundOptions.allowModeChange then dark else UI.Ink
|
||||
changeHint.Text = if roundOptions.allowModeChange then "Голосование после раунда" else "Один режим на все раунды"
|
||||
explanation.Text = if showPlayers then "Выберите игроков с этого сервера и отправьте приглашения."
|
||||
elseif isPrivate then "На сервере пока нет других игроков."
|
||||
elseif localPreview then "В локальном тесте публичная арена доступна игрокам этого сеанса Studio."
|
||||
else "Любой игрок сможет подключиться через список публичных арен."
|
||||
action.Text = if party then "ОТМЕНИТЬ ПРИГЛАШЕНИЯ"
|
||||
elseif isPrivate then "ОТПРАВИТЬ ПРИГЛАШЕНИЯ" else "СОЗДАТЬ АРЕНУ"
|
||||
refreshSelection()
|
||||
end
|
||||
|
||||
for id, card in modeCards do
|
||||
local input = assert(card.button)
|
||||
input.Activated:Connect(function()
|
||||
if sending or party then return end
|
||||
roundOptions.initialMode = id
|
||||
updatePanel()
|
||||
end)
|
||||
end
|
||||
changeToggle.Activated:Connect(function()
|
||||
if sending or party then return end
|
||||
roundOptions.allowModeChange = not roundOptions.allowModeChange
|
||||
updatePanel()
|
||||
end)
|
||||
|
||||
local function setOpen(open: boolean)
|
||||
if not open then
|
||||
if arena and arena.mode then sending = false end
|
||||
arena, arenaDetails, joinNote, preferredSide = nil, nil, nil, nil
|
||||
for _, team in {blueTeam, orangeTeam} do team.hovered, team.focused = false, false end
|
||||
resetTeamReveal()
|
||||
end
|
||||
shade.Visible = open
|
||||
pg:SetAttribute("HunterArenaCreator", if open then true else nil)
|
||||
if opening then opening:Cancel() end
|
||||
if open then
|
||||
panel.Visible, detailsPanel.Visible = not arena, arena ~= nil
|
||||
if not arena then renderList(); updatePanel() end
|
||||
local activePanel = if arena then detailsPanel else panel
|
||||
activePanel.Position = UDim2.fromScale(.5, .53)
|
||||
opening = TweenService:Create(activePanel, TweenInfo.new(.23, Enum.EasingStyle.Quart), {Position = UDim2.fromScale(.5, .5)})
|
||||
opening:Play()
|
||||
end
|
||||
refreshLaunch()
|
||||
end
|
||||
|
||||
launch.Activated:Connect(function()
|
||||
if hosted then request("Exit") else setOpen(true) end
|
||||
end)
|
||||
close.Activated:Connect(function() setOpen(false) end)
|
||||
detailsClose.Activated:Connect(function() setOpen(false) end)
|
||||
public.Activated:Connect(function()
|
||||
isPrivate, status.Text = false, ""
|
||||
renderList()
|
||||
updatePanel()
|
||||
end)
|
||||
private.Activated:Connect(function()
|
||||
isPrivate, status.Text = true, ""
|
||||
renderList()
|
||||
updatePanel()
|
||||
end)
|
||||
action.Activated:Connect(function()
|
||||
if party then
|
||||
remote:FireServer("Cancel")
|
||||
elseif isPrivate then
|
||||
local ids = {}
|
||||
for id in selected do table.insert(ids, id) end
|
||||
request("InvitePrivate", ids, roundOptions)
|
||||
else
|
||||
request("CreatePublic", roundOptions)
|
||||
end
|
||||
end)
|
||||
|
||||
local function localTeams(mode: string): Details
|
||||
local result: Details = {id = mode, players = 0, blue = {}, orange = {}}
|
||||
for _, candidate in Players:GetPlayers() do
|
||||
local side = candidate:GetAttribute("ArenaTeam")
|
||||
if (side == "Blue" or side == "Orange") and Modes.of(candidate) == mode then
|
||||
result.players += 1
|
||||
table.insert(if side == "Blue" then result.blue else result.orange, {
|
||||
userId = candidate.UserId, displayName = candidate.DisplayName,
|
||||
})
|
||||
end
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
local function renderTeam(column: TeamColumn, members: {Hosting.Member})
|
||||
local keys = {}
|
||||
for index, member in members do keys[index] = tostring(member.userId) end
|
||||
local stamp = table.concat(keys, ",")
|
||||
if stamp == column.stamp then return end
|
||||
column.stamp = stamp
|
||||
column.count.Text = string.format("%d / %d", #members, Hosting.MaxPlayers // 2)
|
||||
clearList(column.scroll)
|
||||
if #members == 0 then
|
||||
leftLabel(column.scroll, "Empty", "Пока никого", 8, 0, 249, 34, 14, UI.Muted)
|
||||
return
|
||||
end
|
||||
for index, member in members do
|
||||
local item = UI.element("PlayerRow", column.scroll, UDim2.new(), UDim2.new(1, -9, 0, 36))
|
||||
item.Name = "Player_" .. member.userId
|
||||
item.LayoutOrder = index
|
||||
item.BackgroundColor3 = dark:Lerp(column.accent, .18)
|
||||
UI.hoverRow(item, column.accent)
|
||||
showAvatar(UI.portrait(item, UDim2.fromOffset(6, 4), 28, column.accent), member.userId, member.displayName)
|
||||
leftLabel(item, "PlayerName", member.displayName, 41, 0, 207, 36, 14, UI.Ink)
|
||||
end
|
||||
end
|
||||
|
||||
local function redrawDetails(now: number)
|
||||
local choice = arena
|
||||
if not choice then return end
|
||||
local localMode = choice.mode
|
||||
local data = if localMode then localTeams(localMode) else arenaDetails
|
||||
renderTeam(blueTeam, if data then data.blue else {})
|
||||
renderTeam(orangeTeam, if data then data.orange else {})
|
||||
local full = data ~= nil and data.players >= Hosting.MaxPlayers or player:GetAttribute("HostedArenaFull") == true
|
||||
local isOpen = not localMode or Modes.open(roundState, localMode, now)
|
||||
local ready = not sending and data ~= nil and not full and isOpen
|
||||
local blueIssue = if data then Hosting.teamJoinError(#data.blue, #data.orange) else nil
|
||||
local orangeIssue = if data then Hosting.teamJoinError(#data.orange, #data.blue) else nil
|
||||
local issue = if preferredSide == "Blue" then blueIssue else orangeIssue
|
||||
for side, team in teamColumns do
|
||||
local teamIssue = if side == "Blue" then blueIssue else orangeIssue
|
||||
team.hit.Interactable = ready and teamIssue == nil
|
||||
if not team.hit.Interactable then team.pressed = false end
|
||||
team.marker.Text = if confirmedSide == side then "ВАША КОМАНДА"
|
||||
elseif teamIssue == "Full" then "НЕТ МЕСТ" elseif teamIssue == "Balance" then "БАЛАНС КОМАНД"
|
||||
elseif preferredSide == side then "ВЫБРАНО" else "ВЫБРАТЬ"
|
||||
team.marker.TextColor3 = if teamIssue then UI.Muted else team.accent
|
||||
showTeamFeedback(team, side)
|
||||
end
|
||||
connect.Interactable = ready and preferredSide ~= nil and issue == nil
|
||||
detailsClose.Interactable = not sending
|
||||
connect.Text = if confirmedSide then "ВХОД НА АРЕНУ…"
|
||||
elseif sending and localMode then "ПРОВЕРЯЕМ КОМАНДУ…"
|
||||
elseif preferredSide == "Blue" then "ПОДКЛЮЧИТЬСЯ ЗА СИНИХ ›"
|
||||
elseif preferredSide == "Orange" then "ПОДКЛЮЧИТЬСЯ ЗА ОРАНЖЕВЫХ ›" else "ПОДКЛЮЧИТЬСЯ ›"
|
||||
local accent = if preferredSide == "Orange" then UI.Orange else UI.Blue
|
||||
connect.BackgroundColor3 = if connect.Interactable then accent else dark:Lerp(UI.Muted, .18)
|
||||
connect.TextColor3 = if connect.Interactable then dark else UI.Muted
|
||||
detailsStatus.Text = joinNote or (if confirmedSide == "Blue" then "ВЫ В КОМАНДЕ СИНИХ"
|
||||
elseif confirmedSide == "Orange" then "ВЫ В КОМАНДЕ ОРАНЖЕВЫХ"
|
||||
elseif sending then "Подключаемся…"
|
||||
elseif not data then "Загружаем составы…" elseif full then "Арена заполнена."
|
||||
elseif not isOpen then "Подключение откроется с началом раунда."
|
||||
elseif preferredSide and issue then "Выбранная команда пока недоступна."
|
||||
elseif not preferredSide then "Выберите команду." else "")
|
||||
end
|
||||
|
||||
for side, team in teamColumns do
|
||||
local function feedback() showTeamFeedback(team, side) end
|
||||
team.hit.MouseEnter:Connect(function()
|
||||
team.hovered = true
|
||||
feedback()
|
||||
end)
|
||||
team.hit.MouseLeave:Connect(function()
|
||||
team.hovered, team.pressed = false, false
|
||||
feedback()
|
||||
end)
|
||||
team.hit.SelectionGained:Connect(function()
|
||||
team.focused = true
|
||||
feedback()
|
||||
end)
|
||||
team.hit.SelectionLost:Connect(function()
|
||||
team.focused, team.pressed = false, false
|
||||
feedback()
|
||||
end)
|
||||
team.hit.InputBegan:Connect(function(input)
|
||||
if team.hit.Interactable and (input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch
|
||||
or input.KeyCode == Enum.KeyCode.ButtonA or input.KeyCode == Enum.KeyCode.Return) then
|
||||
team.pressed = true
|
||||
feedback()
|
||||
end
|
||||
end)
|
||||
team.hit.InputEnded:Connect(function(input)
|
||||
if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch
|
||||
or input.KeyCode == Enum.KeyCode.ButtonA or input.KeyCode == Enum.KeyCode.Return then
|
||||
team.pressed = false
|
||||
feedback()
|
||||
end
|
||||
end)
|
||||
team.hit.Activated:Connect(function()
|
||||
if not team.hit.Interactable or sending or not arena then return end
|
||||
preferredSide, joinNote = side, nil
|
||||
redrawDetails(workspace:GetServerTimeNow())
|
||||
end)
|
||||
-- The transparent selector covers the roster, so keep the wheel available there.
|
||||
local function scrollTeam(delta: number)
|
||||
local maximum = math.max(0, team.scroll.AbsoluteCanvasSize.Y - team.scroll.AbsoluteWindowSize.Y)
|
||||
team.scroll.CanvasPosition = Vector2.new(0, math.clamp(team.scroll.CanvasPosition.Y + delta, 0, maximum))
|
||||
end
|
||||
team.hit.MouseWheelForward:Connect(function() scrollTeam(-42) end)
|
||||
team.hit.MouseWheelBackward:Connect(function() scrollTeam(42) end)
|
||||
end
|
||||
|
||||
local function fetchDirectory(more: boolean)
|
||||
local now = workspace:GetServerTimeNow()
|
||||
if hosted or localPreview or listingPending or now - lastListRequest < 1.2 then return end
|
||||
listingPending, lastListRequest = true, now
|
||||
remote:FireServer(if more then "MorePublic" else "PublicList")
|
||||
end
|
||||
|
||||
local function openArena(choice: Choice)
|
||||
arena, arenaDetails, joinNote, preferredSide = choice, nil, nil, nil
|
||||
detailsTitle.Text = choice.name
|
||||
setOpen(true)
|
||||
local now = workspace:GetServerTimeNow()
|
||||
if not choice.mode then
|
||||
lastDetailRequest = now
|
||||
remote:FireServer("PublicDetails", choice.id)
|
||||
end
|
||||
redrawDetails(now)
|
||||
end
|
||||
|
||||
local directoryCards: {[string]: ArenaCard} = {}
|
||||
|
||||
local function localChoice(ownerOverride: Player?): Choice
|
||||
local mode = Modes.Procedural
|
||||
local ownerId = remote:GetAttribute("LocalPublicOwnerUserId")
|
||||
local owner = ownerOverride or (if typeof(ownerId) == "number" then Players:GetPlayerByUserId(ownerId) else nil)
|
||||
return {id = mode, name = if owner then owner.DisplayName else "Динамическая арена",
|
||||
mode = mode, hostId = if owner then owner.UserId else nil, players = localTeams(mode).players,
|
||||
ruleset = Rules.get(Modes.state(roundState, mode):GetAttribute("Ruleset")).id}
|
||||
end
|
||||
|
||||
local function createArenaCard(choice: Choice): ArenaCard
|
||||
local visual = ModeCard.new(arenaList, choice.ruleset, UDim2.new(), UDim2.new(1, -13, 0, cardHeight), true)
|
||||
local item = assert(visual.button)
|
||||
item.Name = choice.id
|
||||
visual.art.Size = UDim2.new(1, -12, 1, -58)
|
||||
visual.title.Position = UDim2.new(0, 8, 1, -51)
|
||||
visual.title.Size = UDim2.new(1, -16, 0, 27)
|
||||
visual.badgePanel.Size = UDim2.fromOffset(65, 27)
|
||||
visual.badge.TextSize = 14
|
||||
local name = UI.label(item, "ArenaName", choice.name, UDim2.new(0, 10, 1, -25), UDim2.new(1, -20, 0, 20), 12, UI.Muted)
|
||||
name.TextTruncate = Enum.TextTruncate.AtEnd
|
||||
local hostId = choice.hostId
|
||||
if hostId then
|
||||
showAvatar(UI.portrait(item, UDim2.new(0, 12, 1, -25), 19, visual.accent), hostId, choice.name)
|
||||
name.Position, name.Size = UDim2.new(0, 38, 1, -25), UDim2.new(1, -48, 0, 20)
|
||||
name.TextXAlignment = Enum.TextXAlignment.Left
|
||||
end
|
||||
local entry = {choice = choice, visual = visual, name = name}
|
||||
item.Activated:Connect(function() openArena(entry.choice) end)
|
||||
return entry
|
||||
end
|
||||
|
||||
local function renderDirectory()
|
||||
local choices: {Choice} = {}
|
||||
table.insert(choices, localChoice())
|
||||
for _, entry in listings do
|
||||
table.insert(choices, {id = entry.id, name = entry.hostName, hostId = entry.hostId, players = entry.players,
|
||||
ruleset = Rules.get(entry.ruleset).id})
|
||||
end
|
||||
local visible: {[string]: boolean} = {}
|
||||
for index, choice in choices do
|
||||
visible[choice.id] = true
|
||||
local entry = directoryCards[choice.id]
|
||||
if not entry or entry.choice.ruleset ~= choice.ruleset or entry.choice.hostId ~= choice.hostId then
|
||||
if entry then entry.visual.root:Destroy() end
|
||||
entry = createArenaCard(choice)
|
||||
directoryCards[choice.id] = entry
|
||||
end
|
||||
entry.choice = choice
|
||||
entry.name.Text = choice.name
|
||||
entry.visual.root.LayoutOrder = index
|
||||
entry.visual.badge.Text = string.format("%d / %d", choice.players, Hosting.MaxPlayers)
|
||||
end
|
||||
for id, entry in directoryCards do
|
||||
if not visible[id] then
|
||||
entry.visual.root:Destroy()
|
||||
directoryCards[id] = nil
|
||||
end
|
||||
end
|
||||
moreArenas.LayoutOrder, moreArenas.Visible = #choices + 1, hasMore
|
||||
local height = #choices * cardHeight + (#choices - 1) * rowGap
|
||||
if hasMore then height += rowGap + moreHeight end
|
||||
if height ~= contentHeight then
|
||||
contentHeight = height
|
||||
fit()
|
||||
end
|
||||
end
|
||||
|
||||
moreArenas.Activated:Connect(function() fetchDirectory(true) end)
|
||||
refreshDirectory.Activated:Connect(function()
|
||||
expandedList = false
|
||||
fetchDirectory(false)
|
||||
end)
|
||||
connect.Activated:Connect(function()
|
||||
local choice = arena
|
||||
local side = preferredSide
|
||||
if not choice or not side or not connect.Interactable then return end
|
||||
joinNote = nil
|
||||
if choice.mode then request("LocalJoin", choice.mode, side) else request("JoinPublic", choice.id, side) end
|
||||
redrawDetails(workspace:GetServerTimeNow())
|
||||
end)
|
||||
|
||||
local function showInvite()
|
||||
local invite = currentInvite
|
||||
invitation.Visible = invite ~= nil and not transferring
|
||||
if not invite then return end
|
||||
inviteTitle.Text = if accepted then "ПРИГЛАШЕНИЕ ПРИНЯТО" else "ПРИГЛАШЕНИЕ НА АРЕНУ"
|
||||
accept.Visible = not accepted
|
||||
decline.Text = if accepted then "ОТМЕНИТЬ [U]" else "ОТКЛОНИТЬ [U]"
|
||||
end
|
||||
|
||||
local function respond(agree: boolean)
|
||||
local invite = currentInvite
|
||||
if not invite or transferring or (agree and accepted) then return end
|
||||
remote:FireServer("Answer", invite.id, agree)
|
||||
end
|
||||
accept.Activated:Connect(function() respond(true) end)
|
||||
decline.Activated:Connect(function() respond(false) end)
|
||||
local inputConnection = UserInputService.InputBegan:Connect(function(input, processed)
|
||||
if processed or UserInputService:GetFocusedTextBox() or not invitation.Visible then return end
|
||||
if input.KeyCode == Enum.KeyCode.Y then respond(true) end
|
||||
if input.KeyCode == Enum.KeyCode.U then respond(false) end
|
||||
end)
|
||||
|
||||
local messageConnection = remote.OnClientEvent:Connect(function(event: string, data: any)
|
||||
if event == "Invite" then
|
||||
local invite: Invite = data
|
||||
currentInvite, accepted = invite, false
|
||||
hostLabel.Text, hostAccount.Text = invite.hostName, "Создатель · @" .. invite.hostUsername
|
||||
showAvatar(portrait, invite.hostId, invite.hostName)
|
||||
showInvite()
|
||||
elseif event == "Accepted" and currentInvite and currentInvite.id == data then
|
||||
accepted = true
|
||||
showInvite()
|
||||
elseif event == "InviteClosed" and currentInvite and currentInvite.id == data then
|
||||
currentInvite, accepted = nil, false
|
||||
showInvite()
|
||||
elseif event == "Party" then
|
||||
party, sending = data, false
|
||||
updatePanel()
|
||||
elseif event == "PartyClosed" then
|
||||
party, sending = nil, false
|
||||
updatePanel()
|
||||
status.Text = data or ""
|
||||
if data and not shade.Visible then showNotice(data) end
|
||||
elseif event == "PublicList" then
|
||||
listingPending = false
|
||||
hasMore, expandedList = data.more, data.append
|
||||
if data.append then
|
||||
local seen: {[string]: boolean} = {}
|
||||
for _, row in listings do seen[row.id] = true end
|
||||
for _, row in data.rows do if not seen[row.id] then table.insert(listings, row) end end
|
||||
else
|
||||
listings = data.rows
|
||||
end
|
||||
renderDirectory()
|
||||
elseif event == "ListUnavailable" then
|
||||
listingPending = false
|
||||
if browser.Visible then showNotice("Список публичных арен временно недоступен.") end
|
||||
elseif event == "PublicDetails" and arena and data.id == arena.id then
|
||||
if not arenaDetails then joinNote = nil end
|
||||
arenaDetails = data
|
||||
redrawDetails(workspace:GetServerTimeNow())
|
||||
elseif event == "DetailsUnavailable" and arena and data == arena.id then
|
||||
arenaDetails = nil
|
||||
joinNote = "Арена закрылась или составы временно недоступны."
|
||||
redrawDetails(workspace:GetServerTimeNow())
|
||||
elseif event == "LocalPublicReady" then
|
||||
sending = false
|
||||
renderDirectory()
|
||||
openArena(localChoice(player))
|
||||
elseif event == "Transfer" then
|
||||
sending, transferring = false, true
|
||||
setOpen(false)
|
||||
showInvite()
|
||||
showNotice(data, true)
|
||||
elseif event == "Error" then
|
||||
sending, transferring = false, false
|
||||
updatePanel()
|
||||
refreshLaunch()
|
||||
showInvite()
|
||||
if arena then
|
||||
joinNote = data
|
||||
redrawDetails(workspace:GetServerTimeNow())
|
||||
elseif shade.Visible then status.Text = data else showNotice(data) end
|
||||
end
|
||||
end)
|
||||
|
||||
local joinErrors: {[string]: string} = {
|
||||
Full = "В выбранной команде нет мест.",
|
||||
Balance = "Составы изменились. Подключитесь ещё раз.",
|
||||
BetweenRounds = "Дождитесь начала следующего раунда.",
|
||||
Spawning = "Персонаж ещё загружается. Попробуйте снова.",
|
||||
AwaitingAdmission = "Проверяем доступ к арене. Попробуйте через секунду.",
|
||||
}
|
||||
local joinConnection = join.OnClientEvent:Connect(function(result: string, side: Side?)
|
||||
if not sending or not arena or not arena.mode then return end
|
||||
if result == "TeamSelected" and (side == "Blue" or side == "Orange") then
|
||||
revealTeam(side)
|
||||
redrawDetails(workspace:GetServerTimeNow())
|
||||
return
|
||||
end
|
||||
sending = false
|
||||
if result == "Joined" or result == "AlreadyPlaying" then
|
||||
setOpen(false)
|
||||
else
|
||||
resetTeamReveal()
|
||||
joinNote = joinErrors[result] or "Не удалось подключиться."
|
||||
redrawDetails(workspace:GetServerTimeNow())
|
||||
end
|
||||
end)
|
||||
local launcherConnection = roundHud:GetAttributeChangedSignal("LobbyAvailable"):Connect(refreshLaunch)
|
||||
local function refreshOwner()
|
||||
local name = remote:GetAttribute("OwnerName")
|
||||
ownerLabel.Text = if typeof(name) == "string" then "Владелец · " .. name else ""
|
||||
end
|
||||
local ownerConnection = remote:GetAttributeChangedSignal("OwnerName"):Connect(refreshOwner)
|
||||
local votingConnection = pg:GetAttributeChangedSignal("HunterVoting"):Connect(function()
|
||||
if pg:GetAttribute("HunterVoting") and shade.Visible then setOpen(false) end
|
||||
end)
|
||||
local teamConnection = player:GetAttributeChangedSignal("ArenaTeam"):Connect(function()
|
||||
if player:GetAttribute("ArenaTeam") and shade.Visible then
|
||||
if arena and arena.mode then sending = false end
|
||||
setOpen(false)
|
||||
end
|
||||
end)
|
||||
local function showFull()
|
||||
if player:GetAttribute("HostedArenaFull") then showNotice("Арена заполнена. Можно вернуться в общее лобби.", true) end
|
||||
end
|
||||
local fullConnection = player:GetAttributeChangedSignal("HostedArenaFull"):Connect(showFull)
|
||||
showFull()
|
||||
local function showTeamNotice()
|
||||
local issue = player:GetAttribute("HostedArenaTeamNotice")
|
||||
if typeof(issue) == "string" then showNotice(joinErrors[issue] or "Выбранная команда недоступна.") end
|
||||
end
|
||||
local arrivalTeamConnection = player:GetAttributeChangedSignal("HostedArenaTeamNotice"):Connect(showTeamNotice)
|
||||
showTeamNotice()
|
||||
local function playersChanged()
|
||||
if shade.Visible and not arena and isPrivate then renderList(); updatePanel() end
|
||||
end
|
||||
local addedConnection = Players.PlayerAdded:Connect(playersChanged)
|
||||
local removingConnection = Players.PlayerRemoving:Connect(function(other)
|
||||
selected[other.UserId] = nil
|
||||
task.defer(playersChanged)
|
||||
end)
|
||||
|
||||
local clock = RunService.Heartbeat:Connect(function()
|
||||
if not browser.Visible and not arena and not invitation.Visible and not party then return end
|
||||
local now = workspace:GetServerTimeNow()
|
||||
local second = math.floor(now * 2)
|
||||
if second == clockSecond then return end
|
||||
clockSecond = second
|
||||
if browser.Visible then
|
||||
renderDirectory()
|
||||
if listingPending and now - lastListRequest > 4 then listingPending = false end
|
||||
if not hosted and not localPreview and not expandedList and now - lastListRequest >= 12 then fetchDirectory(false) end
|
||||
end
|
||||
local choice = arena
|
||||
if choice then
|
||||
if not choice.mode and now - lastDetailRequest > (if arenaDetails then 7 else 2) then
|
||||
lastDetailRequest = now
|
||||
remote:FireServer("PublicDetails", choice.id)
|
||||
end
|
||||
redrawDetails(now)
|
||||
end
|
||||
local invite = currentInvite
|
||||
if invite then
|
||||
local left = math.max(0, math.ceil(invite.expires - now))
|
||||
inviteTimer.Text = string.format("%02d", left)
|
||||
if left == 0 then
|
||||
currentInvite, accepted = nil, false
|
||||
showInvite()
|
||||
end
|
||||
end
|
||||
local pending = party
|
||||
if pending then
|
||||
local left = math.max(0, math.ceil(pending.expires - now))
|
||||
status.Text = string.format("Приняли %d · Ждём %d · %02d с", pending.accepted, pending.pending, left)
|
||||
if not shade.Visible then showNotice(status.Text, true) end
|
||||
end
|
||||
end)
|
||||
script.Destroying:Once(function()
|
||||
for _, connection in {clock, inputConnection, messageConnection, joinConnection, launcherConnection, ownerConnection, votingConnection,
|
||||
teamConnection, fullConnection, arrivalTeamConnection, addedConnection, removingConnection} do
|
||||
connection:Disconnect()
|
||||
end
|
||||
if opening then opening:Cancel() end
|
||||
resetTeamReveal()
|
||||
pg:SetAttribute("HunterArenaCreator", nil)
|
||||
gui:Destroy()
|
||||
end)
|
||||
updatePanel()
|
||||
refreshLaunch()
|
||||
refreshOwner()
|
||||
renderDirectory()
|
||||
@@ -0,0 +1,615 @@
|
||||
--!strict
|
||||
local HttpService = game:GetService("HttpService")
|
||||
local MemoryStoreService = game:GetService("MemoryStoreService")
|
||||
local Players = game:GetService("Players")
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local RunService = game:GetService("RunService")
|
||||
local TeleportService = game:GetService("TeleportService")
|
||||
local Hosting = require(ReplicatedStorage:WaitForChild("HostedArena") :: ModuleScript)
|
||||
local Modes = require(ReplicatedStorage:WaitForChild("ArenaModes") :: ModuleScript)
|
||||
local Rules = require(ReplicatedStorage:WaitForChild("MatchRules") :: ModuleScript)
|
||||
|
||||
type RoundOptions = Hosting.RoundOptions
|
||||
type Session = {
|
||||
hostId: number, hostName: string, access: "Public" | "Private",
|
||||
allowed: {[string]: boolean}, startedAt: number, roundOptions: RoundOptions?,
|
||||
}
|
||||
type Seat = "Pending" | "Accepted" | "Declined"
|
||||
type Party = {id: string, host: Player, answers: {[Player]: Seat}, expires: number, roundOptions: RoundOptions}
|
||||
type Side = Hosting.Side
|
||||
type Transfer = {destination: string?, side: Side?, attempts: number}
|
||||
type Listing = Hosting.Listing
|
||||
type Cursor = {key: string, sortKey: number?}
|
||||
type Page = {rows: {Listing}, next: Cursor?}
|
||||
|
||||
local hosted = Hosting.isReserved()
|
||||
-- An unpublished place has no MemoryStore namespace. Preview hosting on its existing arena.
|
||||
local localPreview = RunService:IsStudio() and (game.GameId == 0 or game.PlaceId == 0)
|
||||
local storesReady, sessionStore, publicStore = pcall(function()
|
||||
if localPreview then return nil, nil end
|
||||
return MemoryStoreService:GetHashMap("HunterHostedArenaSessionsV1"),
|
||||
MemoryStoreService:GetSortedMap("HunterPublicArenasV1")
|
||||
end)
|
||||
local sessions = if storesReady then sessionStore else nil
|
||||
local directory = if storesReady then publicStore else nil
|
||||
local SESSION_TTL = 240
|
||||
local DIRECTORY_TTL = 50
|
||||
local PAGE_SIZE = 24
|
||||
local remote = Instance.new("RemoteEvent")
|
||||
remote.Name = "HostedArenaRemote"
|
||||
remote:SetAttribute("IsHosted", hosted)
|
||||
remote:SetAttribute("LocalPublicPreview", localPreview)
|
||||
local previewOwner: Player? = nil
|
||||
local parties: {[Player]: Party} = {}
|
||||
local invitations: {[Player]: Party} = {}
|
||||
local transfers: {[Player]: Transfer} = {}
|
||||
local lastAction: {[Player]: number} = {}
|
||||
local lastCreate: {[Player]: number} = {}
|
||||
local lastList: {[Player]: number} = {}
|
||||
local lastDetails: {[Player]: number} = {}
|
||||
local moreFrom: {[Player]: Cursor} = {}
|
||||
local firstPage: Page = {rows = {}, next = nil}
|
||||
local hasFirstPage = false
|
||||
local listUpdatedAt = -math.huge
|
||||
|
||||
local function present(player: Player): boolean
|
||||
return player.Parent == Players
|
||||
end
|
||||
|
||||
local function inLobby(player: Player): boolean
|
||||
return present(player) and player:GetAttribute("InArena") ~= true and player:GetAttribute("ArenaTeam") == nil
|
||||
end
|
||||
|
||||
local function send(player: Player, event: string, data: any?)
|
||||
if present(player) then remote:FireClient(player, event, data) end
|
||||
end
|
||||
|
||||
local function fail(player: Player, message: string)
|
||||
send(player, "Error", message)
|
||||
end
|
||||
|
||||
local function setPreviewOwner(player: Player?)
|
||||
previewOwner = player
|
||||
remote:SetAttribute("LocalPublicOwnerUserId", if player then player.UserId else nil)
|
||||
end
|
||||
|
||||
local function configureRound(options: RoundOptions): boolean
|
||||
local endpoint = script.Parent:WaitForChild("ArenaRounds"):WaitForChild("HostedArenaConfigure") :: BindableFunction
|
||||
return endpoint:Invoke(options)
|
||||
end
|
||||
|
||||
local function createLocalPublic(player: Player, options: RoundOptions)
|
||||
if previewOwner and previewOwner ~= player then
|
||||
fail(player, "На этом тестовом сервере уже есть публичная арена. Откройте её карточку.")
|
||||
return
|
||||
end
|
||||
if not previewOwner then
|
||||
if not configureRound(options) then
|
||||
fail(player, "Дождитесь, пока тестовая арена освободится.")
|
||||
return
|
||||
end
|
||||
if not present(player) then return end
|
||||
setPreviewOwner(player)
|
||||
end
|
||||
send(player, "LocalPublicReady")
|
||||
end
|
||||
|
||||
local function transferFailed(player: Player)
|
||||
if not transfers[player] then return end
|
||||
transfers[player] = nil
|
||||
fail(player, "Переход не удался. Попробуйте снова.")
|
||||
end
|
||||
|
||||
local function teleport(group: {Player}, destination: string?, side: Side?): boolean
|
||||
local options = Instance.new("TeleportOptions")
|
||||
if destination then options.ReservedServerId = destination else options.ForcePublicServer = true end
|
||||
if destination and side then options:SetTeleportData({arenaId = destination, team = side}) end
|
||||
local ok, result = pcall(TeleportService.TeleportAsync, TeleportService, game.PlaceId, group, options)
|
||||
if not ok then warn("[HostedArena] TeleportAsync failed:", result) end
|
||||
return ok
|
||||
end
|
||||
|
||||
local function transfer(group: {Player}, destination: string?, side: Side?)
|
||||
for _, player in group do
|
||||
local pending = {destination = destination, side = side, attempts = 1}
|
||||
transfers[player] = pending
|
||||
send(player, "Transfer", if destination then "Загружаем арену…" else "Возвращаем в общее лобби…")
|
||||
task.delay(25, function()
|
||||
if transfers[player] == pending and present(player) then transferFailed(player) end
|
||||
end)
|
||||
end
|
||||
if not teleport(group, destination, side) then
|
||||
for _, player in group do transferFailed(player) end
|
||||
end
|
||||
end
|
||||
|
||||
TeleportService.TeleportInitFailed:Connect(function(player, result, _, placeId, options)
|
||||
local pending = transfers[player]
|
||||
if not pending or placeId ~= game.PlaceId then return end
|
||||
if options.ReservedServerId ~= (pending.destination or "") then return end
|
||||
if pending.attempts >= 2 or (result ~= Enum.TeleportResult.Failure and result ~= Enum.TeleportResult.Flooded) then
|
||||
transferFailed(player)
|
||||
return
|
||||
end
|
||||
pending.attempts += 1
|
||||
task.delay(if result == Enum.TeleportResult.Flooded then 3 else 1, function()
|
||||
if present(player) and transfers[player] == pending and not teleport({player}, pending.destination, pending.side) then
|
||||
transferFailed(player)
|
||||
end
|
||||
end)
|
||||
end)
|
||||
|
||||
local function saveSession(host: Player, destination: string, record: Session): boolean
|
||||
if not sessions then
|
||||
warn("[HostedArena] MemoryStore initialization failed:", sessionStore)
|
||||
return false
|
||||
end
|
||||
for attempt = 1, 3 do
|
||||
if not present(host) then return false end
|
||||
local ok, issue = pcall(sessions.SetAsync, sessions, destination, record, SESSION_TTL)
|
||||
if ok then return true end
|
||||
local reason = string.lower(tostring(issue))
|
||||
local retryable = string.find(reason, "internal", 1, true) or string.find(reason, "throttl", 1, true)
|
||||
or string.find(reason, "requestsoverlimit", 1, true) or string.find(reason, "timeout", 1, true)
|
||||
if not retryable or attempt == 3 then
|
||||
warn("[HostedArena] Could not register session:", issue)
|
||||
return false
|
||||
end
|
||||
task.wait(2 ^ (attempt - 1))
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function launch(host: Player, guests: {Player}?, access: "Public" | "Private", options: RoundOptions)
|
||||
local destination = HttpService:GenerateGUID(false)
|
||||
local members = {host}
|
||||
local allowed = {[tostring(host.UserId)] = true}
|
||||
if guests then
|
||||
for _, player in guests do
|
||||
if present(player) then
|
||||
allowed[tostring(player.UserId)] = true
|
||||
table.insert(members, player)
|
||||
end
|
||||
end
|
||||
end
|
||||
for _, player in members do
|
||||
transfers[player] = {destination = destination, attempts = 1}
|
||||
if access == "Private" then send(player, "Transfer", "Готовим арену…") end
|
||||
end
|
||||
local record: Session = {
|
||||
hostId = host.UserId, hostName = host.DisplayName, access = access,
|
||||
allowed = if access == "Private" then allowed else {},
|
||||
startedAt = workspace:GetServerTimeNow(), roundOptions = options,
|
||||
}
|
||||
local saved = saveSession(host, destination, record)
|
||||
local hostHere = present(host)
|
||||
for index = #members, 2, -1 do
|
||||
if not present(members[index]) then table.remove(members, index) end
|
||||
end
|
||||
if not saved or not hostHere or (access == "Private" and #members < 2) then
|
||||
for _, player in members do
|
||||
transfers[player] = nil
|
||||
fail(player, if not hostHere then "Создатель вышел с сервера."
|
||||
elseif not saved then "Сервис арен Roblox временно недоступен. Попробуйте позже."
|
||||
else "Подтвердившие игроки вышли с сервера.")
|
||||
end
|
||||
if saved and sessions then
|
||||
pcall(sessions.RemoveAsync, sessions, destination)
|
||||
end
|
||||
return
|
||||
end
|
||||
transfer(members, destination)
|
||||
end
|
||||
|
||||
local function closeParty(party: Party, reason: string?)
|
||||
parties[party.host] = nil
|
||||
send(party.host, "PartyClosed", reason)
|
||||
for player in party.answers do
|
||||
if invitations[player] == party then
|
||||
invitations[player] = nil
|
||||
send(player, "InviteClosed", party.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function updateParty(party: Party, expired: boolean?)
|
||||
if parties[party.host] ~= party then return end
|
||||
local accepted: {Player} = {}
|
||||
local waiting = 0
|
||||
for player, answer in party.answers do
|
||||
if not present(player) then continue end
|
||||
if answer == "Accepted" then table.insert(accepted, player) end
|
||||
if answer == "Pending" then waiting += 1 end
|
||||
end
|
||||
if waiting > 0 and not expired then
|
||||
send(party.host, "Party", {accepted = #accepted, pending = waiting, expires = party.expires})
|
||||
return
|
||||
end
|
||||
if #accepted == 0 or not inLobby(party.host) then
|
||||
closeParty(party, if #accepted == 0 then "Никто не подтвердил приглашение." else "Создатель покинул лобби.")
|
||||
return
|
||||
end
|
||||
closeParty(party)
|
||||
launch(party.host, accepted, "Private", party.roundOptions)
|
||||
end
|
||||
|
||||
local function invite(host: Player, selection: unknown, options: RoundOptions)
|
||||
if typeof(selection) ~= "table" then return end
|
||||
local answers: {[Player]: Seat} = {}
|
||||
local checked = 0
|
||||
for _, userId in selection do
|
||||
checked += 1
|
||||
if checked >= Hosting.MaxPlayers or typeof(userId) ~= "number" or userId % 1 ~= 0 or math.abs(userId) >= 2^53 then
|
||||
fail(host, "Выберите до 19 игроков.")
|
||||
return
|
||||
end
|
||||
local player = Players:GetPlayerByUserId(userId)
|
||||
if player == host or not player or not present(player) or invitations[player] or parties[player] or transfers[player] then
|
||||
fail(host, "Кто-то из выбранных уже недоступен. Проверьте список игроков.")
|
||||
return
|
||||
end
|
||||
answers[player] = "Pending"
|
||||
end
|
||||
if not next(answers) then
|
||||
fail(host, "Выберите хотя бы одного игрока.")
|
||||
return
|
||||
end
|
||||
local party = {id = HttpService:GenerateGUID(false), host = host, answers = answers, roundOptions = options,
|
||||
expires = workspace:GetServerTimeNow() + Hosting.InviteSeconds}
|
||||
parties[host] = party
|
||||
local payload = {id = party.id, hostId = host.UserId, hostName = host.DisplayName,
|
||||
hostUsername = host.Name, expires = party.expires}
|
||||
for player in answers do
|
||||
invitations[player] = party
|
||||
send(player, "Invite", payload)
|
||||
end
|
||||
updateParty(party)
|
||||
task.delay(Hosting.InviteSeconds, updateParty, party, true)
|
||||
end
|
||||
|
||||
local function answer(player: Player, id: unknown, accepted: unknown)
|
||||
local party = invitations[player]
|
||||
if not party or id ~= party.id or typeof(accepted) ~= "boolean" or workspace:GetServerTimeNow() >= party.expires then return end
|
||||
local previous = party.answers[player]
|
||||
if previous ~= "Pending" and (previous ~= "Accepted" or accepted) then return end
|
||||
party.answers[player] = if accepted then "Accepted" else "Declined"
|
||||
if accepted then
|
||||
send(player, "Accepted", party.id)
|
||||
else
|
||||
invitations[player] = nil
|
||||
send(player, "InviteClosed", party.id)
|
||||
end
|
||||
updateParty(party)
|
||||
end
|
||||
|
||||
local function readPage(cursor: Cursor?): Page?
|
||||
if not directory then return {rows = {}, next = nil} end
|
||||
local ok, entries = pcall(directory.GetRangeAsync, directory, Enum.SortDirection.Descending, PAGE_SIZE, nil, cursor)
|
||||
if not ok then return nil end
|
||||
local rows: {Listing} = {}
|
||||
for _, entry in entries do
|
||||
local row = entry.value
|
||||
table.insert(rows, {id = entry.key, hostId = row.hostId, hostName = row.hostName, players = row.players,
|
||||
ruleset = Rules.get(row.ruleset).id})
|
||||
end
|
||||
local last = entries[PAGE_SIZE]
|
||||
return {rows = rows, next = if last then {key = last.key, sortKey = last.sortKey} else nil}
|
||||
end
|
||||
|
||||
local function listPublic(player: Player, now: number, more: boolean)
|
||||
if now - (lastList[player] or -math.huge) < 1 then return end
|
||||
lastList[player] = now
|
||||
local page: Page = firstPage
|
||||
if more then
|
||||
local cursor = moreFrom[player]
|
||||
if not cursor then return end
|
||||
local nextPage = readPage(cursor)
|
||||
if not nextPage then
|
||||
send(player, "ListUnavailable")
|
||||
return
|
||||
end
|
||||
page = nextPage
|
||||
elseif now - listUpdatedAt >= 8 then
|
||||
listUpdatedAt = now
|
||||
local refreshed = readPage(nil)
|
||||
if refreshed then
|
||||
firstPage, page, hasFirstPage = refreshed, refreshed, true
|
||||
elseif not hasFirstPage then
|
||||
send(player, "ListUnavailable")
|
||||
return
|
||||
end
|
||||
end
|
||||
moreFrom[player] = page.next
|
||||
send(player, "PublicList", {rows = page.rows, append = more, more = page.next ~= nil})
|
||||
end
|
||||
|
||||
local function publicDetails(player: Player, id: unknown, now: number)
|
||||
if typeof(id) ~= "string" or #id ~= 36 or now - (lastDetails[player] or -math.huge) < 1 then return end
|
||||
lastDetails[player] = now
|
||||
if not directory then send(player, "DetailsUnavailable", id) return end
|
||||
local ok, row = pcall(directory.GetAsync, directory, id)
|
||||
if not ok or not row then
|
||||
send(player, "DetailsUnavailable", id)
|
||||
return
|
||||
end
|
||||
local detail: Hosting.Details = {id = id, blue = row.blue or {}, orange = row.orange or {}, players = row.players}
|
||||
send(player, "PublicDetails", detail)
|
||||
end
|
||||
|
||||
local function joinPublic(player: Player, id: unknown, preference: unknown)
|
||||
if typeof(id) ~= "string" or #id ~= 36 or not directory then return end
|
||||
if preference ~= nil and preference ~= "Blue" and preference ~= "Orange" then return end
|
||||
transfers[player] = {destination = id, attempts = 1}
|
||||
local ok, row = pcall(directory.GetAsync, directory, id)
|
||||
if not inLobby(player) then transfers[player] = nil return end
|
||||
if not ok or not row or row.players >= Hosting.MaxPlayers then
|
||||
transfers[player] = nil
|
||||
fail(player, "Арена закрылась или уже заполнена.")
|
||||
return
|
||||
end
|
||||
if preference then
|
||||
local blue, orange = #(row.blue or {}), #(row.orange or {})
|
||||
local issue = if preference == "Blue" then Hosting.teamJoinError(blue, orange) else Hosting.teamJoinError(orange, blue)
|
||||
if issue then
|
||||
transfers[player] = nil
|
||||
fail(player, if issue == "Full" then "В этой команде нет мест." else "Составы изменились. Выберите другую команду.")
|
||||
return
|
||||
end
|
||||
end
|
||||
transfer({player}, id, preference)
|
||||
end
|
||||
|
||||
remote.OnServerEvent:Connect(function(player: Player, action: unknown, value: unknown, extra: unknown)
|
||||
if typeof(action) ~= "string" then return end
|
||||
local now = workspace:GetServerTimeNow()
|
||||
if not hosted and inLobby(player) then
|
||||
if action == "PublicList" or action == "MorePublic" then listPublic(player, now, action == "MorePublic") return end
|
||||
if action == "PublicDetails" then publicDetails(player, value, now) return end
|
||||
end
|
||||
if now - (lastAction[player] or -math.huge) < .16 then return end
|
||||
lastAction[player] = now
|
||||
if transfers[player] then return end
|
||||
if hosted then
|
||||
if action == "Exit" and inLobby(player) then transfer({player}) end
|
||||
return
|
||||
end
|
||||
if action == "Answer" then answer(player, value, extra) return end
|
||||
if action == "Cancel" then
|
||||
local party = parties[player]
|
||||
if party then closeParty(party, "Приглашения отменены.") end
|
||||
return
|
||||
end
|
||||
if not inLobby(player) then return end
|
||||
if parties[player] or invitations[player] then
|
||||
fail(player, "Сначала завершите текущее приглашение.")
|
||||
return
|
||||
end
|
||||
if action == "JoinPublic" then joinPublic(player, value, extra) return end
|
||||
if action ~= "CreatePublic" and action ~= "InvitePrivate" then return end
|
||||
local options = Hosting.readRoundOptions(if action == "CreatePublic" then value else extra)
|
||||
if not options then
|
||||
fail(player, "Проверьте выбранный режим и настройки арены.")
|
||||
return
|
||||
end
|
||||
if now - (lastCreate[player] or -math.huge) < 3 then
|
||||
fail(player, "Подождите несколько секунд перед повторной попыткой.")
|
||||
return
|
||||
end
|
||||
lastCreate[player] = now
|
||||
if localPreview then
|
||||
if action == "CreatePublic" then createLocalPublic(player, options)
|
||||
else fail(player, "Для приватной арены нужен плейс, сохранённый в Roblox.") end
|
||||
return
|
||||
end
|
||||
if action == "CreatePublic" then launch(player, nil, "Public", options) else invite(player, value, options) end
|
||||
end)
|
||||
|
||||
Players.PlayerRemoving:Connect(function(player)
|
||||
if previewOwner == player then
|
||||
local successor: Player? = nil
|
||||
for _, other in Players:GetPlayers() do
|
||||
if other ~= player and other:GetAttribute("ArenaTeam") ~= nil and Modes.of(other) == Modes.Procedural then
|
||||
successor = other
|
||||
break
|
||||
end
|
||||
end
|
||||
setPreviewOwner(successor)
|
||||
end
|
||||
lastAction[player], lastCreate[player], lastList[player], transfers[player] = nil, nil, nil, nil
|
||||
lastDetails[player], moreFrom[player] = nil, nil
|
||||
local sent = parties[player]
|
||||
if sent then closeParty(sent, "Создатель вышел с сервера.") end
|
||||
local received = invitations[player]
|
||||
if received then
|
||||
invitations[player], received.answers[player] = nil, nil
|
||||
updateParty(received)
|
||||
end
|
||||
end)
|
||||
|
||||
if hosted then
|
||||
local admission = script.Parent:WaitForChild("ArenaRounds"):WaitForChild("HostedArenaAdmission") :: BindableEvent
|
||||
local match = ReplicatedStorage:WaitForChild("ArenaRound"):WaitForChild("Procedural")
|
||||
local reservationId = game.PrivateServerId
|
||||
local session: Session? = nil
|
||||
local loaded = false
|
||||
local closing, removed = false, false
|
||||
local writing, pending = false, false
|
||||
local admitted: {[Player]: number} = {}
|
||||
local nextArrival = 0
|
||||
local ownerDeparted = false
|
||||
local ownerGraceUntil = workspace:GetServerTimeNow() + 20
|
||||
local lastSessionWrite, savedOwner = -math.huge, nil :: number?
|
||||
|
||||
local function showOwner(record: Session)
|
||||
remote:SetAttribute("OwnerUserId", record.hostId)
|
||||
remote:SetAttribute("OwnerName", record.hostName)
|
||||
end
|
||||
|
||||
local function chooseSuccessor(record: Session, now: number)
|
||||
if not ownerDeparted and now < ownerGraceUntil then return end
|
||||
local successor: Player? = nil
|
||||
local oldest = math.huge
|
||||
for player, order in admitted do
|
||||
if player.UserId == record.hostId then return end
|
||||
if order < oldest then successor, oldest = player, order end
|
||||
end
|
||||
if successor then
|
||||
record.hostId, record.hostName = successor.UserId, successor.DisplayName
|
||||
ownerDeparted = false
|
||||
showOwner(record)
|
||||
end
|
||||
end
|
||||
|
||||
local function removeSession(record: Session)
|
||||
local registryRemoved = sessions == nil
|
||||
local listingRemoved = directory == nil or record.access ~= "Public"
|
||||
for attempt = 1, 3 do
|
||||
if not registryRemoved and sessions then registryRemoved = pcall(sessions.RemoveAsync, sessions, reservationId) end
|
||||
if not listingRemoved and directory then listingRemoved = pcall(directory.RemoveAsync, directory, reservationId) end
|
||||
if registryRemoved and listingRemoved then break end
|
||||
if attempt < 3 then task.wait(attempt) end
|
||||
end
|
||||
removed = true
|
||||
end
|
||||
|
||||
-- The same writer publishes and retires the session, so a pending refresh cannot recreate a closed entry.
|
||||
local function sync()
|
||||
local record = session
|
||||
if writing or removed or not record then return end
|
||||
writing = true
|
||||
repeat
|
||||
pending = false
|
||||
if closing then
|
||||
removeSession(record)
|
||||
break
|
||||
end
|
||||
local now = workspace:GetServerTimeNow()
|
||||
chooseSuccessor(record, now)
|
||||
if sessions and (savedOwner ~= record.hostId or now - lastSessionWrite >= 90) then
|
||||
local snapshot = table.clone(record)
|
||||
if pcall(sessions.SetAsync, sessions, reservationId, snapshot, SESSION_TTL) then
|
||||
lastSessionWrite, savedOwner = now, snapshot.hostId
|
||||
end
|
||||
end
|
||||
if not closing and record.access == "Public" and directory and next(admitted) then
|
||||
local count = 0
|
||||
local blue: {Hosting.Member}, orange: {Hosting.Member} = {}, {}
|
||||
for player in admitted do
|
||||
count += 1
|
||||
local side = player:GetAttribute("ArenaTeam")
|
||||
if side == "Blue" or side == "Orange" then
|
||||
table.insert(if side == "Blue" then blue else orange, {userId = player.UserId, displayName = player.DisplayName})
|
||||
end
|
||||
end
|
||||
pcall(directory.SetAsync, directory, reservationId,
|
||||
{hostId = record.hostId, hostName = record.hostName, players = count,
|
||||
blue = blue, orange = orange, ruleset = Rules.get(match:GetAttribute("Ruleset")).id},
|
||||
DIRECTORY_TTL, record.startedAt or now)
|
||||
end
|
||||
until not pending
|
||||
writing = false
|
||||
end
|
||||
|
||||
local function scheduleSync()
|
||||
pending = true
|
||||
task.spawn(sync)
|
||||
end
|
||||
|
||||
local function allowed(record: Session, player: Player): boolean
|
||||
return record.access == "Public" or record.allowed[tostring(player.UserId)] == true
|
||||
end
|
||||
|
||||
local function closeIfEmpty(leaving: Player?)
|
||||
local record = session
|
||||
if closing or not record or nextArrival == 0 or next(admitted) then return end
|
||||
for _, player in Players:GetPlayers() do
|
||||
if player ~= leaving and allowed(record, player) and not player:GetAttribute("HostedArenaFull") then return end
|
||||
end
|
||||
closing = true
|
||||
scheduleSync()
|
||||
end
|
||||
|
||||
local function authorize(player: Player)
|
||||
while not loaded and present(player) do task.wait(.1) end
|
||||
if not present(player) or admitted[player] then return end
|
||||
local record = session
|
||||
if not record or closing then
|
||||
player:Kick("Эта арена больше недоступна.")
|
||||
return
|
||||
end
|
||||
if not allowed(record, player) then
|
||||
player:Kick("Эта арена доступна только участникам с подтверждённым приглашением.")
|
||||
return
|
||||
end
|
||||
local count = 0
|
||||
for _ in admitted do count += 1 end
|
||||
if count >= Hosting.MaxPlayers then
|
||||
player:SetAttribute("HostedArenaFull", true)
|
||||
return
|
||||
end
|
||||
nextArrival += 1
|
||||
admitted[player] = nextArrival
|
||||
local side: Side? = nil
|
||||
if record.access == "Public" then
|
||||
-- The preference grants no admission or team rights. The destination checks its own roster.
|
||||
local data = player:GetJoinData()
|
||||
local payload = data.TeleportData
|
||||
if data.SourcePlaceId == game.PlaceId and data.SourceGameId == game.GameId
|
||||
and typeof(payload) == "table" and payload.arenaId == reservationId
|
||||
and (payload.team == "Blue" or payload.team == "Orange") then
|
||||
side = payload.team
|
||||
end
|
||||
end
|
||||
admission:Fire(player, side)
|
||||
scheduleSync()
|
||||
end
|
||||
|
||||
Players.PlayerAdded:Connect(authorize)
|
||||
Players.PlayerRemoving:Connect(function(player)
|
||||
admitted[player] = nil
|
||||
local record = session
|
||||
if not record then return end
|
||||
if player.UserId == record.hostId then ownerDeparted = true end
|
||||
closeIfEmpty(player)
|
||||
if not closing then scheduleSync() end
|
||||
end)
|
||||
Players.ChildRemoved:Connect(function(child)
|
||||
if child:IsA("Player") then closeIfEmpty(nil) end
|
||||
end)
|
||||
for _, player in Players:GetPlayers() do task.spawn(authorize, player) end
|
||||
|
||||
game:BindToClose(function()
|
||||
if not session or nextArrival == 0 or removed then return end
|
||||
closing = true
|
||||
pending = true
|
||||
sync()
|
||||
while writing do task.wait() end
|
||||
end)
|
||||
|
||||
task.spawn(function()
|
||||
if not sessions then loaded = true return end
|
||||
for attempt = 1, 3 do
|
||||
local ok, record = pcall(sessions.GetAsync, sessions, reservationId)
|
||||
if ok and record then session = record break end
|
||||
if attempt < 3 then task.wait(1) end
|
||||
end
|
||||
local record = session
|
||||
if record then
|
||||
local options = Hosting.readRoundOptions(record.roundOptions)
|
||||
if not options or not configureRound(options) then
|
||||
warn("[HostedArena] Could not configure hosted rounds")
|
||||
session, record = nil, nil
|
||||
end
|
||||
end
|
||||
loaded = true
|
||||
if not record then return end
|
||||
savedOwner = record.hostId
|
||||
showOwner(record)
|
||||
while not closing do
|
||||
task.wait(16)
|
||||
if not closing then scheduleSync() end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
remote.Parent = ReplicatedStorage
|
||||
@@ -0,0 +1,231 @@
|
||||
--!strict
|
||||
local Sites = require(script.Parent:WaitForChild("ArenaObjectiveSites") :: ModuleScript)
|
||||
|
||||
type Side = "Blue" | "Orange"
|
||||
export type Fighter = {player: Player, side: Side, root: BasePart}
|
||||
export type Marker = {body: Part, label: TextLabel, origin: Vector3}
|
||||
type Config = {
|
||||
state: Instance, geometry: RaycastParams, sites: {Sites.Site}, startedAt: number,
|
||||
marker: (Sites.Site) -> Marker, score: (Side, number) -> (), status: (string) -> (),
|
||||
}
|
||||
type Capture = {
|
||||
step: ({Fighter}, number, number) -> (), hit: (Player, number, boolean) -> (),
|
||||
death: (Player) -> (), destroy: () -> (),
|
||||
}
|
||||
|
||||
local HotPoint = {Radius = 18}
|
||||
local CAPTURE_SECONDS = 10
|
||||
local ROTATION_SECONDS = 40
|
||||
local TEAM_SPEED = 1.5
|
||||
local HIT_WINDOW = 1.2
|
||||
local HIT_DECAY = .8
|
||||
|
||||
local neutral = Color3.fromRGB(183, 132, 255)
|
||||
local contested = Color3.fromRGB(255, 211, 124)
|
||||
local teamColor: {[Side]: Color3} = {Blue = Color3.fromRGB(76, 228, 255), Orange = Color3.fromRGB(255, 81, 105)}
|
||||
|
||||
local function magicRing(mark: Marker): (Color3) -> ()
|
||||
local body = mark.body
|
||||
body.Transparency = .92
|
||||
local beams: {Beam} = {}
|
||||
local sparks: {ParticleEmitter} = {}
|
||||
local function anchor(angle: number, height: number): Attachment
|
||||
local radial = Vector3.new(math.cos(angle), 0, math.sin(angle))
|
||||
local tangent = Vector3.new(-radial.Z, 0, radial.X)
|
||||
local item = Instance.new("Attachment")
|
||||
local world = CFrame.fromMatrix(mark.origin + radial * HotPoint.Radius + Vector3.yAxis * height, tangent, Vector3.yAxis)
|
||||
item.CFrame = body.CFrame:ToObjectSpace(world)
|
||||
item.Parent = body
|
||||
return item
|
||||
end
|
||||
local function halo(name: string, height: number, width: number, transparency: number)
|
||||
local corners: {Attachment} = {}
|
||||
for index = 0, 3 do
|
||||
table.insert(corners, anchor(index * math.pi / 2, height))
|
||||
end
|
||||
local handle = 4 * (math.sqrt(2) - 1) / 3 * HotPoint.Radius
|
||||
for index, start in corners do
|
||||
local beam = Instance.new("Beam")
|
||||
beam.Name = name
|
||||
beam.Attachment0, beam.Attachment1 = start, corners[index % #corners + 1]
|
||||
beam.CurveSize0, beam.CurveSize1 = handle, handle
|
||||
beam.Segments, beam.FaceCamera = 18, true
|
||||
beam.Width0, beam.Width1 = width, width
|
||||
beam.Transparency = NumberSequence.new(transparency)
|
||||
beam.LightEmission, beam.LightInfluence, beam.Brightness = 1, 0, 2
|
||||
beam.Parent = body
|
||||
table.insert(beams, beam)
|
||||
end
|
||||
end
|
||||
halo("FloorRing", .29, .32, .1)
|
||||
for index = 0, 19 do
|
||||
local angle = index * math.pi / 10
|
||||
local source = anchor(angle, .28)
|
||||
if index % 2 == 0 then
|
||||
local veil = Instance.new("Beam")
|
||||
veil.Name = "RisingVeil"
|
||||
veil.Attachment0, veil.Attachment1 = source, anchor(angle, 7.4)
|
||||
veil.FaceCamera, veil.Segments = true, 8
|
||||
veil.Width0, veil.Width1 = .78, .3
|
||||
veil.LightEmission, veil.LightInfluence, veil.Brightness = 1, 0, 1.4
|
||||
veil.Transparency = NumberSequence.new({
|
||||
NumberSequenceKeypoint.new(0, .42), NumberSequenceKeypoint.new(.38, .74), NumberSequenceKeypoint.new(1, 1),
|
||||
})
|
||||
veil.Parent = body
|
||||
table.insert(beams, veil)
|
||||
end
|
||||
local emitter = Instance.new("ParticleEmitter")
|
||||
emitter.Name = "RisingSparks"
|
||||
emitter.Texture = "rbxasset://textures/particles/sparkles_main.dds"
|
||||
emitter.EmissionDirection = Enum.NormalId.Top
|
||||
emitter.Rate, emitter.Speed = 12, NumberRange.new(16.5, 27)
|
||||
emitter.Lifetime, emitter.SpreadAngle = NumberRange.new(.6, 1.08), Vector2.new(8, 8)
|
||||
emitter.Rotation, emitter.RotSpeed = NumberRange.new(-180, 180), NumberRange.new(-95, 95)
|
||||
emitter.LightEmission, emitter.LightInfluence, emitter.Brightness = 1, 0, 2
|
||||
emitter.Size = NumberSequence.new({
|
||||
NumberSequenceKeypoint.new(0, .16), NumberSequenceKeypoint.new(.25, .55), NumberSequenceKeypoint.new(1, .08),
|
||||
})
|
||||
emitter.Transparency = NumberSequence.new({
|
||||
NumberSequenceKeypoint.new(0, 1), NumberSequenceKeypoint.new(.22, .12), NumberSequenceKeypoint.new(1, 1),
|
||||
})
|
||||
emitter.Parent = source
|
||||
table.insert(sparks, emitter)
|
||||
end
|
||||
return function(tint: Color3)
|
||||
body.Color, mark.label.TextColor3 = tint, tint
|
||||
local light = body:FindFirstChildOfClass("PointLight")
|
||||
if light then light.Color, light.Range = tint, 18 end
|
||||
local spectrum = ColorSequence.new({
|
||||
ColorSequenceKeypoint.new(0, tint), ColorSequenceKeypoint.new(.5, tint:Lerp(Color3.new(1, 1, 1), .38)),
|
||||
ColorSequenceKeypoint.new(1, tint),
|
||||
})
|
||||
for _, beam in beams do beam.Color = spectrum end
|
||||
for _, emitter in sparks do emitter.Color = spectrum end
|
||||
end
|
||||
end
|
||||
|
||||
function HotPoint.start(config: Config): Capture
|
||||
local state = config.state
|
||||
local index, credit, hitSince, hitUntil, flashUntil = 0, 0, 0, 0, 0
|
||||
local owner: Side? = nil
|
||||
local claiming: Side? = nil
|
||||
local capturers: {[Player]: boolean} = {}
|
||||
local mark: Marker? = nil
|
||||
local paint: ((Color3) -> ())? = nil
|
||||
local lastTint: Color3? = nil
|
||||
|
||||
local function publish(side: Side?, percent: number, phase: string?)
|
||||
if state:GetAttribute("HotPointTeam") ~= side then state:SetAttribute("HotPointTeam", side) end
|
||||
if state:GetAttribute("HotPointProgress") ~= percent then state:SetAttribute("HotPointProgress", percent) end
|
||||
if state:GetAttribute("HotPointPhase") ~= phase then state:SetAttribute("HotPointPhase", phase) end
|
||||
end
|
||||
local function clearCapture()
|
||||
claiming, credit, hitSince, hitUntil = nil, 0, 0, 0
|
||||
table.clear(capturers)
|
||||
end
|
||||
local function paintRing(tint: Color3)
|
||||
if paint and lastTint ~= tint then
|
||||
lastTint = tint
|
||||
paint(tint)
|
||||
end
|
||||
end
|
||||
local function isInside(fighter: Fighter, origin: Vector3): boolean
|
||||
local delta = fighter.root.Position - origin
|
||||
if delta.Y < -.5 or delta.Y > 60 or delta.X * delta.X + delta.Z * delta.Z > HotPoint.Radius ^ 2 then return false end
|
||||
if delta.Y > 8 then
|
||||
-- A jump over the point still counts when the first floor below is the capture floor.
|
||||
local floor = workspace:Raycast(fighter.root.Position, -Vector3.yAxis * (delta.Y + .8), config.geometry)
|
||||
return floor ~= nil and math.abs(floor.Position.Y - origin.Y) < .65
|
||||
end
|
||||
local to = origin + Vector3.yAxis * 2.7 - fighter.root.Position
|
||||
return workspace:Raycast(fighter.root.Position, to, config.geometry) == nil
|
||||
end
|
||||
|
||||
local function step(fighters: {Fighter}, now: number, dt: number)
|
||||
local elapsed = math.max(0, now - config.startedAt)
|
||||
local slot = math.floor(elapsed / ROTATION_SECONDS) % #config.sites + 1
|
||||
local site = config.sites[slot]
|
||||
if index ~= slot then
|
||||
if mark then mark.body:Destroy() end
|
||||
local fresh = config.marker(site)
|
||||
index, mark, paint = slot, fresh, magicRing(fresh)
|
||||
owner, flashUntil, lastTint = nil, 0, nil
|
||||
clearCapture()
|
||||
end
|
||||
|
||||
local blue, orange = 0, 0
|
||||
local inside: {Fighter} = {}
|
||||
for _, fighter in fighters do
|
||||
if not isInside(fighter, site.position) then continue end
|
||||
table.insert(inside, fighter)
|
||||
if fighter.side == "Blue" then blue += 1 else orange += 1 end
|
||||
end
|
||||
local remaining = math.ceil(ROTATION_SECONDS - elapsed % ROTATION_SECONDS)
|
||||
config.status(site.name .. " · Смена точки через " .. remaining .. " с")
|
||||
local soleSide: Side? = if blue > 0 and orange == 0 then "Blue" elseif orange > 0 and blue == 0 then "Orange" else nil
|
||||
local isContested = blue > 0 and orange > 0
|
||||
if soleSide and soleSide ~= owner then
|
||||
if claiming ~= soleSide then
|
||||
clearCapture()
|
||||
claiming = soleSide
|
||||
dt = 0
|
||||
end
|
||||
elseif not isContested or not claiming then
|
||||
clearCapture()
|
||||
end
|
||||
|
||||
local side = claiming
|
||||
if side then
|
||||
table.clear(capturers)
|
||||
for _, fighter in inside do
|
||||
if fighter.side == side then capturers[fighter.player] = true end
|
||||
end
|
||||
local underFire = now < hitUntil
|
||||
local damageTime = math.max(0, math.min(now, hitUntil) - math.max(now - dt, hitSince))
|
||||
if damageTime > 0 then credit = math.max(0, credit - damageTime * HIT_DECAY) end
|
||||
if not isContested then
|
||||
local count = if side == "Blue" then blue else orange
|
||||
credit += (dt - damageTime) * (if count >= 2 then TEAM_SPEED else 1)
|
||||
end
|
||||
if credit >= CAPTURE_SECONDS then
|
||||
owner, flashUntil = side, now + 1.25
|
||||
config.score(side, 1)
|
||||
clearCapture()
|
||||
publish(side, 100, "Captured")
|
||||
paintRing(teamColor[side])
|
||||
else
|
||||
local phase = if isContested then "Contested" elseif underFire then "UnderFire" else "Capturing"
|
||||
publish(side, math.floor(100 * credit / CAPTURE_SECONDS), phase)
|
||||
paintRing(if isContested then contested else teamColor[side])
|
||||
end
|
||||
elseif isContested then
|
||||
publish(nil, 0, "Contested")
|
||||
paintRing(contested)
|
||||
else
|
||||
if owner and now < flashUntil then publish(owner, 100, "Captured") else publish(nil, 0, nil) end
|
||||
paintRing(if owner then teamColor[owner] else neutral)
|
||||
end
|
||||
end
|
||||
|
||||
local function death(player: Player)
|
||||
if not capturers[player] then return end
|
||||
clearCapture()
|
||||
publish(nil, 0, nil)
|
||||
end
|
||||
return {
|
||||
step = step,
|
||||
hit = function(player: Player, now: number, killed: boolean)
|
||||
if killed then death(player)
|
||||
elseif capturers[player] then
|
||||
if now >= hitUntil then hitSince = now end
|
||||
hitUntil = now + HIT_WINDOW
|
||||
end
|
||||
end,
|
||||
death = death,
|
||||
destroy = function()
|
||||
publish(nil, 0, nil)
|
||||
end,
|
||||
}
|
||||
end
|
||||
|
||||
return table.freeze(HotPoint)
|
||||
@@ -0,0 +1,572 @@
|
||||
--!strict
|
||||
local TweenService = game:GetService("TweenService")
|
||||
local RunService = game:GetService("RunService")
|
||||
local UI = {}
|
||||
|
||||
UI.Ink = Color3.fromRGB(241, 247, 253)
|
||||
UI.Muted = Color3.fromRGB(160, 179, 198)
|
||||
UI.Outline = Color3.fromRGB(229, 236, 242)
|
||||
UI.Panel = Color3.fromRGB(25, 29, 34)
|
||||
UI.Blue = Color3.fromRGB(83, 229, 248)
|
||||
UI.Orange = Color3.fromRGB(255, 150, 71)
|
||||
UI.Mint = Color3.fromRGB(114, 242, 178)
|
||||
UI.Gold = Color3.fromRGB(255, 199, 79)
|
||||
UI.Display = Font.new("rbxasset://fonts/families/Montserrat.json", Enum.FontWeight.Heavy, Enum.FontStyle.Italic)
|
||||
|
||||
local combatBottom = {Wallet = 76, Ammo = 16, Skin = 135}
|
||||
type CombatSlot = "Wallet" | "Ammo" | "Skin"
|
||||
|
||||
function UI.combatScale(gui: ScreenGui): number
|
||||
return if gui.AbsoluteSize.X < 560 then .80 else 1
|
||||
end
|
||||
|
||||
function UI.placeCombat(item: GuiObject, slot: CombatSlot)
|
||||
item.AnchorPoint = Vector2.new(1, 1)
|
||||
item.Position = UDim2.new(1, -20, 1, -combatBottom[slot])
|
||||
end
|
||||
|
||||
function UI.frame(name: string, parent: Instance, position: UDim2, size: UDim2, color: Color3): Frame
|
||||
local frame = Instance.new("Frame")
|
||||
frame.Name, frame.Position, frame.Size = name, position, size
|
||||
frame.BackgroundColor3, frame.BorderSizePixel = color, 0
|
||||
frame.Parent = parent
|
||||
return frame
|
||||
end
|
||||
|
||||
function UI.label(parent: Instance, name: string, value: string, pos: UDim2, size: UDim2, textSize: number, color: Color3): TextLabel
|
||||
local text = Instance.new("TextLabel")
|
||||
text.Name, text.Position, text.Size = name, pos, size
|
||||
text.BackgroundTransparency = 1
|
||||
text.Font = Enum.Font.GothamBold
|
||||
text.Text, text.TextSize, text.TextColor3 = value, textSize, color
|
||||
text.Parent = parent
|
||||
return text
|
||||
end
|
||||
|
||||
function UI.edge(target: GuiObject, color: Color3, opacity: number): UIStroke
|
||||
local stroke = Instance.new("UIStroke")
|
||||
stroke.ApplyStrokeMode = Enum.ApplyStrokeMode.Border
|
||||
stroke.Color, stroke.Thickness, stroke.Transparency = color, 1.2, 1 - opacity
|
||||
stroke.Parent = target
|
||||
return stroke
|
||||
end
|
||||
|
||||
local white = Color3.new(1, 1, 1)
|
||||
local zero, full = UDim2.fromScale(0, 0), UDim2.fromScale(1, 1)
|
||||
local function layer(name: string, parent: Instance): Frame
|
||||
local item = UI.frame(name, parent, zero, full, white)
|
||||
item.BackgroundTransparency = 1
|
||||
return item
|
||||
end
|
||||
|
||||
local function plateArt(name: string, parent: Instance, cut: number, thick: number): Frame
|
||||
local art = layer(name, parent)
|
||||
art:SetAttribute("CornerCut", cut)
|
||||
local fills, trim = layer("Surfaces", art), layer("Trim", art)
|
||||
UI.frame("Body", fills, UDim2.fromOffset(0, cut), UDim2.new(1, 0, 1, -2 * cut), UI.Panel)
|
||||
UI.frame("Upper", fills, UDim2.fromOffset(cut, 0), UDim2.new(1, -cut, 0, cut), UI.Panel)
|
||||
UI.frame("Lower", fills, UDim2.new(0, 0, 1, -cut), UDim2.new(1, -cut, 0, cut), UI.Panel)
|
||||
for _, far in {false, true} do
|
||||
local s = if far then 1 else 0
|
||||
local inset = if far then -cut else cut
|
||||
local corner = UI.frame(if far then "LowerCut" else "UpperCut", fills, UDim2.new(s, inset, s, inset),
|
||||
UDim2.fromOffset(cut * math.sqrt(2), cut * math.sqrt(2)), UI.Panel)
|
||||
corner.AnchorPoint, corner.Rotation = Vector2.new(.5, .5), 45
|
||||
local edge = UI.frame(corner.Name, trim, UDim2.new(s, inset / 2, s, inset / 2),
|
||||
UDim2.fromOffset(cut * math.sqrt(2), thick), UI.Outline)
|
||||
edge.AnchorPoint, edge.Rotation = Vector2.new(.5, .5), -45
|
||||
end
|
||||
UI.frame("Top", trim, UDim2.fromOffset(cut, 0), UDim2.new(1, -cut, 0, thick), UI.Outline)
|
||||
UI.frame("Bottom", trim, UDim2.new(0, 0, 1, -thick), UDim2.new(1, -cut, 0, thick), UI.Outline)
|
||||
UI.frame("Left", trim, UDim2.fromOffset(0, cut), UDim2.new(0, thick, 1, -cut), UI.Outline)
|
||||
UI.frame("Right", trim, UDim2.new(1, -thick, 0, 0), UDim2.new(0, thick, 1, -cut), UI.Outline)
|
||||
return art
|
||||
end
|
||||
|
||||
local motion = TweenInfo.new(.13, Enum.EasingStyle.Quart, Enum.EasingDirection.Out)
|
||||
local function paint(art: Instance, fill: Color3, edge: Color3)
|
||||
local surfaces, trim = art:FindFirstChild("Surfaces"), art:FindFirstChild("Trim")
|
||||
assert(surfaces and trim, "Plate is missing its art layers")
|
||||
for _, part in surfaces:GetChildren() do
|
||||
if part:IsA("Frame") then part.BackgroundColor3 = fill end
|
||||
end
|
||||
for _, part in trim:GetChildren() do
|
||||
if part:IsA("Frame") then part.BackgroundColor3 = edge end
|
||||
end
|
||||
end
|
||||
|
||||
local function strokeAt(parent: Instance, name: string, a: Vector2, b: Vector2, width: number, color: Color3): Frame
|
||||
local delta = b - a
|
||||
local mid = (a + b) / 2
|
||||
local line = UI.frame(name, parent, UDim2.fromOffset(mid.X, mid.Y), UDim2.fromOffset(delta.Magnitude + 1.4, width), color)
|
||||
line.AnchorPoint = Vector2.new(.5, .5)
|
||||
line.Rotation = math.deg(math.atan2(delta.Y, delta.X))
|
||||
return line
|
||||
end
|
||||
|
||||
local function coinCamera(view: ViewportFrame): Camera
|
||||
local camera = Instance.new("Camera")
|
||||
camera.Name = "CoinCamera"
|
||||
camera.FieldOfView = 30
|
||||
camera.CFrame = CFrame.lookAt(Vector3.new(0, .035, 2.83), Vector3.zero)
|
||||
camera.Parent = view
|
||||
return camera
|
||||
end
|
||||
|
||||
local function buildCoin(parent: Instance)
|
||||
local art = layer("GoldCoin", parent)
|
||||
art.Size = UDim2.fromOffset(36, 36)
|
||||
local view = Instance.new("ViewportFrame")
|
||||
view.Name = "Viewport"
|
||||
view.Size = full
|
||||
view.BackgroundTransparency = 1
|
||||
view.Ambient = Color3.fromRGB(182, 152, 107)
|
||||
view.LightColor = Color3.fromRGB(255, 232, 166)
|
||||
view.LightDirection = Vector3.new(-.46, -.63, -.79)
|
||||
view.Parent = art
|
||||
view.CurrentCamera = coinCamera(view)
|
||||
local world = Instance.new("WorldModel")
|
||||
world.Parent = view
|
||||
local model = Instance.new("Model")
|
||||
model.Name = "TrophyCoin"
|
||||
model.Parent = world
|
||||
local function part(name: string, size: Vector3, at: CFrame, color: Color3, round: boolean): Part
|
||||
local piece = Instance.new("Part")
|
||||
piece.Name, piece.Size, piece.CFrame = name, size, at
|
||||
piece.Shape = if round then Enum.PartType.Cylinder else Enum.PartType.Block
|
||||
piece.Material = Enum.Material.SmoothPlastic
|
||||
piece.Color = color
|
||||
piece.Anchored, piece.CanCollide, piece.CanQuery, piece.CanTouch = true, false, false, false
|
||||
piece.CastShadow = false
|
||||
piece.Parent = model
|
||||
return piece
|
||||
end
|
||||
local amber = Color3.fromRGB(204, 123, 25)
|
||||
local bevel = Color3.fromRGB(255, 216, 109)
|
||||
local face = Color3.fromRGB(241, 172, 49)
|
||||
local stamp = Color3.fromRGB(142, 73, 17)
|
||||
model.PrimaryPart = part("ReededRim", Vector3.new(.22, 1.27, 1.27), CFrame.identity, amber, true)
|
||||
part("OuterBevel", Vector3.new(.25, 1.19, 1.19), CFrame.identity, bevel, true)
|
||||
part("FaceRing", Vector3.new(.28, 1.09, 1.09), CFrame.identity, amber, true)
|
||||
part("GoldFace", Vector3.new(.30, 1.02, 1.02), CFrame.identity, face, true)
|
||||
for index = 0, 15 do
|
||||
local angle = index * math.pi / 8
|
||||
local at = CFrame.Angles(angle, 0, 0) * CFrame.new(0, .622, 0)
|
||||
local tint = if index % 2 == 0 then bevel else face
|
||||
part("RimReed", Vector3.new(.177, .025, .027), at, tint, false)
|
||||
end
|
||||
for _, side in {-1, 1} do
|
||||
for _, z in {-.135, .135} do
|
||||
part("StampH", Vector3.new(.018, .47, .077), CFrame.new(side * .151, 0, z), stamp, false)
|
||||
end
|
||||
part("StampH", Vector3.new(.019, .079, .27), CFrame.new(side * .151, 0, 0), stamp, false)
|
||||
end
|
||||
model:PivotTo(CFrame.fromOrientation(-.08, math.pi / 2, .08))
|
||||
|
||||
local glint = layer("Glint", art)
|
||||
glint.Size = UDim2.fromOffset(23, 23)
|
||||
glint.AnchorPoint, glint.Position = Vector2.new(.5, .5), UDim2.fromScale(.78, .26)
|
||||
glint.Visible = false
|
||||
local starScale = Instance.new("UIScale", glint)
|
||||
starScale.Name = "Intensity"
|
||||
for i = 0, 3 do
|
||||
local ray = UI.frame("Ray", glint, UDim2.fromScale(.5, .5),
|
||||
UDim2.fromOffset(if i < 2 then 2.5 else 1.3, if i < 2 then 22 - i * 6 else 11), Color3.fromRGB(255, 251, 217))
|
||||
ray.AnchorPoint = Vector2.new(.5, .5)
|
||||
ray.Rotation = if i == 0 then 0 elseif i == 1 then 90 elseif i == 2 then 45 else 135
|
||||
local feather = Instance.new("UIGradient")
|
||||
feather.Rotation = 90
|
||||
feather.Transparency = NumberSequence.new({
|
||||
NumberSequenceKeypoint.new(0, 1), NumberSequenceKeypoint.new(.5, 0), NumberSequenceKeypoint.new(1, 1),
|
||||
})
|
||||
feather.Parent = ray
|
||||
end
|
||||
end
|
||||
|
||||
local function buildElements(): Folder
|
||||
local elements = Instance.new("Folder")
|
||||
elements.Name = "Elements"
|
||||
plateArt("Plate", elements, 13, 2)
|
||||
plateArt("ScoreChip", elements, 11, 1)
|
||||
local lightning = layer("ContourLightning", elements)
|
||||
lightning.ZIndex = 3
|
||||
local glowLayer, coreLayer = layer("Halo", lightning), layer("Core", lightning)
|
||||
for i = 1, 6 do
|
||||
for _, group in {glowLayer, coreLayer} do
|
||||
local piece = UI.frame("Piece" .. i, group, zero, UDim2.fromOffset(0, 0), UI.Blue)
|
||||
piece.AnchorPoint = Vector2.new(.5, .5)
|
||||
end
|
||||
end
|
||||
local states = layer("ButtonStates", elements)
|
||||
for _, name in {"Normal", "Hover", "Pressed", "Disabled"} do
|
||||
local state = plateArt(name, states, 10, 1.7)
|
||||
state.Visible = name == "Normal"
|
||||
local tint = if name == "Hover" then .39 elseif name == "Pressed" then .17 else .03
|
||||
paint(state, UI.Panel:Lerp(UI.Blue, tint), if name == "Disabled" then UI.Panel:Lerp(UI.Muted, .23) else UI.Blue)
|
||||
end
|
||||
local row = UI.frame("RowHighlight", elements, zero, full, UI.Blue)
|
||||
row.BackgroundTransparency = 1
|
||||
Instance.new("UICorner", row).CornerRadius = UDim.new(0, 5)
|
||||
local playerRow = UI.frame("PlayerRow", elements, zero, UDim2.new(1, -5, 0, 28), UI.Panel:Lerp(UI.Blue, .14))
|
||||
Instance.new("UICorner", playerRow).CornerRadius = UDim.new(0, 6)
|
||||
local portrait = Instance.new("ImageLabel")
|
||||
portrait.Name = "Portrait"
|
||||
portrait.Size = UDim2.fromOffset(28, 28)
|
||||
portrait.BackgroundColor3, portrait.BorderSizePixel = UI.Panel:Lerp(UI.Blue, .25), 0
|
||||
portrait.ScaleType = Enum.ScaleType.Crop
|
||||
portrait.Parent = elements
|
||||
Instance.new("UICorner", portrait).CornerRadius = UDim.new(1, 0)
|
||||
UI.edge(portrait, UI.Blue, .8)
|
||||
UI.label(portrait, "Initial", "", zero, full, 13, UI.Ink)
|
||||
local meter = UI.frame("ProgressBar", elements, zero, UDim2.fromOffset(100, 7), Color3.fromRGB(43, 57, 69))
|
||||
meter.ClipsDescendants = true
|
||||
Instance.new("UICorner", meter).CornerRadius = UDim.new(0, 3)
|
||||
local fill = UI.frame("Fill", meter, zero, full, UI.Mint)
|
||||
Instance.new("UICorner", fill).CornerRadius = UDim.new(0, 3)
|
||||
|
||||
local shield = layer("Shield", elements)
|
||||
shield.Size = UDim2.fromOffset(21, 22)
|
||||
local shieldPoints = {Vector2.new(10.5, 2), Vector2.new(19, 5.5), Vector2.new(17.5, 14.5),
|
||||
Vector2.new(10.5, 20), Vector2.new(3.5, 14.5), Vector2.new(2, 5.5)}
|
||||
for i, a in shieldPoints do strokeAt(shield, "Side", a, shieldPoints[i % #shieldPoints + 1], 2, UI.Mint) end
|
||||
local ammo = layer("Ammo", elements)
|
||||
ammo.Size = UDim2.fromOffset(27, 18)
|
||||
for i = 0, 2 do
|
||||
local casing = UI.frame("Cartridge", ammo, UDim2.fromOffset(3 + i * 8, 2), UDim2.fromOffset(5, 15), UI.Ink)
|
||||
casing.Rotation = 13
|
||||
Instance.new("UICorner", casing).CornerRadius = UDim.new(0, 2)
|
||||
end
|
||||
buildCoin(elements)
|
||||
local key = UI.frame("Keycap", elements, zero, UDim2.fromOffset(25, 23), UI.Ink)
|
||||
Instance.new("UICorner", key).CornerRadius = UDim.new(0, 4)
|
||||
UI.label(key, "Key", "E", zero, full, 13, UI.Panel).Font = Enum.Font.GothamBlack
|
||||
local glint = layer("SkinGlint", elements)
|
||||
glint.Size = UDim2.fromOffset(18, 18)
|
||||
local diamond = UI.frame("Mark", glint, UDim2.fromOffset(4, 4), UDim2.fromOffset(10, 10), UI.Blue)
|
||||
diamond.Rotation = 45
|
||||
UI.edge(diamond, UI.Ink, .65)
|
||||
local tick = UI.frame("CrosshairTick", elements, zero, UDim2.fromOffset(2, 9), UI.Ink)
|
||||
tick.AnchorPoint = Vector2.new(.5, .5)
|
||||
UI.edge(tick, Color3.new(0, 0, 0), .65).Thickness = 1
|
||||
|
||||
local arc = layer("StreakArc", elements)
|
||||
arc.Size = UDim2.fromOffset(165, 104)
|
||||
for section = 1, 2 do
|
||||
local group = layer("Segment" .. section, arc)
|
||||
local radius = if section == 1 then Vector2.new(85, 77) else Vector2.new(76, 66)
|
||||
local firstAngle = if section == 1 then 76 else 82
|
||||
local sweep = if section == 1 then 69 else 58
|
||||
for i = 1, 14 do
|
||||
local u = (i - 1) / 14
|
||||
local t = math.rad(firstAngle - u * sweep)
|
||||
local nextT = math.rad(firstAngle - (u + 1 / 14) * sweep)
|
||||
local a = Vector2.new(math.cos(t) * radius.X, math.sin(t) * radius.Y)
|
||||
local b = Vector2.new(math.cos(nextT) * radius.X, math.sin(nextT) * radius.Y)
|
||||
local width = 1.8 + math.sin(math.pi * (u + 1 / 28)) ^ .7 * (if section == 1 then 6.0 else 4.8)
|
||||
local piece = strokeAt(group, "Piece" .. i, a, b, width, UI.Gold)
|
||||
piece.BackgroundTransparency = if section == 1 then .94 else 1
|
||||
end
|
||||
end
|
||||
local multiplier = UI.label(arc, "Multiplier", "×0", UDim2.fromOffset(94, 33), UDim2.fromOffset(72, 37), 27, UI.Gold)
|
||||
multiplier.FontFace = UI.Display
|
||||
multiplier.TextXAlignment = Enum.TextXAlignment.Left
|
||||
multiplier.TextStrokeColor3, multiplier.TextStrokeTransparency = UI.Panel, .22
|
||||
multiplier.Visible = false
|
||||
return elements
|
||||
end
|
||||
UI.buildElements = buildElements
|
||||
|
||||
local elements = script:FindFirstChild("Elements") or buildElements()
|
||||
|
||||
function UI.element(name: string, parent: Instance, position: UDim2?, size: UDim2?): Frame
|
||||
local template = elements:FindFirstChild(name)
|
||||
assert(template and template:IsA("Frame"), "Missing UI element " .. name)
|
||||
local frame = template:Clone()
|
||||
if position then frame.Position = position end
|
||||
if size then frame.Size = size end
|
||||
frame.Parent = parent
|
||||
return frame
|
||||
end
|
||||
|
||||
export type CoinRig = {view: ViewportFrame, model: Model, glint: Frame, intensity: UIScale}
|
||||
|
||||
function UI.bindCoin(art: Frame): CoinRig
|
||||
local view = art:WaitForChild("Viewport") :: ViewportFrame
|
||||
local camera = view:FindFirstChild("CoinCamera")
|
||||
view.CurrentCamera = if camera and camera:IsA("Camera") then camera else coinCamera(view)
|
||||
local glint = art:WaitForChild("Glint") :: Frame
|
||||
return {
|
||||
view = view, model = view:WaitForChild("WorldModel"):WaitForChild("TrophyCoin") :: Model,
|
||||
glint = glint, intensity = glint:WaitForChild("Intensity") :: UIScale,
|
||||
}
|
||||
end
|
||||
|
||||
function UI.spinCoin(rig: CoinRig, angle: number, flash: number, sweep: number)
|
||||
rig.model:PivotTo(CFrame.fromOrientation(-.09, angle, .08 + .09 * math.sin(angle * .7)))
|
||||
rig.glint.Visible = flash > .035
|
||||
if rig.glint.Visible then
|
||||
rig.intensity.Scale = .18 + .98 * flash
|
||||
rig.glint.Position = UDim2.fromScale(.75 - .23 * sweep, .23 - .05 * math.sin(math.pi * sweep))
|
||||
rig.glint.Rotation = 12 + sweep * 34
|
||||
end
|
||||
rig.view.LightColor = Color3.fromRGB(255, 226, 157):Lerp(Color3.fromRGB(255, 251, 220), flash)
|
||||
end
|
||||
|
||||
function UI.portrait(parent: Instance, pos: UDim2, size: number, accent: Color3): ImageLabel
|
||||
local template = elements:FindFirstChild("Portrait")
|
||||
assert(template and template:IsA("ImageLabel"))
|
||||
local art = template:Clone()
|
||||
art.Name, art.Position, art.Size = "Avatar", pos, UDim2.fromOffset(size, size)
|
||||
art.BackgroundColor3 = UI.Panel:Lerp(accent, .25)
|
||||
local ring = art:FindFirstChildOfClass("UIStroke")
|
||||
if ring then ring.Color = accent end
|
||||
art.Parent = parent
|
||||
return art
|
||||
end
|
||||
|
||||
function UI.plate(parent: Instance, name: string, position: UDim2, size: UDim2, accent: Color3, fill: Color3?): Frame
|
||||
local art = UI.element("Plate", parent, position, size)
|
||||
art.Name = name
|
||||
paint(art, fill or UI.Panel, accent)
|
||||
return art
|
||||
end
|
||||
|
||||
function UI.tintPlate(art: Frame, color: Color3, fill: Color3?)
|
||||
paint(art, fill or UI.Panel, color)
|
||||
end
|
||||
|
||||
type Bolt = {
|
||||
art: Frame, core: {Frame}, halo: {Frame}, points: {Vector2}, lengths: {number},
|
||||
size: Vector2, perimeter: number, phase: number,
|
||||
}
|
||||
local outlines: {[Frame]: Bolt} = {}
|
||||
local contourRender: RBXScriptConnection? = nil
|
||||
local lastContourFrame = 0
|
||||
|
||||
local function drawableScale(item: Frame): number?
|
||||
local node: Instance? = item
|
||||
local scale = 1
|
||||
while node do
|
||||
if node:IsA("GuiObject") then
|
||||
if not node.Visible then return nil end
|
||||
local modifier = node:FindFirstChildOfClass("UIScale")
|
||||
if modifier then scale *= modifier.Scale end
|
||||
elseif node:IsA("ScreenGui") then
|
||||
return if node.Enabled then scale else nil
|
||||
end
|
||||
node = node.Parent
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
local function measure(plate: Frame, bolt: Bolt, size: Vector2)
|
||||
bolt.size = size
|
||||
local cut = (plate:GetAttribute("CornerCut") :: number?) or 13
|
||||
local w, h = size.X - 1, size.Y - 1
|
||||
bolt.points = {
|
||||
Vector2.new(cut, 1), Vector2.new(w, 1), Vector2.new(w, size.Y - cut),
|
||||
Vector2.new(size.X - cut, h), Vector2.new(1, h), Vector2.new(1, cut),
|
||||
}
|
||||
bolt.perimeter = 0
|
||||
for i, point in bolt.points do
|
||||
local edgeLength = (bolt.points[i % #bolt.points + 1] - point).Magnitude
|
||||
bolt.lengths[i] = edgeLength
|
||||
bolt.perimeter += edgeLength
|
||||
end
|
||||
end
|
||||
|
||||
local function contourPoint(bolt: Bolt, distance: number, wobble: number): Vector2
|
||||
local remaining = distance % bolt.perimeter
|
||||
for i, edgeLength in bolt.lengths do
|
||||
if remaining <= edgeLength and edgeLength > 0 then
|
||||
local a, b = bolt.points[i], bolt.points[i % #bolt.points + 1]
|
||||
local direction = (b - a) / edgeLength
|
||||
return a + direction * remaining + Vector2.new(-direction.Y, direction.X) * wobble
|
||||
end
|
||||
remaining -= edgeLength
|
||||
end
|
||||
return bolt.points[1]
|
||||
end
|
||||
|
||||
local function playContours()
|
||||
local now = os.clock()
|
||||
if now - lastContourFrame < 1 / 40 then return end
|
||||
lastContourFrame = now
|
||||
for plate, bolt in outlines do
|
||||
local scale = drawableScale(plate)
|
||||
if not scale or scale < .01 then continue end
|
||||
local size = plate.AbsoluteSize / scale
|
||||
if size.X < 25 or size.Y < 24 then continue end
|
||||
if (bolt.size - size).Magnitude > .7 then measure(plate, bolt, size) end
|
||||
local accent = (bolt.art:GetAttribute("Accent") :: Color3?) or UI.Blue
|
||||
local tail = now * 218 + bolt.phase - 28
|
||||
local zigzag = math.floor(now * 16)
|
||||
local a = contourPoint(bolt, tail, 0)
|
||||
for i, core in bolt.core do
|
||||
local strength = i / #bolt.core
|
||||
local wobble = if i == #bolt.core then 0 else math.sin(i * 11.7 + zigzag * 1.9 + bolt.phase) * 2
|
||||
local b = contourPoint(bolt, tail + 28 * strength, wobble)
|
||||
local center, delta = (a + b) / 2, b - a
|
||||
local rotation = math.deg(math.atan2(delta.Y, delta.X))
|
||||
local halo = bolt.halo[i]
|
||||
halo.Rotation, core.Rotation = rotation, rotation
|
||||
local position = UDim2.fromOffset(center.X, center.Y)
|
||||
halo.Position, core.Position = position, position
|
||||
halo.Size = UDim2.fromOffset(delta.Magnitude + 3, 5)
|
||||
core.Size = UDim2.fromOffset(delta.Magnitude + 1.5, 1 + strength * 1.7)
|
||||
halo.BackgroundColor3 = accent
|
||||
core.BackgroundColor3 = accent:Lerp(white, .25 + strength * .68)
|
||||
halo.BackgroundTransparency = .97 - strength * .25
|
||||
core.BackgroundTransparency = .81 - strength * .76
|
||||
a = b
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function UI.contour(plate: Frame, accent: Color3): Frame
|
||||
local art = UI.element("ContourLightning", plate)
|
||||
art:SetAttribute("Accent", accent)
|
||||
local core: {Frame}, halo: {Frame} = {}, {}
|
||||
local coreLayer, haloLayer = art:WaitForChild("Core"), art:WaitForChild("Halo")
|
||||
for i = 1, 6 do
|
||||
table.insert(core, coreLayer:WaitForChild("Piece" .. i) :: Frame)
|
||||
table.insert(halo, haloLayer:WaitForChild("Piece" .. i) :: Frame)
|
||||
end
|
||||
outlines[plate] = {
|
||||
art = art, core = core, halo = halo, points = {}, lengths = {},
|
||||
size = Vector2.zero, perimeter = 0, phase = Random.new():NextNumber(0, 2500),
|
||||
}
|
||||
if not contourRender then contourRender = RunService.RenderStepped:Connect(playContours) end
|
||||
plate.Destroying:Once(function()
|
||||
outlines[plate] = nil
|
||||
if next(outlines) == nil and contourRender then
|
||||
contourRender:Disconnect()
|
||||
contourRender = nil
|
||||
end
|
||||
end)
|
||||
return art
|
||||
end
|
||||
|
||||
function UI.sheen(target: GuiObject)
|
||||
local glint = Instance.new("UIGradient")
|
||||
glint.Name = "Shimmer"
|
||||
glint.Color = ColorSequence.new({
|
||||
ColorSequenceKeypoint.new(0, Color3.fromRGB(163, 171, 181)),
|
||||
ColorSequenceKeypoint.new(.38, Color3.fromRGB(201, 211, 219)),
|
||||
ColorSequenceKeypoint.new(.52, white),
|
||||
ColorSequenceKeypoint.new(.65, Color3.fromRGB(210, 218, 224)),
|
||||
ColorSequenceKeypoint.new(1, Color3.fromRGB(166, 177, 187)),
|
||||
})
|
||||
glint.Offset = Vector2.new(-.64, 0)
|
||||
glint.Parent = target
|
||||
local tween = TweenService:Create(glint, TweenInfo.new(1.75, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, -1, true), {
|
||||
Offset = Vector2.new(.64, 0),
|
||||
})
|
||||
tween:Play()
|
||||
target.Destroying:Once(function() tween:Cancel() end)
|
||||
return glint
|
||||
end
|
||||
|
||||
function UI.bindButton(item: TextButton, accent: Color3, compact: boolean?)
|
||||
item.AutoButtonColor = false
|
||||
local states = if compact then nil else UI.element("ButtonStates", item)
|
||||
local caption = if compact then nil else UI.label(item, "Caption", item.Text, zero, full, item.TextSize, item.TextColor3)
|
||||
local simpleEdge = if compact then UI.edge(item, accent, .26) else nil
|
||||
if caption then
|
||||
item.BackgroundTransparency = 1
|
||||
item.TextTransparency = 1
|
||||
caption.ZIndex = item.ZIndex + 2
|
||||
end
|
||||
local scale = Instance.new("UIScale", item)
|
||||
local hovered, focused, pressed = false, false, false
|
||||
local lastTween: Tween? = nil
|
||||
if states then
|
||||
local hoverArt = states:WaitForChild("Hover") :: Frame
|
||||
local hoverTrim = hoverArt:WaitForChild("Trim"):WaitForChild("Top") :: Frame
|
||||
UI.sheen(hoverTrim)
|
||||
UI.contour(hoverArt, accent)
|
||||
end
|
||||
local function colorStates()
|
||||
if not states then return end
|
||||
local base = item.BackgroundColor3
|
||||
for _, art in states:GetChildren() do
|
||||
if art:IsA("Frame") then
|
||||
local name = art.Name
|
||||
local amount = if name == "Hover" then .27 elseif name == "Pressed" then .08 else 0
|
||||
local edge = if name == "Disabled" then UI.Panel:Lerp(UI.Muted, .28)
|
||||
elseif name == "Normal" then accent:Lerp(UI.Panel, .43) else accent
|
||||
paint(art, base:Lerp(accent, amount), edge)
|
||||
end
|
||||
end
|
||||
end
|
||||
local function update()
|
||||
local enabled = item.Interactable and item.Visible
|
||||
local nextState = if not enabled then "Disabled" elseif pressed then "Pressed" elseif hovered or focused then "Hover" else "Normal"
|
||||
if item:GetAttribute("UIState") == nextState then return end
|
||||
item:SetAttribute("UIState", nextState)
|
||||
if states then
|
||||
for _, art in states:GetChildren() do
|
||||
if art:IsA("GuiObject") then art.Visible = art.Name == nextState end
|
||||
end
|
||||
elseif simpleEdge then
|
||||
simpleEdge.Transparency = if nextState == "Pressed" then 0 elseif nextState == "Hover" then .12 else .74
|
||||
end
|
||||
if lastTween then lastTween:Cancel() end
|
||||
lastTween = TweenService:Create(scale, motion, {Scale = if nextState == "Pressed" then .965 elseif nextState == "Hover" then 1.02 else 1})
|
||||
lastTween:Play()
|
||||
end
|
||||
local function copyText()
|
||||
if not caption then return end
|
||||
caption.Text, caption.TextColor3, caption.TextSize = item.Text, item.TextColor3, item.TextSize
|
||||
caption.FontFace, caption.TextScaled = item.FontFace, item.TextScaled
|
||||
end
|
||||
copyText()
|
||||
if caption then
|
||||
for _, prop in {"Text", "TextColor3", "TextSize", "FontFace", "TextScaled"} do
|
||||
item:GetPropertyChangedSignal(prop):Connect(copyText)
|
||||
end
|
||||
item:GetPropertyChangedSignal("BackgroundColor3"):Connect(colorStates)
|
||||
end
|
||||
item.MouseEnter:Connect(function() hovered = true update() end)
|
||||
item.MouseLeave:Connect(function() hovered, pressed = false, false update() end)
|
||||
item.SelectionGained:Connect(function() focused = true update() end)
|
||||
item.SelectionLost:Connect(function() focused, pressed = false, false update() end)
|
||||
local function isPress(input: InputObject): boolean
|
||||
return input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch
|
||||
or input.KeyCode == Enum.KeyCode.ButtonA or input.KeyCode == Enum.KeyCode.Return
|
||||
end
|
||||
item.InputBegan:Connect(function(input)
|
||||
if isPress(input) and item.Interactable then pressed = true update() end
|
||||
end)
|
||||
item.InputEnded:Connect(function(input)
|
||||
if isPress(input) then pressed = false update() end
|
||||
end)
|
||||
for _, prop in {"Interactable", "Visible"} do
|
||||
item:GetPropertyChangedSignal(prop):Connect(function()
|
||||
if not item.Visible or not item.Interactable then hovered, focused, pressed = false, false, false end
|
||||
update()
|
||||
end)
|
||||
end
|
||||
colorStates()
|
||||
update()
|
||||
end
|
||||
|
||||
function UI.hoverRow(row: Frame, accent: Color3)
|
||||
local overlay = UI.element("RowHighlight", row)
|
||||
overlay.BackgroundColor3 = accent
|
||||
local animation: Tween? = nil
|
||||
local function update(hovered: boolean)
|
||||
local on = hovered and row.Visible and row.Interactable
|
||||
row:SetAttribute("UIState", if on then "Hover" else "Normal")
|
||||
if animation then animation:Cancel() end
|
||||
animation = TweenService:Create(overlay, motion, {BackgroundTransparency = if on then .80 else 1})
|
||||
animation:Play()
|
||||
end
|
||||
row.MouseEnter:Connect(function() update(true) end)
|
||||
row.MouseLeave:Connect(function() update(false) end)
|
||||
row:GetPropertyChangedSignal("Visible"):Connect(function() if not row.Visible then update(false) end end)
|
||||
row:GetPropertyChangedSignal("Interactable"):Connect(function() if not row.Interactable then update(false) end end)
|
||||
row:SetAttribute("UIState", "Normal")
|
||||
end
|
||||
|
||||
return UI
|
||||
@@ -0,0 +1,257 @@
|
||||
--!strict
|
||||
-- LocalScript in StarterPlayerScripts.
|
||||
-- Kill feed in the top right corner: every kill in the server (ReplicatedStorage.KillFeed:
|
||||
-- killerName, victimName, headshot, killerUserId) adds a row "killer [headshot icon] [rifle] victim".
|
||||
-- Rows the local player made have a yellow frame. Newest at the top, up to MAX rows; each stays
|
||||
-- LIFE seconds, then fades out. The rifle icon is the real SniperRifle model in a ViewportFrame.
|
||||
|
||||
local Players = game:GetService("Players")
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local TweenService = game:GetService("TweenService")
|
||||
local UI = require(ReplicatedStorage:WaitForChild("HunterUI") :: ModuleScript)
|
||||
|
||||
local LIFE = 6
|
||||
local FADE = 0.4
|
||||
local MAX = 5
|
||||
local NAME_RED = Color3.fromRGB(255, 166, 141)
|
||||
local OWN_FRAME = UI.Gold
|
||||
local DARK = UI.Panel
|
||||
local OUTLINE = Color3.fromRGB(20, 20, 28)
|
||||
|
||||
local player = Players.LocalPlayer
|
||||
local playerGui = player:WaitForChild("PlayerGui")
|
||||
local feedRemote = ReplicatedStorage:WaitForChild("KillFeed") :: RemoteEvent
|
||||
|
||||
local gui = Instance.new("ScreenGui")
|
||||
gui.Name = "KillFeed"
|
||||
gui.ResetOnSpawn = false
|
||||
gui.DisplayOrder = 11
|
||||
gui.Parent = playerGui
|
||||
|
||||
local stack = Instance.new("Frame")
|
||||
stack.AnchorPoint = Vector2.new(1, 0)
|
||||
stack.Position = UDim2.new(1, -12, 0, 12)
|
||||
stack.Size = UDim2.fromOffset(520, 400)
|
||||
stack.BackgroundTransparency = 1
|
||||
stack.Parent = gui
|
||||
task.defer(function()
|
||||
local matchHud = playerGui:WaitForChild("ArenaRoundHud", 10)
|
||||
if not matchHud then return end
|
||||
local function placeBelowMatchHud()
|
||||
local base = ((matchHud:GetAttribute("ContentBottom") :: number?) or 72) + 8
|
||||
stack.Position = UDim2.new(1, -12, 0, base)
|
||||
end
|
||||
matchHud:GetAttributeChangedSignal("ContentBottom"):Connect(placeBelowMatchHud)
|
||||
placeBelowMatchHud()
|
||||
end)
|
||||
local list = Instance.new("UIListLayout")
|
||||
list.HorizontalAlignment = Enum.HorizontalAlignment.Right
|
||||
list.SortOrder = Enum.SortOrder.LayoutOrder
|
||||
list.Padding = UDim.new(0, 6)
|
||||
list.Parent = stack
|
||||
|
||||
-- the rifle, once: its visible parts in a model, posed side-on (its long axis is X)
|
||||
local rifleModel: Model? = nil
|
||||
do
|
||||
local tool = ReplicatedStorage:WaitForChild("ArenaEquipment"):FindFirstChild("SniperRifle")
|
||||
if tool then
|
||||
local m = Instance.new("Model")
|
||||
for _, p in tool:GetDescendants() do
|
||||
if p:IsA("BasePart") and p.Transparency < 1 then
|
||||
local c = p:Clone()
|
||||
c:ClearAllChildren()
|
||||
c.Anchored = true
|
||||
c.Parent = m
|
||||
end
|
||||
end
|
||||
if #m:GetChildren() > 0 then
|
||||
rifleModel = m
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function rifleIcon(parent: Instance, order: number)
|
||||
local vp = Instance.new("ViewportFrame")
|
||||
vp.Size = UDim2.fromOffset(92, 34)
|
||||
vp.BackgroundTransparency = 1
|
||||
vp.LayoutOrder = order
|
||||
vp.Ambient = Color3.fromRGB(200, 200, 210)
|
||||
vp.LightColor = Color3.new(1, 1, 1)
|
||||
vp.LightDirection = Vector3.new(-0.3, -1, -0.5)
|
||||
vp.Parent = parent
|
||||
local source = rifleModel
|
||||
if not source then
|
||||
return
|
||||
end
|
||||
local m = source:Clone()
|
||||
m.Parent = vp
|
||||
m.WorldPivot = CFrame.new(m:GetPivot().Position) -- world-aligned box
|
||||
local cf, size = m:GetBoundingBox()
|
||||
local cam = Instance.new("Camera")
|
||||
cam.FieldOfView = 20
|
||||
-- side view (looking along Z), far enough for the length to fill the frame width
|
||||
local halfTan = math.tan(math.rad(cam.FieldOfView / 2))
|
||||
local dist = math.max((size.X / 2) / (halfTan * 92 / 34), (size.Y / 2) / halfTan) * 1.08 + size.Z / 2
|
||||
cam.CFrame = CFrame.lookAt(cf.Position + Vector3.zAxis * dist, cf.Position)
|
||||
cam.Parent = vp
|
||||
vp.CurrentCamera = cam
|
||||
end
|
||||
|
||||
-- headshot: a small crosshair (ring, four ticks, dot)
|
||||
local function headshotIcon(parent: Instance, order: number)
|
||||
local icon = Instance.new("Frame")
|
||||
icon.Size = UDim2.fromOffset(24, 24)
|
||||
icon.BackgroundTransparency = 1
|
||||
icon.LayoutOrder = order
|
||||
local ring = Instance.new("Frame")
|
||||
ring.AnchorPoint = Vector2.new(0.5, 0.5)
|
||||
ring.Position = UDim2.fromScale(0.5, 0.5)
|
||||
ring.Size = UDim2.fromOffset(15, 15)
|
||||
ring.BackgroundTransparency = 1
|
||||
local rc = Instance.new("UICorner")
|
||||
rc.CornerRadius = UDim.new(1, 0)
|
||||
rc.Parent = ring
|
||||
local rs = Instance.new("UIStroke")
|
||||
rs.Color = Color3.new(1, 1, 1)
|
||||
rs.Thickness = 2
|
||||
rs.Parent = ring
|
||||
ring.Parent = icon
|
||||
local function tick(x: number, y: number, w: number, h: number)
|
||||
local f = Instance.new("Frame")
|
||||
f.AnchorPoint = Vector2.new(0.5, 0.5)
|
||||
f.Position = UDim2.new(0.5, x, 0.5, y)
|
||||
f.Size = UDim2.fromOffset(w, h)
|
||||
f.BackgroundColor3 = Color3.new(1, 1, 1)
|
||||
f.BorderSizePixel = 0
|
||||
f.Parent = icon
|
||||
end
|
||||
tick(0, -10, 2, 6)
|
||||
tick(0, 10, 2, 6)
|
||||
tick(-10, 0, 6, 2)
|
||||
tick(10, 0, 6, 2)
|
||||
tick(0, 0, 3, 3)
|
||||
icon.Parent = parent
|
||||
end
|
||||
|
||||
local function nameLabel(parent: Instance, text: string, order: number)
|
||||
local l = Instance.new("TextLabel")
|
||||
l.BackgroundTransparency = 1
|
||||
l.AutomaticSize = Enum.AutomaticSize.XY
|
||||
l.Size = UDim2.new()
|
||||
l.Font = Enum.Font.GothamBold
|
||||
l.Text = text
|
||||
l.TextSize = 15
|
||||
l.TextColor3 = if order == 1 then UI.Ink else NAME_RED
|
||||
l.LayoutOrder = order
|
||||
local s = Instance.new("UIStroke")
|
||||
s.Color = OUTLINE
|
||||
s.Thickness = 1.5
|
||||
s.Parent = l
|
||||
l.Parent = parent
|
||||
end
|
||||
|
||||
local order = 0
|
||||
local function addRow(killer: string, victim: string, headshot: boolean, own: boolean)
|
||||
order -= 1 -- newest on top
|
||||
local row = Instance.new("CanvasGroup")
|
||||
row.AutomaticSize = Enum.AutomaticSize.X
|
||||
row.Size = UDim2.fromOffset(0, 42)
|
||||
row.BackgroundColor3 = DARK
|
||||
row.BackgroundTransparency = 0.25
|
||||
row.LayoutOrder = order
|
||||
local c = Instance.new("UICorner")
|
||||
c.CornerRadius = UDim.new(0, 8)
|
||||
c.Parent = row
|
||||
local pad = Instance.new("UIPadding")
|
||||
pad.PaddingLeft = UDim.new(0, 14)
|
||||
pad.PaddingRight = UDim.new(0, 14)
|
||||
pad.Parent = row
|
||||
local layout = Instance.new("UIListLayout")
|
||||
layout.FillDirection = Enum.FillDirection.Horizontal
|
||||
layout.VerticalAlignment = Enum.VerticalAlignment.Center
|
||||
layout.SortOrder = Enum.SortOrder.LayoutOrder
|
||||
layout.Padding = UDim.new(0, 8)
|
||||
layout.Parent = row
|
||||
|
||||
nameLabel(row, killer, 1)
|
||||
if headshot then
|
||||
headshotIcon(row, 2)
|
||||
end
|
||||
rifleIcon(row, 3)
|
||||
nameLabel(row, victim, 4)
|
||||
|
||||
-- the player's own kills: a yellow frame (on a holder: a CanvasGroup clips its own stroke)
|
||||
local holder: GuiObject = row
|
||||
if own then
|
||||
local framed = Instance.new("Frame")
|
||||
framed.AutomaticSize = Enum.AutomaticSize.X
|
||||
framed.Size = UDim2.fromOffset(0, 42)
|
||||
framed.BackgroundTransparency = 1
|
||||
framed.LayoutOrder = order
|
||||
local fc = Instance.new("UICorner")
|
||||
fc.CornerRadius = UDim.new(0, 8)
|
||||
fc.Parent = framed
|
||||
local fs = Instance.new("UIStroke")
|
||||
fs.Color = OWN_FRAME
|
||||
fs.Thickness = 2.5
|
||||
fs.ApplyStrokeMode = Enum.ApplyStrokeMode.Border
|
||||
fs.Parent = framed
|
||||
row.Parent = framed
|
||||
holder = framed
|
||||
end
|
||||
|
||||
local scale = Instance.new("UIScale")
|
||||
scale.Scale = 1.25
|
||||
scale.Parent = holder
|
||||
row.GroupTransparency = 1
|
||||
holder.Parent = stack
|
||||
TweenService:Create(scale, TweenInfo.new(0.2, Enum.EasingStyle.Back, Enum.EasingDirection.Out), { Scale = 1 }):Play()
|
||||
TweenService:Create(row, TweenInfo.new(0.12), { GroupTransparency = 0 }):Play()
|
||||
|
||||
-- keep only the newest MAX rows
|
||||
local rows = {}
|
||||
for _, r in stack:GetChildren() do
|
||||
if r:IsA("GuiObject") then
|
||||
table.insert(rows, r)
|
||||
end
|
||||
end
|
||||
table.sort(rows, function(a, b)
|
||||
return a.LayoutOrder < b.LayoutOrder
|
||||
end)
|
||||
for i = MAX + 1, #rows do
|
||||
rows[i]:Destroy()
|
||||
end
|
||||
|
||||
task.delay(LIFE, function()
|
||||
if not holder.Parent then
|
||||
return
|
||||
end
|
||||
TweenService:Create(row, TweenInfo.new(FADE), { GroupTransparency = 1 }):Play()
|
||||
for _, s in holder:GetChildren() do
|
||||
if s:IsA("UIStroke") then
|
||||
TweenService:Create(s, TweenInfo.new(FADE), { Transparency = 1 }):Play()
|
||||
end
|
||||
end
|
||||
task.wait(FADE)
|
||||
holder:Destroy()
|
||||
end)
|
||||
end
|
||||
|
||||
local SniperEffects = require(ReplicatedStorage:WaitForChild("SniperEffects")) :: any
|
||||
player:GetAttributeChangedSignal("InArena"):Connect(function()
|
||||
if player:GetAttribute("InArena") == true then return end
|
||||
for _, row in stack:GetChildren() do
|
||||
if row:IsA("GuiObject") then row:Destroy() end
|
||||
end
|
||||
end)
|
||||
|
||||
feedRemote.OnClientEvent:Connect(function(killer: unknown, victim: unknown, headshot: unknown, killerId: unknown, model: unknown)
|
||||
if player:GetAttribute("InArena") ~= true then return end
|
||||
if typeof(killer) == "string" and typeof(victim) == "string" then
|
||||
addRow(killer, victim, headshot == true, killerId == player.UserId)
|
||||
end
|
||||
-- the victim's body breaks apart in a fiery blast
|
||||
if typeof(model) == "Instance" and model:IsA("Model") then
|
||||
SniperEffects.destroy(model, killerId == player.UserId)
|
||||
end
|
||||
end)
|
||||
@@ -0,0 +1,109 @@
|
||||
--!strict
|
||||
-- V toggles the lobby camera. Arena entry always selects first person.
|
||||
|
||||
local Players = game:GetService("Players")
|
||||
local RunService = game:GetService("RunService")
|
||||
local StarterGui = game:GetService("StarterGui")
|
||||
local UserInputService = game:GetService("UserInputService")
|
||||
|
||||
local player = Players.LocalPlayer
|
||||
local config = player:WaitForChild("PlayerScripts"):WaitForChild("SniperViewmodel")
|
||||
local lobbyThirdPerson = true
|
||||
|
||||
local respawnGui = Instance.new("ScreenGui")
|
||||
respawnGui.Name = "RespawnScreen"
|
||||
respawnGui.ResetOnSpawn = false
|
||||
respawnGui.DisplayOrder = 1000
|
||||
respawnGui.ScreenInsets = Enum.ScreenInsets.None
|
||||
respawnGui.Enabled = false
|
||||
respawnGui.Parent = player:WaitForChild("PlayerGui")
|
||||
|
||||
local cover = Instance.new("Frame")
|
||||
cover.Name = "Cover"
|
||||
cover.Size = UDim2.fromScale(1, 1)
|
||||
cover.BackgroundColor3 = Color3.fromRGB(10, 16, 28)
|
||||
cover.BorderSizePixel = 0
|
||||
cover.Active = true
|
||||
cover.Parent = respawnGui
|
||||
|
||||
local message = Instance.new("TextLabel")
|
||||
message.AnchorPoint = Vector2.new(.5, .5)
|
||||
message.Position = UDim2.fromScale(.5, .5)
|
||||
message.Size = UDim2.new(1, -32, 0, 38)
|
||||
message.BackgroundTransparency = 1
|
||||
message.Font = Enum.Font.GothamBold
|
||||
message.Text = "Возрождение…"
|
||||
message.TextSize = 24
|
||||
message.TextColor3 = Color3.fromRGB(240, 244, 255)
|
||||
message.Parent = cover
|
||||
|
||||
local deathConnection: RBXScriptConnection? = nil
|
||||
|
||||
local function conceal()
|
||||
respawnGui.Enabled = true
|
||||
local camera = workspace.CurrentCamera
|
||||
if camera then camera.CameraType = Enum.CameraType.Scriptable end
|
||||
end
|
||||
|
||||
local function followCharacter(character: Model)
|
||||
local humanoid = character:WaitForChild("Humanoid", 10)
|
||||
if not humanoid or not humanoid:IsA("Humanoid") or player.Character ~= character then return end
|
||||
if deathConnection then deathConnection:Disconnect() end
|
||||
deathConnection = humanoid.Died:Connect(function()
|
||||
if player.Character == character then conceal() end
|
||||
end)
|
||||
if humanoid.Health <= 0 then
|
||||
conceal()
|
||||
return
|
||||
end
|
||||
if not respawnGui.Enabled then return end
|
||||
|
||||
local root = character:WaitForChild("HumanoidRootPart", 10)
|
||||
if not root or player.Character ~= character or humanoid.Health <= 0 then return end
|
||||
local camera = workspace.CurrentCamera
|
||||
if camera then
|
||||
camera.CameraSubject = humanoid
|
||||
camera.CameraType = Enum.CameraType.Custom
|
||||
end
|
||||
-- Keep the cover in place until the camera has rendered from the new character.
|
||||
RunService.RenderStepped:Wait()
|
||||
RunService.RenderStepped:Wait()
|
||||
if player.Character == character and humanoid.Health > 0 then respawnGui.Enabled = false end
|
||||
end
|
||||
|
||||
player.CharacterRemoving:Connect(function()
|
||||
if deathConnection then deathConnection:Disconnect() deathConnection = nil end
|
||||
if player:GetAttribute("InArena") == true then conceal() end
|
||||
end)
|
||||
player.CharacterAdded:Connect(followCharacter)
|
||||
if player.Character then task.spawn(followCharacter, player.Character) end
|
||||
|
||||
local function applyView(thirdPerson: boolean)
|
||||
config:SetAttribute("ThirdPersonView", thirdPerson)
|
||||
player.CameraMode = if thirdPerson then Enum.CameraMode.Classic else Enum.CameraMode.LockFirstPerson
|
||||
if thirdPerson then
|
||||
player.CameraMaxZoomDistance = 128
|
||||
player.CameraMinZoomDistance = 3
|
||||
else
|
||||
player.CameraMinZoomDistance = 0.5
|
||||
player.CameraMaxZoomDistance = 0.5
|
||||
end
|
||||
end
|
||||
|
||||
local function applyZone()
|
||||
local inArena = player:GetAttribute("InArena") == true
|
||||
applyView(not inArena and lobbyThirdPerson)
|
||||
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
|
||||
end
|
||||
player:GetAttributeChangedSignal("InArena"):Connect(applyZone)
|
||||
applyZone()
|
||||
|
||||
UserInputService.InputBegan:Connect(function(input: InputObject, processed: boolean)
|
||||
if processed or respawnGui.Enabled or UserInputService:GetFocusedTextBox() then
|
||||
return
|
||||
end
|
||||
if input.KeyCode == Enum.KeyCode.V and player:GetAttribute("InArena") ~= true then
|
||||
lobbyThirdPerson = config:GetAttribute("ThirdPersonView") ~= true
|
||||
applyView(lobbyThirdPerson)
|
||||
end
|
||||
end)
|
||||
@@ -0,0 +1,27 @@
|
||||
--!strict
|
||||
local LootMagnet = {Radius = 12, Duration = .38}
|
||||
|
||||
function LootMagnet.canReach(playerPosition: Vector3, dropPosition: Vector3, radius: number, geometry: RaycastParams): boolean
|
||||
local delta = dropPosition - playerPosition
|
||||
local distance = delta.Magnitude
|
||||
return distance <= radius and (distance < .01 or workspace:Raycast(playerPosition, delta, geometry) == nil)
|
||||
end
|
||||
|
||||
function LootMagnet.curve(start: Vector3, target: Vector3, elapsed: number, angle: number): (Vector3, number)
|
||||
local progress = math.clamp(elapsed / LootMagnet.Duration, 0, 1)
|
||||
local t = progress ^ 1.65
|
||||
local side = Vector3.new(math.cos(angle), 0, math.sin(angle)) * 1.5
|
||||
local bend = start:Lerp(target, .35) + Vector3.yAxis * 2.85 + side
|
||||
return start:Lerp(bend, t):Lerp(bend:Lerp(target, t), t), progress
|
||||
end
|
||||
|
||||
function LootMagnet.catchPoint(character: Model?, camera: Camera?): Vector3?
|
||||
local head = character and character:FindFirstChild("Head")
|
||||
if head and head:IsA("BasePart") and camera and (camera.CFrame.Position - head.Position).Magnitude < 3 then
|
||||
return (camera.CFrame * CFrame.new(.43, -.48, -1.7)).Position
|
||||
end
|
||||
local root = character and character.PrimaryPart
|
||||
return if root then root.Position + Vector3.yAxis * 1.35 else nil
|
||||
end
|
||||
|
||||
return table.freeze(LootMagnet)
|
||||
@@ -0,0 +1,379 @@
|
||||
--!strict
|
||||
-- LocalScript in StarterPlayerScripts.
|
||||
-- Main menu shown when the player joins: pick a game mode and customize the weapon,
|
||||
-- then press "Play" to spawn into the map with that loadout. "Play" fires
|
||||
-- ReplicatedStorage.RequestSpawn; the server (EquipRifle) loads the character and equips
|
||||
-- the rifle. The chosen sight is sent to the server through ReplicatedStorage.RifleSight
|
||||
-- (RifleSights keeps it on the player and applies it to every new rifle).
|
||||
|
||||
local Players = game:GetService("Players")
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local TweenService = game:GetService("TweenService")
|
||||
|
||||
local player = Players.LocalPlayer
|
||||
local playerGui = player:WaitForChild("PlayerGui")
|
||||
|
||||
local requestSpawn = ReplicatedStorage:WaitForChild("RequestSpawn") :: RemoteEvent
|
||||
local sightRemote = ReplicatedStorage:WaitForChild("RifleSight") :: RemoteEvent
|
||||
local sights = ReplicatedStorage:WaitForChild("RifleParts"):WaitForChild("Sights")
|
||||
local rifleTemplate = ReplicatedStorage:WaitForChild("SniperViewmodel") :: Model
|
||||
|
||||
-- ---------------------------------------------------------------- theme
|
||||
local DARK = Color3.fromRGB(14, 14, 20)
|
||||
local PANEL = Color3.fromRGB(23, 23, 33)
|
||||
local PANEL_LIGHT = Color3.fromRGB(30, 30, 42)
|
||||
local ACCENT = Color3.fromRGB(255, 200, 40)
|
||||
local ACCENT_DIM = Color3.fromRGB(120, 96, 24)
|
||||
local TEXT = Color3.fromRGB(238, 238, 244)
|
||||
local MUTED = Color3.fromRGB(150, 150, 168)
|
||||
local OUTLINE = Color3.fromRGB(10, 10, 14)
|
||||
local FONT = Enum.Font.GothamBold
|
||||
|
||||
local MODES = { "Free Roam", "Hunt", "Elimination" }
|
||||
local SIGHTS = { "Iron", "RedDot", "Scope" }
|
||||
|
||||
local chosenMode = MODES[1]
|
||||
local chosenSight = SIGHTS[1]
|
||||
|
||||
-- ---------------------------------------------------------------- gui
|
||||
local gui = Instance.new("ScreenGui")
|
||||
gui.Name = "MainMenu"
|
||||
gui.ResetOnSpawn = false
|
||||
gui.DisplayOrder = 100
|
||||
gui.IgnoreGuiInset = true
|
||||
gui.Parent = playerGui
|
||||
|
||||
local backdrop = Instance.new("Frame")
|
||||
backdrop.AnchorPoint = Vector2.new(0.5, 0.5)
|
||||
backdrop.Position = UDim2.fromScale(0.5, 0.5)
|
||||
backdrop.Size = UDim2.fromScale(1, 1)
|
||||
backdrop.BackgroundColor3 = DARK
|
||||
backdrop.BackgroundTransparency = 0.08
|
||||
backdrop.Parent = gui
|
||||
|
||||
local title = Instance.new("TextLabel")
|
||||
title.AnchorPoint = Vector2.new(0.5, 0)
|
||||
title.Position = UDim2.fromScale(0.5, 0.08)
|
||||
title.Size = UDim2.fromOffset(600, 90)
|
||||
title.BackgroundTransparency = 1
|
||||
title.Font = Enum.Font.GothamBlack
|
||||
title.Text = "HUNTER"
|
||||
title.TextSize = 62
|
||||
title.TextColor3 = TEXT
|
||||
title.TextStrokeTransparency = 0.6
|
||||
title.Parent = gui
|
||||
local titleShadow = Instance.new("UIStroke")
|
||||
titleShadow.Color = OUTLINE
|
||||
titleShadow.Thickness = 2
|
||||
titleShadow.Parent = title
|
||||
|
||||
local subtitle = Instance.new("TextLabel")
|
||||
subtitle.AnchorPoint = Vector2.new(0.5, 0)
|
||||
subtitle.Position = UDim2.fromScale(0.5, 0.165)
|
||||
subtitle.Size = UDim2.fromOffset(600, 40)
|
||||
subtitle.BackgroundTransparency = 1
|
||||
subtitle.Font = Enum.Font.Gotham
|
||||
subtitle.Text = "Choose your hunt"
|
||||
subtitle.TextSize = 18
|
||||
subtitle.TextColor3 = MUTED
|
||||
subtitle.Parent = gui
|
||||
|
||||
-- a helper for a rounded panel with a soft border
|
||||
local function panel(parent: Instance): Frame
|
||||
local f = Instance.new("Frame")
|
||||
f.BackgroundColor3 = PANEL
|
||||
f.Parent = parent
|
||||
local corner = Instance.new("UICorner")
|
||||
corner.CornerRadius = UDim.new(0, 14)
|
||||
corner.Parent = f
|
||||
local stroke = Instance.new("UIStroke")
|
||||
stroke.Color = OUTLINE
|
||||
stroke.Thickness = 2
|
||||
stroke.Parent = f
|
||||
return f
|
||||
end
|
||||
|
||||
local function sectionLabel(parent: Instance, text: string): TextLabel
|
||||
local l = Instance.new("TextLabel")
|
||||
l.BackgroundTransparency = 1
|
||||
l.Font = FONT
|
||||
l.Text = text
|
||||
l.TextSize = 15
|
||||
l.TextColor3 = ACCENT
|
||||
l.TextXAlignment = Enum.TextXAlignment.Left
|
||||
l.Parent = parent
|
||||
return l
|
||||
end
|
||||
|
||||
-- ---------------------------------------------------------------- game mode column
|
||||
local modePanel = panel(gui)
|
||||
modePanel.AnchorPoint = Vector2.new(0, 0.5)
|
||||
modePanel.Position = UDim2.fromScale(0.07, 0.55)
|
||||
modePanel.Size = UDim2.fromOffset(360, 460)
|
||||
modePanel.Parent = gui
|
||||
local modeLayout = Instance.new("UIListLayout")
|
||||
modeLayout.Padding = UDim.new(0, 12)
|
||||
modeLayout.SortOrder = Enum.SortOrder.LayoutOrder
|
||||
modeLayout.Parent = modePanel
|
||||
local modePad = Instance.new("UIPadding")
|
||||
modePad.PaddingLeft = UDim.new(0, 22)
|
||||
modePad.PaddingRight = UDim.new(0, 22)
|
||||
modePad.PaddingTop = UDim.new(0, 22)
|
||||
modePad.PaddingBottom = UDim.new(0, 22)
|
||||
modePad.Parent = modePanel
|
||||
sectionLabel(modePanel, "GAME MODE").LayoutOrder = 0
|
||||
|
||||
local modeButtons: { [string]: Frame } = {}
|
||||
local function buildModeButtons()
|
||||
for i, name in MODES do
|
||||
local b = Instance.new("Frame")
|
||||
b.Name = name
|
||||
b.Size = UDim2.fromOffset(316, 110)
|
||||
b.BackgroundColor3 = PANEL_LIGHT
|
||||
b.LayoutOrder = i
|
||||
local corner = Instance.new("UICorner")
|
||||
corner.CornerRadius = UDim.new(0, 10)
|
||||
corner.Parent = b
|
||||
local stroke = Instance.new("UIStroke")
|
||||
stroke.Color = OUTLINE
|
||||
stroke.Thickness = 2
|
||||
stroke.Parent = b
|
||||
local icon = Instance.new("Frame")
|
||||
icon.Size = UDim2.fromOffset(54, 54)
|
||||
icon.Position = UDim2.new(0, 18, 0.5, -27)
|
||||
icon.BackgroundColor3 = ACCENT
|
||||
icon.BackgroundTransparency = 0.15
|
||||
icon.Parent = b
|
||||
local ic = Instance.new("UICorner")
|
||||
ic.CornerRadius = UDim.new(0, 8)
|
||||
ic.Parent = icon
|
||||
local title2 = Instance.new("TextLabel")
|
||||
title2.Position = UDim2.new(0, 86, 0, 22)
|
||||
title2.Size = UDim2.fromOffset(210, 30)
|
||||
title2.BackgroundTransparency = 1
|
||||
title2.Font = FONT
|
||||
title2.Text = name
|
||||
title2.TextSize = 22
|
||||
title2.TextColor3 = TEXT
|
||||
title2.TextXAlignment = Enum.TextXAlignment.Left
|
||||
title2.Parent = b
|
||||
local desc = Instance.new("TextLabel")
|
||||
desc.Position = UDim2.new(0, 86, 0, 56)
|
||||
desc.Size = UDim2.fromOffset(210, 34)
|
||||
desc.BackgroundTransparency = 1
|
||||
desc.Font = Enum.Font.Gotham
|
||||
desc.Text = if name == "Free Roam" then "Explore and hunt freely"
|
||||
elseif name == "Hunt" then "Hunt the target bots"
|
||||
else "Last one standing"
|
||||
desc.TextSize = 13
|
||||
desc.TextColor3 = MUTED
|
||||
desc.TextXAlignment = Enum.TextXAlignment.Left
|
||||
desc.TextWrapped = true
|
||||
desc.Parent = b
|
||||
local check = Instance.new("TextLabel")
|
||||
check.Name = "Check"
|
||||
check.AnchorPoint = Vector2.new(1, 0.5)
|
||||
check.Position = UDim2.new(1, -16, 0.5, 0)
|
||||
check.Size = UDim2.fromOffset(30, 30)
|
||||
check.BackgroundTransparency = 1
|
||||
check.Font = FONT
|
||||
check.Text = "✓"
|
||||
check.TextSize = 26
|
||||
check.TextColor3 = ACCENT
|
||||
check.Visible = false
|
||||
check.Parent = b
|
||||
local btn = Instance.new("TextButton")
|
||||
btn.Size = UDim2.fromScale(1, 1)
|
||||
btn.BackgroundTransparency = 1
|
||||
btn.Text = ""
|
||||
btn.Parent = b
|
||||
btn.MouseButton1Click:Connect(function()
|
||||
chosenMode = name
|
||||
for _, other in modeButtons do
|
||||
other.BackgroundColor3 = PANEL_LIGHT
|
||||
other:FindFirstChild("Check").Visible = false
|
||||
end
|
||||
b.BackgroundColor3 = ACCENT_DIM
|
||||
check.Visible = true
|
||||
end)
|
||||
b.Parent = modePanel
|
||||
modeButtons[name] = b
|
||||
end
|
||||
end
|
||||
|
||||
-- ---------------------------------------------------------------- weapon column
|
||||
local weaponPanel = panel(gui)
|
||||
weaponPanel.AnchorPoint = Vector2.new(1, 0.5)
|
||||
weaponPanel.Position = UDim2.fromScale(0.93, 0.55)
|
||||
weaponPanel.Size = UDim2.fromOffset(360, 460)
|
||||
weaponPanel.Parent = gui
|
||||
local weaponLayout = Instance.new("UIListLayout")
|
||||
weaponLayout.Padding = UDim.new(0, 12)
|
||||
weaponLayout.SortOrder = Enum.SortOrder.LayoutOrder
|
||||
weaponLayout.Parent = weaponPanel
|
||||
local weaponPad = Instance.new("UIPadding")
|
||||
weaponPad.PaddingLeft = UDim.new(0, 22)
|
||||
weaponPad.PaddingRight = UDim.new(0, 22)
|
||||
weaponPad.PaddingTop = UDim.new(0, 22)
|
||||
weaponPad.PaddingBottom = UDim.new(0, 22)
|
||||
weaponPad.Parent = weaponPanel
|
||||
sectionLabel(weaponPanel, "WEAPON — Sniper Rifle").LayoutOrder = 0
|
||||
|
||||
-- rifle preview in a ViewportFrame (the template with the chosen sight applied)
|
||||
local preview = Instance.new("ViewportFrame")
|
||||
preview.Size = UDim2.fromOffset(316, 170)
|
||||
preview.BackgroundColor3 = PANEL_LIGHT
|
||||
preview.LayoutOrder = 1
|
||||
preview.Ambient = Color3.fromRGB(190, 190, 205)
|
||||
preview.LightColor = Color3.new(1, 1, 1)
|
||||
preview.LightDirection = Vector3.new(-0.3, -1, -0.5)
|
||||
local previewCorner = Instance.new("UICorner")
|
||||
previewCorner.CornerRadius = UDim.new(0, 10)
|
||||
previewCorner.Parent = preview
|
||||
preview.Parent = weaponPanel
|
||||
|
||||
local previewModel: Model = rifleTemplate:Clone()
|
||||
for _, d in previewModel:GetDescendants() do
|
||||
if d:IsA("BasePart") then
|
||||
d.Anchored = true
|
||||
d.CastShadow = false
|
||||
end
|
||||
end
|
||||
previewModel.Parent = preview
|
||||
local previewCam = Instance.new("Camera")
|
||||
previewCam.FieldOfView = 18
|
||||
previewCam.Parent = preview
|
||||
preview.CurrentCamera = previewCam
|
||||
|
||||
local function applyPreviewSight()
|
||||
local old = previewModel:FindFirstChild("Sight")
|
||||
if old then
|
||||
old:Destroy()
|
||||
end
|
||||
local source = sights:FindFirstChild(chosenSight)
|
||||
if not source or not source:IsA("Model") then
|
||||
return
|
||||
end
|
||||
local sight = source:Clone()
|
||||
sight.Name = "Sight"
|
||||
sight:PivotTo(previewModel:GetPivot())
|
||||
for _, d in sight:GetDescendants() do
|
||||
if d:IsA("BasePart") then
|
||||
d.Anchored = true
|
||||
d.CastShadow = false
|
||||
end
|
||||
end
|
||||
sight.Parent = previewModel
|
||||
-- frame the rifle in the preview
|
||||
previewModel.WorldPivot = CFrame.new(previewModel:GetPivot().Position)
|
||||
local cf, size = previewModel:GetBoundingBox()
|
||||
local halfTan = math.tan(math.rad(previewCam.FieldOfView / 2))
|
||||
local dist = math.max((size.X / 2) / (halfTan * 316 / 170), (size.Y / 2) / halfTan) * 1.1 + size.Z / 2
|
||||
previewCam.CFrame = CFrame.lookAt(cf.Position + Vector3.zAxis * dist, cf.Position)
|
||||
end
|
||||
|
||||
local sightLabel = Instance.new("TextLabel")
|
||||
sightLabel.BackgroundTransparency = 1
|
||||
sightLabel.Font = FONT
|
||||
sightLabel.Text = "SIGHT"
|
||||
sightLabel.TextSize = 14
|
||||
sightLabel.TextColor3 = MUTED
|
||||
sightLabel.TextXAlignment = Enum.TextXAlignment.Left
|
||||
sightLabel.LayoutOrder = 2
|
||||
sightLabel.Parent = weaponPanel
|
||||
|
||||
local sightRow = Instance.new("Frame")
|
||||
sightRow.Size = UDim2.fromOffset(316, 56)
|
||||
sightRow.BackgroundTransparency = 1
|
||||
sightRow.LayoutOrder = 3
|
||||
sightRow.Parent = weaponPanel
|
||||
local sightLayout = Instance.new("UIListLayout")
|
||||
sightLayout.FillDirection = Enum.FillDirection.Horizontal
|
||||
sightLayout.Padding = UDim.new(0, 10)
|
||||
sightLayout.SortOrder = Enum.SortOrder.LayoutOrder
|
||||
sightLayout.Parent = sightRow
|
||||
|
||||
local sightButtons: { [string]: TextButton } = {}
|
||||
local function buildSightButtons()
|
||||
for i, name in SIGHTS do
|
||||
local b = Instance.new("TextButton")
|
||||
b.Size = UDim2.fromOffset(98, 56)
|
||||
b.LayoutOrder = i
|
||||
b.BackgroundColor3 = PANEL_LIGHT
|
||||
b.Font = FONT
|
||||
b.Text = name
|
||||
b.TextSize = 15
|
||||
b.TextColor3 = TEXT
|
||||
local corner = Instance.new("UICorner")
|
||||
corner.CornerRadius = UDim.new(0, 10)
|
||||
corner.Parent = b
|
||||
local stroke = Instance.new("UIStroke")
|
||||
stroke.Color = OUTLINE
|
||||
stroke.Thickness = 2
|
||||
stroke.Parent = b
|
||||
b.Parent = sightRow
|
||||
b.MouseButton1Click:Connect(function()
|
||||
chosenSight = name
|
||||
for _, other in sightButtons do
|
||||
other.BackgroundColor3 = PANEL_LIGHT
|
||||
other.TextColor3 = TEXT
|
||||
end
|
||||
b.BackgroundColor3 = ACCENT_DIM
|
||||
b.TextColor3 = ACCENT
|
||||
applyPreviewSight()
|
||||
end)
|
||||
sightButtons[name] = b
|
||||
end
|
||||
end
|
||||
|
||||
-- ---------------------------------------------------------------- play button
|
||||
local playBtn = Instance.new("TextButton")
|
||||
playBtn.AnchorPoint = Vector2.new(0.5, 1)
|
||||
playBtn.Position = UDim2.fromScale(0.5, 0.93)
|
||||
playBtn.Size = UDim2.fromOffset(360, 74)
|
||||
playBtn.BackgroundColor3 = ACCENT
|
||||
playBtn.Font = Enum.Font.GothamBlack
|
||||
playBtn.Text = "PLAY"
|
||||
playBtn.TextSize = 34
|
||||
playBtn.TextColor3 = DARK
|
||||
local playCorner = Instance.new("UICorner")
|
||||
playCorner.CornerRadius = UDim.new(0, 16)
|
||||
playCorner.Parent = playBtn
|
||||
local playStroke = Instance.new("UIStroke")
|
||||
playStroke.Color = OUTLINE
|
||||
playStroke.Thickness = 3
|
||||
playStroke.Parent = playBtn
|
||||
local playScale = Instance.new("UIScale")
|
||||
playScale.Parent = playBtn
|
||||
playBtn.Parent = gui
|
||||
playBtn.MouseEnter:Connect(function()
|
||||
TweenService:Create(playScale, TweenInfo.new(0.1), { Scale = 1.05 }):Play()
|
||||
end)
|
||||
playBtn.MouseLeave:Connect(function()
|
||||
TweenService:Create(playScale, TweenInfo.new(0.1), { Scale = 1 }):Play()
|
||||
end)
|
||||
playBtn.MouseButton1Click:Connect(function()
|
||||
-- hand the chosen sight to the server first (it survives on the player)
|
||||
sightRemote:FireServer(chosenSight)
|
||||
-- then ask the server to spawn us
|
||||
requestSpawn:FireServer()
|
||||
-- fade the menu away
|
||||
TweenService:Create(backdrop, TweenInfo.new(0.4), { BackgroundTransparency = 1 }):Play()
|
||||
TweenService:Create(modePanel, TweenInfo.new(0.4), { BackgroundTransparency = 1 }):Play()
|
||||
TweenService:Create(weaponPanel, TweenInfo.new(0.4), { BackgroundTransparency = 1 }):Play()
|
||||
TweenService:Create(title, TweenInfo.new(0.4), { TextTransparency = 1 }):Play()
|
||||
TweenService:Create(subtitle, TweenInfo.new(0.4), { TextTransparency = 1 }):Play()
|
||||
TweenService:Create(playBtn, TweenInfo.new(0.4), { BackgroundTransparency = 1 }):Play()
|
||||
task.delay(0.45, function()
|
||||
gui.Enabled = false
|
||||
end)
|
||||
end)
|
||||
|
||||
-- ---------------------------------------------------------------- build
|
||||
buildModeButtons()
|
||||
buildSightButtons()
|
||||
applyPreviewSight()
|
||||
modeButtons[chosenMode].BackgroundColor3 = ACCENT_DIM
|
||||
modeButtons[chosenMode]:FindFirstChild("Check").Visible = true
|
||||
sightButtons[chosenSight].BackgroundColor3 = ACCENT_DIM
|
||||
sightButtons[chosenSight].TextColor3 = ACCENT
|
||||
@@ -0,0 +1,33 @@
|
||||
--!strict
|
||||
local MatchRules = {}
|
||||
|
||||
export type Rule = {id: string, title: string, detail: string, score: string}
|
||||
|
||||
MatchRules.Default = "TeamDeathmatch"
|
||||
MatchRules.VoteLockSeconds = 3
|
||||
MatchRules.VoteRevealSeconds = 3
|
||||
MatchRules.All = table.freeze({
|
||||
{id = "TeamDeathmatch", title = "Командный бой", detail = "Наберите больше убийств, чем соперники.", score = "Убийства"},
|
||||
{id = "HotPoint", title = "Горячая точка", detail = "Захватите зону за 10 с. С союзником захват в 1,5 раза быстрее.", score = "Захваченные точки"},
|
||||
{id = "Domination", title = "Три точки", detail = "Захватывайте и удерживайте зоны, чтобы получать очки.", score = "Очки контроля"},
|
||||
{id = "CaptureFlag", title = "Захват флага", detail = "Принесите вражеский флаг на свою базу, пока ваш флаг там.", score = "Флаги"},
|
||||
{id = "TrophyHunt", title = "Охота за трофеями", detail = "Собирайте выпавшие жетоны и сдавайте их на своей базе.", score = "Сданные жетоны"},
|
||||
{id = "Siege", title = "Штурм цитадели", detail = "В атаке берите рубежи, в защите удерживайте их. Затем смена ролей.", score = "Захваченные рубежи"},
|
||||
{id = "OneLife", title = "Одна жизнь", detail = "Выиграйте 3 мини-раунда. В каждом у вас одна жизнь.", score = "Победы в мини-раундах"},
|
||||
{id = "HuntLeader", title = "Охота на лидера", detail = "Устраняйте отмеченного лидера соперников. За него дают 3 очка.", score = "Очки за убийства"},
|
||||
} :: {Rule})
|
||||
|
||||
local byId: {[string]: Rule} = {}
|
||||
for _, rule in MatchRules.All do
|
||||
byId[rule.id] = table.freeze(rule)
|
||||
end
|
||||
|
||||
function MatchRules.find(id: unknown): Rule?
|
||||
return if typeof(id) == "string" then byId[id] else nil
|
||||
end
|
||||
|
||||
function MatchRules.get(id: unknown): Rule
|
||||
return MatchRules.find(id) or byId[MatchRules.Default]
|
||||
end
|
||||
|
||||
return table.freeze(MatchRules)
|
||||
@@ -0,0 +1,254 @@
|
||||
--!strict
|
||||
local Players = game:GetService("Players")
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local RunService = game:GetService("RunService")
|
||||
local TweenService = game:GetService("TweenService")
|
||||
local Rules = require(ReplicatedStorage:WaitForChild("MatchRules") :: ModuleScript)
|
||||
local Modes = require(ReplicatedStorage:WaitForChild("ArenaModes") :: ModuleScript)
|
||||
local UI = require(ReplicatedStorage:WaitForChild("HunterUI") :: ModuleScript)
|
||||
local ModeCard = require(ReplicatedStorage:WaitForChild("ModeCard") :: ModuleScript)
|
||||
local state = ReplicatedStorage:WaitForChild("ArenaRound")
|
||||
local vote = state:WaitForChild("ModeVote") :: RemoteEvent
|
||||
local player = Players.LocalPlayer
|
||||
local playerGui = player:WaitForChild("PlayerGui")
|
||||
|
||||
local gui = Instance.new("ScreenGui")
|
||||
gui.Name = "ArenaModeVote"
|
||||
gui.ResetOnSpawn, gui.IgnoreGuiInset = false, true
|
||||
gui.DisplayOrder = 44
|
||||
gui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
|
||||
gui.Enabled = false
|
||||
gui.Parent = playerGui
|
||||
local shade = UI.frame("Shade", gui, UDim2.fromScale(0, 0), UDim2.fromScale(1, 1), Color3.fromRGB(7, 11, 21))
|
||||
shade.Active, shade.BackgroundTransparency = true, .17
|
||||
local panelWidth, panelHeight = 940, 560
|
||||
local panel = UI.plate(shade, "Ballot", UDim2.fromScale(.5, .5), UDim2.fromOffset(panelWidth, panelHeight), UI.Outline, Color3.fromRGB(17, 23, 36))
|
||||
panel.AnchorPoint = Vector2.new(.5, .5)
|
||||
UI.contour(panel, UI.Blue)
|
||||
local scale = Instance.new("UIScale", panel)
|
||||
local function fit()
|
||||
local size = shade.AbsoluteSize
|
||||
scale.Scale = math.clamp(math.min((size.X - 24) / panelWidth, (size.Y - 24) / panelHeight), .01, 1)
|
||||
end
|
||||
local resize = shade:GetPropertyChangedSignal("AbsoluteSize"):Connect(fit)
|
||||
fit()
|
||||
|
||||
local function leftLabel(parent: Instance, name: string, text: string, x: number, y: number, w: number, h: number, fontSize: number, color: Color3): TextLabel
|
||||
local item = UI.label(parent, name, text, UDim2.fromOffset(x, y), UDim2.fromOffset(w, h), fontSize, color)
|
||||
item.TextXAlignment = Enum.TextXAlignment.Left
|
||||
return item
|
||||
end
|
||||
local title = leftLabel(panel, "Title", "СЛЕДУЮЩИЙ РЕЖИМ", 25, 16, 625, 43, 33, UI.Ink)
|
||||
title.FontFace = UI.Display
|
||||
local arenaText = leftLabel(panel, "Arena", "", 26, 57, 620, 21, 14, UI.Muted)
|
||||
local clock = UI.label(panel, "Countdown", "", UDim2.fromOffset(775, 19), UDim2.fromOffset(139, 44), 30, UI.Blue)
|
||||
clock.FontFace = UI.Display
|
||||
clock.TextXAlignment = Enum.TextXAlignment.Right
|
||||
local caption = leftLabel(panel, "VoteStatus", "", 25, 491, 890, 23, 16, UI.Ink)
|
||||
local detail = leftLabel(panel, "ModeDetail", "", 25, 515, 890, 22, 14, UI.Muted)
|
||||
local line = UI.element("ProgressBar", panel, UDim2.fromOffset(25, 542), UDim2.fromOffset(890, 3))
|
||||
local fill = line:WaitForChild("Fill") :: Frame
|
||||
fill.BackgroundColor3 = UI.Blue
|
||||
UI.sheen(fill)
|
||||
|
||||
type VoteCard = {card: ModeCard.Card, group: CanvasGroup, origin: Vector2, zoom: UIScale}
|
||||
type Outcome = {winner: string, endsAt: number}
|
||||
local cards: {[string]: VoteCard} = {}
|
||||
local currentArena: string? = nil
|
||||
local hoveredRule: string? = nil
|
||||
local selectedRule: string? = nil
|
||||
local deadline, duration = 0, 1
|
||||
local locked = false
|
||||
local revealEndsAt: number? = nil
|
||||
local animations: {Tween} = {}
|
||||
|
||||
local function tween(target: Instance, time: number, easing: Enum.EasingStyle, goal: {[string]: any})
|
||||
local animation = TweenService:Create(target, TweenInfo.new(time, easing, Enum.EasingDirection.Out), goal)
|
||||
table.insert(animations, animation)
|
||||
animation:Play()
|
||||
end
|
||||
|
||||
local function stopAnimations()
|
||||
for _, animation in animations do animation:Cancel() end
|
||||
table.clear(animations)
|
||||
end
|
||||
|
||||
local function refreshDetail()
|
||||
local rule = Rules.find(if locked then selectedRule else hoveredRule or selectedRule)
|
||||
if locked then
|
||||
detail.Text = if rule then "Ваш голос · " .. rule.title else ""
|
||||
else
|
||||
detail.Text = if rule then rule.detail else "Наведите на режим, чтобы увидеть его правила."
|
||||
end
|
||||
end
|
||||
|
||||
for i, rule in Rules.All do
|
||||
local center = Vector2.new(131 + ((i - 1) % 4) * 226, 180 + ((i - 1) // 4) * 207)
|
||||
local group = Instance.new("CanvasGroup")
|
||||
group.Name = rule.id .. "Slot"
|
||||
group.AnchorPoint = Vector2.new(.5, .5)
|
||||
group.Position = UDim2.fromOffset(center.X, center.Y)
|
||||
group.Size = UDim2.fromOffset(230, 214)
|
||||
group.BackgroundTransparency = 1
|
||||
group.Parent = panel
|
||||
local zoom = Instance.new("UIScale", group)
|
||||
local card = ModeCard.new(group, rule.id, UDim2.fromOffset(8, 8), UDim2.fromOffset(214, 198), true)
|
||||
local button = assert(card.button)
|
||||
cards[rule.id] = {card = card, group = group, origin = center, zoom = zoom}
|
||||
local function showDetail()
|
||||
if locked then return end
|
||||
hoveredRule = rule.id
|
||||
refreshDetail()
|
||||
end
|
||||
local function hideDetail()
|
||||
if hoveredRule == rule.id then
|
||||
hoveredRule = nil
|
||||
refreshDetail()
|
||||
end
|
||||
end
|
||||
button.MouseEnter:Connect(showDetail)
|
||||
button.MouseLeave:Connect(hideDetail)
|
||||
button.SelectionGained:Connect(showDetail)
|
||||
button.SelectionLost:Connect(hideDetail)
|
||||
button.Activated:Connect(function()
|
||||
if currentArena and not locked and workspace:GetServerTimeNow() < deadline - Rules.VoteLockSeconds then
|
||||
vote:FireServer(currentArena, rule.id)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
local function hide()
|
||||
gui.Enabled = false
|
||||
currentArena = nil
|
||||
hoveredRule, selectedRule = nil, nil
|
||||
locked, revealEndsAt = false, nil
|
||||
playerGui:SetAttribute("HunterVoting", nil)
|
||||
stopAnimations()
|
||||
end
|
||||
|
||||
local function startBallot(id: string, endsAt: number, timeLeft: number)
|
||||
stopAnimations()
|
||||
currentArena, deadline = id, endsAt
|
||||
hoveredRule, selectedRule = nil, nil
|
||||
locked, revealEndsAt = false, nil
|
||||
local match = Modes.state(state, id)
|
||||
duration = (match:GetAttribute("PhaseDuration") :: number?) or timeLeft
|
||||
title.Text = "СЛЕДУЮЩИЙ РЕЖИМ"
|
||||
arenaText.Text = "ДИНАМИЧЕСКАЯ АРЕНА"
|
||||
clock.Visible, line.Visible = true, true
|
||||
clock.TextColor3, fill.BackgroundColor3 = UI.Blue, UI.Blue
|
||||
caption.TextXAlignment, detail.TextXAlignment = Enum.TextXAlignment.Left, Enum.TextXAlignment.Left
|
||||
for _, slot in cards do
|
||||
slot.group.Position = UDim2.fromOffset(slot.origin.X, slot.origin.Y)
|
||||
slot.group.GroupTransparency, slot.group.Rotation, slot.group.ZIndex = 0, 0, 1
|
||||
slot.zoom.Scale = 1
|
||||
assert(slot.card.button).Interactable = true
|
||||
ModeCard.setMuted(slot.card, false)
|
||||
end
|
||||
gui.Enabled = true
|
||||
playerGui:SetAttribute("HunterVoting", true)
|
||||
panel.Position = UDim2.fromScale(.5, .53)
|
||||
tween(panel, .22, Enum.EasingStyle.Quart, {Position = UDim2.fromScale(.5, .5)})
|
||||
end
|
||||
|
||||
local function lockBallot()
|
||||
if locked then return end
|
||||
locked = true
|
||||
hoveredRule = nil
|
||||
clock.TextColor3 = Color3.fromRGB(212, 212, 212)
|
||||
fill.BackgroundColor3 = Color3.fromRGB(145, 145, 145)
|
||||
caption.Text = "ГОЛОСОВАНИЕ ЗАКРЫТО"
|
||||
refreshDetail()
|
||||
for _, slot in cards do
|
||||
assert(slot.card.button).Interactable = false
|
||||
ModeCard.setSelected(slot.card, false)
|
||||
ModeCard.setMuted(slot.card, true)
|
||||
end
|
||||
end
|
||||
|
||||
local function reveal(outcome: Outcome, now: number)
|
||||
local winner = cards[outcome.winner]
|
||||
if revealEndsAt or not winner then return end
|
||||
lockBallot()
|
||||
revealEndsAt = math.max(outcome.endsAt, now + 1.35)
|
||||
title.Text = "РЕЖИМ ВЫБРАН"
|
||||
clock.Visible, line.Visible = false, false
|
||||
caption.TextXAlignment, detail.TextXAlignment = Enum.TextXAlignment.Center, Enum.TextXAlignment.Center
|
||||
caption.Text = "СЛЕДУЮЩИЙ РАУНД"
|
||||
detail.Text = Rules.get(outcome.winner).detail
|
||||
local center = Vector2.new(panelWidth / 2, panelHeight / 2)
|
||||
for _, slot in cards do
|
||||
if slot == winner then
|
||||
slot.group.ZIndex = 3
|
||||
ModeCard.setMuted(slot.card, false)
|
||||
ModeCard.setSelected(slot.card, true)
|
||||
tween(slot.group, .72, Enum.EasingStyle.Quart, {Position = UDim2.fromScale(.5, .5)})
|
||||
tween(slot.zoom, .72, Enum.EasingStyle.Quart, {Scale = 1.65})
|
||||
else
|
||||
local direction = (slot.origin - center).Unit
|
||||
local destination = slot.origin + direction * 490
|
||||
tween(slot.group, .8, Enum.EasingStyle.Cubic, {
|
||||
Position = UDim2.fromOffset(destination.X, destination.Y),
|
||||
Rotation = direction.X * 17,
|
||||
GroupTransparency = 1,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local received = vote.OnClientEvent:Connect(function(id: string, endsAt: number, counts: {[string]: number}, total: number,
|
||||
selection: string?, outcome: Outcome?)
|
||||
if player:GetAttribute("InArena") == true or player:GetAttribute("ArenaWaiting") == true then return end
|
||||
local now = workspace:GetServerTimeNow()
|
||||
local left = endsAt - now
|
||||
if outcome then
|
||||
if outcome.endsAt <= now or (gui.Enabled and (id ~= currentArena or endsAt ~= deadline)) then return end
|
||||
elseif left <= 0 then
|
||||
return
|
||||
end
|
||||
if not gui.Enabled or currentArena ~= id or deadline ~= endsAt then startBallot(id, endsAt, left) end
|
||||
selectedRule = selection
|
||||
for rule, slot in cards do
|
||||
slot.card.badge.Text = tostring(counts[rule] or 0)
|
||||
if not locked then ModeCard.setSelected(slot.card, rule == selection) end
|
||||
end
|
||||
if outcome then
|
||||
reveal(outcome, now)
|
||||
return
|
||||
end
|
||||
if left <= Rules.VoteLockSeconds then lockBallot() end
|
||||
refreshDetail()
|
||||
if not locked then
|
||||
local own = Rules.find(selection)
|
||||
caption.Text = if own then "Ваш голос · " .. own.title .. " / Всего " .. total else "Выберите режим · Всего голосов " .. total
|
||||
end
|
||||
end)
|
||||
|
||||
local timer = RunService.Heartbeat:Connect(function()
|
||||
if not gui.Enabled then return end
|
||||
local now = workspace:GetServerTimeNow()
|
||||
if player:GetAttribute("InArena") == true or player:GetAttribute("ArenaWaiting") == true then
|
||||
hide()
|
||||
return
|
||||
end
|
||||
local dismissAt = revealEndsAt
|
||||
if dismissAt then
|
||||
if now >= dismissAt then hide() end
|
||||
return
|
||||
end
|
||||
if now >= deadline + Rules.VoteRevealSeconds + 2 then
|
||||
hide()
|
||||
return
|
||||
end
|
||||
local left = math.max(0, deadline - now)
|
||||
if left <= Rules.VoteLockSeconds then lockBallot() end
|
||||
clock.Text = string.format("00:%02d", math.ceil(left))
|
||||
fill.Size = UDim2.fromScale(math.clamp(left / math.max(duration, 1), 0, 1), 1)
|
||||
end)
|
||||
script.Destroying:Once(function()
|
||||
hide()
|
||||
received:Disconnect()
|
||||
timer:Disconnect()
|
||||
resize:Disconnect()
|
||||
gui:Destroy()
|
||||
end)
|
||||
@@ -0,0 +1,132 @@
|
||||
--!strict
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local UI = require(ReplicatedStorage:WaitForChild("HunterUI") :: ModuleScript)
|
||||
local Rules = require(ReplicatedStorage:WaitForChild("MatchRules") :: ModuleScript)
|
||||
|
||||
local ModeCard = {}
|
||||
local artIds: {[string]: string} = {
|
||||
TeamDeathmatch = "rbxassetid://86938429785177",
|
||||
HotPoint = "rbxassetid://113230020908274",
|
||||
Domination = "rbxassetid://134414659800619",
|
||||
CaptureFlag = "rbxassetid://133231003741034",
|
||||
TrophyHunt = "rbxassetid://89901991818650",
|
||||
Siege = "rbxassetid://140524141713098",
|
||||
OneLife = "rbxassetid://99724219202486",
|
||||
HuntLeader = "rbxassetid://104751658045911",
|
||||
}
|
||||
local accents: {[string]: Color3} = {
|
||||
TeamDeathmatch = UI.Blue,
|
||||
HotPoint = UI.Orange,
|
||||
Domination = UI.Mint,
|
||||
CaptureFlag = Color3.fromRGB(104, 167, 255),
|
||||
TrophyHunt = UI.Gold,
|
||||
Siege = Color3.fromRGB(185, 131, 255),
|
||||
OneLife = Color3.fromRGB(255, 112, 119),
|
||||
HuntLeader = Color3.fromRGB(169, 157, 255),
|
||||
}
|
||||
|
||||
export type Card = {
|
||||
root: GuiObject, button: TextButton?, image: ImageLabel, title: TextLabel, badge: TextLabel,
|
||||
art: Frame, glow: Frame, frame: Frame?, accent: Color3,
|
||||
badgePanel: Frame, shade: Frame, lockedSurface: Frame?,
|
||||
}
|
||||
|
||||
local dark = Color3.fromRGB(13, 24, 39)
|
||||
local badgeFill = Color3.fromRGB(9, 19, 34)
|
||||
local shadeColor = Color3.fromRGB(6, 12, 23)
|
||||
local function appearance(card: Card, id: string)
|
||||
local color = accents[id] or UI.Blue
|
||||
card.accent = color
|
||||
card.title.Text = Rules.get(id).title
|
||||
card.art.BackgroundColor3 = dark:Lerp(color, .28)
|
||||
card.badge.TextColor3 = color:Lerp(UI.Ink, .28)
|
||||
card.image.Image = artIds[id] or ""
|
||||
card.image.Visible = card.image.Image ~= ""
|
||||
local frame = card.frame
|
||||
if frame then UI.tintPlate(frame, color:Lerp(UI.Panel, .24), dark) end
|
||||
UI.tintPlate(card.badgePanel, color:Lerp(dark, .4), badgeFill)
|
||||
end
|
||||
|
||||
function ModeCard.new(parent: Instance, id: string, position: UDim2, size: UDim2, interactive: boolean?): Card
|
||||
local accent = accents[id] or UI.Blue
|
||||
local root: GuiObject
|
||||
local button: TextButton? = nil
|
||||
local shell: Frame? = nil
|
||||
local lockedSurface: Frame? = nil
|
||||
if interactive then
|
||||
local input = Instance.new("TextButton")
|
||||
input.Name = id
|
||||
input.Position, input.Size = position, size
|
||||
input.Text, input.BorderSizePixel = "", 0
|
||||
input.BackgroundColor3 = dark
|
||||
input.Parent = parent
|
||||
UI.bindButton(input, accent)
|
||||
root, button = input, input
|
||||
lockedSurface = UI.plate(input, "LockedSurface", UDim2.fromScale(0, 0), UDim2.fromScale(1, 1),
|
||||
Color3.fromRGB(104, 104, 104), Color3.fromRGB(38, 38, 38))
|
||||
lockedSurface.Visible = false
|
||||
else
|
||||
local plate = UI.plate(parent, "ModeCard", position, size, accent, dark)
|
||||
root, shell = plate, plate
|
||||
end
|
||||
|
||||
local art = UI.frame("Illustration", root, UDim2.fromOffset(6, 6), UDim2.new(1, -12, 1, -46), dark)
|
||||
art.ClipsDescendants = true
|
||||
local image = Instance.new("ImageLabel")
|
||||
image.Name = "Artwork"
|
||||
image.BackgroundTransparency = 1
|
||||
image.Size = UDim2.fromScale(1, 1)
|
||||
image.ScaleType = Enum.ScaleType.Crop
|
||||
image.Parent = art
|
||||
local shade = UI.frame("Shade", art, UDim2.new(0, 0, .66, 0), UDim2.new(1, 0, .34, 0), shadeColor)
|
||||
local fade = Instance.new("UIGradient", shade)
|
||||
fade.Rotation = 90
|
||||
fade.Transparency = NumberSequence.new(1, .48)
|
||||
local title = UI.label(root, "ModeName", "", UDim2.new(0, 8, 1, -38), UDim2.new(1, -16, 0, 32), 19, UI.Ink)
|
||||
title.FontFace = UI.Display
|
||||
title.TextScaled = true
|
||||
Instance.new("UITextSizeConstraint", title).MaxTextSize = 19
|
||||
local score = UI.plate(root, "Badge", UDim2.new(1, -12, 0, 12), UDim2.fromOffset(if interactive then 46 else 75, 30),
|
||||
accent:Lerp(dark, .4), badgeFill)
|
||||
score.AnchorPoint = Vector2.new(1, 0)
|
||||
local badge = UI.label(score, "Value", "", UDim2.fromScale(0, 0), UDim2.fromScale(1, 1), 17, UI.Ink)
|
||||
badge.FontFace = UI.Display
|
||||
local glow = UI.frame("ChoiceGlow", root, UDim2.fromScale(0, 0), UDim2.fromScale(1, 1), UI.Blue)
|
||||
glow.BackgroundTransparency = 1
|
||||
glow.Visible = false
|
||||
glow:SetAttribute("CornerCut", 8)
|
||||
if interactive then
|
||||
UI.edge(glow, UI.Blue, .85).Thickness = 2
|
||||
UI.contour(glow, UI.Blue)
|
||||
end
|
||||
local result = {root = root, button = button, art = art, image = image, title = title, badge = badge,
|
||||
glow = glow, frame = shell, accent = accent, badgePanel = score, shade = shade, lockedSurface = lockedSurface}
|
||||
appearance(result, id)
|
||||
return result
|
||||
end
|
||||
|
||||
function ModeCard.setMode(card: Card, id: string)
|
||||
appearance(card, id)
|
||||
end
|
||||
|
||||
function ModeCard.setSelected(card: Card, selected: boolean)
|
||||
card.glow.Visible = selected
|
||||
card.title.TextColor3 = if selected then UI.Blue:Lerp(UI.Ink, .45) else UI.Ink
|
||||
local button = card.button
|
||||
if button then button.BackgroundColor3 = if selected then dark:Lerp(UI.Blue, .22) else dark end
|
||||
end
|
||||
|
||||
function ModeCard.setMuted(card: Card, muted: boolean)
|
||||
local surface = card.lockedSurface
|
||||
if surface then surface.Visible = muted end
|
||||
card.art.BackgroundColor3 = if muted then Color3.fromRGB(76, 76, 76) else dark:Lerp(card.accent, .28)
|
||||
card.image.ImageColor3 = if muted then Color3.fromRGB(155, 155, 155) else Color3.new(1, 1, 1)
|
||||
card.image.ImageTransparency = if muted then .83 else 0
|
||||
card.shade.BackgroundColor3 = if muted then Color3.fromRGB(32, 32, 32) else shadeColor
|
||||
card.title.TextColor3 = if muted then Color3.fromRGB(218, 218, 218) else UI.Ink
|
||||
card.badge.TextColor3 = if muted then Color3.fromRGB(201, 201, 201) else card.accent:Lerp(UI.Ink, .28)
|
||||
UI.tintPlate(card.badgePanel, if muted then Color3.fromRGB(113, 113, 113) else card.accent:Lerp(dark, .4),
|
||||
if muted then Color3.fromRGB(39, 39, 39) else badgeFill)
|
||||
end
|
||||
|
||||
return ModeCard
|
||||
@@ -0,0 +1,73 @@
|
||||
--!strict
|
||||
-- Apply saved movement settings on startup and accept previews only in Studio.
|
||||
local Players = game:GetService("Players")
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local RunService = game:GetService("RunService")
|
||||
local StarterPlayer = game:GetService("StarterPlayer")
|
||||
|
||||
local config = StarterPlayer.StarterPlayerScripts:WaitForChild("SniperViewmodel")
|
||||
local defaultGravity = workspace.Gravity
|
||||
local defaultJumpHeight = StarterPlayer.CharacterJumpHeight
|
||||
local ranges: {[string]: {min: number, max: number}} = {
|
||||
MovementWalkSpeed = {min = 1, max = 80},
|
||||
MovementGravity = {min = 40, max = 400},
|
||||
}
|
||||
|
||||
local function validated(name: string, value: unknown): number?
|
||||
local range = ranges[name]
|
||||
if range and typeof(value) == "number" and value == value and value >= range.min and value <= range.max then
|
||||
return value
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
local function currentHumanoids(): {Humanoid}
|
||||
local result: {Humanoid} = {}
|
||||
for _, player in Players:GetPlayers() do
|
||||
local character = player.Character
|
||||
local humanoid = character and character:FindFirstChildOfClass("Humanoid")
|
||||
if humanoid then
|
||||
table.insert(result, humanoid)
|
||||
end
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
local function applySpeed(speed: number)
|
||||
StarterPlayer.CharacterWalkSpeed = speed
|
||||
workspace:SetAttribute("HunterWalkSpeed", speed)
|
||||
for _, humanoid in currentHumanoids() do
|
||||
humanoid.WalkSpeed = speed
|
||||
end
|
||||
end
|
||||
|
||||
local function applyGravity(gravity: number)
|
||||
workspace.Gravity = gravity
|
||||
-- JumpHeight mode compensates for gravity itself; scale its target height as well.
|
||||
local height = defaultJumpHeight * defaultGravity / gravity
|
||||
StarterPlayer.CharacterJumpHeight = height
|
||||
for _, humanoid in currentHumanoids() do
|
||||
humanoid.JumpHeight = height
|
||||
end
|
||||
end
|
||||
|
||||
local speed = validated("MovementWalkSpeed", config:GetAttribute("MovementWalkSpeed"))
|
||||
local gravity = validated("MovementGravity", config:GetAttribute("MovementGravity"))
|
||||
if speed then applySpeed(speed) end
|
||||
if gravity then applyGravity(gravity) end
|
||||
|
||||
if not RunService:IsStudio() then return end
|
||||
|
||||
local remote = Instance.new("RemoteEvent")
|
||||
remote.Name = "MovementTune"
|
||||
remote.OnServerEvent:Connect(function(_player: Player, name: unknown, input: unknown)
|
||||
if typeof(name) ~= "string" then return end
|
||||
local value = validated(name, input)
|
||||
if not value then return end
|
||||
if name == "MovementWalkSpeed" then
|
||||
if StarterPlayer.CharacterWalkSpeed ~= value then applySpeed(value) end
|
||||
elseif math.abs(workspace.Gravity - value) > 0.0001 then
|
||||
applyGravity(value)
|
||||
end
|
||||
end)
|
||||
remote.Parent = ReplicatedStorage
|
||||
@@ -0,0 +1,33 @@
|
||||
--!strict
|
||||
-- Put this Script in ServerScriptService.
|
||||
-- Turns the map into a dark night. Lighting set on the server replicates to every player.
|
||||
|
||||
local Lighting = game:GetService("Lighting")
|
||||
|
||||
Lighting.ClockTime = 0 -- midnight
|
||||
Lighting.Brightness = 0.15
|
||||
Lighting.Ambient = Color3.fromRGB(8, 8, 12)
|
||||
Lighting.OutdoorAmbient = Color3.fromRGB(15, 15, 22)
|
||||
Lighting.ExposureCompensation = -0.5
|
||||
Lighting.EnvironmentDiffuseScale = 0.1
|
||||
Lighting.EnvironmentSpecularScale = 0.1
|
||||
Lighting.GlobalShadows = true
|
||||
|
||||
-- Classic fog (only used if there is no Atmosphere object).
|
||||
Lighting.FogColor = Color3.fromRGB(5, 5, 10)
|
||||
Lighting.FogStart = 0
|
||||
Lighting.FogEnd = 350
|
||||
|
||||
-- Dark, hazy atmosphere so distant things fade into the night.
|
||||
local atmosphere = Lighting:FindFirstChildOfClass("Atmosphere")
|
||||
if not atmosphere then
|
||||
atmosphere = Instance.new("Atmosphere")
|
||||
atmosphere.Parent = Lighting
|
||||
end
|
||||
assert(atmosphere)
|
||||
atmosphere.Density = 0.45
|
||||
atmosphere.Offset = 0
|
||||
atmosphere.Color = Color3.fromRGB(20, 22, 30)
|
||||
atmosphere.Decay = Color3.fromRGB(10, 10, 15)
|
||||
atmosphere.Glare = 0
|
||||
atmosphere.Haze = 1.5
|
||||
@@ -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)
|
||||
@@ -0,0 +1,20 @@
|
||||
--!strict
|
||||
local colors = Color3.fromRGB
|
||||
|
||||
return table.freeze({
|
||||
{ id = "Turbo", title = "Турбоискра", detail = "+30% к скорости на 4 сек.", color = colors(255, 124, 56) },
|
||||
{ id = "Spring", title = "Лунная пружина", detail = "Следующий прыжок выше на 80% · 18 сек.", color = colors(181, 88, 255) },
|
||||
{ id = "Double", title = "Второй импульс", detail = "Один прыжок в воздухе · 8 сек.", color = colors(66, 216, 255) },
|
||||
{ id = "Feather", title = "Перо бури", detail = "Удерживай пробел для плавного падения · 5 сек.", color = colors(121, 241, 220) },
|
||||
{ id = "Shield", title = "Хрустальный щит", detail = "Поглощает 25 урона · 7 сек.", color = colors(79, 143, 255) },
|
||||
{ id = "Heal", title = "Искра жизни", detail = "Восстанавливает 25 HP", color = colors(112, 255, 112) },
|
||||
{ id = "Magnet", title = "Золотой магнит", detail = "Притягивание монет с 20 студов · 8 сек.", color = colors(255, 180, 66) },
|
||||
{ id = "Lucky", title = "Золотая жила", detail = "+25% к ценности следующих пяти монет", color = colors(250, 241, 95) },
|
||||
{ id = "Reload", title = "Быстрые руки", detail = "Следующая перезарядка вдвое быстрее", color = colors(255, 103, 158) },
|
||||
{ id = "Ammo", title = "Запасной магазин", detail = "Мгновенно пополняет магазин", color = colors(255, 82, 100) },
|
||||
{ id = "Steady", title = "Стальная хватка", detail = "Меньше отдачи и разброса · 5 сек.", color = colors(168, 181, 204) },
|
||||
{ id = "Quiet", title = "Шёпот", detail = "Приглушает шаги на 6 сек.", color = colors(106, 98, 249) },
|
||||
{ id = "Phantom", title = "Фантом", detail = "Создаёт движущуюся копию на 2 сек.", color = colors(213, 157, 255) },
|
||||
{ id = "Storm", title = "Грозовая печать", detail = "Следующее приземление замедляет врагов", color = colors(233, 77, 237) },
|
||||
{ id = "Team", title = "Искра отряда", detail = "+20% к скорости тебе и ближайшим союзникам · 3 сек.", color = colors(42, 255, 171) },
|
||||
})
|
||||
@@ -0,0 +1,389 @@
|
||||
--!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)
|
||||
@@ -0,0 +1,139 @@
|
||||
--!strict
|
||||
local Players = game:GetService("Players")
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local RunService = game:GetService("RunService")
|
||||
|
||||
local Catalog = require(ReplicatedStorage:WaitForChild("PowerUpCatalog") :: ModuleScript)
|
||||
local Magnet = require(ReplicatedStorage:WaitForChild("LootMagnet") :: ModuleScript)
|
||||
local Effects = require(script.Parent:WaitForChild("PowerUpEffects") :: ModuleScript)
|
||||
local Modes = require(ReplicatedStorage:WaitForChild("ArenaModes") :: ModuleScript)
|
||||
local round = ReplicatedStorage:WaitForChild("ArenaRound")
|
||||
|
||||
local LIFE, AIR_TIME = 60, .63
|
||||
local container = Instance.new("Folder")
|
||||
container.Name = "PowerUpDrops"
|
||||
container:SetAttribute("Life", LIFE)
|
||||
container:SetAttribute("AirTime", AIR_TIME)
|
||||
local collected = Instance.new("RemoteEvent")
|
||||
collected.Name = "Collected"
|
||||
collected.Parent = container
|
||||
container.Parent = ReplicatedStorage
|
||||
|
||||
type Drop = {
|
||||
data: Configuration, key: string, mode: string, position: Vector3, ready: number, expires: number,
|
||||
collector: Player?, character: Model?, launch: number?,
|
||||
}
|
||||
type Candidate = {player: Player, character: Model, position: Vector3}
|
||||
local drops: {[Configuration]: Drop} = {}
|
||||
local nextId = 0
|
||||
local random = Random.new()
|
||||
local function groundNear(origin: Vector3, geometry: RaycastParams): Vector3?
|
||||
local floor = workspace:Raycast(origin + Vector3.yAxis * 2, -Vector3.yAxis * 155, geometry)
|
||||
if not floor then return nil end
|
||||
local center = floor.Position + Vector3.yAxis * 2.15
|
||||
local angle = random:NextNumber(0, math.pi * 2)
|
||||
for i = 1, 5 do
|
||||
local offset = Vector3.new(math.cos(angle + i * 2.4), 0, math.sin(angle + i * 2.4)) * 5.8
|
||||
if workspace:Raycast(center, offset, geometry) then continue end
|
||||
local nearby = workspace:Raycast(center + offset + Vector3.yAxis, -Vector3.yAxis * 7, geometry)
|
||||
if nearby then
|
||||
local rest = nearby.Position + Vector3.yAxis * 2.15
|
||||
if not workspace:Raycast(center, rest - center, geometry) then return rest end
|
||||
end
|
||||
end
|
||||
return center
|
||||
end
|
||||
|
||||
local PowerUpDrops = {}
|
||||
function PowerUpDrops.spawn(origin: Vector3, requested: string?, arenaMode: string?)
|
||||
local now = workspace:GetServerTimeNow()
|
||||
local mode = arenaMode or Modes.Procedural
|
||||
if not Modes.open(round, mode, now) then return end
|
||||
local position = groundNear(origin, Modes.collision(mode))
|
||||
if not position then return end
|
||||
local definition = Catalog[random:NextInteger(1, #Catalog)]
|
||||
if requested then
|
||||
for _, spec in Catalog do
|
||||
if spec.id == requested then definition = spec break end
|
||||
end
|
||||
end
|
||||
nextId += 1
|
||||
local data = Instance.new("Configuration")
|
||||
data.Name = tostring(nextId)
|
||||
data:SetAttribute("Kind", definition.id)
|
||||
data:SetAttribute("ArenaMode", mode)
|
||||
data:SetAttribute("Origin", origin)
|
||||
data:SetAttribute("Rest", position)
|
||||
data:SetAttribute("Born", now)
|
||||
data:SetAttribute("Expires", now + LIFE)
|
||||
drops[data] = {data = data, key = definition.id, mode = mode, position = position, ready = now + AIR_TIME + .18, expires = now + LIFE}
|
||||
data.Parent = container
|
||||
end
|
||||
|
||||
local function remove(drop: Drop)
|
||||
drops[drop.data] = nil
|
||||
drop.data:Destroy()
|
||||
end
|
||||
|
||||
local function acquire(drop: Drop, candidates: {Candidate}, now: number)
|
||||
local geometry = Modes.collision(drop.mode)
|
||||
local best: Candidate? = nil
|
||||
local distance = Magnet.Radius
|
||||
for _, candidate in candidates do
|
||||
local range = (candidate.position - drop.position).Magnitude
|
||||
if range <= distance and Magnet.canReach(candidate.position, drop.position, distance, geometry) then
|
||||
best, distance = candidate, range
|
||||
end
|
||||
end
|
||||
if not best then return end
|
||||
local launch = now + .05
|
||||
drop.collector, drop.character, drop.launch = best.player, best.character, launch
|
||||
drop.data:SetAttribute("Collector", best.player.UserId)
|
||||
drop.data:SetAttribute("Launch", launch)
|
||||
end
|
||||
|
||||
local function complete(drop: Drop, byPlayer: {[Player]: Candidate}, now: number)
|
||||
local owner = drop.collector
|
||||
local current = owner and byPlayer[owner]
|
||||
if not owner or not current or current.character ~= drop.character or Modes.of(owner) ~= drop.mode
|
||||
or not Magnet.canReach(current.position, drop.position, 80, Modes.collision(drop.mode)) then
|
||||
drop.collector, drop.character, drop.launch = nil, nil, nil
|
||||
drop.data:SetAttribute("Collector", nil)
|
||||
drop.data:SetAttribute("Launch", nil)
|
||||
return
|
||||
end
|
||||
Effects.grant(owner, drop.key, now)
|
||||
collected:FireClient(owner, drop.key)
|
||||
remove(drop)
|
||||
end
|
||||
|
||||
local elapsed = 0
|
||||
RunService.Heartbeat:Connect(function(dt)
|
||||
elapsed += dt
|
||||
if elapsed < .05 then return end
|
||||
elapsed %= .05
|
||||
if not next(drops) then return end
|
||||
local now = workspace:GetServerTimeNow()
|
||||
local candidates: {[string]: {Candidate}} = {[Modes.Procedural] = {}}
|
||||
local byPlayer: {[Player]: Candidate} = {}
|
||||
for _, p in Players:GetPlayers() do
|
||||
local character = p.Character
|
||||
local root = character and character.PrimaryPart
|
||||
local humanoid = character and character:FindFirstChildOfClass("Humanoid")
|
||||
if p:GetAttribute("InArena") ~= true or not character or not root or not humanoid or humanoid.Health <= 0 then continue end
|
||||
local candidate = {player = p, character = character, position = root.Position}
|
||||
table.insert(candidates[Modes.of(p)], candidate)
|
||||
byPlayer[p] = candidate
|
||||
end
|
||||
for _, drop in drops do
|
||||
if now >= drop.expires or not Modes.open(round, drop.mode, now) then
|
||||
remove(drop)
|
||||
elseif drop.launch then
|
||||
if now >= drop.launch + Magnet.Duration then complete(drop, byPlayer, now) end
|
||||
elseif now >= drop.ready and now + .05 + Magnet.Duration < drop.expires then
|
||||
acquire(drop, candidates[drop.mode], now)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
return PowerUpDrops
|
||||
@@ -0,0 +1,247 @@
|
||||
--!strict
|
||||
local Debris = game:GetService("Debris")
|
||||
local Players = game:GetService("Players")
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local RunService = game:GetService("RunService")
|
||||
local StarterPlayer = game:GetService("StarterPlayer")
|
||||
local TweenService = game:GetService("TweenService")
|
||||
local Mobility = require(ReplicatedStorage:WaitForChild("ArenaMobility") :: ModuleScript)
|
||||
local Modes = require(ReplicatedStorage:WaitForChild("ArenaModes") :: ModuleScript)
|
||||
local round = ReplicatedStorage:WaitForChild("ArenaRound")
|
||||
local jumpCharge = Instance.new("RemoteEvent")
|
||||
jumpCharge.Name = "PowerJumpCharge"
|
||||
jumpCharge.Parent = ReplicatedStorage
|
||||
|
||||
local flat = Vector3.new(1, 0, 1)
|
||||
local timed: {[string]: number} = {Turbo = 4, Double = 8, Feather = 5, Shield = 7, Magnet = 8, Steady = 5, Quiet = 6, Team = 3}
|
||||
local lootAttributes = {"TurboUntil", "Spring", "DoubleUntil", "FeatherUntil", "Shield", "ShieldUntil", "MagnetUntil", "Lucky",
|
||||
"Reload", "Ammo", "SteadyUntil", "QuietUntil", "Storm", "TeamUntil", "SlowUntil"}
|
||||
type Spring = {height: number, power: number, charge: number, used: boolean?}
|
||||
type State = {character: Model, human: Humanoid, speed: number, spring: Spring?, stormAir: boolean}
|
||||
type Decoy = {
|
||||
model: Model, owner: Player, mode: string, born: number, start: CFrame, distance: number,
|
||||
legs: {[BasePart]: CFrame},
|
||||
}
|
||||
local active: {[Player]: State} = {}
|
||||
local decoys: {Decoy} = {}
|
||||
local Effects = {}
|
||||
|
||||
local function alive(player: Player): (Model?, Humanoid?, BasePart?)
|
||||
local character = player.Character
|
||||
local humanoid = character and character:FindFirstChildOfClass("Humanoid")
|
||||
local root = character and character.PrimaryPart
|
||||
if player:GetAttribute("InArena") == true and character and humanoid and humanoid.Health > 0 and root then
|
||||
return character, humanoid, root
|
||||
end
|
||||
return nil, nil, nil
|
||||
end
|
||||
|
||||
local function applySpeed(state: State, now: number)
|
||||
local base = (workspace:GetAttribute("HunterWalkSpeed") :: number?) or StarterPlayer.CharacterWalkSpeed
|
||||
state.speed = Mobility.walkMultiplier(state.character, now)
|
||||
state.human.WalkSpeed = base * state.speed
|
||||
end
|
||||
|
||||
local function restoreSpring(state: State)
|
||||
local spring = state.spring
|
||||
if not spring then return end
|
||||
state.spring = nil
|
||||
state.character:SetAttribute("LootSpring", nil)
|
||||
local human = state.human
|
||||
if math.abs(human.JumpHeight - spring.height * 1.8) < .01 then human.JumpHeight = spring.height end
|
||||
if math.abs(human.JumpPower - spring.power * math.sqrt(1.8)) < .01 then human.JumpPower = spring.power end
|
||||
end
|
||||
|
||||
local function clear(player: Player, now: number)
|
||||
local state = active[player]
|
||||
if not state then return end
|
||||
active[player] = nil
|
||||
restoreSpring(state)
|
||||
for _, key in lootAttributes do state.character:SetAttribute("Loot" .. key, nil) end
|
||||
if state.human.Parent and state.human.Health > 0 then applySpeed(state, now) end
|
||||
end
|
||||
|
||||
local function stateOf(player: Player, character: Model, human: Humanoid, now: number): State
|
||||
local state = active[player]
|
||||
if state and state.character == character then return state end
|
||||
if state then clear(player, now) end
|
||||
state = {character = character, human = human, speed = Mobility.walkMultiplier(character, now), stormAir = false}
|
||||
active[player] = state
|
||||
return state
|
||||
end
|
||||
|
||||
local function pulse(position: Vector3)
|
||||
local ring = Instance.new("Part")
|
||||
ring.Name, ring.Shape = "StormLanding", Enum.PartType.Cylinder
|
||||
ring.Anchored, ring.CanCollide, ring.CanTouch, ring.CanQuery, ring.CastShadow = true, false, false, false, false
|
||||
ring.Color, ring.Material, ring.Transparency = Color3.fromRGB(213, 104, 255), Enum.Material.Neon, .55
|
||||
ring.Size = Vector3.new(.12, 1, 1)
|
||||
ring.CFrame = CFrame.new(position + Vector3.yAxis * .2) * CFrame.Angles(0, 0, math.pi / 2)
|
||||
ring.Parent = workspace
|
||||
TweenService:Create(ring, TweenInfo.new(.45, Enum.EasingStyle.Quart), {Size = Vector3.new(.12, 22, 22), Transparency = 1}):Play()
|
||||
Debris:AddItem(ring, .55)
|
||||
end
|
||||
|
||||
local function phantom(player: Player, character: Model, root: BasePart, now: number)
|
||||
local mode = Modes.of(player)
|
||||
local wasArchivable = character.Archivable
|
||||
character.Archivable = true
|
||||
local copy = character:Clone()
|
||||
character.Archivable = wasArchivable
|
||||
for _, child in copy:GetDescendants() do
|
||||
if not child.Parent then continue end
|
||||
if child:IsA("LuaSourceContainer") or child:IsA("Humanoid") or child:IsA("Tool")
|
||||
or child:IsA("Sound") or child:IsA("AudioPlayer") or child:IsA("ParticleEmitter") or child:IsA("Light") then
|
||||
child:Destroy()
|
||||
elseif child:IsA("BasePart") then
|
||||
child.Anchored, child.CanCollide, child.CanTouch, child.CanQuery, child.CastShadow = true, false, false, false, false
|
||||
child.Transparency = math.max(child.Transparency, .36)
|
||||
end
|
||||
end
|
||||
local velocity = root.AssemblyLinearVelocity * flat
|
||||
local direction = if velocity.Magnitude > 3 then velocity.Unit else (root.CFrame.LookVector * flat).Unit
|
||||
local start = CFrame.lookAt(root.Position, root.Position + direction)
|
||||
local wall = workspace:Blockcast(start, Vector3.new(3.2, 3.6, 3.2), direction * 30, Modes.collision(mode))
|
||||
local distance = if wall then math.max(0, wall.Distance - .6) else 30
|
||||
copy.Name = "HunterPhantom"
|
||||
local legs: {[BasePart]: CFrame} = {}
|
||||
for _, limbName in {"LeftUpperLeg", "RightUpperLeg", "LeftUpperArm", "RightUpperArm", "Left Leg", "Right Leg", "Left Arm", "Right Arm"} do
|
||||
local limb = copy:FindFirstChild(limbName)
|
||||
if limb and limb:IsA("BasePart") then legs[limb] = copy:GetPivot():ToObjectSpace(limb.CFrame) end
|
||||
end
|
||||
local glow = Instance.new("Highlight")
|
||||
glow.FillColor, glow.FillTransparency = Color3.fromRGB(147, 83, 255), .8
|
||||
glow.OutlineColor, glow.OutlineTransparency = Color3.fromRGB(214, 176, 255), .4
|
||||
glow.DepthMode = Enum.HighlightDepthMode.Occluded
|
||||
glow.Parent = copy
|
||||
copy:PivotTo(start)
|
||||
copy.Parent = workspace
|
||||
table.insert(decoys, {model = copy, owner = player, mode = mode, born = now, start = start, distance = distance, legs = legs})
|
||||
end
|
||||
|
||||
function Effects.grant(player: Player, key: string, now: number)
|
||||
local character, human, root = alive(player)
|
||||
if not character or not human or not root or not Modes.open(round, Modes.of(player), now) then return end
|
||||
local state = stateOf(player, character, human, now)
|
||||
if timed[key] then character:SetAttribute("Loot" .. key .. "Until", now + timed[key]) end
|
||||
if key == "Turbo" then
|
||||
applySpeed(state, now)
|
||||
elseif key == "Team" then
|
||||
applySpeed(state, now)
|
||||
for _, teammate in Players:GetPlayers() do
|
||||
if teammate == player or not player.Team or teammate.Team ~= player.Team then continue end
|
||||
local ally, h, r = alive(teammate)
|
||||
if ally and h and r and (r.Position - root.Position).Magnitude <= 15 then
|
||||
ally:SetAttribute("LootTeamUntil", now + 3)
|
||||
applySpeed(stateOf(teammate, ally, h, now), now)
|
||||
end
|
||||
end
|
||||
elseif key == "Heal" then
|
||||
human.Health = math.min(human.MaxHealth, human.Health + 25)
|
||||
elseif key == "Shield" then
|
||||
character:SetAttribute("LootShield", 25)
|
||||
elseif key == "Spring" then
|
||||
restoreSpring(state)
|
||||
state.spring = {height = human.JumpHeight, power = human.JumpPower, charge = now}
|
||||
human.JumpHeight *= 1.8
|
||||
human.JumpPower *= math.sqrt(1.8)
|
||||
character:SetAttribute("LootSpring", now)
|
||||
elseif key == "Lucky" then
|
||||
character:SetAttribute("LootLucky", 5)
|
||||
elseif key == "Reload" or key == "Ammo" then
|
||||
character:SetAttribute("Loot" .. key, now)
|
||||
elseif key == "Phantom" then
|
||||
phantom(player, character, root, now)
|
||||
elseif key == "Storm" then
|
||||
state.stormAir = false
|
||||
character:SetAttribute("LootStorm", now)
|
||||
end
|
||||
end
|
||||
|
||||
function Effects.damage(character: Model, humanoid: Humanoid, amount: number, now: number)
|
||||
local shield = character:GetAttribute("LootShield")
|
||||
if typeof(shield) == "number" and shield > 0 and Mobility.active(character, "Shield", now)
|
||||
and not character:FindFirstChildOfClass("ForceField") then
|
||||
local absorbed = math.min(shield, amount)
|
||||
character:SetAttribute("LootShield", shield - absorbed)
|
||||
amount -= absorbed
|
||||
end
|
||||
if amount > 0 then humanoid:TakeDamage(amount) end
|
||||
end
|
||||
|
||||
jumpCharge.OnServerEvent:Connect(function(player: Player, key: unknown, token: unknown)
|
||||
if (key ~= "Spring" and key ~= "Double") or typeof(token) ~= "number" then return end
|
||||
local now = workspace:GetServerTimeNow()
|
||||
if not Modes.open(round, Modes.of(player), now) then return end
|
||||
local character, humanoid, root = alive(player)
|
||||
local state = active[player]
|
||||
if not character or not humanoid or not root or not state or state.character ~= character then return end
|
||||
if key == "Spring" then
|
||||
if state.spring and not state.spring.used and state.spring.charge == token then
|
||||
state.spring.used = true
|
||||
task.delay(.16, function()
|
||||
if active[player] == state and state.spring and state.spring.charge == token then restoreSpring(state) end
|
||||
end)
|
||||
end
|
||||
elseif token == character:GetAttribute("LootDoubleUntil") and token > now then
|
||||
character:SetAttribute("LootDoubleUntil", nil)
|
||||
end
|
||||
end)
|
||||
|
||||
local function checkStorm(player: Player, state: State, root: BasePart, now: number)
|
||||
if not state.character:GetAttribute("LootStorm") then return end
|
||||
local geometry = Modes.collision(Modes.of(player))
|
||||
local hit = workspace:Raycast(root.Position, -Vector3.yAxis * Mobility.groundReach(root, state.human), geometry)
|
||||
if not hit then state.stormAir = true return end
|
||||
if not state.stormAir or math.abs(root.AssemblyLinearVelocity.Y) > 12 then return end
|
||||
state.stormAir = false
|
||||
state.character:SetAttribute("LootStorm", nil)
|
||||
pulse(hit.Position)
|
||||
for _, enemy in Players:GetPlayers() do
|
||||
if enemy == player or enemy.Team == player.Team or not Modes.same(player, enemy) then continue end
|
||||
local character, human, otherRoot = alive(enemy)
|
||||
if not character or not human or not otherRoot then continue end
|
||||
local offset = otherRoot.Position - root.Position
|
||||
if offset.Magnitude <= 11 and not workspace:Raycast(root.Position, offset, geometry) then
|
||||
character:SetAttribute("LootSlowUntil", now + 1)
|
||||
applySpeed(stateOf(enemy, character, human, now), now)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local elapsed = 0
|
||||
RunService.Heartbeat:Connect(function(dt)
|
||||
elapsed += dt
|
||||
if elapsed < .05 then return end
|
||||
elapsed %= .05
|
||||
local now = workspace:GetServerTimeNow()
|
||||
for player, state in active do
|
||||
local char, _, root = alive(player)
|
||||
if char ~= state.character or not root or not Modes.open(round, Modes.of(player), now) then
|
||||
clear(player, now)
|
||||
continue
|
||||
end
|
||||
if Mobility.walkMultiplier(state.character, now) ~= state.speed then applySpeed(state, now) end
|
||||
if state.spring and now - state.spring.charge > 18 then restoreSpring(state) end
|
||||
checkStorm(player, state, root, now)
|
||||
end
|
||||
for i = #decoys, 1, -1 do
|
||||
local decoy = decoys[i]
|
||||
local age = now - decoy.born
|
||||
if age >= 2 or decoy.owner:GetAttribute("InArena") ~= true or Modes.of(decoy.owner) ~= decoy.mode
|
||||
or not Modes.open(round, decoy.mode, now) then
|
||||
decoy.model:Destroy()
|
||||
table.remove(decoys, i)
|
||||
else
|
||||
local pose = decoy.start * CFrame.new(0, .12 * math.abs(math.sin(age * 14)), -decoy.distance * age / 2)
|
||||
decoy.model:PivotTo(pose)
|
||||
for leg, rest in decoy.legs do
|
||||
local swing = math.sin(age * 14) * (if leg.Name:find("Left") then .48 else -.48)
|
||||
leg.CFrame = pose * rest * CFrame.Angles(swing, 0, 0)
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
Players.PlayerRemoving:Connect(function(player) clear(player, workspace:GetServerTimeNow()) end)
|
||||
|
||||
return Effects
|
||||
@@ -0,0 +1,89 @@
|
||||
--!strict
|
||||
local Players = game:GetService("Players")
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local RunService = game:GetService("RunService")
|
||||
local UserInputService = game:GetService("UserInputService")
|
||||
local Mobility = require(ReplicatedStorage:WaitForChild("ArenaMobility") :: ModuleScript)
|
||||
local jumpCharge = ReplicatedStorage:WaitForChild("PowerJumpCharge") :: RemoteEvent
|
||||
local player = Players.LocalPlayer
|
||||
local springWatcher: RBXScriptConnection? = nil
|
||||
local lastSpring, lastDouble = 0, 0
|
||||
|
||||
local function body(): (Model?, Humanoid?, BasePart?)
|
||||
local character = player.Character
|
||||
local h = character and character:FindFirstChildOfClass("Humanoid")
|
||||
local root = character and character.PrimaryPart
|
||||
if player:GetAttribute("InArena") == true and character and h and root and h.Health > 0 and not h.Sit and not root.Anchored then
|
||||
return character, h, root
|
||||
end
|
||||
return nil, nil, nil
|
||||
end
|
||||
|
||||
local function watch(character: Model)
|
||||
local h = character:WaitForChild("Humanoid", 8)
|
||||
if not h or not h:IsA("Humanoid") or player.Character ~= character then return end
|
||||
if springWatcher then springWatcher:Disconnect() end
|
||||
springWatcher = h.Jumping:Connect(function(jumping)
|
||||
local spring = character:GetAttribute("LootSpring")
|
||||
if jumping and character == player.Character and typeof(spring) == "number" and spring ~= lastSpring
|
||||
and player:GetAttribute("InArena") == true then
|
||||
lastSpring = spring
|
||||
jumpCharge:FireServer("Spring", spring)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
local respawn = player.CharacterAdded:Connect(watch)
|
||||
if player.Character then task.spawn(watch, player.Character) end
|
||||
local input = UserInputService.InputBegan:Connect(function(event, processed)
|
||||
if event.KeyCode ~= Enum.KeyCode.Space or processed or UserInputService:GetFocusedTextBox() then return end
|
||||
local character, h, root = body()
|
||||
if not character or not h or not root or h.FloorMaterial ~= Enum.Material.Air then return end
|
||||
local token = character:GetAttribute("LootDoubleUntil")
|
||||
if typeof(token) ~= "number" or token <= workspace:GetServerTimeNow() or token == lastDouble then return end
|
||||
local state = h:GetState()
|
||||
if state ~= Enum.HumanoidStateType.Jumping and state ~= Enum.HumanoidStateType.Freefall then return end
|
||||
local speed = math.sqrt(2 * workspace.Gravity * 8)
|
||||
root:ApplyImpulse(Vector3.yAxis * math.max(0, speed - root.AssemblyLinearVelocity.Y) * root.AssemblyMass)
|
||||
lastDouble = token
|
||||
jumpCharge:FireServer("Double", token)
|
||||
end)
|
||||
|
||||
local quietSounds: {[Sound | AudioPlayer]: number} = {}
|
||||
local elapsed = 0
|
||||
local movement = RunService.PreSimulation:Connect(function(dt)
|
||||
local character, h, root = body()
|
||||
local now = workspace:GetServerTimeNow()
|
||||
if root and h and h.FloorMaterial == Enum.Material.Air and Mobility.active(character, "Feather", now)
|
||||
and UserInputService:IsKeyDown(Enum.KeyCode.Space) and not UserInputService:GetFocusedTextBox() then
|
||||
local gravityDrop = workspace.Gravity * dt
|
||||
local lift = -13 - root.AssemblyLinearVelocity.Y + gravityDrop
|
||||
if lift > 0 and root.AssemblyLinearVelocity.Y < 0 then root:ApplyImpulse(Vector3.yAxis * lift * root.AssemblyMass) end
|
||||
end
|
||||
elapsed += dt
|
||||
if elapsed < .12 then return end
|
||||
elapsed %= .12
|
||||
for sound, before in quietSounds do
|
||||
local model = sound:FindFirstAncestorOfClass("Model")
|
||||
if not sound.Parent or not Mobility.active(model, "Quiet", now) then
|
||||
if sound.Parent then sound.Volume = before end
|
||||
quietSounds[sound] = nil
|
||||
end
|
||||
end
|
||||
for _, other in Players:GetPlayers() do
|
||||
local model = other.Character
|
||||
if not model or not Mobility.active(model, "Quiet", now) then continue end
|
||||
local running = model.PrimaryPart and model.PrimaryPart:FindFirstChild("Running")
|
||||
if running and (running:IsA("Sound") or running:IsA("AudioPlayer")) then
|
||||
if quietSounds[running] == nil then quietSounds[running] = running.Volume end
|
||||
running.Volume = quietSounds[running] * .18
|
||||
end
|
||||
end
|
||||
end)
|
||||
script.Destroying:Once(function()
|
||||
if springWatcher then springWatcher:Disconnect() end
|
||||
input:Disconnect()
|
||||
respawn:Disconnect()
|
||||
movement:Disconnect()
|
||||
for sound, before in quietSounds do if sound.Parent then sound.Volume = before end end
|
||||
end)
|
||||
@@ -0,0 +1,48 @@
|
||||
--!strict
|
||||
-- Script in ServerScriptService.
|
||||
-- Passes a player's reload on to the other players, so they see it in third person.
|
||||
-- Client -> server: ReplicatedStorage.SniperReload:FireServer() (no arguments).
|
||||
-- Server -> other clients: SniperReload:FireClient(other, character, duration).
|
||||
-- Only accepted while the player holds the rifle, and at most once per reload time.
|
||||
|
||||
local Players = game:GetService("Players")
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local StarterPlayer = game:GetService("StarterPlayer")
|
||||
|
||||
local TOOL_NAME = "SniperRifle"
|
||||
local remote = ReplicatedStorage:WaitForChild("SniperReload") :: RemoteEvent
|
||||
local config = StarterPlayer:WaitForChild("StarterPlayerScripts"):WaitForChild("SniperViewmodel")
|
||||
local Modes = require(ReplicatedStorage:WaitForChild("ArenaModes") :: ModuleScript)
|
||||
local round = ReplicatedStorage:WaitForChild("ArenaRound")
|
||||
|
||||
local nextReload: { [Player]: number } = {}
|
||||
|
||||
remote.OnServerEvent:Connect(function(player: Player)
|
||||
local character = player.Character
|
||||
local humanoid = character and character:FindFirstChildOfClass("Humanoid")
|
||||
if player:GetAttribute("InArena") ~= true or not humanoid or humanoid.Health <= 0
|
||||
or not Modes.open(round, Modes.of(player), workspace:GetServerTimeNow()) then return end
|
||||
local tool = character and character:FindFirstChild(TOOL_NAME)
|
||||
if not character or not tool or not tool:IsA("Tool") then
|
||||
return
|
||||
end
|
||||
local reloadTime = (config:GetAttribute("ReloadTime") :: number?) or 2.6
|
||||
local now = os.clock()
|
||||
if now < (nextReload[player] or 0) then
|
||||
return -- still reloading (or spamming the remote)
|
||||
end
|
||||
if character:GetAttribute("LootReload") ~= nil then
|
||||
character:SetAttribute("LootReload", nil)
|
||||
reloadTime *= .5
|
||||
end
|
||||
nextReload[player] = now + reloadTime * .9
|
||||
for _, other in Players:GetPlayers() do
|
||||
if other ~= player and other:GetAttribute("InArena") == true and Modes.same(player, other) then
|
||||
remote:FireClient(other, character, reloadTime)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
Players.PlayerRemoving:Connect(function(player)
|
||||
nextReload[player] = nil
|
||||
end)
|
||||
@@ -0,0 +1,114 @@
|
||||
--!strict
|
||||
-- ModuleScript in ReplicatedStorage.
|
||||
-- The shape of the sniper reload, shared by the first-person viewmodel (SniperViewmodel) and the
|
||||
-- third-person pose seen by other players (ThirdPersonRifle). Times are fractions of the reload
|
||||
-- (0 = start, 1 = end); positions are in the rifle's grip space (-Z = barrel, +Y = up, +X = right).
|
||||
-- 0.00-0.18 the weapon goes into pose A (magazine change: muzzle up, canted)
|
||||
-- 0.04-0.30 left hand: handguard -> magazine -> pulls it down -> throws it away to the left
|
||||
-- 0.30-0.38 left hand out of view, takes a new magazine
|
||||
-- 0.38-0.68 left hand brings it up from below, pushes it in, back to the handguard
|
||||
-- 0.55-0.65 the weapon swings into pose B (bolt: to the left, rolled over)
|
||||
-- 0.62-0.93 right hand: grip -> bolt -> lifts it -> pulls it back -> pushes it forward ->
|
||||
-- locks it down -> back to the grip
|
||||
-- 0.85-1.00 the weapon returns to the normal pose
|
||||
|
||||
local ReloadTimeline = {}
|
||||
|
||||
ReloadTimeline.MAG_GRAB = 0.14 -- the left hand reaches the old magazine
|
||||
ReloadTimeline.MAG_RELEASE = 0.30 -- the old magazine is thrown
|
||||
ReloadTimeline.MAG_NEW = 0.38 -- the new magazine appears in the hand (out of view)
|
||||
ReloadTimeline.MAG_IN = 0.55 -- the new magazine is in the rifle
|
||||
|
||||
local function smooth(a: number): number
|
||||
a = math.clamp(a, 0, 1)
|
||||
return a * a * (3 - 2 * a)
|
||||
end
|
||||
ReloadTimeline.smooth = smooth
|
||||
|
||||
type Key = { number | Vector3 }
|
||||
|
||||
local function track(keys: { Key }, u: number): Vector3
|
||||
local first = keys[1]
|
||||
if u <= (first[1] :: number) then
|
||||
return first[2] :: Vector3
|
||||
end
|
||||
for i = 2, #keys do
|
||||
local k0, k1 = keys[i - 1], keys[i]
|
||||
local u0, u1 = k0[1] :: number, k1[1] :: number
|
||||
if u <= u1 then
|
||||
local a = smooth((u - u0) / math.max(u1 - u0, 1e-3))
|
||||
return (k0[2] :: Vector3):Lerp(k1[2] :: Vector3, a)
|
||||
end
|
||||
end
|
||||
return keys[#keys][2] :: Vector3
|
||||
end
|
||||
|
||||
-- How strongly the weapon is in pose A and pose B. Apply as
|
||||
-- CFrame.identity:Lerp(A, a):Lerp(B, b) (B fully replaces A while b = 1).
|
||||
function ReloadTimeline.weapon(u: number): (number, number)
|
||||
local b = math.min(smooth((u - 0.55) / 0.10), 1 - smooth((u - 0.85) / 0.15))
|
||||
local a = if u < 0.65 then smooth(u / 0.18) else 0
|
||||
return a, b
|
||||
end
|
||||
|
||||
-- Left hand position at time u. rest = its normal place on the handguard, mag = the bottom of
|
||||
-- the magazine, drop = how far down the magazine is pulled out.
|
||||
function ReloadTimeline.leftHand(u: number, rest: Vector3, mag: Vector3, drop: number): Vector3
|
||||
local down = mag - Vector3.new(0, drop, 0)
|
||||
local toss = down + Vector3.new(-drop * 0.5, -drop * 0.2, 0)
|
||||
local away = mag + Vector3.new(-drop * 0.4, -drop * 1.6, drop * 0.3) -- below the view
|
||||
local push = mag + Vector3.new(0, drop * 0.05, 0)
|
||||
return track({
|
||||
{ 0.04, rest },
|
||||
{ ReloadTimeline.MAG_GRAB, mag },
|
||||
{ 0.24, down },
|
||||
{ ReloadTimeline.MAG_RELEASE, toss },
|
||||
{ ReloadTimeline.MAG_NEW, away },
|
||||
{ 0.48, down },
|
||||
{ ReloadTimeline.MAG_IN, mag },
|
||||
{ 0.58, push },
|
||||
{ 0.60, mag },
|
||||
{ 0.68, rest },
|
||||
}, u)
|
||||
end
|
||||
|
||||
-- Right hand position at time u. rest = its normal place on the pistol grip, bolt = the bolt
|
||||
-- handle, lift = how far the bolt is lifted, pull = how far it is pulled back.
|
||||
function ReloadTimeline.rightHand(u: number, rest: Vector3, bolt: Vector3, lift: number, pull: number): Vector3
|
||||
return ReloadTimeline.boltCycle((u - 0.62) / 0.31, rest, bolt, lift, pull)
|
||||
end
|
||||
|
||||
-- One working of the bolt by the right hand, a = 0..1 (also used after every shot):
|
||||
-- grip -> bolt -> lift -> pull back -> push forward -> lock down -> grip.
|
||||
function ReloadTimeline.boltCycle(a: number, rest: Vector3, bolt: Vector3, lift: number, pull: number): Vector3
|
||||
local up = bolt + Vector3.new(0, lift, 0)
|
||||
local back = up + Vector3.new(0, 0, pull)
|
||||
return track({
|
||||
{ 0.00, rest },
|
||||
{ 0.19, bolt },
|
||||
{ 0.29, up },
|
||||
{ 0.48, back },
|
||||
{ 0.61, up },
|
||||
{ 0.71, bolt },
|
||||
{ 1.00, rest },
|
||||
}, a)
|
||||
end
|
||||
|
||||
-- The loose magazines.
|
||||
-- Old one: "held" while the left hand pulls it out, then "flying" after the throw (2nd value =
|
||||
-- seconds since the throw), nil otherwise. New one (3rd value): true while it is in the left
|
||||
-- hand on its way into the rifle.
|
||||
function ReloadTimeline.magazine(u: number, reloadTime: number): (string?, number, boolean)
|
||||
local old: string? = nil
|
||||
local flyTime = 0
|
||||
if u >= ReloadTimeline.MAG_GRAB and u < ReloadTimeline.MAG_RELEASE then
|
||||
old = "held"
|
||||
elseif u >= ReloadTimeline.MAG_RELEASE and u < ReloadTimeline.MAG_RELEASE + 0.25 then
|
||||
old = "flying"
|
||||
flyTime = (u - ReloadTimeline.MAG_RELEASE) * reloadTime
|
||||
end
|
||||
local new = u >= ReloadTimeline.MAG_NEW and u < ReloadTimeline.MAG_IN
|
||||
return old, flyTime, new
|
||||
end
|
||||
|
||||
return ReloadTimeline
|
||||
@@ -0,0 +1,116 @@
|
||||
--!strict
|
||||
-- Script in ServerScriptService.
|
||||
-- Interchangeable sights of the rifle: ReplicatedStorage.RifleParts.Sights holds one model per
|
||||
-- sight (Iron, RedDot, Scope), all in grip space (the Handle's frame). The chosen sight is part of
|
||||
-- the tool itself (Tool.RifleMesh.Sight, welded to the Handle), so every player sees it in third
|
||||
-- person; the tool's "Sight" attribute names it, and the first-person viewmodel copies it.
|
||||
-- Client -> server: ReplicatedStorage.RifleSight:FireServer(sightName)
|
||||
-- The choice is kept on the player (attribute RifleSight) and given to every new rifle, so it
|
||||
-- survives respawns.
|
||||
|
||||
local Players = game:GetService("Players")
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
|
||||
local TOOL_NAME = "SniperRifle"
|
||||
local DEFAULT_SIGHT = "Iron"
|
||||
local sights = ReplicatedStorage:WaitForChild("RifleParts"):WaitForChild("Sights")
|
||||
local remote = ReplicatedStorage:WaitForChild("RifleSight") :: RemoteEvent
|
||||
|
||||
local function setSight(tool: Tool, name: string)
|
||||
local mesh = tool:FindFirstChild("RifleMesh")
|
||||
local handle = tool:FindFirstChild("Handle")
|
||||
local model = sights:FindFirstChild(name)
|
||||
if not mesh or not handle or not handle:IsA("BasePart") or not model then
|
||||
return
|
||||
end
|
||||
if tool:GetAttribute("Sight") == name and mesh:FindFirstChild("Sight") then
|
||||
return
|
||||
end
|
||||
local old = mesh:FindFirstChild("Sight")
|
||||
if old then
|
||||
old:Destroy()
|
||||
end
|
||||
local sight = Instance.new("Model")
|
||||
sight.Name = "Sight"
|
||||
for _, p in model:GetChildren() do
|
||||
if p:IsA("BasePart") then
|
||||
local c = p:Clone()
|
||||
c.CFrame = handle.CFrame * p.CFrame
|
||||
c.Anchored = false
|
||||
local weld = Instance.new("WeldConstraint")
|
||||
weld.Part0 = handle
|
||||
weld.Part1 = c
|
||||
weld.Parent = c
|
||||
c.Parent = sight
|
||||
end
|
||||
end
|
||||
sight.Parent = mesh
|
||||
tool:SetAttribute("Sight", name)
|
||||
end
|
||||
|
||||
local function chosen(player: Player): string
|
||||
local name = player:GetAttribute("RifleSight")
|
||||
return if typeof(name) == "string" and sights:FindFirstChild(name) then name else DEFAULT_SIGHT
|
||||
end
|
||||
|
||||
local function rifles(player: Player): { Tool }
|
||||
local list = {}
|
||||
for _, container in { player.Character, player:FindFirstChildOfClass("Backpack") } do
|
||||
local tool = container and container:FindFirstChild(TOOL_NAME)
|
||||
if tool and tool:IsA("Tool") then
|
||||
table.insert(list, tool)
|
||||
end
|
||||
end
|
||||
return list
|
||||
end
|
||||
|
||||
local function watch(player: Player, container: Instance)
|
||||
container.ChildAdded:Connect(function(child)
|
||||
if child:IsA("Tool") and child.Name == TOOL_NAME then
|
||||
setSight(child, chosen(player))
|
||||
end
|
||||
end)
|
||||
for _, tool in rifles(player) do
|
||||
setSight(tool, chosen(player))
|
||||
end
|
||||
end
|
||||
|
||||
local lastChange: { [Player]: number } = {}
|
||||
remote.OnServerEvent:Connect(function(player: Player, name: unknown)
|
||||
if typeof(name) ~= "string" or not sights:FindFirstChild(name) then
|
||||
return
|
||||
end
|
||||
local now = os.clock()
|
||||
if now - (lastChange[player] or -math.huge) < 0.25 then
|
||||
return
|
||||
end
|
||||
lastChange[player] = now
|
||||
player:SetAttribute("RifleSight", name)
|
||||
for _, tool in rifles(player) do
|
||||
setSight(tool, name)
|
||||
end
|
||||
end)
|
||||
|
||||
local function onPlayer(player: Player)
|
||||
-- Every respawn brings a new character and Backpack; the arena grants the rifle.
|
||||
player.CharacterAdded:Connect(function(character)
|
||||
watch(player, character)
|
||||
end)
|
||||
player.ChildAdded:Connect(function(child)
|
||||
if child:IsA("Backpack") then
|
||||
watch(player, child)
|
||||
end
|
||||
end)
|
||||
for _, container in { player.Character, player:FindFirstChildOfClass("Backpack") } do
|
||||
if container then
|
||||
watch(player, container)
|
||||
end
|
||||
end
|
||||
end
|
||||
Players.PlayerAdded:Connect(onPlayer)
|
||||
for _, player in Players:GetPlayers() do
|
||||
onPlayer(player)
|
||||
end
|
||||
Players.PlayerRemoving:Connect(function(player)
|
||||
lastChange[player] = nil
|
||||
end)
|
||||
@@ -0,0 +1,378 @@
|
||||
--!strict
|
||||
-- Cosmetic skin for the camera viewmodel and the equipped world rifle.
|
||||
local Variants = require(script.Parent:WaitForChild("RifleSkinVariants") :: ModuleScript)
|
||||
local RifleSkin = {}
|
||||
|
||||
type Palette = {cool: Color3, hot: Color3, phase: number, reflectance: number}
|
||||
local bodyPalette: {[string]: Palette} = {
|
||||
Rifle_TitaniumPanels = {
|
||||
cool = Color3.fromRGB(185, 203, 246), hot = Color3.fromRGB(242, 253, 255),
|
||||
phase = .82, reflectance = .13,
|
||||
},
|
||||
Rifle_CeramicGraphite = {
|
||||
cool = Color3.fromRGB(43, 73, 226), hot = Color3.fromRGB(74, 133, 251),
|
||||
phase = 0, reflectance = .14,
|
||||
},
|
||||
Rifle_Rubber = {
|
||||
cool = Color3.fromRGB(41, 71, 168), hot = Color3.fromRGB(76, 125, 218),
|
||||
phase = 1.7, reflectance = .035,
|
||||
},
|
||||
}
|
||||
local channelPalette: {[string]: Palette} = {
|
||||
Rifle_CyanChannel = {
|
||||
cool = Color3.fromRGB(26, 150, 247), hot = Color3.fromRGB(103, 244, 255),
|
||||
phase = .25, reflectance = 0,
|
||||
},
|
||||
Rifle_AmberChannel = {
|
||||
cool = Color3.fromRGB(51, 131, 255), hot = Color3.fromRGB(156, 247, 255),
|
||||
phase = 1.15, reflectance = 0,
|
||||
},
|
||||
}
|
||||
local paletteSlots: {[string]: number} = {
|
||||
Rifle_TitaniumPanels = 1, Rifle_CeramicGraphite = 2, Rifle_Rubber = 3,
|
||||
Rifle_CyanChannel = 4, Rifle_AmberChannel = 5,
|
||||
}
|
||||
|
||||
local flameColor = ColorSequence.new({
|
||||
ColorSequenceKeypoint.new(0, Color3.fromRGB(210, 252, 255)),
|
||||
ColorSequenceKeypoint.new(.28, Color3.fromRGB(53, 203, 255)),
|
||||
ColorSequenceKeypoint.new(.72, Color3.fromRGB(22, 112, 255)),
|
||||
ColorSequenceKeypoint.new(1, Color3.fromRGB(34, 70, 230)),
|
||||
})
|
||||
local flameSize = NumberSequence.new({
|
||||
NumberSequenceKeypoint.new(0, .29, .06),
|
||||
NumberSequenceKeypoint.new(.37, .52, .11),
|
||||
NumberSequenceKeypoint.new(1, .22, .08),
|
||||
})
|
||||
local flameOpacity = NumberSequence.new({
|
||||
NumberSequenceKeypoint.new(0, .57),
|
||||
NumberSequenceKeypoint.new(.18, .44, .08),
|
||||
NumberSequenceKeypoint.new(.6, .61, .12),
|
||||
NumberSequenceKeypoint.new(1, 1),
|
||||
})
|
||||
local locations = {
|
||||
Vector3.new(.26, .61, -.04),
|
||||
Vector3.new(.28, .62, -1.00),
|
||||
Vector3.new(-.27, .62, -.65),
|
||||
Vector3.new(.24, .61, -2.17),
|
||||
Vector3.new(-.22, .64, -2.63),
|
||||
Vector3.new(.12, .64, -3.40),
|
||||
}
|
||||
|
||||
type Layer = {emitter: ParticleEmitter, rate: number, focusedRate: number}
|
||||
type Panel = {part: BasePart, palette: Palette}
|
||||
type Tongue = {base: Vector3, tip: Attachment, core: Beam, halo: Beam, phase: number}
|
||||
type Stream = {start: Attachment, finish: Attachment, core: Beam, halo: Beam, side: number, phase: number}
|
||||
export type Effect = {
|
||||
grip: BasePart,
|
||||
panels: {Panel},
|
||||
anchors: {Attachment},
|
||||
layers: {Layer},
|
||||
tongues: {Tongue},
|
||||
streams: {Stream},
|
||||
variant: Variants.Effect?,
|
||||
light: PointLight,
|
||||
mode: "Hidden" | "Full" | "Focused",
|
||||
nextFrame: number,
|
||||
flashUntil: number,
|
||||
}
|
||||
|
||||
local tongueCore = ColorSequence.new({
|
||||
ColorSequenceKeypoint.new(0, Color3.fromRGB(197, 251, 255)),
|
||||
ColorSequenceKeypoint.new(.36, Color3.fromRGB(47, 220, 255)),
|
||||
ColorSequenceKeypoint.new(1, Color3.fromRGB(43, 124, 255)),
|
||||
})
|
||||
local tongueHalo = ColorSequence.new(Color3.fromRGB(28, 163, 255), Color3.fromRGB(28, 90, 238))
|
||||
local streamCore = ColorSequence.new({
|
||||
ColorSequenceKeypoint.new(0, Color3.fromRGB(32, 123, 255)),
|
||||
ColorSequenceKeypoint.new(.55, Color3.fromRGB(109, 237, 255)),
|
||||
ColorSequenceKeypoint.new(1, Color3.fromRGB(211, 255, 255)),
|
||||
})
|
||||
|
||||
local function ribbon(base: Attachment, tip: Attachment, name: string, color: ColorSequence, transparency: NumberSequence): Beam
|
||||
local beam = Instance.new("Beam")
|
||||
beam.Name = name
|
||||
beam.Attachment0 = base
|
||||
beam.Attachment1 = tip
|
||||
beam.FaceCamera = true
|
||||
beam.Segments = 14
|
||||
beam.LightEmission = 1
|
||||
beam.Color = color
|
||||
beam.Transparency = transparency
|
||||
beam.Width0 = 0
|
||||
beam.Width1 = 0
|
||||
beam.Enabled = false
|
||||
beam.Parent = base
|
||||
return beam
|
||||
end
|
||||
|
||||
local function fadeTip(transparency: number): NumberSequence
|
||||
return NumberSequence.new({
|
||||
NumberSequenceKeypoint.new(0, transparency),
|
||||
NumberSequenceKeypoint.new(.44, transparency),
|
||||
NumberSequenceKeypoint.new(1, 1),
|
||||
})
|
||||
end
|
||||
|
||||
local streamFade = NumberSequence.new({
|
||||
NumberSequenceKeypoint.new(0, 1),
|
||||
NumberSequenceKeypoint.new(.32, .45),
|
||||
NumberSequenceKeypoint.new(.74, .12),
|
||||
NumberSequenceKeypoint.new(1, 1),
|
||||
})
|
||||
local haloFade = NumberSequence.new({
|
||||
NumberSequenceKeypoint.new(0, 1),
|
||||
NumberSequenceKeypoint.new(.45, .81),
|
||||
NumberSequenceKeypoint.new(.76, .57),
|
||||
NumberSequenceKeypoint.new(1, 1),
|
||||
})
|
||||
|
||||
local function streamAnchor(grip: BasePart, name: string): Attachment
|
||||
local anchor = Instance.new("Attachment")
|
||||
anchor.Name = name
|
||||
anchor.Axis = Vector3.zAxis
|
||||
anchor.Parent = grip
|
||||
return anchor
|
||||
end
|
||||
|
||||
local function streamPoint(side: number, position: number, phase: number): Vector3
|
||||
local wave = math.sin(position * 15 + phase)
|
||||
local z = -3.7 + position * 4.32
|
||||
return Vector3.new(side * (.32 + .033 * wave), .44 + .12 * math.sin(position * 9 + phase), z)
|
||||
end
|
||||
|
||||
local function channel(anchor: Attachment, name: string, texture: string): ParticleEmitter
|
||||
local emitter = Instance.new("ParticleEmitter")
|
||||
emitter.Name = name
|
||||
emitter.Texture = texture
|
||||
emitter.LightEmission = 1
|
||||
emitter.Orientation = Enum.ParticleOrientation.FacingCamera
|
||||
emitter.EmissionDirection = Enum.NormalId.Right -- attachment X axis points up from the receiver
|
||||
emitter.LockedToPart = true
|
||||
emitter.Enabled = false
|
||||
emitter.Parent = anchor
|
||||
return emitter
|
||||
end
|
||||
|
||||
function RifleSkin.setMode(effect: Effect?, mode: "Hidden" | "Full" | "Focused")
|
||||
if not effect or effect.mode == mode then return end
|
||||
effect.mode = mode
|
||||
for _, layer in effect.layers do
|
||||
local rate = if mode == "Full" then layer.rate elseif mode == "Focused" then layer.focusedRate else 0
|
||||
local emitter = layer.emitter
|
||||
emitter.Rate = rate
|
||||
emitter.Enabled = rate > 0
|
||||
if rate == 0 then emitter:Clear() end
|
||||
end
|
||||
for _, tongue in effect.tongues do
|
||||
tongue.core.Enabled = mode == "Full"
|
||||
tongue.halo.Enabled = mode == "Full"
|
||||
end
|
||||
for _, stream in effect.streams do
|
||||
stream.core.Enabled = mode == "Full"
|
||||
stream.halo.Enabled = mode == "Full"
|
||||
end
|
||||
if effect.variant then Variants.setVisible(effect.variant, mode == "Full") end
|
||||
effect.light.Enabled = mode ~= "Hidden"
|
||||
effect.light.Brightness = if mode == "Focused" then .18 else .65
|
||||
end
|
||||
|
||||
local FLASH_TIME = .23
|
||||
function RifleSkin.pulse(effect: Effect?)
|
||||
if effect then effect.flashUntil = os.clock() + FLASH_TIME end
|
||||
end
|
||||
|
||||
function RifleSkin.animate(effect: Effect?, now: number)
|
||||
if not effect or effect.mode == "Hidden" or now < effect.nextFrame then return end
|
||||
effect.nextFrame = now + 1 / 50
|
||||
local camera = workspace.CurrentCamera
|
||||
local grazing = 0
|
||||
if camera then
|
||||
local ray = camera.CFrame.Position - effect.grip.Position
|
||||
if ray.Magnitude > .01 then
|
||||
grazing = (1 - math.abs(ray.Unit:Dot(effect.grip.CFrame.RightVector))) ^ 2
|
||||
end
|
||||
end
|
||||
local flash = math.clamp((effect.flashUntil - now) / FLASH_TIME, 0, 1)
|
||||
for _, panel in effect.panels do
|
||||
local colors = panel.palette
|
||||
local t = now * 2.8 + colors.phase
|
||||
local heat = .42 + .31 * math.sin(t) + .08 * math.sin(t * 2.3) + .16 * grazing + .18 * flash
|
||||
panel.part.Color = colors.cool:Lerp(colors.hot, math.clamp(heat, 0, 1))
|
||||
end
|
||||
|
||||
if effect.mode ~= "Full" then return end
|
||||
effect.light.Brightness = .52 + .12 * math.sin(now * 12) + .48 * flash
|
||||
if effect.variant then
|
||||
effect.variant.animate(now, flash)
|
||||
return
|
||||
end
|
||||
for _, tongue in effect.tongues do
|
||||
local t = now * 15 + tongue.phase
|
||||
local sway = math.sin(t)
|
||||
local heat = .58 + .26 * math.sin(t * .91) + .16 * math.sin(t * 1.83)
|
||||
local rise = .09 + .30 * heat + .10 * flash
|
||||
local sweep = .20 + .44 * heat + .19 * flash
|
||||
tongue.tip.Position = tongue.base + Vector3.new(.11 * sway, rise, sweep)
|
||||
local width = .03 + .115 * heat + .055 * flash
|
||||
tongue.core.Width0 = width
|
||||
tongue.halo.Width0 = width * 1.95
|
||||
tongue.core.CurveSize0 = rise * .93
|
||||
tongue.halo.CurveSize0 = tongue.core.CurveSize0
|
||||
tongue.core.CurveSize1 = .20 + .13 * sway
|
||||
tongue.halo.CurveSize1 = tongue.core.CurveSize1
|
||||
end
|
||||
for _, stream in effect.streams do
|
||||
local head = (now * .9 + stream.phase) % 1
|
||||
local tail = math.max(0, head - .34)
|
||||
local strength = math.sin(head * math.pi) ^ .7
|
||||
local ripple = now * 6 + stream.phase * 5
|
||||
stream.start.Position = streamPoint(stream.side, tail, ripple)
|
||||
stream.finish.Position = streamPoint(stream.side, head, ripple)
|
||||
local width = strength * (.16 + .10 * flash)
|
||||
stream.core.Width0 = width * .45
|
||||
stream.core.Width1 = width
|
||||
stream.halo.Width0 = width
|
||||
stream.halo.Width1 = width * 2.45
|
||||
end
|
||||
end
|
||||
|
||||
function RifleSkin.apply(model: Instance, grip: BasePart, id: string, accent: Color3): Effect
|
||||
local mesh = model:FindFirstChild("RifleMesh") or model
|
||||
local theme = Variants.palettes[id]
|
||||
local panels: {Panel} = {}
|
||||
for _, child in mesh:GetChildren() do
|
||||
if not child:IsA("BasePart") then continue end
|
||||
local colors = bodyPalette[child.Name]
|
||||
if colors then
|
||||
-- The stock PBR map is nearly black and absorbs the blue tint.
|
||||
local surface = child:FindFirstChildOfClass("SurfaceAppearance")
|
||||
if surface then surface:Destroy() end
|
||||
child.Material = Enum.Material.SmoothPlastic
|
||||
child.Reflectance = colors.reflectance
|
||||
else
|
||||
colors = channelPalette[child.Name]
|
||||
end
|
||||
if colors then
|
||||
local alternate = theme and theme[paletteSlots[child.Name]]
|
||||
if alternate then
|
||||
colors = {
|
||||
cool = alternate.cool, hot = alternate.hot, phase = colors.phase, reflectance = colors.reflectance,
|
||||
}
|
||||
end
|
||||
child.Color = colors.cool:Lerp(colors.hot, .42)
|
||||
table.insert(panels, {part = child, palette = colors})
|
||||
end
|
||||
end
|
||||
|
||||
local anchors: {Attachment} = {}
|
||||
local layers: {Layer} = {}
|
||||
local tongues: {Tongue} = {}
|
||||
local streams: {Stream} = {}
|
||||
local light = Instance.new("PointLight")
|
||||
light.Name = "FlameGlow"
|
||||
light.Color = if theme then accent else Color3.fromRGB(47, 170, 255)
|
||||
light.Range = 3.4
|
||||
light.Enabled = false
|
||||
local effect: Effect = {
|
||||
grip = grip, panels = panels, anchors = anchors, layers = layers, tongues = tongues,
|
||||
streams = streams, light = light, mode = "Hidden", nextFrame = 0, flashUntil = 0,
|
||||
}
|
||||
if theme then
|
||||
local variant = Variants.create(id, grip)
|
||||
light.Parent = variant.root
|
||||
effect.variant = variant
|
||||
return effect
|
||||
end
|
||||
|
||||
for index, position in locations do
|
||||
local anchor = Instance.new("Attachment")
|
||||
anchor.Name = "BlueFlame" .. index
|
||||
anchor.Position = position
|
||||
anchor.Parent = grip
|
||||
table.insert(anchors, anchor)
|
||||
|
||||
local flame = channel(anchor, "Flame", "rbxasset://textures/particles/fire_main.dds")
|
||||
flame.Color = flameColor
|
||||
flame.Size = flameSize
|
||||
flame.Transparency = flameOpacity
|
||||
flame.Lifetime = NumberRange.new(.24, .48)
|
||||
flame.Speed = NumberRange.new(.72, 1.8)
|
||||
flame.SpreadAngle = Vector2.new(22, 22)
|
||||
flame.Rotation = NumberRange.new(-25, 25)
|
||||
flame.RotSpeed = NumberRange.new(-65, 65)
|
||||
flame.Brightness = 2
|
||||
table.insert(layers, {emitter = flame, rate = 12, focusedRate = if index == 6 then 4 else 0})
|
||||
|
||||
-- The face-camera ribbons give the softer particles a distinct flame shape.
|
||||
anchor.Axis = Vector3.new(0, .78, .63).Unit
|
||||
local tip = Instance.new("Attachment")
|
||||
tip.Name = "BlueFlameTip" .. index
|
||||
tip.Position = position + Vector3.new(0, .45, .25)
|
||||
tip.Axis = Vector3.new(0, .2, 1).Unit
|
||||
tip.Parent = grip
|
||||
table.insert(tongues, {
|
||||
base = position, tip = tip, phase = index * 3.43,
|
||||
core = ribbon(anchor, tip, "FlameCore", tongueCore, fadeTip(.22)),
|
||||
halo = ribbon(anchor, tip, "FlameHalo", tongueHalo, fadeTip(.64)),
|
||||
})
|
||||
end
|
||||
|
||||
-- Two staggered pulses per side follow the casing from muzzle to receiver.
|
||||
for _, side in {-1, 1} do
|
||||
for lane = 1, 2 do
|
||||
local start = streamAnchor(grip, "BlueFlameStream")
|
||||
local finish = streamAnchor(grip, "BlueFlameStreamEnd")
|
||||
table.insert(anchors, start)
|
||||
table.insert(anchors, finish)
|
||||
local core = ribbon(start, finish, "StreamCore", streamCore, streamFade)
|
||||
local halo = ribbon(start, finish, "StreamHalo", tongueHalo, haloFade)
|
||||
core.CurveSize0, core.CurveSize1 = .22, .18
|
||||
halo.CurveSize0, halo.CurveSize1 = .22, .18
|
||||
table.insert(streams, {
|
||||
start = start, finish = finish, core = core, halo = halo, side = side,
|
||||
phase = (lane - 1) * .5 + (if side == 1 then .18 else 0),
|
||||
})
|
||||
if lane == 1 then
|
||||
local glint = channel(finish, "StreamGlint", "rbxasset://textures/particles/sparkles_main.dds")
|
||||
glint.Brightness = 2.4
|
||||
glint.Color = ColorSequence.new(Color3.fromRGB(191, 252, 255), Color3.fromRGB(47, 139, 252))
|
||||
glint.Size = NumberSequence.new({
|
||||
NumberSequenceKeypoint.new(0, .24),
|
||||
NumberSequenceKeypoint.new(.3, .42),
|
||||
NumberSequenceKeypoint.new(1, .12),
|
||||
})
|
||||
glint.Transparency = NumberSequence.new(.2, 1)
|
||||
glint.Lifetime = NumberRange.new(.11, .18)
|
||||
glint.Speed = NumberRange.new(.06, .18)
|
||||
glint.Rotation = NumberRange.new(-40, 40)
|
||||
table.insert(layers, {emitter = glint, rate = 8, focusedRate = 0})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for _, index in {2, 5} do
|
||||
local embers = channel(anchors[index], "Sparks", "rbxasset://textures/particles/sparkles_main.dds")
|
||||
embers.Color = ColorSequence.new(Color3.fromRGB(193, 246, 255), Color3.fromRGB(26, 144, 255))
|
||||
embers.Size = NumberSequence.new(.075, .015)
|
||||
embers.Transparency = NumberSequence.new(.13, 1)
|
||||
embers.Lifetime = NumberRange.new(.28, .51)
|
||||
embers.Speed = NumberRange.new(1.65, 3.2)
|
||||
embers.SpreadAngle = Vector2.new(42, 42)
|
||||
embers.Rotation = NumberRange.new(0, 360)
|
||||
embers.RotSpeed = NumberRange.new(-80, 80)
|
||||
table.insert(layers, {emitter = embers, rate = 9, focusedRate = 0})
|
||||
end
|
||||
|
||||
light.Parent = anchors[4]
|
||||
return effect
|
||||
end
|
||||
|
||||
function RifleSkin.destroy(effect: Effect?)
|
||||
if not effect then return end
|
||||
if effect.variant then effect.variant.root:Destroy() end
|
||||
for _, anchor in effect.anchors do anchor:Destroy() end
|
||||
for _, tongue in effect.tongues do tongue.tip:Destroy() end
|
||||
end
|
||||
|
||||
return RifleSkin
|
||||
@@ -0,0 +1,28 @@
|
||||
--!strict
|
||||
local entries = table.freeze({
|
||||
table.freeze({ id = "BlueFlame", name = "Голубое пламя", accent = Color3.fromRGB(100, 223, 255) }),
|
||||
table.freeze({ id = "ThunderBlade", name = "Грозовой клинок", accent = Color3.fromRGB(193, 142, 255) }),
|
||||
table.freeze({ id = "CrimsonSeal", name = "Алая печать", accent = Color3.fromRGB(255, 113, 81) }),
|
||||
table.freeze({ id = "Sakura", name = "Сакура", accent = Color3.fromRGB(255, 161, 209) }),
|
||||
table.freeze({ id = "NeonGlitch", name = "Неоновый сбой", accent = Color3.fromRGB(138, 255, 80) }),
|
||||
table.freeze({ id = "LunarOrbit", name = "Лунная орбита", accent = Color3.fromRGB(255, 210, 120) }),
|
||||
})
|
||||
|
||||
local Catalog = {}
|
||||
|
||||
local function indexOf(id: unknown): number
|
||||
for index, entry in entries do
|
||||
if id == entry.id then return index end
|
||||
end
|
||||
return 1
|
||||
end
|
||||
|
||||
function Catalog.get(id: unknown)
|
||||
return entries[indexOf(id)]
|
||||
end
|
||||
|
||||
function Catalog.next(id: unknown)
|
||||
return entries[indexOf(id) % #entries + 1]
|
||||
end
|
||||
|
||||
return table.freeze(Catalog)
|
||||
@@ -0,0 +1,308 @@
|
||||
--!strict
|
||||
-- Cosmetic components live on each client. Palettes are ordered armor, body, grip, and two channels.
|
||||
local Variants = {}
|
||||
type Colors = {cool: Color3, hot: Color3}
|
||||
type Animator = (now: number, flash: number) -> ()
|
||||
type Switch = Beam | Trail | ParticleEmitter
|
||||
export type Effect = {
|
||||
root: Attachment,
|
||||
animate: Animator,
|
||||
switches: {Switch},
|
||||
decorations: {Part},
|
||||
}
|
||||
|
||||
local function palette(hex: {string}): {Colors}
|
||||
local colors = {}
|
||||
for i = 1, #hex, 2 do
|
||||
table.insert(colors, {cool = Color3.fromHex(hex[i]), hot = Color3.fromHex(hex[i + 1])})
|
||||
end
|
||||
return colors
|
||||
end
|
||||
|
||||
Variants.palettes = {
|
||||
ThunderBlade = palette({"a06ce9", "e9dcff", "261b69", "5740c1", "26264c", "555377", "7745ff", "d3b1ff", "9956ff", "f8e5ff"}),
|
||||
CrimsonSeal = palette({"a24051", "ed8862", "560f28", "a02235", "411627", "762634", "ff492c", "ff9870", "e81a39", "ffd18a"}),
|
||||
Sakura = palette({"f5c8d6", "fff1ea", "98466f", "e88eaf", "6e385d", "a95884", "ff72b1", "ffe4f2", "b84387", "ffadcf"}),
|
||||
NeonGlitch = palette({"608b69", "a6eab4", "142b32", "315d52", "263842", "4c6459", "51ec27", "c4ff77", "13b587", "63ffd7"}),
|
||||
LunarOrbit = palette({"bd8841", "fbe6a6", "1d2955", "4b58a4", "282e4b", "56587c", "ffc15e", "fff3c9", "8574ff", "adc4ff"}),
|
||||
}
|
||||
|
||||
local SPARK = "rbxasset://textures/particles/sparkles_main.dds"
|
||||
local PIXEL = "rbxasset://textures/particles/SquareParticle.png"
|
||||
|
||||
local function pin(parent: Attachment): Attachment
|
||||
local point = Instance.new("Attachment")
|
||||
point.Parent = parent
|
||||
return point
|
||||
end
|
||||
|
||||
local function line(a: Attachment, b: Attachment, color: Color3, width: number, alpha: number): Beam
|
||||
local beam = Instance.new("Beam")
|
||||
beam.Attachment0 = a
|
||||
beam.Attachment1 = b
|
||||
beam.FaceCamera = true
|
||||
beam.Segments = 1
|
||||
beam.Width0 = width
|
||||
beam.Width1 = width
|
||||
beam.LightEmission = .98
|
||||
beam.Color = ColorSequence.new(color)
|
||||
beam.Transparency = NumberSequence.new(alpha)
|
||||
beam.Enabled = false
|
||||
beam.Parent = a
|
||||
return beam
|
||||
end
|
||||
|
||||
local function path(root: Attachment, count: number, closed: boolean, color: Color3, width: number, alpha: number): {Attachment}
|
||||
local points: {Attachment} = {}
|
||||
for i = 1, count do points[i] = pin(root) end
|
||||
for i = 1, (if closed then count else count - 1) do
|
||||
line(points[i], points[i % count + 1], color, width, alpha)
|
||||
end
|
||||
return points
|
||||
end
|
||||
|
||||
local function specks(root: Attachment, color: Color3, texture: string, rate: number)
|
||||
local emitter = Instance.new("ParticleEmitter")
|
||||
emitter.Name = "SkinSpecks"
|
||||
emitter.Texture = texture
|
||||
emitter.Color = ColorSequence.new(Color3.fromRGB(255, 250, 248), color)
|
||||
emitter.LightEmission = .9
|
||||
emitter.Size = NumberSequence.new(.10, .02)
|
||||
emitter.Transparency = NumberSequence.new(.16, 1)
|
||||
emitter.Rate = rate
|
||||
emitter.Lifetime = NumberRange.new(.24, .49)
|
||||
emitter.Speed = NumberRange.new(.48, 1.18)
|
||||
emitter.SpreadAngle = Vector2.new(48, 48)
|
||||
emitter.EmissionDirection = Enum.NormalId.Top
|
||||
emitter.Rotation = NumberRange.new(0, 360)
|
||||
emitter.LockedToPart = true
|
||||
emitter.Enabled = false
|
||||
emitter.Parent = root
|
||||
end
|
||||
|
||||
local function shape(root: Attachment, name: string, size: Vector3, color: Color3, kind: Enum.PartType): Part
|
||||
local piece = Instance.new("Part")
|
||||
piece.Name = name
|
||||
piece.Shape = kind
|
||||
piece.Size = size
|
||||
piece.Color = color
|
||||
piece.Material = Enum.Material.Neon
|
||||
piece.Anchored = true
|
||||
piece.CanCollide = false
|
||||
piece.CanTouch = false
|
||||
piece.CanQuery = false
|
||||
piece.CastShadow = false
|
||||
piece.Transparency = 1
|
||||
piece.Parent = root
|
||||
return piece
|
||||
end
|
||||
|
||||
local function thunder(root: Attachment, _grip: BasePart): Animator
|
||||
local lilac = Color3.fromRGB(165, 102, 255)
|
||||
local white = Color3.fromRGB(240, 225, 255)
|
||||
local rng = Random.new()
|
||||
local bolts = {}
|
||||
for _, side in {-1, 1} do
|
||||
local bus = path(root, 8, false, white, .04, .08)
|
||||
for i = 1, #bus - 1 do line(bus[i], bus[i + 1], lilac, .125, .66) end
|
||||
table.insert(bolts, {side = side, bus = bus, branch = path(root, 4, false, lilac, .045, .24)})
|
||||
end
|
||||
local sparks = pin(root)
|
||||
sparks.Position = Vector3.new(.05, .64, -1.8)
|
||||
specks(sparks, lilac, SPARK, 25)
|
||||
local nextArc = 0
|
||||
return function(now, flash)
|
||||
if now < nextArc then return end
|
||||
nextArc = now + rng:NextNumber(.055, .092)
|
||||
for _, bolt in bolts do
|
||||
local start = -3.65 + rng:NextNumber(0, .55)
|
||||
for i, point in bolt.bus do
|
||||
local z = start + (i - 1) * .56
|
||||
local jitter = rng:NextNumber(-.19, .19) * (1 + flash * .35)
|
||||
point.Position = Vector3.new(bolt.side * (.34 + rng:NextNumber(0, .072)), .47 + jitter, z)
|
||||
end
|
||||
local origin = bolt.bus[rng:NextInteger(3, 5)].Position
|
||||
for i, point in bolt.branch do
|
||||
local step = i - 1
|
||||
point.Position = origin + Vector3.new(.036 * step * bolt.side, .13 * step, .21 * step)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function seal(root: Attachment, _grip: BasePart): Animator
|
||||
local gold = Color3.fromRGB(255, 181, 83)
|
||||
local red = Color3.fromRGB(255, 54, 47)
|
||||
local marks = {}
|
||||
for _, side in {-1, 1} do
|
||||
local center = Vector3.new(.38 * side, .49, -.74)
|
||||
local hex = path(root, 6, true, red, .060, .15)
|
||||
for i, node in hex do line(node, hex[i % #hex + 1], red, .16, .76) end
|
||||
table.insert(marks, {center = center, outer = hex, inner = path(root, 3, true, gold, .048, .08), side = side})
|
||||
end
|
||||
local embers = pin(root)
|
||||
embers.Position = Vector3.new(0, .8, -.73)
|
||||
specks(embers, Color3.fromRGB(255, 93, 47), PIXEL, 17)
|
||||
return function(now, flash)
|
||||
for _, mark in marks do
|
||||
local radius = .34 + .041 * math.sin(now * 5.6) + .072 * flash
|
||||
for i, point in mark.outer do
|
||||
local theta = now * 1.75 * mark.side + (i - 1) * math.pi / 3
|
||||
point.Position = mark.center + Vector3.new(0, math.cos(theta) * radius, math.sin(theta) * radius)
|
||||
end
|
||||
for i, point in mark.inner do
|
||||
local theta = -now * 1.34 * mark.side + (i - 1) * 2 * math.pi / 3
|
||||
point.Position = mark.center + Vector3.new(.013 * mark.side, math.cos(theta) * radius * .67, math.sin(theta) * radius * .67)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function sakura(root: Attachment, grip: BasePart): Animator
|
||||
local pink = Color3.fromRGB(249, 82, 150)
|
||||
local pale = Color3.fromRGB(255, 208, 226)
|
||||
local petals: {Part} = {}
|
||||
for i = 1, 12 do
|
||||
local tint = pink:Lerp(pale, (i % 4) / 3)
|
||||
local petal = shape(root, "Petal", Vector3.new(.14, .14, .14), tint, Enum.PartType.Block)
|
||||
petal.Material = Enum.Material.SmoothPlastic
|
||||
local mesh = Instance.new("SpecialMesh")
|
||||
mesh.MeshType = Enum.MeshType.Sphere
|
||||
mesh.Scale = Vector3.new(1.12, .25, 1.9)
|
||||
mesh.Parent = petal
|
||||
table.insert(petals, petal)
|
||||
end
|
||||
local pollen = pin(root)
|
||||
pollen.Position = Vector3.new(0, .56, -2.4)
|
||||
specks(pollen, pink, SPARK, 18)
|
||||
return function(now, flash)
|
||||
local base = grip.CFrame
|
||||
for i, petal in petals do
|
||||
local u = (now * (.58 + (i % 3) * .076) + i * .134) % 1
|
||||
local spin = now * 4.3 + i * 2.39
|
||||
local spread = .24 + .36 * u + .05 * flash
|
||||
local at = Vector3.new(math.cos(spin) * spread, .47 + math.sin(spin) * spread * .66 + .25 * u, -3.4 + u * 4.42)
|
||||
petal.CFrame = base * CFrame.new(at) * CFrame.fromOrientation(spin * .9, spin * .37, spin * 1.33)
|
||||
petal.Transparency = 1 - .95 * math.sin(u * math.pi) ^ .49
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function glitch(root: Attachment, grip: BasePart): Animator
|
||||
local mint = Color3.fromRGB(115, 255, 62)
|
||||
local sea = Color3.fromRGB(30, 245, 177)
|
||||
local scans: {Part} = {}
|
||||
local scanlines = {}
|
||||
for _, side in {-1, 1} do
|
||||
local a, b = pin(root), pin(root)
|
||||
line(a, b, mint, .021, .25)
|
||||
line(a, b, sea, .086, .72)
|
||||
table.insert(scanlines, {side = side, bottom = a, top = b})
|
||||
end
|
||||
for i = 1, 14 do
|
||||
local color = if i % 3 == 0 then sea else mint
|
||||
table.insert(scans, shape(root, "GlitchPixel", Vector3.new(.028, .065, .19), color, Enum.PartType.Block))
|
||||
end
|
||||
local bits = pin(root)
|
||||
bits.Position = Vector3.new(0, .67, -1.6)
|
||||
specks(bits, mint, PIXEL, 21)
|
||||
return function(now, flash)
|
||||
local base = grip.CFrame
|
||||
local tick = math.floor(now * 15)
|
||||
local sweep = (now * 1.05) % 1
|
||||
for _, band in scanlines do
|
||||
local x = .35 * band.side
|
||||
local z = -3.35 + 4.08 * sweep
|
||||
band.bottom.Position = Vector3.new(x, .22, z)
|
||||
band.top.Position = Vector3.new(x, .84, z + .06)
|
||||
end
|
||||
for i, pixel in scans do
|
||||
local side = if i % 2 == 0 then -1 else 1
|
||||
local offset = math.sin(tick * 7.8 + i * 18.8)
|
||||
local bank = (i - 1) % 7
|
||||
local z = -3.82 + ((sweep + math.floor(bank / 3) * .34) % 1) * 4.9 + offset * .22
|
||||
pixel.Size = Vector3.new(.028, .043 + .018 * bank, .13 + .20 * math.abs(offset) + .08 * flash)
|
||||
pixel.CFrame = base * CFrame.new(side * (.322 + bank * .015), .28 + bank * .103, z)
|
||||
pixel.Transparency = if (tick + i * 3) % 8 < 2 then 1 else .21 + math.abs(offset) * .3
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function orbit(root: Attachment, grip: BasePart): Animator
|
||||
local gold = Color3.fromRGB(255, 218, 123)
|
||||
local violet = Color3.fromRGB(165, 169, 255)
|
||||
local stars: {Part} = {}
|
||||
for i = 1, 5 do
|
||||
local tint = if i % 2 == 0 then violet else gold
|
||||
local bead = shape(root, "OrbitStar", Vector3.new(.065, .065, .065), tint, Enum.PartType.Ball)
|
||||
table.insert(stars, bead)
|
||||
local a = Instance.new("Attachment")
|
||||
a.Position = Vector3.new(0, -.029, 0)
|
||||
a.Parent = bead
|
||||
local b = Instance.new("Attachment")
|
||||
b.Position = Vector3.new(0, .029, 0)
|
||||
b.Parent = bead
|
||||
local trail = Instance.new("Trail")
|
||||
trail.Attachment0 = a
|
||||
trail.Attachment1 = b
|
||||
trail.Color = ColorSequence.new(tint, Color3.fromRGB(93, 100, 248))
|
||||
trail.Transparency = NumberSequence.new({
|
||||
NumberSequenceKeypoint.new(0, .15),
|
||||
NumberSequenceKeypoint.new(.5, .58),
|
||||
NumberSequenceKeypoint.new(1, 1),
|
||||
})
|
||||
trail.WidthScale = NumberSequence.new(1, 0)
|
||||
trail.FaceCamera = true
|
||||
trail.LightEmission = .94
|
||||
trail.Lifetime = .24
|
||||
trail.MaxLength = .76
|
||||
trail.Enabled = false
|
||||
trail.Parent = bead
|
||||
end
|
||||
local dust = pin(root)
|
||||
dust.Position = Vector3.new(.11, .67, -.69)
|
||||
specks(dust, gold, SPARK, 26)
|
||||
return function(now, flash)
|
||||
local base = grip.CFrame
|
||||
for i, star in stars do
|
||||
local theta = now * (5.1 + i * .18) + i * 2.39
|
||||
local radius = .37 + .048 * i + .09 * flash
|
||||
local z = -1.15 - math.cos(theta * .51 + i) * 1.59
|
||||
star.CFrame = base * CFrame.new(math.cos(theta) * radius, .46 + math.sin(theta) * radius, z)
|
||||
star.Transparency = .05 + .18 * (1 + math.sin(theta * 2))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local builders: {[string]: (Attachment, BasePart) -> Animator} = {
|
||||
ThunderBlade = thunder, CrimsonSeal = seal, Sakura = sakura, NeonGlitch = glitch, LunarOrbit = orbit,
|
||||
}
|
||||
|
||||
function Variants.create(id: string, grip: BasePart): Effect
|
||||
local root = Instance.new("Attachment")
|
||||
root.Name = "SkinFx_" .. id
|
||||
root.Parent = grip
|
||||
local animate = builders[id](root, grip)
|
||||
local switches: {Switch} = {}
|
||||
local decorations: {Part} = {}
|
||||
for _, instance in root:GetDescendants() do
|
||||
if instance:IsA("Beam") or instance:IsA("Trail") or instance:IsA("ParticleEmitter") then
|
||||
table.insert(switches, instance)
|
||||
elseif instance:IsA("Part") then
|
||||
table.insert(decorations, instance)
|
||||
end
|
||||
end
|
||||
return {root = root, animate = animate, switches = switches, decorations = decorations}
|
||||
end
|
||||
|
||||
function Variants.setVisible(effect: Effect, visible: boolean)
|
||||
for _, switch in effect.switches do
|
||||
switch.Enabled = visible
|
||||
if not visible and (switch:IsA("ParticleEmitter") or switch:IsA("Trail")) then switch:Clear() end
|
||||
end
|
||||
if not visible then
|
||||
for _, decoration in effect.decorations do decoration.Transparency = 1 end
|
||||
end
|
||||
end
|
||||
|
||||
return Variants
|
||||
@@ -0,0 +1,34 @@
|
||||
--!strict
|
||||
local RifleSpray = {PreciseShots = 4}
|
||||
|
||||
-- The rifle climbs, sweeps left, crosses right, then settles into a smaller sweep.
|
||||
-- X is right on screen and Y is up. Scale each pair by the configured spray angle.
|
||||
local pattern = {
|
||||
Vector2.new(.08, 1), Vector2.new(.11, 1), Vector2.new(.10, 1), Vector2.new(.04, 1),
|
||||
Vector2.new(-.03, 1), Vector2.new(-.14, 1), Vector2.new(-.24, 1), Vector2.new(-.36, .98),
|
||||
Vector2.new(-.50, .96), Vector2.new(-.65, .92), Vector2.new(-.74, .88), Vector2.new(-.78, .85),
|
||||
Vector2.new(-.70, .83), Vector2.new(-.58, .81), Vector2.new(-.36, .79), Vector2.new(-.05, .77),
|
||||
Vector2.new(.24, .75), Vector2.new(.48, .73), Vector2.new(.67, .72), Vector2.new(.73, .71),
|
||||
Vector2.new(.61, .70), Vector2.new(.42, .68), Vector2.new(.17, .66), Vector2.new(-.12, .67),
|
||||
Vector2.new(-.36, .69), Vector2.new(-.54, .71),
|
||||
}
|
||||
local tailStart = 19
|
||||
|
||||
function RifleSpray.resetDelay(interval: number, recovery: number): number
|
||||
return math.max(interval * 1.75, math.clamp(2 / math.max(recovery, .1), .24, .95))
|
||||
end
|
||||
|
||||
function RifleSpray.offset(shot: number, base: number, growth: number, limit: number): Vector2
|
||||
local index = shot - RifleSpray.PreciseShots
|
||||
if index <= 0 then return Vector2.zero end
|
||||
local angle = math.clamp(base + math.min(index * math.max(growth, 0), math.max(limit, 0)), 0, 15)
|
||||
if index > #pattern then
|
||||
-- Magazines larger than 30 retain the final sweep without jumping back to the centre.
|
||||
local width = #pattern - tailStart
|
||||
local phase = (index - tailStart) % (width * 2)
|
||||
index = tailStart + math.min(phase, width * 2 - phase)
|
||||
end
|
||||
return pattern[index] * (angle / 3)
|
||||
end
|
||||
|
||||
return table.freeze(RifleSpray)
|
||||
@@ -0,0 +1,129 @@
|
||||
--!strict
|
||||
-- Server-owned poses for hitscan. Parts stay in their live positions.
|
||||
local ShotHistory = {}
|
||||
local FRAME_LIMIT = 14
|
||||
local TELEPORT_DISTANCE = 11
|
||||
local zones: {[string]: string} = {
|
||||
Head = "Head",
|
||||
Torso = "Body", UpperTorso = "Body", LowerTorso = "Body",
|
||||
["Left Arm"] = "Limb", ["Right Arm"] = "Limb", ["Left Leg"] = "Limb", ["Right Leg"] = "Limb",
|
||||
LeftUpperArm = "Limb", LeftLowerArm = "Limb", LeftHand = "Limb",
|
||||
RightUpperArm = "Limb", RightLowerArm = "Limb", RightHand = "Limb",
|
||||
LeftUpperLeg = "Limb", LeftLowerLeg = "Limb", LeftFoot = "Limb",
|
||||
RightUpperLeg = "Limb", RightLowerLeg = "Limb", RightFoot = "Limb",
|
||||
}
|
||||
|
||||
type Pose = {time: number, eye: Vector3, boxes: {[BasePart]: CFrame}}
|
||||
type Track = {character: Model, poses: {Pose}, newest: number, count: number}
|
||||
export type Hit = {part: BasePart, distance: number, position: Vector3, normal: Vector3, localPoint: Vector3, zone: string}
|
||||
local tracks: {[Player]: Track} = {}
|
||||
|
||||
local function poseAtIndex(track: Track, age: number): Pose
|
||||
return track.poses[(track.newest - 1 - age) % FRAME_LIMIT + 1]
|
||||
end
|
||||
|
||||
function ShotHistory.record(player: Player, character: Model, head: BasePart, now: number)
|
||||
local track = tracks[player]
|
||||
if not track or track.character ~= character then
|
||||
track = {character = character, poses = {}, newest = 0, count = 0}
|
||||
tracks[player] = track
|
||||
elseif track.count > 0 and (poseAtIndex(track, 0).eye - head.Position).Magnitude > TELEPORT_DISTANCE then
|
||||
track.newest, track.count = 0, 0
|
||||
end
|
||||
|
||||
local index = track.newest % FRAME_LIMIT + 1
|
||||
local pose = track.poses[index]
|
||||
if not pose then
|
||||
pose = {time = now, eye = head.Position, boxes = {}}
|
||||
track.poses[index] = pose
|
||||
end
|
||||
pose.time, pose.eye = now, head.Position
|
||||
table.clear(pose.boxes)
|
||||
for _, part in character:GetChildren() do
|
||||
if part:IsA("BasePart") and zones[part.Name] then
|
||||
pose.boxes[part] = part.CFrame
|
||||
end
|
||||
end
|
||||
track.newest = index
|
||||
track.count = math.min(track.count + 1, FRAME_LIMIT)
|
||||
end
|
||||
|
||||
function ShotHistory.clear(player: Player)
|
||||
tracks[player] = nil
|
||||
end
|
||||
|
||||
local function between(player: Player?, character: Model, time: number): (Pose?, Pose?, number)
|
||||
local track = player and tracks[player]
|
||||
if not track or track.character ~= character or track.count == 0 then return nil, nil, 0 end
|
||||
local newer = poseAtIndex(track, 0)
|
||||
if time >= newer.time then return newer, nil, 0 end
|
||||
for age = 1, track.count - 1 do
|
||||
local older = poseAtIndex(track, age)
|
||||
if time >= older.time then
|
||||
return older, newer, math.clamp((time - older.time) / math.max(newer.time - older.time, .001), 0, 1)
|
||||
end
|
||||
newer = older
|
||||
end
|
||||
return newer, nil, 0
|
||||
end
|
||||
|
||||
function ShotHistory.eyeAt(player: Player, character: Model, time: number): Vector3?
|
||||
local older, newer, blend = between(player, character, time)
|
||||
if not older then return nil end
|
||||
return if newer then older.eye:Lerp(newer.eye, blend) else older.eye
|
||||
end
|
||||
|
||||
local function slab(point: number, direction: number, half: number): (number, number)
|
||||
if math.abs(direction) < 1e-7 then
|
||||
if math.abs(point) > half then return math.huge, -math.huge end
|
||||
return -math.huge, math.huge
|
||||
end
|
||||
local a = (-half - point) / direction
|
||||
local b = (half - point) / direction
|
||||
return math.min(a, b), math.max(a, b)
|
||||
end
|
||||
|
||||
local function intersect(origin: Vector3, direction: Vector3, box: CFrame, half: Vector3, maximum: number): (number?, Vector3?)
|
||||
local from = box:PointToObjectSpace(origin)
|
||||
local ray = box:VectorToObjectSpace(direction)
|
||||
local x, endX = slab(from.X, ray.X, half.X)
|
||||
local y, endY = slab(from.Y, ray.Y, half.Y)
|
||||
local z, endZ = slab(from.Z, ray.Z, half.Z)
|
||||
local near = math.max(x, y, z, 0)
|
||||
if near > math.min(endX, endY, endZ, maximum) then return nil, nil end
|
||||
local normal = if near == 0 then -ray
|
||||
elseif x == near then Vector3.new(-math.sign(ray.X), 0, 0)
|
||||
elseif y == near then Vector3.new(0, -math.sign(ray.Y), 0)
|
||||
else Vector3.new(0, 0, -math.sign(ray.Z))
|
||||
return near, box:VectorToWorldSpace(normal)
|
||||
end
|
||||
|
||||
function ShotHistory.cast(character: Model, player: Player?, time: number, origin: Vector3, direction: Vector3, maximum: number): Hit?
|
||||
local older, newer, weight = between(player, character, time)
|
||||
local eye = if older then older.eye else character:GetPivot().Position
|
||||
if newer then eye = eye:Lerp(newer.eye, weight) end
|
||||
local along = math.clamp((eye - origin):Dot(direction), 0, maximum)
|
||||
if (origin + direction * along - eye).Magnitude > 9 then return nil end
|
||||
local hit: Hit? = nil
|
||||
for _, part in character:GetChildren() do
|
||||
if not part:IsA("BasePart") then continue end
|
||||
local zone = zones[part.Name]
|
||||
if not zone then continue end
|
||||
local box = if older then older.boxes[part] else part.CFrame
|
||||
if not box then continue end
|
||||
local nextBox = newer and newer.boxes[part]
|
||||
if nextBox then box = box:Lerp(nextBox, weight) end
|
||||
local distance, normal = intersect(origin, direction, box, part.Size * .5, maximum)
|
||||
if distance and normal then
|
||||
local position = origin + direction * distance
|
||||
maximum = distance
|
||||
hit = {
|
||||
part = part, distance = distance, position = position, normal = normal,
|
||||
localPoint = box:PointToObjectSpace(position), zone = zone,
|
||||
}
|
||||
end
|
||||
end
|
||||
return hit
|
||||
end
|
||||
|
||||
return ShotHistory
|
||||
@@ -0,0 +1,629 @@
|
||||
--!strict
|
||||
-- ModuleScript in ReplicatedStorage. Client-side shot effects for the SniperRifle, used by the
|
||||
-- first-person viewmodel (SniperViewmodel) and for other players' shots (ThirdPersonRifle):
|
||||
-- flash(cframe, scale, parent) muzzle flash: a hot core, a star of spikes, sparks and a light;
|
||||
-- cframe = the muzzle, -Z pointing out of the barrel
|
||||
-- tracer(from, to) glowing streak flying from the muzzle to where the bullet went
|
||||
-- impact(position, normal, flesh?) bullet hole on the surface plus a puff of dust (flesh: a red
|
||||
-- puff, no hole)
|
||||
-- sound(name, at?) plays one of SOUNDS: flat (own weapon) when `at` is nil,
|
||||
-- from a part/attachment in the world otherwise
|
||||
-- cues(list, from, to, at?) plays the sounds of a cue list whose time is in (from, to]
|
||||
-- RELOAD_CUES / BOLT_CUES when the sounds go, as a fraction of the reload / the bolt
|
||||
-- cycle after a shot (matching ReloadTimeline's hand keys)
|
||||
|
||||
local ContentProvider = game:GetService("ContentProvider")
|
||||
local Debris = game:GetService("Debris")
|
||||
local RunService = game:GetService("RunService")
|
||||
local SoundService = game:GetService("SoundService")
|
||||
|
||||
local SniperEffects = {}
|
||||
|
||||
-- Free Creator Store sounds. volume, plus how far the sound carries when it is in the world.
|
||||
-- group: which volume setting scales it (attribute Vol<group> of the SniperViewmodel config
|
||||
-- script, times VolMaster).
|
||||
-- cut: fade the sound out over this many seconds (a long rumble tail would pile up on auto fire)
|
||||
type SoundDef = { id: string, volume: number, speed: number, near: number, far: number, group: string, cut: number? }
|
||||
local SOUNDS: { [string]: SoundDef } = {
|
||||
Shot = { id = "rbxassetid://128598607431847", volume = 0.9, speed = 1, near = 20, far = 120, group = "Shot" }, -- AS_gun_shot-02 (Audioscape)
|
||||
BoltBack = { id = "rbxassetid://93265832279166", volume = 0.7, speed = 1, near = 4, far = 60, group = "Reload" },
|
||||
BoltForward = { id = "rbxassetid://133390161654321", volume = 0.7, speed = 1, near = 4, far = 60, group = "Reload" },
|
||||
MagOut = { id = "rbxassetid://6239156710", volume = 0.6, speed = 1, near = 4, far = 50, group = "Reload" },
|
||||
MagIn = { id = "rbxassetid://78157229382345", volume = 0.7, speed = 1, near = 4, far = 50, group = "Reload" },
|
||||
DryFire = { id = "rbxassetid://117629133235583", volume = 0.6, speed = 1, near = 3, far = 30, group = "Reload" },
|
||||
-- The original hitmarker is the main cue; the lighter arcade layers use short fades.
|
||||
Hit = { id = "rbxassetid://125235091454234", volume = 0.7, speed = 1, near = 4, far = 60, group = "Hit" }, -- hitmarker_2
|
||||
Hurt = { id = "rbxasset://sounds/ouch.ogg", volume = 0.48, speed = .9, near = 0, far = 0, group = "Hurt", cut = .16 },
|
||||
BoostRune = { id = "rbxassetid://84201439618760", volume = .30, speed = .80, near = 0, far = 0, group = "Mobility" }, -- BLD_MACH_RUSH
|
||||
JumpRune = { id = "rbxassetid://119573908217733", volume = .30, speed = 1, near = 0, far = 0, group = "Mobility" }, -- Dash Wind Burst
|
||||
Critical = { id = "rbxassetid://6875009415", volume = 0.2, speed = 1, near = 0, far = 0, group = "Critical" }, -- Magic Hit
|
||||
Elimination = { id = "rbxassetid://15675043410", volume = 0.78, speed = 1.18, near = 0, far = 0, group = "Kill", cut = 0.52 },
|
||||
StreakAccent = { id = "rbxassetid://3120909354", volume = 0.5, speed = 1, near = 0, far = 0, group = "Kill" }, -- Level_up
|
||||
ReloadReady = { id = "rbxassetid://15675085146", volume = 0.24, speed = 1.15, near = 0, far = 0, group = "Reload", cut = 0.19 },
|
||||
RoundCountdown = { id = "rbxassetid://113416294133952", volume = 0.48, speed = 1, near = 0, far = 0, group = "HUD" }, -- timer tick
|
||||
HotPointStart = { id = "rbxassetid://2789428506", volume = 0.35, speed = 1, near = 0, far = 0, group = "HUD" }, -- Unlock_phoenix
|
||||
HotPointCaptured = { id = "rbxassetid://4612374036", volume = 0.4, speed = 1, near = 0, far = 0, group = "HUD" }, -- bling_big_diamond_pickup
|
||||
MoneyCollect1 = { id = "rbxassetid://84894146013271", volume = 0.15, speed = 1, near = 0, far = 0, group = "Pickup", cut = 0.16 },
|
||||
CupidKnife = { id = "rbxassetid://120151468640015", volume = 0.32, speed = 1, near = 0, far = 0, group = "Pickup" },
|
||||
-- a player / bot destroyed: the body breaks apart like blocks (heard by everyone, from the body)
|
||||
Break = { id = "rbxassetid://130215756597524", volume = 1, speed = 1, near = 25, far = 300, group = "Kill" }, -- blockbreak sfx
|
||||
}
|
||||
SniperEffects.SOUNDS = SOUNDS
|
||||
|
||||
-- the settings live as attributes on the local player's SniperViewmodel script
|
||||
local configScript: Instance? = nil
|
||||
local function setting(name: string, default: number): number
|
||||
if not configScript or not configScript.Parent then
|
||||
local player = game:GetService("Players").LocalPlayer
|
||||
local scripts = player and player:FindFirstChild("PlayerScripts")
|
||||
configScript = scripts and scripts:FindFirstChild("SniperViewmodel")
|
||||
end
|
||||
local v = configScript and configScript:GetAttribute(name)
|
||||
return if type(v) == "number" then v else default
|
||||
end
|
||||
SniperEffects.setting = setting
|
||||
|
||||
type Cue = { at: number, sound: string }
|
||||
-- reload (0..1 of ReloadTime): the hand pulls the magazine (.14 -> .24), pushes the new one
|
||||
-- in (.55 -> .58), then works the bolt (boltCycle over .62 .. .93: back at .29-.48, forward at .61-.71)
|
||||
SniperEffects.RELOAD_CUES = {
|
||||
{ at = 0.19, sound = "MagOut" },
|
||||
{ at = 0.57, sound = "MagIn" },
|
||||
{ at = 0.62 + 0.31 * 0.30, sound = "BoltBack" },
|
||||
{ at = 0.62 + 0.31 * 0.62, sound = "BoltForward" },
|
||||
} :: { Cue }
|
||||
-- bolt after a shot (0..1 of ShotBoltTime, same boltCycle)
|
||||
SniperEffects.BOLT_CUES = {
|
||||
{ at = 0.30, sound = "BoltBack" },
|
||||
{ at = 0.62, sound = "BoltForward" },
|
||||
} :: { Cue }
|
||||
|
||||
task.spawn(function()
|
||||
-- Sound instances, not bare ids: a bare id string is preloaded as an image and fails
|
||||
local preload = {}
|
||||
for _, def in SOUNDS do
|
||||
local s = Instance.new("Sound")
|
||||
s.SoundId = def.id
|
||||
table.insert(preload, s)
|
||||
end
|
||||
pcall(ContentProvider.PreloadAsync, ContentProvider, preload)
|
||||
for _, s in preload do
|
||||
s:Destroy()
|
||||
end
|
||||
end)
|
||||
|
||||
function SniperEffects.sound(name: string, at: Instance?, pitch: number?): Sound?
|
||||
local def = SOUNDS[name]
|
||||
if not def then
|
||||
return nil
|
||||
end
|
||||
local volume = def.volume * math.max(setting("VolMaster", 1), 0) * math.max(setting("Vol" .. def.group, 1), 0)
|
||||
if volume <= 0 then
|
||||
return nil
|
||||
end
|
||||
local s = Instance.new("Sound")
|
||||
s.Name = "Sniper" .. name
|
||||
s.SoundId = def.id
|
||||
s.Volume = volume
|
||||
s.PlaybackSpeed = def.speed * (pitch or 1) * (0.96 + math.random() * 0.08) -- no two exactly alike
|
||||
if at then
|
||||
s.RollOffMode = Enum.RollOffMode.InverseTapered
|
||||
s.RollOffMinDistance = def.near
|
||||
s.RollOffMaxDistance = def.far
|
||||
end
|
||||
s.Parent = at or SoundService
|
||||
s:Play()
|
||||
if def.cut then
|
||||
local fade = def.cut
|
||||
task.delay(0.12, function()
|
||||
if not s.Parent then return end
|
||||
game:GetService("TweenService"):Create(s, TweenInfo.new(fade, Enum.EasingStyle.Quad, Enum.EasingDirection.In), { Volume = 0 }):Play()
|
||||
Debris:AddItem(s, fade + 0.05)
|
||||
end)
|
||||
end
|
||||
s.Ended:Once(function()
|
||||
s:Destroy()
|
||||
end)
|
||||
Debris:AddItem(s, 6)
|
||||
return s
|
||||
end
|
||||
|
||||
function SniperEffects.cues(list: { Cue }, from: number, to: number, at: Instance?)
|
||||
for _, cue in list do
|
||||
if cue.at > from and cue.at <= to then
|
||||
SniperEffects.sound(cue.sound, at)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local FLASH_TIME = 0.06 -- seconds the flash itself is visible
|
||||
local CORE_COLOR = Color3.fromRGB(255, 236, 160)
|
||||
local SPIKE_COLOR = Color3.fromRGB(255, 170, 60)
|
||||
local HOLE_LIFETIME = 20
|
||||
|
||||
local function effectPart(name: string, color: Color3, size: Vector3): Part
|
||||
local p = Instance.new("Part")
|
||||
p.Name = name
|
||||
p.Anchored = true
|
||||
p.CanCollide = false
|
||||
p.CanQuery = false
|
||||
p.CanTouch = false
|
||||
p.CastShadow = false
|
||||
p.Material = Enum.Material.Neon
|
||||
p.Color = color
|
||||
p.Size = size
|
||||
return p
|
||||
end
|
||||
|
||||
local function sparks(parent: Instance, color: Color3, count: number, speed: NumberRange, size: number)
|
||||
local emitter = Instance.new("ParticleEmitter")
|
||||
emitter.Texture = "rbxasset://textures/particles/sparkles_main.dds"
|
||||
emitter.Color = ColorSequence.new(color)
|
||||
emitter.LightEmission = 1
|
||||
emitter.Size = NumberSequence.new(size, 0)
|
||||
emitter.Lifetime = NumberRange.new(0.1, 0.3)
|
||||
emitter.Speed = speed
|
||||
emitter.SpreadAngle = Vector2.new(35, 35)
|
||||
emitter.Drag = 4
|
||||
emitter.Rate = 0
|
||||
emitter.EmissionDirection = Enum.NormalId.Front
|
||||
emitter.Parent = parent
|
||||
emitter:Emit(count)
|
||||
end
|
||||
|
||||
-- one burst of particles from an attachment (Front = -Z = out of the barrel)
|
||||
type Burst = {
|
||||
texture: string,
|
||||
color: ColorSequence,
|
||||
count: number,
|
||||
life: NumberRange,
|
||||
speed: NumberRange,
|
||||
size: NumberSequence,
|
||||
transparency: NumberSequence,
|
||||
spread: number, -- degrees around the barrel axis
|
||||
light: number, -- LightEmission
|
||||
bright: number, -- Brightness (above 1 glows)
|
||||
drag: number,
|
||||
accel: Vector3,
|
||||
}
|
||||
local function burst(parent: Instance, b: Burst)
|
||||
local emitter = Instance.new("ParticleEmitter")
|
||||
emitter.Texture = b.texture
|
||||
emitter.Color = b.color
|
||||
emitter.LightEmission = b.light
|
||||
emitter.Brightness = b.bright
|
||||
emitter.Size = b.size
|
||||
emitter.Transparency = b.transparency
|
||||
emitter.Lifetime = b.life
|
||||
emitter.Speed = b.speed
|
||||
emitter.SpreadAngle = Vector2.new(b.spread, b.spread)
|
||||
emitter.Rotation = NumberRange.new(0, 360)
|
||||
emitter.RotSpeed = NumberRange.new(-200, 200)
|
||||
emitter.Drag = b.drag
|
||||
emitter.Acceleration = b.accel
|
||||
emitter.Rate = 0
|
||||
emitter.EmissionDirection = Enum.NormalId.Front
|
||||
emitter.Parent = parent
|
||||
emitter:Emit(b.count)
|
||||
end
|
||||
|
||||
local FIRE_TEXTURE = "rbxasset://textures/particles/fire_main.dds"
|
||||
local EMBER_TEXTURE = "rbxasset://textures/particles/fire_sparks_main.dds"
|
||||
local SMOKE_TEXTURE = "rbxasset://textures/particles/smoke_main.dds"
|
||||
-- white-hot at the barrel, through yellow to orange-red at the tips
|
||||
local FLAME_COLORS = ColorSequence.new({
|
||||
ColorSequenceKeypoint.new(0, Color3.fromRGB(255, 245, 160)),
|
||||
ColorSequenceKeypoint.new(0.3, Color3.fromRGB(255, 195, 40)),
|
||||
ColorSequenceKeypoint.new(0.7, Color3.fromRGB(255, 110, 10)),
|
||||
ColorSequenceKeypoint.new(1, Color3.fromRGB(200, 40, 0)),
|
||||
})
|
||||
|
||||
-- Muzzle flash: a short fiery burst. Hot core and a star of flame tongues (Neon parts, one frame
|
||||
-- or two), flame particles thrown forward and to the sides, embers that fall, a puff of smoke.
|
||||
-- aimed: the shooter looks down the sight right behind the muzzle, so nothing goes forward
|
||||
-- into the view (no glow ball, no cone, no forward flame or smoke), only short side tongues.
|
||||
function SniperEffects.flash(at: CFrame, scale: number, parent: Instance, aimed: boolean?)
|
||||
local holder = Instance.new("Model")
|
||||
holder.Name = "MuzzleFlash"
|
||||
-- random turn about the barrel, so no two flashes look alike
|
||||
local base = at * CFrame.Angles(0, 0, math.random() * math.pi * 2)
|
||||
local core = effectPart("Core", CORE_COLOR, Vector3.one * 0.35 * scale)
|
||||
core.Shape = Enum.PartType.Ball
|
||||
core.CFrame = base * CFrame.new(0, 0, -0.25 * scale)
|
||||
core.Parent = holder
|
||||
local glow = effectPart("Glow", SPIKE_COLOR, Vector3.one * (0.7 + math.random() * 0.2) * scale)
|
||||
glow.Shape = Enum.PartType.Ball
|
||||
glow.Transparency = 0.8
|
||||
glow.CFrame = core.CFrame
|
||||
glow.Parent = if aimed then nil else holder
|
||||
-- star: ragged flame tongues around the barrel, leaning forward, of uneven length
|
||||
local blades = 10
|
||||
for i = 0, blades - 1 do
|
||||
local long = i % 2 == 0
|
||||
local length = (if long then 0.9 + math.random() * 0.7 else 0.4 + math.random() * 0.4) * scale * (if aimed then 0.6 else 1)
|
||||
local width = (if long then 0.2 else 0.13) * scale
|
||||
local blade = effectPart("Tongue", if long then SPIKE_COLOR else CORE_COLOR, Vector3.new(width, length, width * 0.4))
|
||||
blade.Transparency = if long then 0.15 else 0.3
|
||||
blade.CFrame = base
|
||||
* CFrame.Angles(0, 0, (i + math.random() * 0.4) * math.pi * 2 / blades)
|
||||
* CFrame.Angles(math.rad(-35 - math.random() * 15), 0, 0) -- lean forward
|
||||
* CFrame.new(0, length / 2, -0.25 * scale)
|
||||
blade.Parent = holder
|
||||
end
|
||||
local forward = (1.2 + math.random() * 0.6) * scale
|
||||
local cone = effectPart("Tongue", SPIKE_COLOR, Vector3.new(0.3 * scale, 0.3 * scale, forward))
|
||||
cone.Transparency = 0.2
|
||||
cone.CFrame = base * CFrame.new(0, 0, -forward / 2 - 0.2 * scale) * CFrame.Angles(0, 0, math.pi / 4)
|
||||
cone.Parent = if aimed then nil else holder
|
||||
local light = Instance.new("PointLight")
|
||||
light.Color = Color3.fromRGB(255, 170, 70)
|
||||
light.Brightness = 8
|
||||
light.Range = 16 * scale
|
||||
light.Shadows = false
|
||||
light.Parent = core
|
||||
holder.Parent = parent
|
||||
|
||||
-- particles outlive the flash, on a separate invisible part in the world (particles under the
|
||||
-- Camera, where the viewmodel lives, are not drawn)
|
||||
local emitPart = effectPart("FlashParticles", SPIKE_COLOR, Vector3.one * 0.05)
|
||||
emitPart.Transparency = 1
|
||||
emitPart.CFrame = base * CFrame.new(0, 0, -0.2 * scale)
|
||||
emitPart.Parent = workspace
|
||||
local attachment = Instance.new("Attachment")
|
||||
attachment.Parent = emitPart
|
||||
local fade = NumberSequence.new({ NumberSequenceKeypoint.new(0, 0), NumberSequenceKeypoint.new(0.6, 0.15), NumberSequenceKeypoint.new(1, 1) })
|
||||
-- flame bursting out to the sides (when aimed: fewer and smaller, the only flame there is)
|
||||
burst(attachment, {
|
||||
texture = FIRE_TEXTURE,
|
||||
color = FLAME_COLORS,
|
||||
count = if aimed then 6 else 12,
|
||||
life = NumberRange.new(0.06, 0.12),
|
||||
speed = NumberRange.new(6 * scale, 13 * scale),
|
||||
size = NumberSequence.new({
|
||||
NumberSequenceKeypoint.new(0, (if aimed then 0.25 else 0.45) * scale),
|
||||
NumberSequenceKeypoint.new(1, 0.05 * scale),
|
||||
}),
|
||||
transparency = fade,
|
||||
spread = 85,
|
||||
light = 1,
|
||||
bright = 5,
|
||||
drag = 10,
|
||||
accel = Vector3.zero,
|
||||
})
|
||||
task.delay(FLASH_TIME, function()
|
||||
holder:Destroy()
|
||||
end)
|
||||
Debris:AddItem(emitPart, 0.8)
|
||||
if aimed then
|
||||
return
|
||||
end
|
||||
-- flame thrown forward
|
||||
burst(attachment, {
|
||||
texture = FIRE_TEXTURE,
|
||||
color = FLAME_COLORS,
|
||||
count = 16,
|
||||
life = NumberRange.new(0.07, 0.16),
|
||||
speed = NumberRange.new(5 * scale, 11 * scale),
|
||||
size = NumberSequence.new({
|
||||
NumberSequenceKeypoint.new(0, 0.5 * scale),
|
||||
NumberSequenceKeypoint.new(0.4, 1.1 * scale),
|
||||
NumberSequenceKeypoint.new(1, 0.2 * scale),
|
||||
}),
|
||||
transparency = fade,
|
||||
spread = 25,
|
||||
light = 1,
|
||||
bright = 5,
|
||||
drag = 8,
|
||||
accel = Vector3.zero,
|
||||
})
|
||||
-- sparks flying out, and embers that drift and fall
|
||||
sparks(attachment, SPIKE_COLOR, 12, NumberRange.new(12 * scale, 24 * scale), 0.12 * scale)
|
||||
burst(attachment, {
|
||||
texture = EMBER_TEXTURE,
|
||||
color = ColorSequence.new(Color3.fromRGB(255, 200, 90), Color3.fromRGB(255, 90, 20)),
|
||||
count = 6,
|
||||
life = NumberRange.new(0.25, 0.5),
|
||||
speed = NumberRange.new(4 * scale, 10 * scale),
|
||||
size = NumberSequence.new(0.1 * scale, 0),
|
||||
transparency = NumberSequence.new(0, 1),
|
||||
spread = 60,
|
||||
light = 1,
|
||||
bright = 3,
|
||||
drag = 3,
|
||||
accel = Vector3.new(0, -14 * scale, 0),
|
||||
})
|
||||
-- a thin puff of smoke left hanging at the muzzle
|
||||
burst(attachment, {
|
||||
texture = SMOKE_TEXTURE,
|
||||
color = ColorSequence.new(Color3.fromRGB(200, 190, 180)),
|
||||
count = 2,
|
||||
life = NumberRange.new(0.35, 0.6),
|
||||
speed = NumberRange.new(1 * scale, 3 * scale),
|
||||
size = NumberSequence.new(0.3 * scale, 1.4 * scale),
|
||||
transparency = NumberSequence.new(0.75, 1),
|
||||
spread = 30,
|
||||
light = 0,
|
||||
bright = 1,
|
||||
drag = 4,
|
||||
accel = Vector3.new(0, 1.5 * scale, 0),
|
||||
})
|
||||
end
|
||||
|
||||
-- Tracer: a glowing streak running from the muzzle to where the bullet went.
|
||||
local TRACER_SPEED = 800 -- studs per second
|
||||
local TRACER_LENGTH = 7
|
||||
local TRACER_WIDTH = 0.09
|
||||
local TRACER_COLOR = Color3.fromRGB(255, 205, 110)
|
||||
function SniperEffects.tracer(from: Vector3, to: Vector3)
|
||||
local delta = to - from
|
||||
local dist = delta.Magnitude
|
||||
if dist < 1 then
|
||||
return
|
||||
end
|
||||
local dir = delta / dist
|
||||
local streak = effectPart("Tracer", TRACER_COLOR, Vector3.new(TRACER_WIDTH, TRACER_WIDTH, 0.1))
|
||||
streak.Transparency = 0.1
|
||||
streak.CFrame = CFrame.lookAt(from, to)
|
||||
streak.Parent = workspace
|
||||
local start = os.clock()
|
||||
local shown = false
|
||||
local connection: RBXScriptConnection
|
||||
connection = RunService.RenderStepped:Connect(function()
|
||||
local travelled = (os.clock() - start) * TRACER_SPEED
|
||||
local head = math.min(travelled, dist)
|
||||
local tail = math.clamp(travelled - TRACER_LENGTH, 0, dist)
|
||||
if tail >= dist then
|
||||
if shown then
|
||||
connection:Disconnect()
|
||||
streak:Destroy()
|
||||
return
|
||||
end
|
||||
-- A nearby impact can finish in under one frame. Show its final segment once.
|
||||
tail = math.max(0, dist - TRACER_LENGTH)
|
||||
end
|
||||
shown = true
|
||||
local length = math.max(head - tail, 0.05)
|
||||
streak.Size = Vector3.new(TRACER_WIDTH, TRACER_WIDTH, length)
|
||||
streak.CFrame = CFrame.lookAt(from + dir * (tail + length / 2), to)
|
||||
end)
|
||||
Debris:AddItem(streak, dist / TRACER_SPEED + 1) -- in case the frame loop stops
|
||||
end
|
||||
|
||||
-- deep orange: an orange core going red at the edges (not the white-hot muzzle colours)
|
||||
local BLAST_HOT = Color3.fromRGB(255, 175, 50)
|
||||
local BLAST_COLORS = ColorSequence.new({
|
||||
ColorSequenceKeypoint.new(0, Color3.fromRGB(255, 190, 60)),
|
||||
ColorSequenceKeypoint.new(0.35, Color3.fromRGB(255, 120, 20)),
|
||||
ColorSequenceKeypoint.new(0.75, Color3.fromRGB(235, 70, 10)),
|
||||
ColorSequenceKeypoint.new(1, Color3.fromRGB(150, 30, 10)),
|
||||
})
|
||||
|
||||
-- Small fiery blast where a bullet hits a body: a hot flash ball, a puff of flame thrown out of
|
||||
-- the surface, sparks flying out and embers that fall, a short orange light. scale: 1 = normal.
|
||||
function SniperEffects.blast(position: Vector3, normal: Vector3, scale: number)
|
||||
if scale <= 0 then
|
||||
return
|
||||
end
|
||||
-- farther away: bigger, so it still reads on screen (a hit 60 studs off is 2x the size)
|
||||
local cam = workspace.CurrentCamera
|
||||
if cam then
|
||||
scale *= math.clamp((cam.CFrame.Position - position).Magnitude / 30, 1, 3)
|
||||
end
|
||||
local out = CFrame.lookAt(position, position + normal) -- Front (-Z) = out of the surface
|
||||
local ball = effectPart("HitFlash", BLAST_HOT, Vector3.one * 0.8 * scale)
|
||||
ball.Shape = Enum.PartType.Ball
|
||||
ball.Transparency = 0.1
|
||||
ball.CFrame = out * CFrame.new(0, 0, -0.35 * scale)
|
||||
ball.Parent = workspace
|
||||
local light = Instance.new("PointLight")
|
||||
light.Color = Color3.fromRGB(255, 150, 50)
|
||||
light.Brightness = 6
|
||||
light.Range = 10 * scale
|
||||
light.Shadows = false
|
||||
light.Parent = ball
|
||||
local t0 = os.clock()
|
||||
local connection: RBXScriptConnection
|
||||
connection = RunService.RenderStepped:Connect(function()
|
||||
local k = (os.clock() - t0) / 0.14
|
||||
if k >= 1 then
|
||||
connection:Disconnect()
|
||||
ball:Destroy()
|
||||
return
|
||||
end
|
||||
ball.Size = Vector3.one * (0.8 + 1.2 * k) * scale -- swells and fades
|
||||
ball.Transparency = 0.1 + 0.9 * k
|
||||
ball.Color = BLAST_HOT:Lerp(Color3.fromRGB(230, 70, 10), k)
|
||||
light.Brightness = 6 * (1 - k)
|
||||
end)
|
||||
Debris:AddItem(ball, 0.5)
|
||||
|
||||
local emitPart = effectPart("HitParticles", SPIKE_COLOR, Vector3.one * 0.05)
|
||||
emitPart.Transparency = 1
|
||||
emitPart.CFrame = out * CFrame.new(0, 0, -0.3 * scale) -- just out of the body, not inside it
|
||||
emitPart.Parent = workspace
|
||||
local attachment = Instance.new("Attachment")
|
||||
attachment.Parent = emitPart
|
||||
local fade = NumberSequence.new({ NumberSequenceKeypoint.new(0, 0), NumberSequenceKeypoint.new(0.55, 0.1), NumberSequenceKeypoint.new(1, 1) })
|
||||
-- the fireball: flame puffs bursting out in a half-sphere
|
||||
burst(attachment, {
|
||||
texture = FIRE_TEXTURE,
|
||||
color = BLAST_COLORS,
|
||||
count = 20,
|
||||
life = NumberRange.new(0.18, 0.35),
|
||||
speed = NumberRange.new(4 * scale, 10 * scale),
|
||||
size = NumberSequence.new({
|
||||
NumberSequenceKeypoint.new(0, 0.6 * scale),
|
||||
NumberSequenceKeypoint.new(0.35, 1.6 * scale),
|
||||
NumberSequenceKeypoint.new(1, 0.3 * scale),
|
||||
}),
|
||||
transparency = fade,
|
||||
spread = 85,
|
||||
light = 0.6,
|
||||
bright = 3,
|
||||
drag = 9,
|
||||
accel = Vector3.new(0, 3 * scale, 0),
|
||||
})
|
||||
-- sharp sparks shooting out
|
||||
sparks(attachment, SPIKE_COLOR, 16, NumberRange.new(14 * scale, 30 * scale), 0.25 * scale)
|
||||
-- embers that fly off and fall
|
||||
burst(attachment, {
|
||||
texture = EMBER_TEXTURE,
|
||||
color = ColorSequence.new(Color3.fromRGB(255, 210, 100), Color3.fromRGB(255, 80, 15)),
|
||||
count = 14,
|
||||
life = NumberRange.new(0.35, 0.7),
|
||||
speed = NumberRange.new(6 * scale, 15 * scale),
|
||||
size = NumberSequence.new(0.25 * scale, 0),
|
||||
transparency = NumberSequence.new(0, 1),
|
||||
spread = 75,
|
||||
light = 1,
|
||||
bright = 3,
|
||||
drag = 3,
|
||||
accel = Vector3.new(0, -18 * scale, 0),
|
||||
})
|
||||
-- a wisp of dark smoke left behind
|
||||
burst(attachment, {
|
||||
texture = SMOKE_TEXTURE,
|
||||
color = ColorSequence.new(Color3.fromRGB(90, 80, 75)),
|
||||
count = 3,
|
||||
life = NumberRange.new(0.35, 0.6),
|
||||
speed = NumberRange.new(1 * scale, 2.5 * scale),
|
||||
size = NumberSequence.new(0.5 * scale, 1.8 * scale),
|
||||
transparency = NumberSequence.new(0.6, 1),
|
||||
spread = 40,
|
||||
light = 0,
|
||||
bright = 1,
|
||||
drag = 4,
|
||||
accel = Vector3.new(0, 2 * scale, 0),
|
||||
})
|
||||
Debris:AddItem(emitPart, 0.8)
|
||||
end
|
||||
|
||||
-- A player / bot destroyed (each client, on KillFeed): the name and health bar go at once, the
|
||||
-- body vanishes in a big fiery blast and breaks into blocks of its own colours that fly out,
|
||||
-- bounce and fade; the break sound plays from the body. Only this client's view changes.
|
||||
local DEBRIS_LIFE = 1.6
|
||||
function SniperEffects.destroy(model: Model, own: boolean?)
|
||||
local humanoid = model:FindFirstChildOfClass("Humanoid")
|
||||
if humanoid then
|
||||
humanoid.HealthDisplayType = Enum.HumanoidHealthDisplayType.AlwaysOff
|
||||
humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
|
||||
end
|
||||
local root = model:FindFirstChild("UpperTorso") or model:FindFirstChild("Torso") or model:FindFirstChild("HumanoidRootPart")
|
||||
if not root or not root:IsA("BasePart") then
|
||||
return
|
||||
end
|
||||
local center = root.Position
|
||||
local scale = math.max(setting("HitFxSize", 1), 0)
|
||||
|
||||
-- the sound: for the killer flat, at full volume whichever way they look (it is their
|
||||
-- confirmation, like the hit tick); for everyone else from where the body was
|
||||
if own then
|
||||
SniperEffects.sound("Break")
|
||||
else
|
||||
local at = Instance.new("Attachment")
|
||||
at.WorldPosition = center
|
||||
at.Parent = workspace.Terrain
|
||||
SniperEffects.sound("Break", at)
|
||||
Debris:AddItem(at, 4)
|
||||
end
|
||||
|
||||
-- the fire: a big blast facing up, and one facing the camera
|
||||
if scale > 0 then
|
||||
SniperEffects.blast(center, Vector3.yAxis, scale * 2.2)
|
||||
local cam = workspace.CurrentCamera
|
||||
if cam then
|
||||
SniperEffects.blast(center, (cam.CFrame.Position - center).Unit, scale * 1.6)
|
||||
end
|
||||
end
|
||||
|
||||
-- the body: every visible part is hidden and breaks into a few blocks of its colour
|
||||
local folder = Instance.new("Folder")
|
||||
folder.Name = "BodyDebris"
|
||||
folder.Parent = workspace
|
||||
local pieces: { BasePart } = {}
|
||||
for _, p in model:GetDescendants() do
|
||||
if p:IsA("Decal") then
|
||||
p.Transparency = 1 -- the face
|
||||
elseif p:IsA("BasePart") and p.Transparency < 1 and p.Name ~= "HumanoidRootPart" then
|
||||
local count = math.clamp(math.floor(p.Size.Magnitude * 1.5), 2, 5)
|
||||
for _ = 1, count do
|
||||
local s = math.min(p.Size.X, p.Size.Y, p.Size.Z, 1) * (0.45 + math.random() * 0.35)
|
||||
local block = Instance.new("Part")
|
||||
block.Name = "Block"
|
||||
block.Size = Vector3.one * math.max(s, 0.25)
|
||||
block.Color = p.Color
|
||||
block.Material = Enum.Material.SmoothPlastic
|
||||
block.CastShadow = false
|
||||
block.CanQuery = false
|
||||
block.CanTouch = false
|
||||
block.CollisionGroup = p.CollisionGroup
|
||||
local offset = Vector3.new(math.random() - 0.5, math.random() - 0.5, math.random() - 0.5) * p.Size * 0.6
|
||||
block.CFrame = p.CFrame * CFrame.new(offset) * CFrame.Angles(math.random() * 6, math.random() * 6, math.random() * 6)
|
||||
local away = (block.Position - center)
|
||||
away = if away.Magnitude > 0.01 then away.Unit else Vector3.yAxis
|
||||
block.AssemblyLinearVelocity = away * (10 + math.random() * 14) + Vector3.yAxis * (12 + math.random() * 14)
|
||||
block.AssemblyAngularVelocity = Vector3.new(math.random() - 0.5, math.random() - 0.5, math.random() - 0.5) * 30
|
||||
block.Parent = folder
|
||||
table.insert(pieces, block)
|
||||
end
|
||||
p.Transparency = 1
|
||||
end
|
||||
end
|
||||
-- glowing hot shards among them
|
||||
for _ = 1, 8 do
|
||||
local shard = effectPart("Shard", if math.random() < 0.5 then SPIKE_COLOR else BLAST_HOT, Vector3.one * (0.2 + math.random() * 0.2))
|
||||
shard.Anchored = false
|
||||
shard.CFrame = CFrame.new(center) * CFrame.Angles(math.random() * 6, math.random() * 6, math.random() * 6)
|
||||
local dir = Vector3.new(math.random() - 0.5, 0.3 + math.random() * 0.7, math.random() - 0.5).Unit
|
||||
shard.AssemblyLinearVelocity = dir * (20 + math.random() * 20)
|
||||
shard.Parent = folder
|
||||
table.insert(pieces, shard)
|
||||
end
|
||||
-- fade out and go
|
||||
task.delay(DEBRIS_LIFE - 0.5, function()
|
||||
for _, b in pieces do
|
||||
if b.Parent then
|
||||
game:GetService("TweenService"):Create(b, TweenInfo.new(0.5), { Transparency = 1, Size = b.Size * 0.3 }):Play()
|
||||
end
|
||||
end
|
||||
end)
|
||||
Debris:AddItem(folder, DEBRIS_LIFE)
|
||||
end
|
||||
|
||||
local holes: Folder? = nil
|
||||
function SniperEffects.impact(position: Vector3, normal: Vector3, flesh: boolean?)
|
||||
if flesh then
|
||||
-- a body: a small fiery blast, no hole (bodies move and fall apart)
|
||||
SniperEffects.blast(position, normal, setting("HitFxSize", 1))
|
||||
return
|
||||
end
|
||||
if not holes or not holes.Parent then
|
||||
local f = Instance.new("Folder")
|
||||
f.Name = "BulletHoles"
|
||||
f.Parent = workspace
|
||||
holes = f
|
||||
end
|
||||
local hole = Instance.new("Part")
|
||||
hole.Name = "BulletHole"
|
||||
hole.Anchored = true
|
||||
hole.CanCollide = false
|
||||
hole.CanQuery = false
|
||||
hole.CanTouch = false
|
||||
hole.CastShadow = false
|
||||
hole.Material = Enum.Material.SmoothPlastic
|
||||
hole.Color = Color3.fromRGB(25, 22, 20)
|
||||
hole.Shape = Enum.PartType.Cylinder
|
||||
hole.Size = Vector3.new(0.02, 0.28, 0.28) -- cylinder axis = X
|
||||
hole.CFrame = CFrame.lookAt(position, position + normal) * CFrame.Angles(0, math.pi / 2, 0)
|
||||
* CFrame.new(0.004, 0, 0) -- local X = the normal: a hair out of the wall
|
||||
hole.Parent = holes
|
||||
Debris:AddItem(hole, HOLE_LIFETIME)
|
||||
local puff = Instance.new("Attachment")
|
||||
puff.WorldCFrame = CFrame.lookAt(position, position + normal) -- Front (-Z) = out of the wall
|
||||
puff.Parent = workspace.Terrain
|
||||
sparks(puff, Color3.fromRGB(200, 180, 150), 8, NumberRange.new(3, 8), 0.15)
|
||||
sparks(puff, SPIKE_COLOR, 4, NumberRange.new(8, 14), 0.08)
|
||||
Debris:AddItem(puff, 0.6)
|
||||
end
|
||||
|
||||
return SniperEffects
|
||||
@@ -0,0 +1,279 @@
|
||||
--!strict
|
||||
-- Script in ServerScriptService.
|
||||
-- SniperRifle hitscan. The shooter draws the flash, recoil, and tracer immediately.
|
||||
-- The server owns damage and confirms the impact for clients in the shooter's arena.
|
||||
-- The client sends the direction, camera origin, and its synchronized fire time.
|
||||
-- The server bounds the request against its own poses and collision geometry.
|
||||
-- Server -> same arena: SniperShot(character, endPosition, hitNormal?, flesh?)
|
||||
-- (hitNormal only when something was hit; endPosition is the end of the range on a miss;
|
||||
-- flesh = a body was hit: blood puff instead of a bullet hole)
|
||||
-- Damage: opponents in the same arena. By where the bullet
|
||||
-- went: head = Damage * HeadshotMultiplier, torso = Damage, arms / legs = Damage * LimbMultiplier
|
||||
-- (attributes of the SniperViewmodel config script). The shooter is told how much it took:
|
||||
-- Server -> shooter: SniperHit:FireClient(shooter, position, damage, zone, killed, victimName)
|
||||
-- (zone = "Head" / "Body" / "Limb"; their client shows the number, DamageNumbers, and on a kill
|
||||
-- the kill icon, DamageNumbers). Kills also go to the shooter's arena via KillFeed.
|
||||
|
||||
local Players = game:GetService("Players")
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local RunService = game:GetService("RunService")
|
||||
local StarterPlayer = game:GetService("StarterPlayer")
|
||||
|
||||
local TOOL_NAME = "SniperRifle"
|
||||
local RANGE = 1000
|
||||
local remote = ReplicatedStorage:WaitForChild("SniperShot") :: RemoteEvent
|
||||
local config = StarterPlayer:WaitForChild("StarterPlayerScripts"):WaitForChild("SniperViewmodel")
|
||||
|
||||
local hitRemote = ReplicatedStorage:WaitForChild("SniperHit") :: RemoteEvent
|
||||
local damageTaken = Instance.new("RemoteEvent")
|
||||
damageTaken.Name = "DamageTaken"
|
||||
damageTaken.Parent = ReplicatedStorage
|
||||
-- KillFeed: killerName, victimName, headshot, killerUserId, victimModel
|
||||
local killFeed: RemoteEvent = (ReplicatedStorage:FindFirstChild("KillFeed") :: RemoteEvent?) or (function()
|
||||
local r = Instance.new("RemoteEvent")
|
||||
r.Name = "KillFeed"
|
||||
r.Parent = ReplicatedStorage
|
||||
return r
|
||||
end)()
|
||||
|
||||
type Cadence = {fireTime: number, received: number, tokens: number}
|
||||
local cadence: {[Player]: Cadence} = {}
|
||||
local ShotHistory = require(script.Parent:WaitForChild("ShotHistory") :: ModuleScript)
|
||||
local MAX_REWIND = .24
|
||||
local VIEW_BUFFER = .045
|
||||
local SAMPLE_STEP = 1 / 30
|
||||
local round = ReplicatedStorage:WaitForChild("ArenaRound")
|
||||
local ArenaModes = require(ReplicatedStorage:WaitForChild("ArenaModes") :: ModuleScript)
|
||||
local Objectives = require(script.Parent:WaitForChild("ArenaObjectives") :: ModuleScript)
|
||||
local TrophyDrops = require(script.Parent:WaitForChild("TrophyDrops"))
|
||||
local PowerDrops = require(script.Parent:WaitForChild("PowerUpDrops"))
|
||||
local PowerEffects = require(script.Parent:WaitForChild("PowerUpEffects"))
|
||||
|
||||
local function inMode(player: Player, mode: string): boolean
|
||||
return player:GetAttribute("InArena") == true and ArenaModes.of(player) == mode
|
||||
end
|
||||
|
||||
local function broadcast(mode: string, event: RemoteEvent, ...: any)
|
||||
for _, member in Players:GetPlayers() do
|
||||
if inMode(member, mode) then event:FireClient(member, ...) end
|
||||
end
|
||||
end
|
||||
|
||||
local function recordArenaKill(player: Player, victim: Player, origin: Vector3, mode: string): number?
|
||||
local now = workspace:GetServerTimeNow()
|
||||
if not ArenaModes.open(round, mode, now) or not inMode(player, mode) or not inMode(victim, mode)
|
||||
or not player.Team or not victim.Team or player.Team == victim.Team then return nil end
|
||||
local side = player:GetAttribute("ArenaTeam")
|
||||
if side ~= "Blue" and side ~= "Orange" then return nil end
|
||||
local scoreAttribute = side .. "Kills"
|
||||
local state = ArenaModes.state(round, mode)
|
||||
player:SetAttribute("RoundKills", ((player:GetAttribute("RoundKills") :: number?) or 0) + 1)
|
||||
state:SetAttribute(scoreAttribute, ((state:GetAttribute(scoreAttribute) :: number?) or 0) + 1)
|
||||
local match = Objectives.current(mode)
|
||||
if match then match.kill(player, victim, origin, now) end
|
||||
TrophyDrops.spawn(player, origin)
|
||||
PowerDrops.spawn(origin, nil, mode)
|
||||
local streak = ((player:GetAttribute("StreakKills") :: number?) or 0) + 1
|
||||
player:SetAttribute("StreakUntil", now + (round:GetAttribute("StreakWindow") :: number))
|
||||
player:SetAttribute("StreakKills", streak)
|
||||
return streak
|
||||
end
|
||||
|
||||
local function damageFor(zone: string): number
|
||||
local base = (config:GetAttribute("Damage") :: number?) or 35
|
||||
if zone == "Head" then
|
||||
return base * ((config:GetAttribute("HeadshotMultiplier") :: number?) or 2)
|
||||
elseif zone == "Limb" then
|
||||
return base * ((config:GetAttribute("LimbMultiplier") :: number?) or 0.75)
|
||||
end
|
||||
return base
|
||||
end
|
||||
|
||||
local function finiteVector(value: Vector3): boolean
|
||||
local magnitude = value.Magnitude
|
||||
return magnitude == magnitude and magnitude < math.huge
|
||||
end
|
||||
|
||||
local function headOf(character: Model): BasePart?
|
||||
local head = character:FindFirstChild("Head")
|
||||
return if head and head:IsA("BasePart") then head else nil
|
||||
end
|
||||
|
||||
local function obstruction(from: Vector3, to: Vector3, params: RaycastParams): RaycastResult?
|
||||
local delta = to - from
|
||||
local distance = delta.Magnitude
|
||||
if distance < .06 then return nil end
|
||||
return workspace:Raycast(from, delta * ((distance - .03) / distance), params)
|
||||
end
|
||||
|
||||
local function permitShot(player: Player, at: number, received: number): boolean
|
||||
local interval = math.max((config:GetAttribute("FireInterval") :: number?) or .1, .025)
|
||||
local rate = cadence[player]
|
||||
local tokens = if rate then math.min(3, rate.tokens + (received - rate.received) / interval) else 3
|
||||
-- A reliable remote may deliver a few legal shots together after network jitter.
|
||||
if tokens < 1 or (rate and at - rate.fireTime < interval * .56) then return false end
|
||||
cadence[player] = {fireTime = at, received = received, tokens = tokens - 1}
|
||||
return true
|
||||
end
|
||||
|
||||
local function validVictim(victim: Player?, player: Player, model: Model, mode: string): boolean
|
||||
if not victim then return false end
|
||||
return victim.Character == model and inMode(victim, mode) and (not victim.Team or victim.Team ~= player.Team)
|
||||
end
|
||||
|
||||
local function applyHit(
|
||||
player: Player, character: Model, shooter: Humanoid, model: Model, humanoid: Humanoid,
|
||||
victim: Player?, hit: ShotHistory.Hit, origin: Vector3, params: RaycastParams, mode: string
|
||||
)
|
||||
local eye = headOf(character)
|
||||
if player.Character ~= character or not inMode(player, mode) or shooter.Health <= 0
|
||||
or not model.Parent or humanoid.Health <= 0 or not hit.part:IsDescendantOf(model)
|
||||
or not validVictim(victim, player, model, mode) or not ArenaModes.open(round, mode, workspace:GetServerTimeNow()) or not eye then
|
||||
return
|
||||
end
|
||||
-- Even a rewind-confirmed hit must respect live cover on both sides.
|
||||
local livePoint = hit.part.CFrame:PointToWorldSpace(hit.localPoint)
|
||||
local cover = obstruction(origin, livePoint, params) or obstruction(eye.Position, livePoint, params)
|
||||
if cover then
|
||||
broadcast(mode, remote, character, cover.Position, cover.Normal, false)
|
||||
return
|
||||
end
|
||||
|
||||
local before = humanoid.Health
|
||||
PowerEffects.damage(model, humanoid, math.floor(damageFor(hit.zone) + .5), workspace:GetServerTimeNow())
|
||||
local damage = before - humanoid.Health
|
||||
if damage <= 0 then
|
||||
broadcast(mode, remote, character, hit.position)
|
||||
return
|
||||
end
|
||||
if victim then
|
||||
-- Only the victim receives the direction of a shot that actually removed health.
|
||||
damageTaken:FireClient(victim, model, origin - hit.position, damage)
|
||||
local match = Objectives.current(mode)
|
||||
local onHit = match and match.hit
|
||||
if onHit then onHit(victim, workspace:GetServerTimeNow(), humanoid.Health <= 0) end
|
||||
end
|
||||
|
||||
local name = if victim then victim.DisplayName elseif humanoid.DisplayName ~= "" then humanoid.DisplayName else model.Name
|
||||
local killed = humanoid.Health <= 0
|
||||
local root = model.PrimaryPart
|
||||
local streak = if killed and victim then recordArenaKill(player, victim, if root then root.Position else hit.position, mode) else nil
|
||||
hitRemote:FireClient(player, hit.position, math.max(1, math.round(damage)), hit.zone, killed, name, streak)
|
||||
if killed then
|
||||
humanoid.HealthDisplayType = Enum.HumanoidHealthDisplayType.AlwaysOff
|
||||
humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
|
||||
broadcast(mode, killFeed, player.Name, if victim then victim.Name else name, hit.zone == "Head", player.UserId, model)
|
||||
end
|
||||
broadcast(mode, remote, character, hit.position, hit.normal, true)
|
||||
end
|
||||
|
||||
remote.OnServerEvent:Connect(function(player: Player, direction: unknown, cameraOrigin: unknown, timestamp: unknown)
|
||||
if typeof(direction) ~= "Vector3" or typeof(cameraOrigin) ~= "Vector3" or typeof(timestamp) ~= "number" then return end
|
||||
if not finiteVector(direction) or not finiteVector(cameraOrigin) or direction.Magnitude < .5 or direction.Magnitude > 1.5
|
||||
or timestamp ~= timestamp or math.abs(timestamp) == math.huge then return end
|
||||
local received = workspace:GetServerTimeNow()
|
||||
local mode = ArenaModes.of(player)
|
||||
if player:GetAttribute("InArena") ~= true or not ArenaModes.open(round, mode, received) then return end
|
||||
local oneWay = math.clamp(player:GetNetworkPing() * .5, 0, .20)
|
||||
local ageLimit = math.clamp(oneWay + .10, .12, .30)
|
||||
if timestamp > received + .035 or timestamp < received - ageLimit then return end
|
||||
local shotTime = math.min(timestamp, received)
|
||||
local character = player.Character
|
||||
local shooter = character and character:FindFirstChildOfClass("Humanoid")
|
||||
if not character or not shooter or shooter.Health <= 0 then return end
|
||||
local tool = character:FindFirstChild(TOOL_NAME)
|
||||
local head = headOf(character)
|
||||
if not tool or not tool:IsA("Tool") or not head then return end
|
||||
local eye = head.Position
|
||||
if (cameraOrigin - eye).Magnitude > 3.1 or not permitShot(player, shotTime, received) then return end
|
||||
|
||||
local members = Players:GetPlayers()
|
||||
local excluded: {Instance} = {}
|
||||
for _, member in members do
|
||||
local current = member.Character
|
||||
if current then table.insert(excluded, current) end
|
||||
end
|
||||
local world = RaycastParams.new()
|
||||
world.FilterType = Enum.RaycastFilterType.Exclude
|
||||
world.FilterDescendantsInstances = excluded
|
||||
world.RespectCanCollide = true
|
||||
if obstruction(eye, cameraOrigin, world) then return end
|
||||
|
||||
local origin, dir = cameraOrigin, direction.Unit
|
||||
local worldHit = workspace:Raycast(origin, dir * RANGE, world)
|
||||
local remaining = if worldHit then math.max(0, worldHit.Distance - .025) else RANGE
|
||||
local targetTime = math.max(received - MAX_REWIND, shotTime - oneWay - VIEW_BUFFER)
|
||||
local model: Model? = nil
|
||||
local humanoid: Humanoid? = nil
|
||||
local victim: Player? = nil
|
||||
local found: ShotHistory.Hit? = nil
|
||||
local function consider(candidate: Model, owner: Player?)
|
||||
if candidate == character then return end
|
||||
local health = candidate:FindFirstChildOfClass("Humanoid")
|
||||
if not health or health.Health <= 0 then return end
|
||||
local result = ShotHistory.cast(candidate, owner, targetTime, origin, dir, remaining)
|
||||
if result then
|
||||
model, humanoid, victim, found = candidate, health, owner, result
|
||||
remaining = result.distance
|
||||
end
|
||||
end
|
||||
for _, member in members do
|
||||
local candidate = member.Character
|
||||
if candidate and inMode(member, mode) then consider(candidate, member) end
|
||||
end
|
||||
|
||||
local hit, target, health, owner = found, model, humanoid, victim
|
||||
if not hit or not target or not health then
|
||||
if worldHit then
|
||||
broadcast(mode, remote, character, worldHit.Position, worldHit.Normal, false)
|
||||
else
|
||||
broadcast(mode, remote, character, origin + dir * RANGE)
|
||||
end
|
||||
return
|
||||
end
|
||||
if not validVictim(owner, player, target, mode) then
|
||||
broadcast(mode, remote, character, hit.position)
|
||||
return
|
||||
end
|
||||
local cover = obstruction(eye, hit.position, world)
|
||||
if cover then
|
||||
broadcast(mode, remote, character, cover.Position, cover.Normal, false)
|
||||
return
|
||||
end
|
||||
|
||||
if owner then
|
||||
local targetHead = headOf(target)
|
||||
local delivery = math.clamp(owner:GetNetworkPing() * .5 + VIEW_BUFFER, VIEW_BUFFER, .14)
|
||||
local previousEye = ShotHistory.eyeAt(player, character, received - delivery)
|
||||
if targetHead and previousEye and obstruction(targetHead.Position, previousEye, world) then
|
||||
-- The defender can still be seeing the previous, occluded shooter pose.
|
||||
task.delay(delivery, applyHit, player, character, shooter, target, health, owner, hit, origin, world, mode)
|
||||
return
|
||||
end
|
||||
end
|
||||
applyHit(player, character, shooter, target, health, owner, hit, origin, world, mode)
|
||||
end)
|
||||
|
||||
local elapsed = 0
|
||||
local tracking = RunService.Heartbeat:Connect(function(dt)
|
||||
elapsed += dt
|
||||
if elapsed < SAMPLE_STEP then return end
|
||||
elapsed %= SAMPLE_STEP
|
||||
local now = workspace:GetServerTimeNow()
|
||||
for _, player in Players:GetPlayers() do
|
||||
local character = player.Character
|
||||
local head = character and headOf(character)
|
||||
local humanoid = character and character:FindFirstChildOfClass("Humanoid")
|
||||
if character and head and humanoid and humanoid.Health > 0 and player:GetAttribute("InArena") == true then
|
||||
ShotHistory.record(player, character, head, now)
|
||||
else
|
||||
ShotHistory.clear(player)
|
||||
end
|
||||
end
|
||||
end)
|
||||
script.Destroying:Once(function() tracking:Disconnect() end)
|
||||
|
||||
Players.PlayerRemoving:Connect(function(player)
|
||||
cadence[player] = nil
|
||||
ShotHistory.clear(player)
|
||||
end)
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,46 @@
|
||||
--!strict
|
||||
-- Script in ServerScriptService.
|
||||
-- Target bots: a copy of ServerStorage.TargetBot stands on every part in Workspace.BotSpawns
|
||||
-- (move / add / remove those parts to place them; each bot faces where its part faces).
|
||||
-- They do nothing but stand and take bullets (SniperShots deals the damage to models tagged
|
||||
-- "TargetBot"); a dead bot falls apart and a new one stands up on the same spot after RESPAWN_TIME.
|
||||
|
||||
local CollectionService = game:GetService("CollectionService")
|
||||
local ServerStorage = game:GetService("ServerStorage")
|
||||
|
||||
local TAG = "TargetBot"
|
||||
local RESPAWN_TIME = 4
|
||||
local template = ServerStorage:WaitForChild("TargetBot") :: Model
|
||||
local spawns = workspace:WaitForChild("BotSpawns")
|
||||
|
||||
local botsFolder = Instance.new("Folder")
|
||||
botsFolder.Name = "TargetBots"
|
||||
botsFolder.Parent = workspace
|
||||
|
||||
local function spawnBot(marker: BasePart)
|
||||
local bot = template:Clone()
|
||||
local root = bot:FindFirstChild("HumanoidRootPart") :: BasePart
|
||||
local humanoid = bot:FindFirstChildOfClass("Humanoid") :: Humanoid
|
||||
-- feet on the marker: the root sits half its height plus the hip height above the ground
|
||||
local lift = root.Size.Y / 2 + humanoid.HipHeight
|
||||
bot:PivotTo(marker.CFrame * CFrame.new(0, lift - marker.Size.Y / 2, 0))
|
||||
root.Anchored = true -- stands still, cannot be pushed over
|
||||
bot.Name = "Bot_" .. marker.Name
|
||||
CollectionService:AddTag(bot, TAG)
|
||||
bot.Parent = botsFolder
|
||||
humanoid.Died:Once(function()
|
||||
root.Anchored = false -- let the body fall
|
||||
task.delay(RESPAWN_TIME, function()
|
||||
bot:Destroy()
|
||||
if marker.Parent then
|
||||
spawnBot(marker)
|
||||
end
|
||||
end)
|
||||
end)
|
||||
end
|
||||
|
||||
for _, marker in spawns:GetChildren() do
|
||||
if marker:IsA("BasePart") then
|
||||
spawnBot(marker)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,349 @@
|
||||
--!strict
|
||||
-- Third-person rifle pose: how the SniperRifle looks in the hands of a character seen from outside.
|
||||
-- The server (ServerScriptService.ThirdPersonRifle) welds the rifle to the UpperTorso; this script
|
||||
-- runs on every client for every character holding the rifle and bends both arms onto it with
|
||||
-- IKControls: the right hand to the pistol grip, the left hand to the handguard, elbows toward
|
||||
-- pole points next to the torso. Same values on every client, so all players see the same pose.
|
||||
-- The inspect animation is first-person only and is never shown here; the reload is (other
|
||||
-- players' reloads arrive through ReplicatedStorage.SniperReload, the own one through the
|
||||
-- ReloadStamp attribute set by SniperViewmodel). Shots (ReplicatedStorage.SniperShot) show a
|
||||
-- muzzle flash and a small kick of the rifle, and the bullet hole for other players' shots.
|
||||
-- Tuned through attributes on PlayerScripts.SniperViewmodel (prefix TP), live-editable with the
|
||||
-- ViewmodelTuner panel (P); its "Вид" button switches the local camera to third person.
|
||||
|
||||
local Players = game:GetService("Players")
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local RunService = game:GetService("RunService")
|
||||
|
||||
local TOOL_NAME = "SniperRifle"
|
||||
local WELD_NAME = "TPRifleWeld"
|
||||
local player = Players.LocalPlayer
|
||||
local config = player:WaitForChild("PlayerScripts"):WaitForChild("SniperViewmodel")
|
||||
local ReloadTimeline = require(ReplicatedStorage:WaitForChild("ReloadTimeline") :: ModuleScript)
|
||||
local reloadRemote = ReplicatedStorage:WaitForChild("SniperReload") :: RemoteEvent
|
||||
local shotRemote = ReplicatedStorage:WaitForChild("SniperShot") :: RemoteEvent
|
||||
local SniperEffects = require(ReplicatedStorage:WaitForChild("SniperEffects") :: ModuleScript)
|
||||
local RifleSkin = require(ReplicatedStorage:WaitForChild("RifleSkin") :: ModuleScript)
|
||||
local SkinCatalog = require(ReplicatedStorage:WaitForChild("RifleSkinCatalog") :: ModuleScript)
|
||||
|
||||
-- All positions in studs, angles in degrees.
|
||||
-- TPGun*: rifle grip (Handle) relative to the UpperTorso (+X right, +Y up, -Z forward).
|
||||
-- TPRHand* / TPLHand*: where each hand grabs the rifle, in rifle space (-Z = barrel, +Y = up).
|
||||
-- TPRElbow* / TPLElbow*: points the elbows bend toward, relative to the UpperTorso.
|
||||
local DEFAULTS = {
|
||||
TPGunX = 0.45,
|
||||
TPGunY = -0.25,
|
||||
TPGunZ = -0.8,
|
||||
TPGunYawDeg = 0,
|
||||
TPGunPitchDeg = 0,
|
||||
TPGunRollDeg = 0,
|
||||
TPRHandX = 0,
|
||||
TPRHandY = 0,
|
||||
TPRHandZ = 0,
|
||||
TPRHandYawDeg = 0,
|
||||
TPRHandPitchDeg = 0,
|
||||
TPRHandRollDeg = 0,
|
||||
TPLHandX = 0,
|
||||
TPLHandY = 0.1,
|
||||
TPLHandZ = -0.6,
|
||||
TPLHandYawDeg = 0,
|
||||
TPLHandPitchDeg = 0,
|
||||
TPLHandRollDeg = 0,
|
||||
TPRElbowX = 2,
|
||||
TPRElbowY = -1.5,
|
||||
TPRElbowZ = 0.5,
|
||||
TPLElbowX = -2,
|
||||
TPLElbowY = -1.5,
|
||||
TPLElbowZ = 0,
|
||||
-- reload, rifle space (the third-person rifle is about half the viewmodel's size)
|
||||
TPMagX = 0,
|
||||
TPMagY = 0.03,
|
||||
TPMagZ = -0.49,
|
||||
TPMagDrop = 0.8,
|
||||
TPBoltX = 0.19,
|
||||
TPBoltY = 0.46,
|
||||
TPBoltZ = -0.05,
|
||||
TPBoltLift = 0.08,
|
||||
TPBoltPull = 0.25,
|
||||
-- shot
|
||||
TPMuzzleX = 0, -- muzzle end, rifle space
|
||||
TPMuzzleY = 0.43,
|
||||
TPMuzzleZ = -2.19,
|
||||
TPFlashSize = 0.6,
|
||||
TPRecoilBack = 0, -- automatic rifle: the weapon does not jump
|
||||
TPRecoilPitchDeg = 0,
|
||||
}
|
||||
for name, value in DEFAULTS do
|
||||
if config:GetAttribute(name) == nil then
|
||||
config:SetAttribute(name, value)
|
||||
end
|
||||
end
|
||||
local function attr(name: string): number
|
||||
-- ReloadTime / ReloadPreviewU belong to SniperViewmodel, which sets them on start
|
||||
return (config:GetAttribute(name) :: number?) or (DEFAULTS :: any)[name] or 0
|
||||
end
|
||||
local function pose(prefix: string): CFrame
|
||||
return CFrame.new(attr(prefix .. "X"), attr(prefix .. "Y"), attr(prefix .. "Z"))
|
||||
* CFrame.Angles(0, math.rad(attr(prefix .. "YawDeg")), 0)
|
||||
* CFrame.Angles(math.rad(attr(prefix .. "PitchDeg")), 0, 0)
|
||||
* CFrame.Angles(0, 0, math.rad(attr(prefix .. "RollDeg")))
|
||||
end
|
||||
local function point(prefix: string): Vector3
|
||||
return Vector3.new(attr(prefix .. "X"), attr(prefix .. "Y"), attr(prefix .. "Z"))
|
||||
end
|
||||
|
||||
-- ---------------------------------------------------------------- per-character arm IK
|
||||
type Arm = { key: string, target: Attachment, pole: Attachment }
|
||||
type Rig = {
|
||||
handle: BasePart, arms: { Arm }, extra: { Instance }, flames: RifleSkin.Effect?,
|
||||
skinChanged: RBXScriptConnection?,
|
||||
}
|
||||
local rigs: { [Model]: Rig } = {}
|
||||
local reloadStarts: { [Model]: {start: number, duration: number} } = {}
|
||||
|
||||
-- Reload time (0..1) of a character, or nil when it is not reloading.
|
||||
local function reloadU(character: Model): number?
|
||||
if character == player.Character and config:GetAttribute("ReloadPreview") == true then
|
||||
return math.clamp(attr("ReloadPreviewU"), 0, 1) -- tuner's frozen frame
|
||||
end
|
||||
local reload = reloadStarts[character]
|
||||
if not reload then
|
||||
return nil
|
||||
end
|
||||
local u = (os.clock() - reload.start) / math.max(reload.duration, 0.1)
|
||||
if u >= 1 then
|
||||
reloadStarts[character] = nil
|
||||
return nil
|
||||
end
|
||||
return u
|
||||
end
|
||||
|
||||
local function handPose(key: string, u: number?): CFrame
|
||||
local base = pose(key .. "Hand")
|
||||
if not u then
|
||||
return base
|
||||
end
|
||||
local position = if key == "TPL"
|
||||
then ReloadTimeline.leftHand(u, base.Position, point("TPMag"), attr("TPMagDrop"))
|
||||
else ReloadTimeline.rightHand(u, base.Position, point("TPBolt"), attr("TPBoltLift"), attr("TPBoltPull"))
|
||||
return base.Rotation + position
|
||||
end
|
||||
|
||||
-- the rifle of a character, as the place its sounds come from
|
||||
local function rifleHandle(character: Model): BasePart?
|
||||
local tool = character:FindFirstChild(TOOL_NAME)
|
||||
local handle = tool and tool:FindFirstChild("Handle")
|
||||
return if handle and handle:IsA("BasePart") then handle else nil
|
||||
end
|
||||
|
||||
-- Another player's sounds, from their rifle: each cue at its moment, unless `still` says the
|
||||
-- action was cut short (the own player's sounds come from SniperViewmodel instead).
|
||||
local function scheduleCues(character: Model, list: { any }, delay: number, length: number, still: () -> boolean)
|
||||
for _, cue in list do
|
||||
task.delay(delay + cue.at * length, function()
|
||||
local handle = rifleHandle(character)
|
||||
if handle and still() then
|
||||
SniperEffects.sound(cue.sound, handle)
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
reloadRemote.OnClientEvent:Connect(function(character: Model, duration: number)
|
||||
if typeof(character) == "Instance" and character:IsA("Model") then
|
||||
local reload = {start = os.clock(), duration = if typeof(duration) == "number" then duration else attr("ReloadTime")}
|
||||
reloadStarts[character] = reload
|
||||
scheduleCues(character, SniperEffects.RELOAD_CUES, 0, reload.duration, function()
|
||||
return reloadStarts[character] == reload
|
||||
end)
|
||||
end
|
||||
end)
|
||||
config:GetAttributeChangedSignal("ReloadStamp"):Connect(function()
|
||||
local character = player.Character
|
||||
if character then
|
||||
reloadStarts[character] = {
|
||||
start = os.clock(),
|
||||
duration = (config:GetAttribute("ReloadDuration") :: number?) or attr("ReloadTime"),
|
||||
}
|
||||
end
|
||||
end)
|
||||
|
||||
local function makeRig(character: Model, tool: Tool, handle: BasePart, torso: BasePart): Rig
|
||||
local rig: Rig = { handle = handle, arms = {}, extra = {} }
|
||||
local function updateSkin()
|
||||
local choice = SkinCatalog.get(tool:GetAttribute("Skin"))
|
||||
RifleSkin.destroy(rig.flames)
|
||||
rig.flames = RifleSkin.apply(tool, handle, choice.id, choice.accent)
|
||||
end
|
||||
updateSkin()
|
||||
rig.skinChanged = tool:GetAttributeChangedSignal("Skin"):Connect(updateSkin)
|
||||
local humanoid = character:FindFirstChildOfClass("Humanoid")
|
||||
for _, side in { "Right", "Left" } do
|
||||
local target = Instance.new("Attachment")
|
||||
target.Name = "TP" .. side .. "HandTarget"
|
||||
target.Parent = handle
|
||||
local pole = Instance.new("Attachment")
|
||||
pole.Name = "TP" .. side .. "ElbowPole"
|
||||
pole.Parent = torso
|
||||
table.insert(rig.extra, target)
|
||||
table.insert(rig.extra, pole)
|
||||
local upper = character:FindFirstChild(side .. "UpperArm")
|
||||
local hand = character:FindFirstChild(side .. "Hand")
|
||||
if humanoid and upper and hand then -- R15 only; R6 arms have no joints to bend
|
||||
local c = Instance.new("IKControl")
|
||||
c.Name = "TP" .. side .. "ArmIK"
|
||||
c.Type = Enum.IKControlType.Transform
|
||||
c.ChainRoot = upper
|
||||
c.EndEffector = hand:FindFirstChild(side .. "GripAttachment") or hand
|
||||
c.Target = target
|
||||
c.Pole = pole
|
||||
c.Weight = 1
|
||||
c.SmoothTime = 0
|
||||
c.Parent = humanoid
|
||||
table.insert(rig.extra, c)
|
||||
end
|
||||
table.insert(rig.arms, { key = if side == "Right" then "TPR" else "TPL", target = target, pole = pole })
|
||||
end
|
||||
return rig
|
||||
end
|
||||
|
||||
-- ---------------------------------------------------------------- shots
|
||||
local shotStarts: { [Model]: number } = {}
|
||||
|
||||
-- 0..1 kick of a character's rifle: snaps back fast, settles in 0.3 s.
|
||||
local function kick(character: Model): number
|
||||
local start = shotStarts[character]
|
||||
if not start then
|
||||
return 0
|
||||
end
|
||||
local t = os.clock() - start
|
||||
if t >= 0.34 then
|
||||
shotStarts[character] = nil
|
||||
return 0
|
||||
end
|
||||
if t < 0.04 then
|
||||
return t / 0.04
|
||||
end
|
||||
return 1 - ReloadTimeline.smooth((t - 0.04) / 0.3)
|
||||
end
|
||||
|
||||
shotRemote.OnClientEvent:Connect(function(character: Model, hitPosition: Vector3?, hitNormal: Vector3?, flesh: boolean?)
|
||||
if typeof(character) ~= "Instance" or not character:IsA("Model") then
|
||||
return
|
||||
end
|
||||
local own = character == player.Character
|
||||
if typeof(hitPosition) == "Vector3" and typeof(hitNormal) == "Vector3" then
|
||||
SniperEffects.impact(hitPosition, hitNormal, flesh == true)
|
||||
end
|
||||
-- the shot and the bolt after it, heard from the shooter's rifle
|
||||
local shooterHandle = rifleHandle(character)
|
||||
if not own and shooterHandle then
|
||||
SniperEffects.sound("Shot", shooterHandle)
|
||||
if attr("ShotBoltTime") > 0 then -- 0 = automatic, no bolt
|
||||
scheduleCues(character, SniperEffects.BOLT_CUES, attr("ShotBoltDelay"), attr("ShotBoltTime"), function()
|
||||
return reloadStarts[character] == nil -- a reload cuts the bolt short
|
||||
end)
|
||||
end
|
||||
end
|
||||
-- in first person the shooter sees the viewmodel's flash instead
|
||||
if own and config:GetAttribute("ThirdPersonView") ~= true then
|
||||
return
|
||||
end
|
||||
shotStarts[character] = os.clock()
|
||||
local rig = rigs[character]
|
||||
RifleSkin.pulse(if rig then rig.flames else nil)
|
||||
local tool = character:FindFirstChild(TOOL_NAME)
|
||||
local handle = tool and tool:FindFirstChild("Handle")
|
||||
if handle and handle:IsA("BasePart") then
|
||||
local muzzle = handle.CFrame * CFrame.new(point("TPMuzzle"))
|
||||
SniperEffects.flash(muzzle, attr("TPFlashSize"), workspace)
|
||||
-- hitPosition is where the bullet stopped (the end of its range when it hit nothing)
|
||||
if typeof(hitPosition) == "Vector3" then
|
||||
SniperEffects.tracer(muzzle.Position, hitPosition)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
local function removeRig(character: Model)
|
||||
local rig = rigs[character]
|
||||
if rig then
|
||||
rigs[character] = nil
|
||||
if rig.skinChanged then rig.skinChanged:Disconnect() end
|
||||
RifleSkin.destroy(rig.flames)
|
||||
for _, inst in rig.extra do
|
||||
inst:Destroy()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function update()
|
||||
local seen: { [Model]: boolean } = {}
|
||||
for _, p in Players:GetPlayers() do
|
||||
local character = p.Character
|
||||
local tool = character and character:FindFirstChild(TOOL_NAME)
|
||||
local handle = tool and tool:FindFirstChild("Handle")
|
||||
local torso = character and (character:FindFirstChild("UpperTorso") or character:FindFirstChild("Torso"))
|
||||
if character and tool and tool:IsA("Tool") and handle and handle:IsA("BasePart") and torso and torso:IsA("BasePart") then
|
||||
seen[character] = true
|
||||
local rig = rigs[character]
|
||||
if rig and rig.handle ~= handle then
|
||||
removeRig(character)
|
||||
rig = nil
|
||||
end
|
||||
if not rig then
|
||||
rig = makeRig(character, tool, handle, torso)
|
||||
rigs[character] = rig
|
||||
end
|
||||
if rig.flames then
|
||||
local own = p == player
|
||||
local camera = workspace.CurrentCamera
|
||||
local nearby = camera ~= nil and (camera.CFrame.Position - handle.Position).Magnitude < 100
|
||||
local showFlames = (not own or config:GetAttribute("ThirdPersonView") == true)
|
||||
and p:GetAttribute("InArena") == true and nearby
|
||||
local humanoid = character:FindFirstChildOfClass("Humanoid")
|
||||
RifleSkin.setMode(rig.flames, if showFlames and humanoid and humanoid.Health > 0 then "Full" else "Hidden")
|
||||
RifleSkin.animate(rig.flames, os.clock())
|
||||
end
|
||||
-- live tuning: show the rifle offset at once (the server applies it to everyone)
|
||||
local weld = torso:FindFirstChild(WELD_NAME)
|
||||
if weld and weld:IsA("Weld") then
|
||||
local k = kick(character)
|
||||
weld.C0 = pose("TPGun")
|
||||
* CFrame.new(0, 0, attr("TPRecoilBack") * k)
|
||||
* CFrame.Angles(math.rad(attr("TPRecoilPitchDeg")) * k, 0, 0)
|
||||
end
|
||||
local u = reloadU(character)
|
||||
for _, arm in (rig :: Rig).arms do
|
||||
arm.target.CFrame = handPose(arm.key, u)
|
||||
arm.pole.Position = point(arm.key .. "Elbow")
|
||||
end
|
||||
end
|
||||
end
|
||||
for character in rigs do
|
||||
if not seen[character] then
|
||||
removeRig(character)
|
||||
reloadStarts[character] = nil
|
||||
shotStarts[character] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
RunService.PreSimulation:Connect(update)
|
||||
|
||||
-- ---------------------------------------------------------------- local third-person view (tuning)
|
||||
local function applyView()
|
||||
if config:GetAttribute("ThirdPersonView") == true then
|
||||
player.CameraMode = Enum.CameraMode.Classic
|
||||
player.CameraMaxZoomDistance = 128
|
||||
player.CameraMinZoomDistance = 8 -- pushes the camera out of the head
|
||||
task.delay(0.2, function()
|
||||
if config:GetAttribute("ThirdPersonView") == true then
|
||||
player.CameraMinZoomDistance = 3 -- allow zooming in closer afterwards
|
||||
end
|
||||
end)
|
||||
else
|
||||
player.CameraMinZoomDistance = 0.5
|
||||
player.CameraMode = Enum.CameraMode.LockFirstPerson
|
||||
end
|
||||
end
|
||||
config:GetAttributeChangedSignal("ThirdPersonView"):Connect(applyView)
|
||||
@@ -0,0 +1,76 @@
|
||||
--!strict
|
||||
-- Script in ServerScriptService.
|
||||
-- Third-person rifle mount: while a character holds the SniperRifle, the tool's RightGrip weld is
|
||||
-- switched off and the rifle is welded to the UpperTorso instead, at the TPGun* offset from the
|
||||
-- attributes of StarterPlayerScripts.SniperViewmodel (the same values the ViewmodelTuner edits).
|
||||
-- Done on the server so every client (and the physics owner) agrees on how the rifle is attached;
|
||||
-- the arms are bent onto the rifle on each client by the ThirdPersonRifle LocalScript.
|
||||
|
||||
local Players = game:GetService("Players")
|
||||
local RunService = game:GetService("RunService")
|
||||
local StarterPlayer = game:GetService("StarterPlayer")
|
||||
|
||||
local TOOL_NAME = "SniperRifle"
|
||||
local WELD_NAME = "TPRifleWeld"
|
||||
local config = StarterPlayer:WaitForChild("StarterPlayerScripts"):WaitForChild("SniperViewmodel")
|
||||
|
||||
local function attr(name: string): number
|
||||
return (config:GetAttribute(name) :: number?) or 0
|
||||
end
|
||||
local function gunPose(): CFrame
|
||||
return CFrame.new(attr("TPGunX"), attr("TPGunY"), attr("TPGunZ"))
|
||||
* CFrame.Angles(0, math.rad(attr("TPGunYawDeg")), 0)
|
||||
* CFrame.Angles(math.rad(attr("TPGunPitchDeg")), 0, 0)
|
||||
* CFrame.Angles(0, 0, math.rad(attr("TPGunRollDeg")))
|
||||
end
|
||||
|
||||
local mounted: { [Model]: Weld } = {}
|
||||
|
||||
local function setGrip(character: Model, enabled: boolean)
|
||||
local hand = character:FindFirstChild("RightHand") or character:FindFirstChild("Right Arm")
|
||||
local grip = hand and hand:FindFirstChild("RightGrip")
|
||||
if grip and grip:IsA("JointInstance") and grip.Enabled ~= enabled then
|
||||
grip.Enabled = enabled
|
||||
end
|
||||
end
|
||||
|
||||
RunService.Heartbeat:Connect(function()
|
||||
local seen: { [Model]: boolean } = {}
|
||||
for _, p in Players:GetPlayers() do
|
||||
local character = p.Character
|
||||
local tool = character and character:FindFirstChild(TOOL_NAME)
|
||||
local handle = tool and tool:FindFirstChild("Handle")
|
||||
local torso = character and (character:FindFirstChild("UpperTorso") or character:FindFirstChild("Torso"))
|
||||
if character and tool and tool:IsA("Tool") and handle and handle:IsA("BasePart") and torso and torso:IsA("BasePart") then
|
||||
seen[character] = true
|
||||
local weld = mounted[character]
|
||||
if not weld or weld.Parent ~= torso or weld.Part1 ~= handle then
|
||||
if weld then
|
||||
weld:Destroy()
|
||||
end
|
||||
local w = Instance.new("Weld")
|
||||
w.Name = WELD_NAME
|
||||
w.Part0 = torso
|
||||
w.Part1 = handle
|
||||
w.C0 = gunPose()
|
||||
w.Parent = torso
|
||||
mounted[character] = w
|
||||
weld = w
|
||||
end
|
||||
setGrip(character, false) -- the tool system re-creates it on every equip
|
||||
local pose = gunPose()
|
||||
if (weld :: Weld).C0 ~= pose then
|
||||
(weld :: Weld).C0 = pose
|
||||
end
|
||||
end
|
||||
end
|
||||
for character, weld in mounted do
|
||||
if not seen[character] then
|
||||
mounted[character] = nil
|
||||
weld:Destroy()
|
||||
if character.Parent then
|
||||
setGrip(character, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
@@ -0,0 +1,284 @@
|
||||
--!strict
|
||||
local Players = game:GetService("Players")
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local RunService = game:GetService("RunService")
|
||||
local TweenService = game:GetService("TweenService")
|
||||
|
||||
local UI = require(ReplicatedStorage:WaitForChild("HunterUI") :: ModuleScript)
|
||||
local player = Players.LocalPlayer
|
||||
local gold = Color3.fromRGB(255, 211, 95)
|
||||
|
||||
local gui = Instance.new("ScreenGui")
|
||||
gui.Name = "TrophyBalance"
|
||||
gui.ResetOnSpawn = false
|
||||
gui.DisplayOrder = 24
|
||||
gui.Parent = player:WaitForChild("PlayerGui")
|
||||
|
||||
local function frame(name: string, parent: Instance, size: UDim2, color: Color3, radius: number): Frame
|
||||
local item = Instance.new("Frame")
|
||||
item.Name = name
|
||||
item.Size = size
|
||||
item.BackgroundColor3 = color
|
||||
item.BorderSizePixel = 0
|
||||
item.Parent = parent
|
||||
Instance.new("UICorner", item).CornerRadius = UDim.new(0, radius)
|
||||
return item
|
||||
end
|
||||
|
||||
local function edge(item: GuiObject, color: Color3, thickness: number, transparency: number): UIStroke
|
||||
local stroke = Instance.new("UIStroke")
|
||||
stroke.Color = color
|
||||
stroke.Thickness = thickness
|
||||
stroke.Transparency = transparency
|
||||
stroke.ApplyStrokeMode = Enum.ApplyStrokeMode.Border
|
||||
stroke.Parent = item
|
||||
return stroke
|
||||
end
|
||||
|
||||
local function label(name: string, parent: Instance, text: string, position: UDim2, size: UDim2, fontSize: number, color: Color3): TextLabel
|
||||
local item = Instance.new("TextLabel")
|
||||
item.Name = name
|
||||
item.BackgroundTransparency = 1
|
||||
item.Position = position
|
||||
item.Size = size
|
||||
item.Font = Enum.Font.GothamBold
|
||||
item.Text = text
|
||||
item.TextSize = fontSize
|
||||
item.TextColor3 = color
|
||||
item.Parent = parent
|
||||
return item
|
||||
end
|
||||
|
||||
local pill = UI.plate(gui, "Wallet", UDim2.fromOffset(0, 0), UDim2.fromOffset(236, 51), UI.Outline)
|
||||
UI.contour(pill, UI.Gold)
|
||||
pill.AnchorPoint = Vector2.new(1, 0)
|
||||
local coin = UI.element("GoldCoin", pill, UDim2.fromOffset(13, 7), UDim2.fromOffset(36, 36))
|
||||
local walletCoin = UI.bindCoin(coin)
|
||||
|
||||
local title = label("CurrencyName", pill, "ТРОФЕИ", UDim2.fromOffset(158, 8), UDim2.fromOffset(72, 35), 13, UI.Ink)
|
||||
title.FontFace = UI.Display
|
||||
title.TextXAlignment = Enum.TextXAlignment.Left
|
||||
local divider = UI.frame("Divider", pill, UDim2.fromOffset(146, 12), UDim2.fromOffset(1, 26), UI.Outline)
|
||||
divider.Rotation = 12
|
||||
local balance = label("Balance", pill, "0", UDim2.fromOffset(60, 5), UDim2.fromOffset(81, 42), 27, UI.Ink)
|
||||
balance.FontFace = UI.Display
|
||||
balance.TextXAlignment = Enum.TextXAlignment.Left
|
||||
balance.TextScaled = true
|
||||
Instance.new("UITextSizeConstraint", balance).MaxTextSize = 27
|
||||
local gain = label("Gain", pill, "", UDim2.fromOffset(-64, 15), UDim2.fromOffset(55, 21), 16, gold)
|
||||
gain.FontFace = UI.Display
|
||||
gain.TextStrokeTransparency = .55
|
||||
gain.TextXAlignment = Enum.TextXAlignment.Right
|
||||
gain.Visible = false
|
||||
local pulse = Instance.new("UIScale", pill)
|
||||
local layoutScale = 1
|
||||
local progressMotion: Tween? = nil
|
||||
local sessionGain = 0
|
||||
local lastDrop: number? = nil
|
||||
local gainUntil = 0
|
||||
local lastLanding = -math.huge
|
||||
local progressTrack = UI.element("ProgressBar", pill, UDim2.new(0, 8, 1, -5), UDim2.new(1, -16, 0, 2))
|
||||
progressTrack.Name = "PickupProgress"
|
||||
progressTrack.Visible = false
|
||||
local progressFill = progressTrack:WaitForChild("Fill") :: Frame
|
||||
progressFill.BackgroundColor3 = gold
|
||||
progressFill.Size = UDim2.fromScale(0, 1)
|
||||
UI.sheen(progressFill)
|
||||
local flash = frame("CreditFlash", pill, UDim2.fromOffset(38, 38), gold, 99)
|
||||
flash.AnchorPoint = Vector2.new(.5, .5)
|
||||
flash.Position = UDim2.fromOffset(31, 25)
|
||||
flash.BackgroundTransparency = 1
|
||||
local flashEdge = edge(flash, Color3.fromRGB(255, 237, 146), 2, 1)
|
||||
|
||||
local flightLayer = frame("CoinFlights", gui, UDim2.fromScale(1, 1), gold, 0)
|
||||
flightLayer.BackgroundTransparency = 1
|
||||
flightLayer.ZIndex = 5
|
||||
|
||||
type Flight = {
|
||||
icon: Frame, rig: UI.CoinRig, scale: UIScale, tail: {Frame}, from: Vector2, started: number,
|
||||
amount: number, id: number, progress: number, milestone: boolean,
|
||||
}
|
||||
local flights: {Flight} = {}
|
||||
local nextLaunch = 0
|
||||
local sessionShown = 0
|
||||
local originBalance = 0
|
||||
local FLIGHT_TIME = .46
|
||||
|
||||
local function formatBalance(amount: number): string
|
||||
local digits = tostring(math.floor(amount))
|
||||
local grouped = digits:reverse():gsub("(%d%d%d)", "%1 "):reverse()
|
||||
return (grouped:gsub("^ ", ""))
|
||||
end
|
||||
|
||||
local function inArena(): boolean
|
||||
return player:GetAttribute("InArena") == true
|
||||
end
|
||||
|
||||
local function paintBalance()
|
||||
local amount = if inArena() then originBalance + sessionShown else (player:GetAttribute("TrophyBalance") :: number?) or 0
|
||||
balance.Text = formatBalance(amount)
|
||||
end
|
||||
|
||||
local function fit()
|
||||
layoutScale = UI.combatScale(gui)
|
||||
pulse.Scale = layoutScale
|
||||
if inArena() then
|
||||
UI.placeCombat(pill, "Wallet")
|
||||
else
|
||||
pill.AnchorPoint = Vector2.new(1, 0)
|
||||
pill.Position = UDim2.new(1, -12, 0, if gui.AbsoluteSize.X < 620 then 68 else 7)
|
||||
end
|
||||
end
|
||||
|
||||
local function updateZone()
|
||||
if progressMotion then progressMotion:Cancel() end
|
||||
for _, flight in flights do
|
||||
flight.icon:Destroy()
|
||||
for _, particle in flight.tail do particle:Destroy() end
|
||||
end
|
||||
table.clear(flights)
|
||||
nextLaunch = 0
|
||||
originBalance = (player:GetAttribute("TrophyOriginBalance") :: number?) or 0
|
||||
sessionShown = ((player:GetAttribute("TrophyBalance") :: number?) or 0) - originBalance
|
||||
gain.Visible = false
|
||||
progressTrack.Visible = false
|
||||
lastDrop = nil
|
||||
sessionGain = 0
|
||||
lastLanding = -math.huge
|
||||
pulse.Scale = layoutScale
|
||||
flashEdge.Transparency = 1
|
||||
fit()
|
||||
paintBalance()
|
||||
end
|
||||
|
||||
gui:GetPropertyChangedSignal("AbsoluteSize"):Connect(fit)
|
||||
player:GetAttributeChangedSignal("InArena"):Connect(updateZone)
|
||||
player:GetAttributeChangedSignal("TrophyBalance"):Connect(function()
|
||||
if not inArena() then paintBalance() end
|
||||
end)
|
||||
player:GetAttributeChangedSignal("TrophyOriginBalance"):Connect(function()
|
||||
originBalance = (player:GetAttribute("TrophyOriginBalance") :: number?) or 0
|
||||
paintBalance()
|
||||
end)
|
||||
updateZone()
|
||||
|
||||
local function acknowledge(flight: Flight, now: number)
|
||||
lastLanding = now
|
||||
sessionShown += flight.amount
|
||||
paintBalance()
|
||||
if progressMotion then progressMotion:Cancel() end
|
||||
if not gain.Visible then sessionGain = 0 end
|
||||
if flight.id ~= lastDrop then progressFill.Size = UDim2.fromScale(0, 1) end
|
||||
lastDrop = flight.id
|
||||
sessionGain += flight.amount
|
||||
gainUntil = now + 1.8
|
||||
gain.Text = "+" .. sessionGain
|
||||
gain.Visible = true
|
||||
progressTrack.Visible = true
|
||||
pulse.Scale = layoutScale * (if flight.milestone then 1.15 else 1.055)
|
||||
TweenService:Create(pulse, TweenInfo.new(.22, Enum.EasingStyle.Quart), {Scale = layoutScale}):Play()
|
||||
flash.Size = UDim2.fromOffset(34, 34)
|
||||
flashEdge.Transparency = if flight.milestone then .06 else .28
|
||||
TweenService:Create(flash, TweenInfo.new(.24), {Size = UDim2.fromOffset(57, 57)}):Play()
|
||||
TweenService:Create(flashEdge, TweenInfo.new(.24), {Transparency = 1}):Play()
|
||||
progressMotion = TweenService:Create(progressFill, TweenInfo.new(.14), {Size = UDim2.fromScale(flight.progress, 1)})
|
||||
progressMotion:Play()
|
||||
end
|
||||
|
||||
local function worldOrigin(point: Vector3?): Vector2
|
||||
local camera = workspace.CurrentCamera
|
||||
local size = flightLayer.AbsoluteSize
|
||||
if point and camera and size.X > 0 and size.Y > 0 then
|
||||
local projected, visible = camera:WorldToScreenPoint(point)
|
||||
if visible and projected.Z > 0 then
|
||||
local offset = Vector2.new(projected.X, projected.Y) - flightLayer.AbsolutePosition
|
||||
return Vector2.new(math.clamp(offset.X / size.X, .03, .97), math.clamp(offset.Y / size.Y, .03, .97))
|
||||
end
|
||||
end
|
||||
return Vector2.new(.59, .67)
|
||||
end
|
||||
|
||||
type Arrival = {amount: number, milestone: boolean}
|
||||
local pickupArrived = Instance.new("BindableEvent")
|
||||
pickupArrived.Name = "PickupArrived"
|
||||
pickupArrived.Event:Connect(function(id: number, arrivals: {Arrival}, collected: number, total: number, point: Vector3?)
|
||||
if not inArena() or total <= 0 then return end
|
||||
local from = worldOrigin(point)
|
||||
local now = os.clock()
|
||||
for index, arrival in ipairs(arrivals) do
|
||||
local icon = coin:Clone()
|
||||
icon.Name = "FlyingCoin"
|
||||
icon.AnchorPoint = Vector2.new(.5, .5)
|
||||
icon.Visible = false
|
||||
icon.Parent = flightLayer
|
||||
local scale = Instance.new("UIScale", icon)
|
||||
local tail: {Frame} = {}
|
||||
for i = 1, 3 do
|
||||
local dot = frame("GoldenTrail", flightLayer, UDim2.fromOffset(11 - i * 2, 11 - i * 2), gold, 99)
|
||||
dot.AnchorPoint = Vector2.new(.5, .5)
|
||||
dot.BackgroundTransparency = .12 + i * .17
|
||||
dot.Visible = false
|
||||
table.insert(tail, dot)
|
||||
end
|
||||
local started = math.max(now, nextLaunch)
|
||||
nextLaunch = started + .032
|
||||
table.insert(flights, {
|
||||
icon = icon, rig = UI.bindCoin(icon), scale = scale, tail = tail, from = from, started = started, id = id,
|
||||
amount = arrival.amount, milestone = arrival.milestone,
|
||||
progress = math.clamp((collected - #arrivals + index) / total, 0, 1),
|
||||
})
|
||||
end
|
||||
end)
|
||||
pickupArrived.Parent = gui
|
||||
|
||||
local function curve(from: Vector2, to: Vector2, control: Vector2, t: number): Vector2
|
||||
return from:Lerp(control, t):Lerp(control:Lerp(to, t), t)
|
||||
end
|
||||
|
||||
local render = RunService.RenderStepped:Connect(function()
|
||||
local now = os.clock()
|
||||
local cycle = (now / 2.8) % 1
|
||||
local sweep = math.min(cycle * 3.8, 1)
|
||||
local sparkle = math.sin(sweep * math.pi) ^ 2
|
||||
local creditFlash = math.max(0, 1 - (now - lastLanding) / .22)
|
||||
UI.spinCoin(walletCoin, now * 2.24, math.max(sparkle, creditFlash), sweep)
|
||||
if gain.Visible and now >= gainUntil then
|
||||
gain.Visible = false
|
||||
progressTrack.Visible = false
|
||||
end
|
||||
if #flights == 0 then return end
|
||||
local layerSize = flightLayer.AbsoluteSize
|
||||
local destination = coin.AbsolutePosition + coin.AbsoluteSize / 2 - flightLayer.AbsolutePosition
|
||||
local i = 1
|
||||
while i <= #flights do
|
||||
local flight = flights[i]
|
||||
local u = (now - flight.started) / FLIGHT_TIME
|
||||
if u >= 1 then
|
||||
flight.icon:Destroy()
|
||||
for _, dot in flight.tail do dot:Destroy() end
|
||||
acknowledge(flight, now)
|
||||
table.remove(flights, i)
|
||||
continue
|
||||
elseif u >= 0 then
|
||||
local from = Vector2.new(flight.from.X * layerSize.X, flight.from.Y * layerSize.Y)
|
||||
local control = from:Lerp(destination, .53) - Vector2.new(0, math.min(86, layerSize.Y * .11))
|
||||
local t = u^1.45
|
||||
local pos = curve(from, destination, control, t)
|
||||
flight.icon.Position = UDim2.fromOffset(pos.X, pos.Y)
|
||||
flight.scale.Scale = .97 - .38 * t
|
||||
UI.spinCoin(flight.rig, math.pi / 2 + 7.5 * u, math.sin(u * math.pi) ^ 4, u)
|
||||
flight.icon.Visible = true
|
||||
for j, dot in flight.tail do
|
||||
local behind = t - j * .053
|
||||
dot.Visible = behind > 0
|
||||
if behind > 0 then
|
||||
local path = curve(from, destination, control, behind)
|
||||
dot.Position = UDim2.fromOffset(path.X, path.Y)
|
||||
end
|
||||
end
|
||||
end
|
||||
i += 1
|
||||
end
|
||||
end)
|
||||
|
||||
script.Destroying:Once(function() render:Disconnect() end)
|
||||
@@ -0,0 +1,267 @@
|
||||
--!strict
|
||||
local Debris = game:GetService("Debris")
|
||||
local Players = game:GetService("Players")
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local RunService = game:GetService("RunService")
|
||||
|
||||
local player = Players.LocalPlayer
|
||||
local remote = ReplicatedStorage:WaitForChild("TrophyDropFX") :: RemoteEvent
|
||||
local walletGui = player:WaitForChild("PlayerGui"):WaitForChild("TrophyBalance")
|
||||
local pickupArrived = walletGui:WaitForChild("PickupArrived") :: BindableEvent
|
||||
local effects = require(ReplicatedStorage:WaitForChild("SniperEffects"))
|
||||
local Magnet = require(ReplicatedStorage:WaitForChild("LootMagnet") :: ModuleScript)
|
||||
local airTime = remote:GetAttribute("AirTime") :: number
|
||||
local gold, rimGold, shine = Color3.fromRGB(251, 168, 33), Color3.fromRGB(219, 124, 22), Color3.fromRGB(255, 231, 126)
|
||||
|
||||
local folder = Instance.new("Folder")
|
||||
folder.Name = "LocalTrophyDrops"
|
||||
folder.Parent = workspace
|
||||
|
||||
type Coin = {
|
||||
model: Model, trail: Trail, coreTrail: Trail, valueLabel: TextLabel, glint: Frame, glintScale: UIScale,
|
||||
rest: Vector3, rotation: number, takeoff: Vector3?, launchAt: number?,
|
||||
}
|
||||
type Drop = {origin: Vector3, born: number, coins: {[number]: Coin}}
|
||||
local drops: {[number]: Drop} = {}
|
||||
|
||||
local function solid(parent: Model, name: string, size: Vector3, at: Vector3, color: Color3, round: boolean): Part
|
||||
local p = Instance.new("Part")
|
||||
p.Name = name
|
||||
p.Size = size
|
||||
p.Position = at
|
||||
p.Color = color
|
||||
p.Shape = if round then Enum.PartType.Cylinder else Enum.PartType.Block
|
||||
p.Material = Enum.Material.SmoothPlastic
|
||||
p.Anchored = true
|
||||
p.CanCollide = false
|
||||
p.CanQuery = false
|
||||
p.CanTouch = false
|
||||
p.CastShadow = false
|
||||
p.Parent = parent
|
||||
return p
|
||||
end
|
||||
|
||||
local function createCoin(rest: Vector3, index: number, amount: number): Coin
|
||||
local model = Instance.new("Model")
|
||||
model.Name = "TrophyCoin"
|
||||
local rim = solid(model, "GoldRim", Vector3.new(.22, 1.24, 1.24), Vector3.zero, rimGold, true)
|
||||
model.PrimaryPart = rim
|
||||
local bevel = solid(model, "CoinBevel", Vector3.new(.25, 1.16, 1.16), Vector3.zero, shine, true)
|
||||
bevel.Material = Enum.Material.Neon
|
||||
solid(model, "GoldFace", Vector3.new(.29, .97, .97), Vector3.zero, gold, true)
|
||||
for _, side in {-1, 1} do
|
||||
for _, z in {-.16, .16} do
|
||||
solid(model, "HunterStamp", Vector3.new(.035, .52, .105), Vector3.new(side * .159, 0, z), shine, false)
|
||||
end
|
||||
solid(model, "HunterStamp", Vector3.new(.035, .105, .26), Vector3.new(side * .159, 0, 0), shine, false)
|
||||
end
|
||||
local top = Instance.new("Attachment")
|
||||
top.Position = Vector3.new(0, .52, 0)
|
||||
top.Parent = rim
|
||||
local bottom = Instance.new("Attachment")
|
||||
bottom.Position = Vector3.new(0, -.52, 0)
|
||||
bottom.Parent = rim
|
||||
local trail = Instance.new("Trail")
|
||||
trail.Attachment0, trail.Attachment1 = top, bottom
|
||||
trail.Color = ColorSequence.new(shine, gold)
|
||||
trail.Transparency = NumberSequence.new(.19, 1)
|
||||
trail.WidthScale = NumberSequence.new(1, .04)
|
||||
trail.Lifetime = .22
|
||||
trail.LightEmission = 1
|
||||
trail.FaceCamera = true
|
||||
trail.Enabled = false
|
||||
trail.Parent = rim
|
||||
local coreTrail = trail:Clone()
|
||||
coreTrail.Name = "RibbonCore"
|
||||
coreTrail.Attachment0, coreTrail.Attachment1 = top, bottom
|
||||
coreTrail.Color = ColorSequence.new(Color3.fromRGB(255, 255, 228), shine)
|
||||
coreTrail.WidthScale = NumberSequence.new(.29, .03)
|
||||
coreTrail.Transparency = NumberSequence.new(.06, 1)
|
||||
coreTrail.Lifetime = .18
|
||||
coreTrail.Parent = rim
|
||||
|
||||
local badge = Instance.new("BillboardGui")
|
||||
badge.Name = "CoinBadge"
|
||||
badge.Size = UDim2.fromOffset(63, 58)
|
||||
badge.StudsOffsetWorldSpace = Vector3.new(0, 1.19, 0)
|
||||
badge.MaxDistance = 78
|
||||
badge.Parent = rim
|
||||
local valueLabel = Instance.new("TextLabel")
|
||||
valueLabel.Name = "Value"
|
||||
valueLabel.Size = UDim2.new(1, 0, 0, 23)
|
||||
valueLabel.Position = UDim2.fromOffset(0, 10)
|
||||
valueLabel.BackgroundTransparency = 1
|
||||
valueLabel.Font = Enum.Font.GothamBlack
|
||||
valueLabel.Text = tostring(amount)
|
||||
valueLabel.TextSize = 21
|
||||
valueLabel.TextColor3 = shine
|
||||
valueLabel.TextStrokeColor3 = Color3.fromRGB(38, 23, 11)
|
||||
valueLabel.TextStrokeTransparency = .08
|
||||
valueLabel.Parent = badge
|
||||
|
||||
local glint = Instance.new("Frame")
|
||||
glint.Name = "GoldGlint"
|
||||
glint.BackgroundTransparency = 1
|
||||
glint.Size = UDim2.fromOffset(28, 28)
|
||||
glint.AnchorPoint = Vector2.new(.5, .5)
|
||||
glint.Position = UDim2.fromScale(.65, .82)
|
||||
glint.Parent = badge
|
||||
local glintScale = Instance.new("UIScale", glint)
|
||||
for i = 0, 1 do
|
||||
local ray = Instance.new("Frame")
|
||||
ray.Name = "Ray"
|
||||
ray.AnchorPoint = Vector2.new(.5, .5)
|
||||
ray.Position = UDim2.fromScale(.5, .5)
|
||||
ray.Size = UDim2.fromOffset(3, 28 - i * 6)
|
||||
ray.Rotation = i * 90
|
||||
ray.BackgroundColor3 = Color3.fromRGB(255, 249, 187)
|
||||
ray.BorderSizePixel = 0
|
||||
ray.Parent = glint
|
||||
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 = ray
|
||||
end
|
||||
return {
|
||||
model = model, trail = trail, coreTrail = coreTrail, valueLabel = valueLabel, glint = glint, glintScale = glintScale,
|
||||
rest = rest, rotation = index * 1.37, takeoff = nil, launchAt = nil,
|
||||
}
|
||||
end
|
||||
|
||||
local function sparks(position: Vector3, count: number, fast: boolean)
|
||||
local emitterAnchor = Instance.new("Part")
|
||||
emitterAnchor.Name = "TrophySpark"
|
||||
emitterAnchor.Anchored = true
|
||||
emitterAnchor.Transparency = 1
|
||||
emitterAnchor.CanCollide, emitterAnchor.CanQuery, emitterAnchor.CanTouch = false, false, false
|
||||
emitterAnchor.Position = position
|
||||
emitterAnchor.Parent = folder
|
||||
local emitter = Instance.new("ParticleEmitter")
|
||||
emitter.Texture = "rbxasset://textures/particles/sparkles_main.dds"
|
||||
emitter.Color = ColorSequence.new(shine, gold)
|
||||
emitter.LightEmission = 1
|
||||
emitter.Brightness = 2.6
|
||||
emitter.Rate = 0
|
||||
emitter.Lifetime = NumberRange.new(.18, .39)
|
||||
emitter.Speed = if fast then NumberRange.new(2, 4) else NumberRange.new(5, 12)
|
||||
emitter.SpreadAngle = Vector2.new(175, 175)
|
||||
emitter.Size = NumberSequence.new(if fast then .20 else .43, 0)
|
||||
emitter.Acceleration = Vector3.new(0, -12, 0)
|
||||
emitter.Parent = emitterAnchor
|
||||
emitter:Emit(count)
|
||||
Debris:AddItem(emitterAnchor, .65)
|
||||
end
|
||||
|
||||
local function remove(id: number)
|
||||
local drop = drops[id]
|
||||
if not drop then return end
|
||||
drops[id] = nil
|
||||
for _, coin in drop.coins do coin.model:Destroy() end
|
||||
end
|
||||
|
||||
local function catchPoint(): Vector3?
|
||||
return Magnet.catchPoint(player.Character, workspace.CurrentCamera)
|
||||
end
|
||||
|
||||
local function updateCoin(coin: Coin, index: number, drop: Drop, age: number, now: number, target: Vector3?)
|
||||
if not coin.model.Parent then return end
|
||||
local rotation = coin.rotation
|
||||
local position: Vector3
|
||||
local launchAt = coin.launchAt
|
||||
local localTime = if launchAt then now - launchAt else -1
|
||||
if localTime >= 0 and target then
|
||||
local start = coin.takeoff or coin.model:GetPivot().Position
|
||||
coin.takeoff = start
|
||||
local progress
|
||||
position, progress = Magnet.curve(start, target, localTime, rotation)
|
||||
if progress >= 1 then
|
||||
coin.model.Parent = nil
|
||||
return
|
||||
end
|
||||
coin.trail.Enabled = true
|
||||
coin.coreTrail.Enabled = true
|
||||
coin.valueLabel.Visible = progress < .74
|
||||
if progress > .58 then coin.model:ScaleTo(1 - .72 * ((progress - .58) / .42)) end
|
||||
else
|
||||
local t = math.clamp(age / (airTime + index % 4 * .035), 0, 1)
|
||||
local spread = 1 - (1 - t)^1.5
|
||||
position = drop.origin:Lerp(coin.rest, spread) + Vector3.yAxis * ((3.4 + index % 5 * .44) * math.sin(t * math.pi))
|
||||
if t >= 1 then position += Vector3.yAxis * (.18 * math.sin(age * 4 + rotation)) end
|
||||
coin.trail.Enabled = t < .96
|
||||
coin.coreTrail.Enabled = t < .86
|
||||
end
|
||||
coin.glintScale.Scale = .24 + .84 * math.max(0, math.sin(age * 5.5 + rotation))^5
|
||||
coin.glint.Rotation = age * 34 + index * 13
|
||||
coin.model:PivotTo(CFrame.new(position) * CFrame.Angles(.14, rotation + age * 5.5, .12))
|
||||
end
|
||||
|
||||
remote.OnClientEvent:Connect(function(action: unknown, id: unknown, origin: unknown, positions: unknown, born: unknown, total: unknown)
|
||||
if typeof(id) ~= "number" then return end
|
||||
if action == "Drop" and typeof(origin) == "Vector3" and typeof(positions) == "table" and typeof(born) == "number" then
|
||||
local coins: {[number]: Coin} = {}
|
||||
for i, spec in positions do
|
||||
if typeof(i) ~= "number" or typeof(spec) ~= "table" or typeof(spec.position) ~= "Vector3" or typeof(spec.amount) ~= "number" then continue end
|
||||
local coin = createCoin(spec.position, i, spec.amount)
|
||||
coin.model:PivotTo(CFrame.new(origin))
|
||||
coin.model.Parent = folder
|
||||
coins[i] = coin
|
||||
end
|
||||
drops[id] = {origin = origin, born = born, coins = coins}
|
||||
sparks(origin, 36, false)
|
||||
elseif action == "Magnet" and typeof(origin) == "table" then
|
||||
local drop = drops[id]
|
||||
if not drop then return end
|
||||
for _, movement in origin do
|
||||
local coin = drop.coins[movement.index]
|
||||
if coin then coin.launchAt = movement.start end
|
||||
end
|
||||
elseif action == "Collected" and typeof(origin) == "table" then
|
||||
local drop = drops[id]
|
||||
local target = catchPoint()
|
||||
local milestone = false
|
||||
for _, arrival in origin do
|
||||
effects.sound("MoneyCollect1", nil, 1 + (arrival.index % 5) * .035)
|
||||
milestone = milestone or arrival.milestone == true
|
||||
local coin = drop and drop.coins[arrival.index]
|
||||
if drop and coin then
|
||||
coin.model:Destroy()
|
||||
drop.coins[arrival.index] = nil
|
||||
end
|
||||
end
|
||||
if milestone then effects.sound("CupidKnife") end
|
||||
if target then sparks(target, if milestone then 16 else 4, true) end
|
||||
if typeof(born) == "number" and typeof(total) == "number" then
|
||||
pickupArrived:Fire(id, origin, born, total, target)
|
||||
end
|
||||
if drop and next(drop.coins) == nil then drops[id] = nil end
|
||||
elseif action == "Remove" then
|
||||
remove(id)
|
||||
end
|
||||
end)
|
||||
|
||||
local render = RunService.RenderStepped:Connect(function()
|
||||
if next(drops) == nil then return end
|
||||
local now = workspace:GetServerTimeNow()
|
||||
local target = catchPoint()
|
||||
for id, drop in drops do
|
||||
local age = math.max(now - drop.born, 0)
|
||||
if age > 18 then
|
||||
remove(id)
|
||||
else
|
||||
for index, coin in drop.coins do
|
||||
updateCoin(coin, index, drop, age, now, target)
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
player:GetAttributeChangedSignal("InArena"):Connect(function()
|
||||
if player:GetAttribute("InArena") == true then return end
|
||||
for id in drops do remove(id) end
|
||||
end)
|
||||
script.Destroying:Once(function()
|
||||
render:Disconnect()
|
||||
folder:Destroy()
|
||||
end)
|
||||
@@ -0,0 +1,135 @@
|
||||
--!strict
|
||||
-- Each coin is awarded once, by the server. The remote only describes effects.
|
||||
local Players = game:GetService("Players")
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local RunService = game:GetService("RunService")
|
||||
|
||||
local TrophyWallet = require(script.Parent:WaitForChild("TrophyWallet"))
|
||||
local Magnet = require(ReplicatedStorage:WaitForChild("LootMagnet") :: ModuleScript)
|
||||
local Mobility = require(ReplicatedStorage:WaitForChild("ArenaMobility") :: ModuleScript)
|
||||
local Modes = require(ReplicatedStorage:WaitForChild("ArenaModes") :: ModuleScript)
|
||||
local round = ReplicatedStorage:WaitForChild("ArenaRound")
|
||||
|
||||
local MIN_COINS, MAX_COINS = 10, 20
|
||||
local MIN_VALUE, MAX_VALUE = 10, 15
|
||||
local AIR_TIME = .59
|
||||
local COIN_STAGGER = .065
|
||||
local LIFE = 16
|
||||
|
||||
local remote = Instance.new("RemoteEvent")
|
||||
remote.Name = "TrophyDropFX"
|
||||
remote:SetAttribute("AirTime", AIR_TIME)
|
||||
remote:SetAttribute("MagnetTime", Magnet.Duration)
|
||||
remote.Parent = ReplicatedStorage
|
||||
|
||||
type Coin = {position: Vector3, amount: number, launchAt: number?, collected: boolean}
|
||||
type Drop = {
|
||||
owner: Player, mode: string, center: Vector3, coins: {Coin}, readyAt: number, expiresAt: number,
|
||||
nextLaunch: number, collected: number, threshold: number,
|
||||
}
|
||||
local drops: {[number]: Drop} = {}
|
||||
local nextId = 0
|
||||
local random = Random.new()
|
||||
local function ground(at: Vector3, length: number, geometry: RaycastParams): Vector3?
|
||||
local hit = workspace:Raycast(at + Vector3.yAxis * 2, -Vector3.yAxis * length, geometry)
|
||||
return if hit then hit.Position + Vector3.yAxis * 1.12 else nil
|
||||
end
|
||||
|
||||
local TrophyDrops = {}
|
||||
function TrophyDrops.spawn(owner: Player, origin: Vector3)
|
||||
local now = workspace:GetServerTimeNow()
|
||||
local mode = Modes.of(owner)
|
||||
if owner.Parent ~= Players or not Modes.open(round, mode, now) then return end
|
||||
local geometry = Modes.collision(mode)
|
||||
local center = ground(origin, 180, geometry)
|
||||
if not center then return end
|
||||
|
||||
local count = random:NextInteger(MIN_COINS, MAX_COINS)
|
||||
local coins: {Coin} = {}
|
||||
local visual = {}
|
||||
local rotation = random:NextNumber(0, math.pi * 2)
|
||||
for i = 1, count do
|
||||
-- Spread across the whole patch; offset the arms so the value labels can breathe.
|
||||
local angle = rotation + i * 2.39996
|
||||
local dir = Vector3.new(math.cos(angle), 0, math.sin(angle))
|
||||
local distance = 1.5 + 8.6 * math.sqrt((i - .5) / count)
|
||||
local wall = workspace:Raycast(center, dir * distance, geometry)
|
||||
if wall then distance = math.max(0, wall.Distance - .65) end
|
||||
local position = ground(center + dir * distance, 9, geometry) or center
|
||||
local amount = random:NextInteger(MIN_VALUE, MAX_VALUE)
|
||||
coins[i] = {position = position, amount = amount, launchAt = nil, collected = false}
|
||||
visual[i] = {position = position, amount = amount}
|
||||
end
|
||||
nextId += 1
|
||||
drops[nextId] = {
|
||||
owner = owner, mode = mode, center = center, coins = coins, readyAt = now + AIR_TIME + .14, expiresAt = now + LIFE,
|
||||
nextLaunch = now, collected = 0, threshold = math.ceil(count * .8),
|
||||
}
|
||||
remote:FireClient(owner, "Drop", nextId, origin, visual, now)
|
||||
end
|
||||
|
||||
local function checkCoins(id: number, drop: Drop, now: number)
|
||||
local owner = drop.owner
|
||||
local geometry = Modes.collision(drop.mode)
|
||||
local character = owner.Character
|
||||
local humanoid = character and character:FindFirstChildOfClass("Humanoid")
|
||||
local root = character and character.PrimaryPart
|
||||
local position = if root and humanoid and humanoid.Health > 0 then root.Position else nil
|
||||
local radius = if Mobility.active(character, "Magnet", now) then 20 else Magnet.Radius
|
||||
local near = position and (drop.center - position).Magnitude <= radius + 11
|
||||
local motions = {}
|
||||
local arrivals = {}
|
||||
local total = 0
|
||||
for index, coin in drop.coins do
|
||||
if coin.collected then continue end
|
||||
local launchAt = coin.launchAt
|
||||
if launchAt then
|
||||
if now < launchAt + Magnet.Duration then continue end
|
||||
coin.collected = true
|
||||
drop.collected += 1
|
||||
local value = coin.amount
|
||||
local lucky = character and character:GetAttribute("LootLucky")
|
||||
if character and typeof(lucky) == "number" and lucky > 0 then
|
||||
value = math.round(value * 1.25)
|
||||
character:SetAttribute("LootLucky", lucky - 1)
|
||||
end
|
||||
total += value
|
||||
table.insert(arrivals, {index = index, amount = value, milestone = drop.collected == drop.threshold})
|
||||
elseif position and near then
|
||||
if Magnet.canReach(position, coin.position, radius, geometry) then
|
||||
local start = math.max(now + .06, drop.nextLaunch)
|
||||
coin.launchAt = start
|
||||
drop.nextLaunch = start + COIN_STAGGER
|
||||
table.insert(motions, {index = index, start = start})
|
||||
end
|
||||
end
|
||||
end
|
||||
if #motions > 0 then remote:FireClient(owner, "Magnet", id, motions) end
|
||||
if total > 0 then
|
||||
TrophyWallet.awardPickup(owner, total)
|
||||
remote:FireClient(owner, "Collected", id, arrivals, owner:GetAttribute("TrophyBalance"), drop.collected, #drop.coins)
|
||||
end
|
||||
if drop.collected == #drop.coins then drops[id] = nil end
|
||||
end
|
||||
|
||||
local elapsed = 0
|
||||
RunService.Heartbeat:Connect(function(dt)
|
||||
elapsed += dt
|
||||
if elapsed < .05 then return end
|
||||
elapsed %= .05
|
||||
if next(drops) == nil then return end
|
||||
local now = workspace:GetServerTimeNow()
|
||||
for id, drop in drops do
|
||||
local owner = drop.owner
|
||||
local connected = owner.Parent == Players
|
||||
if not connected or now >= drop.expiresAt or owner:GetAttribute("InArena") ~= true or Modes.of(owner) ~= drop.mode
|
||||
or not Modes.open(round, drop.mode, now) then
|
||||
drops[id] = nil
|
||||
if connected then remote:FireClient(owner, "Remove", id) end
|
||||
elseif now >= drop.readyAt then
|
||||
checkCoins(id, drop, now)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
return TrophyDrops
|
||||
@@ -0,0 +1,155 @@
|
||||
--!strict
|
||||
-- Server-only wallet. Studio uses session balances instead of writing to a live experience.
|
||||
local DataStoreService = game:GetService("DataStoreService")
|
||||
local HttpService = game:GetService("HttpService")
|
||||
local Players = game:GetService("Players")
|
||||
local RunService = game:GetService("RunService")
|
||||
|
||||
local store = if RunService:IsStudio() then nil else DataStoreService:GetDataStore("HunterTrophies_V1")
|
||||
local AUTOSAVE_SECONDS = 75
|
||||
local RECEIPT_SECONDS = 24 * 60 * 60
|
||||
|
||||
type Batch = {id: string, amount: number}
|
||||
type Wallet = {
|
||||
saved: number,
|
||||
pending: number,
|
||||
earned: number,
|
||||
batch: Batch?,
|
||||
loading: boolean,
|
||||
saving: boolean,
|
||||
active: boolean,
|
||||
}
|
||||
local wallets: {[Player]: Wallet} = {}
|
||||
local TrophyWallet = {}
|
||||
|
||||
local function savedBalance(value: unknown): number
|
||||
if typeof(value) == "table" then
|
||||
local balance = value.balance
|
||||
if typeof(balance) == "number" and balance >= 0 and balance < math.huge then return math.floor(balance) end
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
local function publish(player: Player, wallet: Wallet)
|
||||
if not wallet.active then return end
|
||||
local total = wallet.saved + wallet.pending + (if wallet.batch then wallet.batch.amount else 0)
|
||||
player:SetAttribute("TrophyBalance", total)
|
||||
-- Let the HUD refresh loaded savings independently of the coin animation.
|
||||
player:SetAttribute("TrophyOriginBalance", total - wallet.earned)
|
||||
end
|
||||
|
||||
local function open(player: Player)
|
||||
if wallets[player] then return end
|
||||
local wallet: Wallet = {saved = 0, pending = 0, earned = 0, batch = nil, loading = store ~= nil, saving = false, active = true}
|
||||
wallets[player] = wallet
|
||||
publish(player, wallet)
|
||||
local dataStore = store
|
||||
if not dataStore then return end
|
||||
task.spawn(function()
|
||||
for attempt = 1, 3 do
|
||||
local ok, data = pcall(function()
|
||||
return dataStore:GetAsync(tostring(player.UserId))
|
||||
end)
|
||||
if ok then
|
||||
wallet.saved = savedBalance(data)
|
||||
break
|
||||
end
|
||||
if attempt < 3 and wallet.active then task.wait(attempt) else break end
|
||||
end
|
||||
wallet.loading = false
|
||||
publish(player, wallet)
|
||||
end)
|
||||
end
|
||||
|
||||
local function flush(player: Player, wallet: Wallet): boolean
|
||||
local dataStore = store
|
||||
if not dataStore or wallet.loading or wallet.saving then return false end
|
||||
local batch = wallet.batch
|
||||
if not batch then
|
||||
if wallet.pending == 0 then return true end
|
||||
batch = {id = HttpService:GenerateGUID(false), amount = wallet.pending}
|
||||
wallet.batch = batch
|
||||
wallet.pending = 0
|
||||
end
|
||||
local receiptId, amount = batch.id, batch.amount
|
||||
local now = os.time()
|
||||
wallet.saving = true
|
||||
local ok, data = pcall(function()
|
||||
return dataStore:UpdateAsync(tostring(player.UserId), function(old)
|
||||
local balance = savedBalance(old)
|
||||
local receipts: {[string]: number} = {}
|
||||
if typeof(old) == "table" and typeof(old.receipts) == "table" then
|
||||
for id, timestamp in old.receipts do
|
||||
if typeof(id) == "string" and typeof(timestamp) == "number" and now - timestamp < RECEIPT_SECONDS then
|
||||
receipts[id] = timestamp
|
||||
end
|
||||
end
|
||||
end
|
||||
-- Reuse the same receipt if the request may have been committed before an error.
|
||||
if not receipts[receiptId] then
|
||||
balance += amount
|
||||
receipts[receiptId] = now
|
||||
end
|
||||
return {balance = balance, receipts = receipts}
|
||||
end)
|
||||
end)
|
||||
wallet.saving = false
|
||||
if not ok then return false end
|
||||
wallet.saved = savedBalance(data)
|
||||
wallet.batch = nil
|
||||
publish(player, wallet)
|
||||
return true
|
||||
end
|
||||
|
||||
local function drain(player: Player, wallet: Wallet)
|
||||
if not store then return end
|
||||
local deadline = os.clock() + 18
|
||||
while (wallet.batch or wallet.pending > 0) and os.clock() < deadline do
|
||||
if not flush(player, wallet) then task.wait(1) end
|
||||
end
|
||||
if wallet.batch or wallet.pending > 0 then
|
||||
warn("Could not finish saving Hunter Trophies for user " .. player.UserId)
|
||||
end
|
||||
end
|
||||
|
||||
function TrophyWallet.awardPickup(player: Player, amount: number)
|
||||
local wallet = wallets[player]
|
||||
if not wallet or not wallet.active then return end
|
||||
wallet.pending += amount
|
||||
wallet.earned += amount
|
||||
publish(player, wallet)
|
||||
end
|
||||
|
||||
Players.PlayerAdded:Connect(open)
|
||||
for _, player in Players:GetPlayers() do open(player) end
|
||||
Players.PlayerRemoving:Connect(function(player)
|
||||
local wallet = wallets[player]
|
||||
if not wallet then return end
|
||||
wallet.active = false
|
||||
drain(player, wallet)
|
||||
wallets[player] = nil
|
||||
end)
|
||||
|
||||
if store then
|
||||
task.spawn(function()
|
||||
while task.wait(AUTOSAVE_SECONDS) do
|
||||
for player, wallet in wallets do
|
||||
if wallet.active then task.spawn(flush, player, wallet) end
|
||||
end
|
||||
end
|
||||
end)
|
||||
game:BindToClose(function()
|
||||
local remaining = 0
|
||||
for player, wallet in wallets do
|
||||
remaining += 1
|
||||
task.spawn(function()
|
||||
drain(player, wallet)
|
||||
remaining -= 1
|
||||
end)
|
||||
end
|
||||
local deadline = os.clock() + 23
|
||||
while remaining > 0 and os.clock() < deadline do task.wait(.1) end
|
||||
end)
|
||||
end
|
||||
|
||||
return TrophyWallet
|
||||
@@ -0,0 +1,631 @@
|
||||
--!strict
|
||||
-- Viewmodel tuning mode (Studio playtests only). Press P to open the panel and adjust the weapon's
|
||||
-- position relative to the camera live: -/+ buttons (hold to repeat) or type a value.
|
||||
-- "Сохранить" hands the values to the ViewmodelTuneSaver Studio plugin, which writes them into the
|
||||
-- attributes of StarterPlayerScripts.SniperViewmodel once the playtest stops (also printed to Output).
|
||||
|
||||
local Players = game:GetService("Players")
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local RunService = game:GetService("RunService")
|
||||
local UserInputService = game:GetService("UserInputService")
|
||||
local HttpService = game:GetService("HttpService")
|
||||
|
||||
if not RunService:IsStudio() then
|
||||
return
|
||||
end
|
||||
|
||||
local UI = require(ReplicatedStorage:WaitForChild("HunterUI") :: ModuleScript)
|
||||
local TOGGLE_KEY = Enum.KeyCode.P
|
||||
local player = Players.LocalPlayer
|
||||
local target = player:WaitForChild("PlayerScripts"):WaitForChild("SniperViewmodel")
|
||||
local movementRemote = ReplicatedStorage:WaitForChild("MovementTune") :: RemoteEvent
|
||||
local movementRanges: {[string]: {min: number, max: number}} = {
|
||||
MovementWalkSpeed = {min = 1, max = 80},
|
||||
MovementGravity = {min = 40, max = 400},
|
||||
}
|
||||
|
||||
type Param = { name: string, label: string, unit: number }
|
||||
-- buttons: "Inspect" / "Reload" / "Shot" / "Aim" adds a row with "▶ Проиграть" and a hold toggle;
|
||||
-- sight: for "Aim" tabs, which sight the buttons put on the rifle and aim through
|
||||
-- group: tabs of one group share a single button in the tab bar; their pages get a selector row
|
||||
type Tab = { title: string, params: { Param }, buttons: string?, sight: string?, group: string? }
|
||||
local TABS: { Tab } = {
|
||||
{
|
||||
title = "Оружие",
|
||||
params = {
|
||||
{ name = "OffsetX", label = "Вправо / влево", unit = 1 },
|
||||
{ name = "OffsetY", label = "Вверх / вниз", unit = 1 },
|
||||
{ name = "OffsetZ", label = "Вперёд / назад", unit = 1 },
|
||||
{ name = "YawDeg", label = "Поворот (yaw)", unit = 20 },
|
||||
{ name = "PitchDeg", label = "Наклон (pitch)", unit = 20 },
|
||||
{ name = "RollDeg", label = "Крен (roll)", unit = 20 },
|
||||
{ name = "SwayAmount", label = "Инерция", unit = 4 },
|
||||
{ name = "BobAmount", label = "Покачивание", unit = 0.2 },
|
||||
},
|
||||
},
|
||||
}
|
||||
local function armTab(title: string, prefix: string): Tab
|
||||
return {
|
||||
title = title,
|
||||
params = {
|
||||
{ name = prefix .. "HandX", label = "Кисть: вправо/влево", unit = 1 },
|
||||
{ name = prefix .. "HandY", label = "Кисть: вверх/вниз", unit = 1 },
|
||||
{ name = prefix .. "HandZ", label = "Кисть: вперёд/назад", unit = 1 },
|
||||
{ name = prefix .. "ArmYawDeg", label = "Рука: поворот", unit = 20 },
|
||||
{ name = prefix .. "ArmPitchDeg", label = "Рука: наклон", unit = 20 },
|
||||
{ name = prefix .. "ArmRollDeg", label = "Рука: крен", unit = 20 },
|
||||
{ name = prefix .. "ArmLength", label = "Длина руки", unit = 2 },
|
||||
{ name = prefix .. "ArmThickness", label = "Толщина руки", unit = 0.2 },
|
||||
{ name = prefix .. "HandLength", label = "Длина кисти", unit = 0.5 },
|
||||
{ name = prefix .. "HandThickness", label = "Толщина кисти", unit = 0.2 },
|
||||
},
|
||||
}
|
||||
end
|
||||
table.insert(TABS, armTab("Левая рука", ""))
|
||||
table.insert(TABS, armTab("Правая рука", "R"))
|
||||
table.insert(TABS, {
|
||||
title = "Осмотр",
|
||||
buttons = "Inspect",
|
||||
params = {
|
||||
{ name = "InspX", label = "Вправо / влево", unit = 1 },
|
||||
{ name = "InspY", label = "Вверх / вниз", unit = 1 },
|
||||
{ name = "InspZ", label = "Вперёд / назад", unit = 1 },
|
||||
{ name = "InspYawDeg", label = "Поворот (yaw)", unit = 20 },
|
||||
{ name = "InspPitchDeg", label = "Наклон (pitch)", unit = 20 },
|
||||
{ name = "InspRollDeg", label = "Крен (roll)", unit = 20 },
|
||||
{ name = "InspDriftDeg", label = "Дрейф при удержании", unit = 20 },
|
||||
{ name = "InspBlendIn", label = "Выход в позу, с", unit = 2 },
|
||||
{ name = "InspHold", label = "Удержание, с", unit = 2 },
|
||||
{ name = "InspBlendOut", label = "Возврат, с", unit = 2 },
|
||||
},
|
||||
})
|
||||
table.insert(TABS, {
|
||||
title = "Перезарядка",
|
||||
buttons = "Reload",
|
||||
params = {
|
||||
{ name = "ReloadTime", label = "Длительность, с", unit = 2 },
|
||||
{ name = "ReloadPreviewU", label = "Кадр (0–1)", unit = 0.2 },
|
||||
{ name = "RlX", label = "Магазин: вправо/влево", unit = 1 },
|
||||
{ name = "RlY", label = "Магазин: вверх/вниз", unit = 1 },
|
||||
{ name = "RlZ", label = "Магазин: вперёд/назад", unit = 1 },
|
||||
{ name = "RlYawDeg", label = "Магазин: поворот", unit = 20 },
|
||||
{ name = "RlPitchDeg", label = "Магазин: наклон", unit = 20 },
|
||||
{ name = "RlRollDeg", label = "Магазин: крен", unit = 20 },
|
||||
},
|
||||
})
|
||||
-- weapon pose while the bolt is worked (pose B)
|
||||
table.insert(TABS, {
|
||||
title = "Перезарядка: затвор",
|
||||
buttons = "Reload",
|
||||
params = {
|
||||
{ name = "RlBX", label = "Затвор: вправо/влево", unit = 1 },
|
||||
{ name = "RlBY", label = "Затвор: вверх/вниз", unit = 1 },
|
||||
{ name = "RlBZ", label = "Затвор: вперёд/назад", unit = 1 },
|
||||
{ name = "RlBYawDeg", label = "Затвор: поворот", unit = 20 },
|
||||
{ name = "RlBPitchDeg", label = "Затвор: наклон", unit = 20 },
|
||||
{ name = "RlBRollDeg", label = "Затвор: крен", unit = 20 },
|
||||
{ name = "ReloadPreviewU", label = "Кадр (0–1)", unit = 0.2 },
|
||||
},
|
||||
})
|
||||
local function reloadHandParams(prefix: string): { Param }
|
||||
return {
|
||||
{ name = prefix .. "MagX", label = "Магазин: вправо/влево", unit = 1 },
|
||||
{ name = prefix .. "MagY", label = "Магазин: вверх/вниз", unit = 1 },
|
||||
{ name = prefix .. "MagZ", label = "Магазин: вперёд/назад", unit = 1 },
|
||||
{ name = prefix .. "MagDrop", label = "Магазин: вынуть вниз", unit = 1 },
|
||||
{ name = prefix .. "BoltX", label = "Затвор: вправо/влево", unit = 1 },
|
||||
{ name = prefix .. "BoltY", label = "Затвор: вверх/вниз", unit = 1 },
|
||||
{ name = prefix .. "BoltZ", label = "Затвор: вперёд/назад", unit = 1 },
|
||||
{ name = prefix .. "BoltLift", label = "Затвор: подъём", unit = 0.5 },
|
||||
{ name = prefix .. "BoltPull", label = "Затвор: ход назад", unit = 1 },
|
||||
}
|
||||
end
|
||||
local fpHands = reloadHandParams("")
|
||||
table.insert(fpHands, { name = "MagSizeX", label = "Магазин: толщина", unit = 0.2 })
|
||||
table.insert(fpHands, { name = "MagSizeY", label = "Магазин: высота", unit = 0.5 })
|
||||
table.insert(fpHands, { name = "MagSizeZ", label = "Магазин: ширина", unit = 0.5 })
|
||||
table.insert(TABS, { title = "Перезарядка: руки", buttons = "Reload", params = fpHands })
|
||||
|
||||
table.insert(TABS, {
|
||||
title = "Движение",
|
||||
params = {
|
||||
{ name = "MovementWalkSpeed", label = "Скорость игрока, студ/с", unit = 20 },
|
||||
{ name = "MovementGravity", label = "Гравитация, студ/с²", unit = 100 },
|
||||
{ name = "FovBase", label = "Обзор (FOV)", unit = 20 },
|
||||
{ name = "FovBoost", label = "Обзор: + на бегу", unit = 20 },
|
||||
{ name = "FovSpeed", label = "Скорость для макс. FOV", unit = 20 },
|
||||
{ name = "MoveDipY", label = "Оружие: вниз на бегу", unit = 1 },
|
||||
{ name = "MoveBack", label = "Оружие: назад на бегу", unit = 1 },
|
||||
{ name = "MoveRollDeg", label = "Оружие: крен на бегу", unit = 20 },
|
||||
{ name = "MoveLag", label = "Запаздывание", unit = 0.2 },
|
||||
{ name = "FallLag", label = "Оружие: прыжок / падение", unit = 0.2 },
|
||||
},
|
||||
})
|
||||
table.insert(TABS, {
|
||||
title = "Выстрел",
|
||||
buttons = "Shot",
|
||||
params = {
|
||||
{ name = "FireInterval", label = "Между выстрелами, с", unit = 2 },
|
||||
{ name = "MagCapacity", label = "Патронов в магазине", unit = 20 },
|
||||
{ name = "ShotZoomPct", label = "Зум при очереди, %", unit = 20 },
|
||||
{ name = "SpreadBase", label = "Спрей: начальный увод, °", unit = 4 },
|
||||
{ name = "SpreadPerShot", label = "Спрей: рост за выстрел, °", unit = 4 },
|
||||
{ name = "SpreadMax", label = "Спрей: предел роста, °", unit = 4 },
|
||||
{ name = "SpreadRecover", label = "Спрей: скорость сброса", unit = 20 },
|
||||
{ name = "SpreadAim", label = "Спрей в прицеле, ×", unit = 1 },
|
||||
{ name = "ShotBoltDelay", label = "Затвор: пауза, с", unit = 1 },
|
||||
{ name = "ShotBoltTime", label = "Затвор, с (0 = автомат)", unit = 1 },
|
||||
{ name = "ShotBoltTilt", label = "Затвор: наклон (0–1)", unit = 1 },
|
||||
{ name = "ShotPreviewT", label = "Кадр, с после выстрела", unit = 1 },
|
||||
},
|
||||
})
|
||||
table.insert(TABS, {
|
||||
title = "Выстрел: ствол",
|
||||
buttons = "Shot",
|
||||
params = {
|
||||
{ name = "MuzzleX", label = "Дуло: вправо/влево", unit = 1 },
|
||||
{ name = "MuzzleY", label = "Дуло: вверх/вниз", unit = 1 },
|
||||
{ name = "MuzzleZ", label = "Дуло: вперёд/назад", unit = 1 },
|
||||
{ name = "FlashSize", label = "Вспышка: размер", unit = 1 },
|
||||
{ name = "TPMuzzleX", label = "3л дуло: вправо/влево", unit = 1 },
|
||||
{ name = "TPMuzzleY", label = "3л дуло: вверх/вниз", unit = 1 },
|
||||
{ name = "TPMuzzleZ", label = "3л дуло: вперёд/назад", unit = 1 },
|
||||
{ name = "TPFlashSize", label = "3л вспышка: размер", unit = 1 },
|
||||
{ name = "TPRecoilBack", label = "3л отдача: назад", unit = 1 },
|
||||
{ name = "TPRecoilPitchDeg", label = "3л отдача: вверх", unit = 20 },
|
||||
},
|
||||
})
|
||||
|
||||
-- aiming down the sights: one tab "Прицеливание", a page per sight inside it (attributes Aim<Sight>...)
|
||||
for _, s in { { "Iron", "Мушка" }, { "RedDot", "Коллиматор" }, { "Scope", "Оптика" } } do
|
||||
local p = "Aim" .. s[1]
|
||||
table.insert(TABS, {
|
||||
title = s[2],
|
||||
group = "Прицел",
|
||||
buttons = "Aim",
|
||||
sight = s[1],
|
||||
params = {
|
||||
{ name = p .. "X", label = "Вправо / влево", unit = 1 },
|
||||
{ name = p .. "Y", label = "Вверх / вниз", unit = 1 },
|
||||
{ name = p .. "Z", label = "Вперёд / назад", unit = 1 },
|
||||
{ name = p .. "YawDeg", label = "Поворот (yaw)", unit = 20 },
|
||||
{ name = p .. "PitchDeg", label = "Наклон (pitch)", unit = 20 },
|
||||
{ name = p .. "RollDeg", label = "Крен (roll)", unit = 20 },
|
||||
{ name = p .. "Fov", label = "FOV / зум (меньше = ближе)", unit = 20 },
|
||||
{ name = p .. "Sens", label = "Чувствительность мыши", unit = 1 },
|
||||
{ name = "AimTime", label = "Время прицеливания, с", unit = 1 },
|
||||
{ name = "AimSway", label = "Покачивание в прицеле", unit = 1 },
|
||||
{ name = "AimSlow", label = "Замедление в прицеле (0–1)", unit = 1 },
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
-- mouse sensitivity: from the hip and through each sight (1 = the player's own setting)
|
||||
table.insert(TABS, {
|
||||
title = "Чувствительность",
|
||||
params = {
|
||||
{ name = "HipSens", label = "От бедра", unit = 1 },
|
||||
{ name = "AimIronSens", label = "Мушка", unit = 1 },
|
||||
{ name = "AimRedDotSens", label = "Коллиматор", unit = 1 },
|
||||
{ name = "AimScopeSens", label = "Оптика", unit = 1 },
|
||||
},
|
||||
})
|
||||
|
||||
-- sound volumes, the blast on hits, the damage numbers
|
||||
table.insert(TABS, {
|
||||
title = "Звук и попадания",
|
||||
params = {
|
||||
{ name = "VolMaster", label = "Громкость: общая", unit = 1 },
|
||||
{ name = "VolShot", label = "Громкость: выстрел", unit = 1 },
|
||||
{ name = "VolReload", label = "Громкость: перезарядка/затвор", unit = 1 },
|
||||
{ name = "VolHit", label = "Громкость: попадание", unit = 1 },
|
||||
{ name = "VolKill", label = "Громкость: разрушение", unit = 1 },
|
||||
{ name = "HitFxSize", label = "Размер взрыва при попадании", unit = 1 },
|
||||
{ name = "DmgNumSpread", label = "Цифры урона: разлёт в стороны", unit = 1 },
|
||||
{ name = "DmgNumRise", label = "Цифры урона: подъём вверх", unit = 1 },
|
||||
{ name = "KillPopRise", label = "Убийство: высота вылета", unit = 1 },
|
||||
},
|
||||
})
|
||||
|
||||
-- third person (what other players see): ThirdPersonRifle reads these
|
||||
local function poseParams(prefix: string, what: string): { Param }
|
||||
return {
|
||||
{ name = prefix .. "X", label = what .. ": вправо/влево", unit = 1 },
|
||||
{ name = prefix .. "Y", label = what .. ": вверх/вниз", unit = 1 },
|
||||
{ name = prefix .. "Z", label = what .. ": вперёд/назад", unit = 1 },
|
||||
{ name = prefix .. "YawDeg", label = what .. ": поворот", unit = 20 },
|
||||
{ name = prefix .. "PitchDeg", label = what .. ": наклон", unit = 20 },
|
||||
{ name = prefix .. "RollDeg", label = what .. ": крен", unit = 20 },
|
||||
}
|
||||
end
|
||||
table.insert(TABS, { title = "3л: оружие", params = poseParams("TPGun", "Оружие") })
|
||||
for _, side in { { "R", "3л: правая рука" }, { "L", "3л: левая рука" } } do
|
||||
local params = poseParams("TP" .. side[1] .. "Hand", "Кисть")
|
||||
table.insert(params, { name = "TP" .. side[1] .. "ElbowX", label = "Локоть: вправо/влево", unit = 1 })
|
||||
table.insert(params, { name = "TP" .. side[1] .. "ElbowY", label = "Локоть: вверх/вниз", unit = 1 })
|
||||
table.insert(params, { name = "TP" .. side[1] .. "ElbowZ", label = "Локоть: вперёд/назад", unit = 1 })
|
||||
table.insert(TABS, { title = side[2], params = params })
|
||||
end
|
||||
table.insert(TABS, { title = "3л: перезарядка", buttons = "Reload", params = reloadHandParams("TP") })
|
||||
local TABS_PER_ROW = 4
|
||||
local PARAMS: { Param } = {}
|
||||
local maxRows = 0
|
||||
local barCount = 0 -- buttons in the tab bar: one per tab, one per group
|
||||
local seenGroups: { [string]: boolean } = {}
|
||||
for _, tab in TABS do
|
||||
for _, p in tab.params do
|
||||
table.insert(PARAMS, p)
|
||||
end
|
||||
maxRows = math.max(maxRows, #tab.params + (if tab.buttons then 1 else 0) + (if tab.group then 1 else 0))
|
||||
local group = tab.group
|
||||
if not group or not seenGroups[group] then
|
||||
barCount += 1
|
||||
end
|
||||
if group then
|
||||
seenGroups[group] = true
|
||||
end
|
||||
end
|
||||
local STEPS = { 0.01, 0.05, 0.2 }
|
||||
local stepIndex = 2
|
||||
|
||||
-- the viewmodel script creates its attributes on start; wait so "Сброс" has real values
|
||||
local function missing(): boolean
|
||||
for _, p in PARAMS do
|
||||
if target:GetAttribute(p.name) == nil then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
local waited = 0
|
||||
while missing() and waited < 10 do
|
||||
waited += task.wait(0.1)
|
||||
end
|
||||
|
||||
local initial: { [string]: number } = {}
|
||||
for _, p in PARAMS do
|
||||
initial[p.name] = (target:GetAttribute(p.name) :: number?) or 0
|
||||
end
|
||||
|
||||
local function round(v: number): number
|
||||
return math.floor(v * 1000 + 0.5) / 1000
|
||||
end
|
||||
|
||||
-- ---------------------------------------------------------------- UI
|
||||
local gui = Instance.new("ScreenGui")
|
||||
gui.Name = "ViewmodelTuner"
|
||||
gui.ResetOnSpawn = false
|
||||
gui.DisplayOrder = 50
|
||||
gui.Enabled = false
|
||||
gui.Parent = player:WaitForChild("PlayerGui")
|
||||
|
||||
local panel = Instance.new("Frame")
|
||||
local ROWS_TOP = 34 + math.ceil(barCount / TABS_PER_ROW) * 30 -- title + tab bar
|
||||
panel.Size = UDim2.fromOffset(330, ROWS_TOP + maxRows * 34 + 46)
|
||||
panel.Position = UDim2.new(0, 16, 0.5, 0)
|
||||
panel.AnchorPoint = Vector2.new(0, 0.5)
|
||||
panel.BackgroundColor3 = Color3.fromRGB(20, 22, 28)
|
||||
panel.BackgroundTransparency = 0.15
|
||||
panel.Parent = gui
|
||||
Instance.new("UICorner", panel).CornerRadius = UDim.new(0, 8)
|
||||
|
||||
local function label(parent: Instance, text: string, pos: UDim2, size: UDim2, align: Enum.TextXAlignment?): TextLabel
|
||||
local l = Instance.new("TextLabel")
|
||||
l.BackgroundTransparency = 1
|
||||
l.Text = text
|
||||
l.Font = Enum.Font.GothamMedium
|
||||
l.TextScaled = true -- long labels shrink instead of running under the buttons
|
||||
local limit = Instance.new("UITextSizeConstraint")
|
||||
limit.MaxTextSize = 14
|
||||
limit.Parent = l
|
||||
l.TextColor3 = Color3.fromRGB(230, 232, 238)
|
||||
l.TextXAlignment = align or Enum.TextXAlignment.Left
|
||||
l.Position = pos
|
||||
l.Size = size
|
||||
l.Parent = parent
|
||||
return l
|
||||
end
|
||||
|
||||
local function button(parent: Instance, text: string, pos: UDim2, size: UDim2): TextButton
|
||||
local b = Instance.new("TextButton")
|
||||
b.Text = text
|
||||
b.Font = Enum.Font.GothamBold
|
||||
b.TextSize = 14
|
||||
b.TextColor3 = Color3.new(1, 1, 1)
|
||||
b.BackgroundColor3 = Color3.fromRGB(55, 60, 75)
|
||||
b.Position = pos
|
||||
b.Size = size
|
||||
b.Parent = parent
|
||||
Instance.new("UICorner", b).CornerRadius = UDim.new(0, 5)
|
||||
UI.bindButton(b, UI.Blue, true)
|
||||
return b
|
||||
end
|
||||
|
||||
label(panel, "Настройка (P — закрыть)", UDim2.fromOffset(12, 6), UDim2.new(1, -124, 0, 22))
|
||||
|
||||
-- switches the local camera between first person and a third-person view of the character
|
||||
local viewButton = button(panel, "", UDim2.fromOffset(214, 5), UDim2.fromOffset(96, 22))
|
||||
viewButton.TextSize = 12
|
||||
local function refreshView()
|
||||
local on = target:GetAttribute("ThirdPersonView") == true
|
||||
viewButton.Text = if on then "Вид: 3-е лицо" else "Вид: 1-е лицо"
|
||||
viewButton.BackgroundColor3 = if on then Color3.fromRGB(70, 110, 190) else Color3.fromRGB(55, 60, 75)
|
||||
end
|
||||
viewButton.MouseButton1Click:Connect(function()
|
||||
target:SetAttribute("ThirdPersonView", not (target:GetAttribute("ThirdPersonView") == true))
|
||||
end)
|
||||
target:GetAttributeChangedSignal("ThirdPersonView"):Connect(refreshView)
|
||||
refreshView()
|
||||
|
||||
-- Modal button keeps the mouse free while the panel is open in first person.
|
||||
local modal = Instance.new("TextButton")
|
||||
modal.Modal = true
|
||||
modal.BackgroundTransparency = 1
|
||||
modal.Text = ""
|
||||
modal.Size = UDim2.fromOffset(0, 0)
|
||||
modal.Parent = panel
|
||||
|
||||
local boxes: { [string]: { TextBox } } = {} -- a value may sit on several tabs
|
||||
|
||||
local function setValue(name: string, v: number)
|
||||
if v ~= v or math.abs(v) == math.huge then
|
||||
v = (target:GetAttribute(name) :: number?) or initial[name]
|
||||
end
|
||||
local range = movementRanges[name]
|
||||
if range then
|
||||
v = math.clamp(v, range.min, range.max)
|
||||
end
|
||||
v = round(v)
|
||||
if target:GetAttribute(name) ~= v then
|
||||
target:SetAttribute(name, v)
|
||||
if range then
|
||||
movementRemote:FireServer(name, v)
|
||||
end
|
||||
end
|
||||
for _, box in boxes[name] or {} do
|
||||
if not box:IsFocused() then
|
||||
box.Text = tostring(v)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function nudge(p: Param, dir: number)
|
||||
local v = (target:GetAttribute(p.name) :: number?) or 0
|
||||
setValue(p.name, v + dir * STEPS[stepIndex] * p.unit)
|
||||
end
|
||||
|
||||
local function holdRepeat(b: TextButton, fn: () -> ())
|
||||
local holding = false
|
||||
b.MouseButton1Down:Connect(function()
|
||||
holding = true
|
||||
fn()
|
||||
task.delay(0.35, function()
|
||||
while holding do
|
||||
fn()
|
||||
task.wait(0.05)
|
||||
end
|
||||
end)
|
||||
end)
|
||||
b.MouseButton1Up:Connect(function()
|
||||
holding = false
|
||||
end)
|
||||
b.MouseLeave:Connect(function()
|
||||
holding = false
|
||||
end)
|
||||
end
|
||||
|
||||
-- tabs: a button bar plus one page of rows per tab
|
||||
local ON_COLOR = Color3.fromRGB(70, 110, 190)
|
||||
local OFF_COLOR = Color3.fromRGB(55, 60, 75)
|
||||
local pages: { Frame } = {}
|
||||
local tabButtons: { TextButton } = {} -- by tab index; the tabs of a group share their group's button
|
||||
local subButtons: { { index: number, button: TextButton } } = {} -- selector rows inside groups
|
||||
local groupChoice: { [string]: number } = {} -- last page opened in each group
|
||||
local function selectTab(index: number)
|
||||
local group = TABS[index].group
|
||||
if group then
|
||||
groupChoice[group] = index
|
||||
end
|
||||
for i, page in pages do
|
||||
page.Visible = i == index
|
||||
local on = i == index or (group ~= nil and TABS[i].group == group)
|
||||
tabButtons[i].BackgroundColor3 = if on then ON_COLOR else OFF_COLOR
|
||||
end
|
||||
for _, sub in subButtons do
|
||||
sub.button.BackgroundColor3 = if sub.index == index then ON_COLOR else OFF_COLOR
|
||||
end
|
||||
-- holding the aim while switching sight pages: aim through the newly chosen sight
|
||||
local sight = TABS[index].sight
|
||||
if sight and target:GetAttribute("AimPreview") == true then
|
||||
target:SetAttribute("AimPreviewSight", sight)
|
||||
end
|
||||
end
|
||||
|
||||
local function addRow(page: Frame, p: Param, y: number)
|
||||
label(page, p.label, UDim2.fromOffset(12, y + 4), UDim2.fromOffset(136, 22))
|
||||
local minus = button(page, "−", UDim2.fromOffset(150, y), UDim2.fromOffset(30, 28))
|
||||
local box = Instance.new("TextBox")
|
||||
box.Font = Enum.Font.Code
|
||||
box.TextSize = 14
|
||||
box.TextColor3 = Color3.new(1, 1, 1)
|
||||
box.BackgroundColor3 = Color3.fromRGB(35, 38, 48)
|
||||
box.ClearTextOnFocus = false
|
||||
box.Position = UDim2.fromOffset(184, y)
|
||||
box.Size = UDim2.fromOffset(92, 28)
|
||||
box.Text = tostring(round((target:GetAttribute(p.name) :: number?) or 0))
|
||||
box.Parent = page
|
||||
Instance.new("UICorner", box).CornerRadius = UDim.new(0, 5)
|
||||
boxes[p.name] = boxes[p.name] or {}
|
||||
table.insert(boxes[p.name], box)
|
||||
local plus = button(page, "+", UDim2.fromOffset(280, y), UDim2.fromOffset(30, 28))
|
||||
holdRepeat(minus, function()
|
||||
nudge(p, -1)
|
||||
end)
|
||||
holdRepeat(plus, function()
|
||||
nudge(p, 1)
|
||||
end)
|
||||
box.FocusLost:Connect(function()
|
||||
local v = tonumber((box.Text:gsub(",", ".")))
|
||||
if v then
|
||||
setValue(p.name, v)
|
||||
else
|
||||
box.Text = tostring(round((target:GetAttribute(p.name) :: number?) or 0))
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
local tabWidth = math.floor((306 - (TABS_PER_ROW - 1) * 4) / TABS_PER_ROW)
|
||||
local barIndex = 0
|
||||
local groupButtons: { [string]: TextButton } = {}
|
||||
for i, tab in TABS do
|
||||
local group = tab.group
|
||||
local b: TextButton? = if group then groupButtons[group] else nil
|
||||
if not b then
|
||||
local col, row = barIndex % TABS_PER_ROW, barIndex // TABS_PER_ROW
|
||||
barIndex += 1
|
||||
local nb = button(panel, group or tab.title, UDim2.fromOffset(12 + col * (tabWidth + 4), 30 + row * 30), UDim2.fromOffset(tabWidth, 26))
|
||||
nb.TextScaled = true -- four tabs: long titles shrink to fit
|
||||
local fit = Instance.new("UITextSizeConstraint")
|
||||
fit.MaxTextSize = 13
|
||||
fit.Parent = nb
|
||||
local pad = Instance.new("UIPadding")
|
||||
pad.PaddingLeft = UDim.new(0, 3)
|
||||
pad.PaddingRight = UDim.new(0, 3)
|
||||
pad.Parent = nb
|
||||
nb.MouseButton1Click:Connect(function()
|
||||
selectTab(if group then groupChoice[group] or i else i)
|
||||
end)
|
||||
if group then
|
||||
groupButtons[group] = nb
|
||||
end
|
||||
b = nb
|
||||
end
|
||||
tabButtons[i] = b :: TextButton
|
||||
local page = Instance.new("Frame")
|
||||
page.Name = tab.title
|
||||
page.BackgroundTransparency = 1
|
||||
page.Position = UDim2.fromOffset(0, ROWS_TOP)
|
||||
page.Size = UDim2.new(1, 0, 0, maxRows * 34)
|
||||
page.Parent = panel
|
||||
pages[i] = page
|
||||
local top = 0
|
||||
if group then
|
||||
-- selector row: one button per page of the group
|
||||
local members = {}
|
||||
for j, t in TABS do
|
||||
if t.group == group then
|
||||
table.insert(members, j)
|
||||
end
|
||||
end
|
||||
local w = math.floor((298 - (#members - 1) * 4) / #members)
|
||||
for k, j in members do
|
||||
local sb = button(page, TABS[j].title, UDim2.fromOffset(12 + (k - 1) * (w + 4), 0), UDim2.fromOffset(w, 28))
|
||||
sb.TextSize = 13
|
||||
sb.MouseButton1Click:Connect(function()
|
||||
selectTab(j)
|
||||
end)
|
||||
table.insert(subButtons, { index = j, button = sb })
|
||||
end
|
||||
top = 34
|
||||
end
|
||||
for r, p in tab.params do
|
||||
addRow(page, p, top + (r - 1) * 34)
|
||||
end
|
||||
if tab.title == "Движение" then
|
||||
label(page, "Меньше гравитация — выше прыжок", UDim2.fromOffset(12, top + #tab.params * 34), UDim2.fromOffset(298, 24))
|
||||
end
|
||||
local kind = tab.buttons
|
||||
if kind then
|
||||
-- InspectPreview/InspectTrigger or ReloadPreview/ReloadTrigger on SniperViewmodel
|
||||
local previewAttr, triggerAttr = kind .. "Preview", kind .. "Trigger"
|
||||
local y = top + #tab.params * 34
|
||||
local sight = tab.sight
|
||||
local play = button(page, if kind == "Aim" then "▶ Прицелиться" else "▶ Проиграть", UDim2.fromOffset(12, y), UDim2.fromOffset(145, 28))
|
||||
play.MouseButton1Click:Connect(function()
|
||||
if sight then
|
||||
target:SetAttribute("AimPreviewSight", sight) -- SniperViewmodel puts this sight on the rifle
|
||||
end
|
||||
target:SetAttribute(previewAttr, false)
|
||||
target:SetAttribute(triggerAttr, os.clock())
|
||||
end)
|
||||
local holdText = if kind == "Inspect" then "Держать позу" elseif kind == "Aim" then "Держать прицел" else "Держать кадр"
|
||||
local holdPose = button(page, holdText, UDim2.fromOffset(165, y), UDim2.fromOffset(145, 28))
|
||||
local function refreshHold()
|
||||
local on = target:GetAttribute(previewAttr) == true
|
||||
and (not sight or target:GetAttribute("AimPreviewSight") == sight)
|
||||
holdPose.BackgroundColor3 = if on then ON_COLOR else OFF_COLOR
|
||||
end
|
||||
holdPose.MouseButton1Click:Connect(function()
|
||||
if sight and target:GetAttribute("AimPreviewSight") ~= sight then
|
||||
-- another sight's tab was holding: switch the held sight, stay aimed
|
||||
target:SetAttribute("AimPreviewSight", sight)
|
||||
target:SetAttribute(previewAttr, true)
|
||||
return
|
||||
end
|
||||
target:SetAttribute(previewAttr, not (target:GetAttribute(previewAttr) == true))
|
||||
end)
|
||||
target:GetAttributeChangedSignal(previewAttr):Connect(refreshHold) -- several tabs share it
|
||||
target:GetAttributeChangedSignal("AimPreviewSight"):Connect(refreshHold)
|
||||
refreshHold()
|
||||
end
|
||||
end
|
||||
selectTab(1)
|
||||
|
||||
local bottom = ROWS_TOP + maxRows * 34 + 6
|
||||
local stepButton = button(panel, "", UDim2.fromOffset(12, bottom), UDim2.fromOffset(96, 30))
|
||||
local function refreshStep()
|
||||
stepButton.Text = "Шаг: " .. tostring(STEPS[stepIndex])
|
||||
end
|
||||
refreshStep()
|
||||
stepButton.MouseButton1Click:Connect(function()
|
||||
stepIndex = stepIndex % #STEPS + 1
|
||||
refreshStep()
|
||||
end)
|
||||
|
||||
local reset = button(panel, "Сброс", UDim2.fromOffset(114, bottom), UDim2.fromOffset(80, 30))
|
||||
reset.MouseButton1Click:Connect(function()
|
||||
for _, p in PARAMS do
|
||||
setValue(p.name, initial[p.name])
|
||||
end
|
||||
end)
|
||||
|
||||
local save = button(panel, "Сохранить", UDim2.fromOffset(200, bottom), UDim2.fromOffset(110, 30))
|
||||
save.BackgroundColor3 = Color3.fromRGB(40, 140, 80)
|
||||
save.MouseButton1Click:Connect(function()
|
||||
local values = {}
|
||||
for _, p in PARAMS do
|
||||
values[p.name] = target:GetAttribute(p.name)
|
||||
end
|
||||
local json = HttpService:JSONEncode(values)
|
||||
print("VIEWMODEL_TUNE " .. json)
|
||||
-- picked up by the ViewmodelTuneSaver Studio plugin and written into the place after the playtest
|
||||
target:SetAttribute("SavedTune", HttpService:JSONEncode({ t = DateTime.now().UnixTimestampMillis, values = values }))
|
||||
save.Text = "Сохранено ✓"
|
||||
task.delay(1.5, function()
|
||||
save.Text = "Сохранить"
|
||||
end)
|
||||
end)
|
||||
|
||||
local function toggle()
|
||||
gui.Enabled = not gui.Enabled
|
||||
if not gui.Enabled then
|
||||
target:SetAttribute("InspectPreview", false) -- never leave the weapon frozen in the inspect pose
|
||||
target:SetAttribute("ReloadPreview", false)
|
||||
target:SetAttribute("ShotPreview", false)
|
||||
target:SetAttribute("AimPreview", false)
|
||||
target:SetAttribute("ThirdPersonView", false) -- back to the game's first-person camera
|
||||
end
|
||||
if gui.Enabled then
|
||||
for name, list in boxes do
|
||||
for _, box in list do
|
||||
box.Text = tostring(round((target:GetAttribute(name) :: number?) or 0))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
UserInputService.InputBegan:Connect(function(input, processed)
|
||||
if input.KeyCode == TOGGLE_KEY and not UserInputService:GetFocusedTextBox() then
|
||||
toggle()
|
||||
end
|
||||
end)
|
||||
@@ -0,0 +1,187 @@
|
||||
--!strict
|
||||
-- Run in the Studio Edit command bar before installing ProceduralArena.
|
||||
local MaterialService = game:GetService("MaterialService")
|
||||
local RunService = game:GetService("RunService")
|
||||
local ServerStorage = game:GetService("ServerStorage")
|
||||
|
||||
assert(RunService:IsStudio() and not RunService:IsRunning(), "BuildProceduralKit requires Studio Edit mode")
|
||||
|
||||
local source = ServerStorage:FindFirstChild("HunterMonolithImport") or workspace:FindFirstChild("HunterMonolithImport")
|
||||
assert(source and source:IsA("Model"), "HunterMonolithImport is missing")
|
||||
|
||||
local kitName = "ProceduralArenaKit"
|
||||
local existingKit = ServerStorage:FindFirstChild(kitName)
|
||||
if existingKit then
|
||||
local version = existingKit:GetAttribute("Version")
|
||||
assert(existingKit:IsA("Folder") and typeof(version) == "number" and version >= 1 and version <= 6,
|
||||
"ServerStorage.ProceduralArenaKit is occupied by an unrecognized instance")
|
||||
end
|
||||
|
||||
local arena = workspace:FindFirstChild("ProceduralArena")
|
||||
assert(not arena or arena:IsA("Model"), "Workspace.ProceduralArena must be a Model")
|
||||
local spawns = if arena then arena:FindFirstChild("PlayerSpawns") else nil
|
||||
assert(not spawns or spawns:IsA("Folder"), "ProceduralArena.PlayerSpawns must be a Folder")
|
||||
|
||||
local assetNames = {
|
||||
A0040 = "Foundation",
|
||||
A0083 = "Boundary",
|
||||
A0085 = "Ramp",
|
||||
A0084 = "Terrace",
|
||||
A0002 = "CitadelRamp",
|
||||
A0039 = "DeckPanel",
|
||||
A0071 = "LowCover",
|
||||
A0075 = "TallCover",
|
||||
A0079 = "SquareCover",
|
||||
A0090 = "Crate",
|
||||
A0025 = "Screen",
|
||||
A0023 = "Wall",
|
||||
A0005 = "Parapet",
|
||||
}
|
||||
local assets: {[string]: MeshPart} = {}
|
||||
for _, child in source:GetDescendants() do
|
||||
if child:IsA("MeshPart") then
|
||||
local id = child.Name:match("^([AL]%d%d%d%d)_")
|
||||
if id and (assetNames[id] or id == "A0105") then
|
||||
assert(not assets[id], "Duplicate source mesh " .. id)
|
||||
assets[id] = child
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for id in assetNames do
|
||||
local asset = assets[id]
|
||||
assert(asset and asset.Archivable and asset.MeshId ~= "", "Missing or unclonable source mesh " .. id)
|
||||
assert(asset.CollisionFidelity == Enum.CollisionFidelity.Hull, "Expected solid hull for " .. id)
|
||||
end
|
||||
|
||||
local kit = Instance.new("Folder")
|
||||
kit.Name = kitName
|
||||
kit:SetAttribute("Version", 6)
|
||||
|
||||
-- The source floor spans 896 Blender studs with one texture repeat every 32 studs (four cells).
|
||||
local textureRepeat = assets.A0040.Size.X / (896 / 32)
|
||||
local cell = textureRepeat / 4
|
||||
kit:SetAttribute("GridCell", cell)
|
||||
local materialNames: {[string]: string} = {}
|
||||
for _, spec in {
|
||||
{name = "HunterArenaGridFloor", source = assets.A0040},
|
||||
{name = "HunterArenaGridNavy", source = assets.A0023},
|
||||
{name = "HunterArenaGridAmber", source = assets.A0002},
|
||||
} do
|
||||
local image = spec.source.TextureID
|
||||
assert(image ~= "" and not materialNames[image], "Missing or duplicate source grid image: " .. spec.name)
|
||||
local existing = MaterialService:FindFirstChild(spec.name)
|
||||
assert(not existing or existing:IsA("MaterialVariant"), "Grid material name is occupied: " .. spec.name)
|
||||
local material = existing :: MaterialVariant? or Instance.new("MaterialVariant")
|
||||
material.Name = spec.name
|
||||
material.BaseMaterial = Enum.Material.Plastic
|
||||
material.ColorMap = image
|
||||
material.MaterialPattern = Enum.MaterialPattern.Regular
|
||||
material.StudsPerTile = textureRepeat
|
||||
material.Parent = MaterialService
|
||||
materialNames[image] = spec.name
|
||||
end
|
||||
|
||||
local function box(size: Vector3, color: Color3, variant: string): Part
|
||||
local part = Instance.new("Part")
|
||||
part.Size, part.Color = size, color
|
||||
part.Material, part.MaterialVariant = Enum.Material.Plastic, variant
|
||||
part.TopSurface, part.BottomSurface = Enum.SurfaceType.Smooth, Enum.SurfaceType.Smooth
|
||||
part.Anchored, part.CanCollide, part.CanQuery, part.CanTouch = true, true, true, false
|
||||
return part
|
||||
end
|
||||
|
||||
local function strip(part: BasePart)
|
||||
-- Keep mesh appearance, without copying scene attachments, lights, tags, or behavior.
|
||||
for _, child in part:GetChildren() do
|
||||
if not child:IsA("SurfaceAppearance") and not child:IsA("Texture") and not child:IsA("Decal") then
|
||||
child:Destroy()
|
||||
end
|
||||
end
|
||||
for _, tag in part:GetTags() do
|
||||
part:RemoveTag(tag)
|
||||
end
|
||||
for key in part:GetAttributes() do
|
||||
part:SetAttribute(key, nil)
|
||||
end
|
||||
part.PivotOffset = CFrame.identity
|
||||
part.Anchored = true
|
||||
part.CanTouch = false
|
||||
part.CollisionGroup = "Default"
|
||||
end
|
||||
|
||||
for id, name in assetNames do
|
||||
local asset = assets[id]
|
||||
local material = materialNames[asset.TextureID]
|
||||
assert(material, "Unexpected arena texture on " .. asset.Name)
|
||||
local part: BasePart
|
||||
if name == "Ramp" or name == "CitadelRamp" then
|
||||
local slope = asset:Clone()
|
||||
strip(slope)
|
||||
slope.TextureID = ""
|
||||
slope.Material = Enum.Material.Plastic
|
||||
slope.MaterialVariant = materialNames[assets.A0002.TextureID]
|
||||
slope.CanCollide, slope.CanQuery = true, true
|
||||
part = slope
|
||||
else
|
||||
-- Box materials start at the face edge on native parts. Imported meshes can start half a cell in.
|
||||
part = box(asset.Size, asset.Color, material)
|
||||
end
|
||||
part.Name = name
|
||||
part:SetAttribute("SourceMesh", id)
|
||||
part.CFrame = CFrame.identity
|
||||
part.Parent = kit
|
||||
end
|
||||
|
||||
local gateAsset = assets.A0105
|
||||
assert(gateAsset and gateAsset.Archivable, "Missing flank gate mesh")
|
||||
local proxies = source:WaitForChild("HunterImportSetup"):WaitForChild("PassageCollisions")
|
||||
local lintel: BasePart? = nil
|
||||
for _, body in proxies:GetChildren() do
|
||||
if body:IsA("BasePart") and body.Name == "A0105_Collision" and math.abs(body.Position.X - gateAsset.Position.X) < .1 then
|
||||
lintel = body
|
||||
break
|
||||
end
|
||||
end
|
||||
assert(lintel, "Missing flank gate opening")
|
||||
local function grid(value: number): number
|
||||
return math.round(value / cell) * cell
|
||||
end
|
||||
local width, height, depth = grid(gateAsset.Size.X), grid(gateAsset.Size.Y), grid(gateAsset.Size.Z)
|
||||
local opening = grid(lintel.Size.X)
|
||||
local clearHeight = height - grid(lintel.Size.Y)
|
||||
assert(opening > 0 and opening < width and clearHeight > 0 and clearHeight < height, "Invalid flank gate opening")
|
||||
local stone = materialNames[gateAsset.TextureID]
|
||||
assert(stone, "Missing flank gate material")
|
||||
local gate = Instance.new("Model")
|
||||
gate.Name = "Gate"
|
||||
gate.WorldPivot = CFrame.identity
|
||||
local roof = box(Vector3.new(width, height - clearHeight, depth), gateAsset.Color, stone)
|
||||
roof.Name = "GateRoof"
|
||||
roof.Position = Vector3.new(0, (height + clearHeight) / 2, 0)
|
||||
roof.Parent = gate
|
||||
for _, side in {-1, 1} do
|
||||
local pier = box(Vector3.new((width - opening) / 2, clearHeight, depth), gateAsset.Color, stone)
|
||||
pier.Name = if side < 0 then "WestPier" else "EastPier"
|
||||
pier.Position = Vector3.new(side * (width + opening) / 4, clearHeight / 2, 0)
|
||||
pier.Parent = gate
|
||||
end
|
||||
gate.Parent = kit
|
||||
|
||||
if not arena then
|
||||
local model = Instance.new("Model")
|
||||
model.Name = "ProceduralArena"
|
||||
model.WorldPivot = CFrame.new(6500, 8, 0)
|
||||
arena = model
|
||||
end
|
||||
if not spawns then
|
||||
local folder = Instance.new("Folder")
|
||||
folder.Name = "PlayerSpawns"
|
||||
folder.Parent = arena
|
||||
end
|
||||
if existingKit then
|
||||
existingKit:Destroy()
|
||||
end
|
||||
kit.Parent = ServerStorage
|
||||
arena.Parent = workspace
|
||||
return kit
|
||||
@@ -0,0 +1,750 @@
|
||||
--!strict
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local ServerStorage = game:GetService("ServerStorage")
|
||||
local Mobility = require(ReplicatedStorage:WaitForChild("ArenaMobility") :: ModuleScript)
|
||||
|
||||
local arena = workspace:WaitForChild("ProceduralArena") :: Model
|
||||
local spawns = arena:WaitForChild("PlayerSpawns")
|
||||
local kit = ServerStorage:WaitForChild("ProceduralArenaKit")
|
||||
local origin = arena:GetPivot().Position
|
||||
local random = Random.new()
|
||||
local cell = kit:GetAttribute("GridCell") :: number
|
||||
local halfX, halfZ = 42 * cell, 49 * cell
|
||||
local flankX = 30 * cell
|
||||
local tile = 2 * cell
|
||||
local clearance = 6
|
||||
local middle = tile * 3
|
||||
local deckHalfX, deckHalfZ = 14 * cell, 10 * cell
|
||||
local ringX, ringZ = 13 * cell, 8.5 * cell
|
||||
local roofHalfX = 4 * cell
|
||||
local slab = cell
|
||||
-- The 6:8:10 rise, run and slope keep the incline on whole tiles as well.
|
||||
local rampRun = 8 * cell
|
||||
|
||||
local function grid(value: number): number
|
||||
return math.round(value / cell) * cell
|
||||
end
|
||||
|
||||
type Route = {name: string, points: {Vector3}, flat: boolean}
|
||||
type Footprint = {point: Vector3, halfWidth: number, halfLength: number}
|
||||
type Cover = {asset: string, x: number, z: number, turn: number}
|
||||
type Plan = {keep: number, tunnels: number, ramps: number, hand: number, crossing: number}
|
||||
type Layout = {
|
||||
model: Model, markers: Folder, routes: {Route}, bounds: {Footprint}, positions: {[string]: {Vector3}},
|
||||
covers: number, ramps: number, variant: string, plan: Plan, runes: Folder, boostSurfaces: {[Model]: MeshPart},
|
||||
}
|
||||
|
||||
type BoostArt = {model: Model, width: number, length: number}
|
||||
local boostArt: {BoostArt} = {}
|
||||
local jumpArt: Model? = nil
|
||||
local archivedRunes = ServerStorage:WaitForChild("HunterMonolithImport"):WaitForChild("ArenaRunes")
|
||||
for _, rune in archivedRunes:GetChildren() do
|
||||
if not rune:IsA("Model") or not rune.PrimaryPart then continue end
|
||||
local kind = rune:GetAttribute("Kind")
|
||||
if kind == "Jump" then
|
||||
if not jumpArt or rune.Name < jumpArt.Name then jumpArt = rune end
|
||||
elseif kind == "Boost" then
|
||||
local width, length = rune:GetAttribute("HalfWidth"), rune:GetAttribute("HalfLength")
|
||||
if typeof(width) == "number" and width > 0 and typeof(length) == "number" and length > 0 then
|
||||
table.insert(boostArt, {model = rune, width = width, length = length})
|
||||
end
|
||||
end
|
||||
end
|
||||
assert(jumpArt and #boostArt > 0, "Arena mobility templates are missing")
|
||||
table.sort(boostArt, function(a, b) return a.model.Name < b.model.Name end)
|
||||
|
||||
local keeps = {
|
||||
{name = "Бастионы", roofHalfZ = 23, wingX = 12, width = 32, depth = 18, balconyX = -12},
|
||||
{name = "Галереи", roofHalfZ = 20, wingX = 0, width = 46, depth = 25, balconyX = 0},
|
||||
{name = "Террасы", roofHalfZ = 27, wingX = -14, width = 24, depth = 13, balconyX = 17},
|
||||
}
|
||||
local tunnels = {
|
||||
{name = "Парные тоннели", openings = {{x = -37, width = 21}, {x = 37, width = 21}}},
|
||||
{name = "Тоннель со смещением", openings = {{x = -25, width = 27}}},
|
||||
{name = "Три прохода", openings = {{x = -49, width = 17}, {x = 0, width = 21}, {x = 49, width = 17}}},
|
||||
}
|
||||
local rampPlans = {"Боковые подъёмы", "Торцевые подъёмы", "Угловые подъёмы"}
|
||||
local recentProfiles: {string} = {}
|
||||
|
||||
local function profileKey(plan: Plan): string
|
||||
return plan.keep .. "/" .. plan.tunnels .. "/" .. plan.ramps
|
||||
end
|
||||
|
||||
local function selectPlan(rng: Random): Plan
|
||||
return {
|
||||
keep = rng:NextInteger(1, #keeps), tunnels = rng:NextInteger(1, #tunnels), ramps = rng:NextInteger(1, #rampPlans),
|
||||
hand = if rng:NextInteger(0, 1) == 0 then -1 else 1, crossing = rng:NextInteger(23, 24) * cell,
|
||||
}
|
||||
end
|
||||
|
||||
local function template(asset: string): BasePart
|
||||
local part = kit:FindFirstChild(asset)
|
||||
assert(part and part:IsA("BasePart"), "Missing arena module " .. asset)
|
||||
return part
|
||||
end
|
||||
|
||||
local function localPoint(x: number, z: number, y: number?): Vector3
|
||||
return Vector3.new(x, y or 0, z)
|
||||
end
|
||||
|
||||
local function folder(parent: Instance, name: string): Folder
|
||||
local group = Instance.new("Folder")
|
||||
group.Name = name
|
||||
group.Parent = parent
|
||||
return group
|
||||
end
|
||||
|
||||
local function extent(position: Vector3, orientation: CFrame, size: Vector3): Footprint
|
||||
local r, b = orientation.RightVector, -orientation.LookVector
|
||||
return {
|
||||
point = position,
|
||||
halfWidth = (math.abs(r.X) * size.X + math.abs(b.X) * size.Z) / 2,
|
||||
halfLength = (math.abs(r.Z) * size.X + math.abs(b.Z) * size.Z) / 2,
|
||||
}
|
||||
end
|
||||
|
||||
local function fittedVolume(point: Vector3, rotation: CFrame, size: Vector3): (Vector3, Vector3)
|
||||
local rotated = math.abs(rotation.RightVector.Z) > .5
|
||||
local width, depth = if rotated then size.Z else size.X, if rotated then size.X else size.Z
|
||||
local left, right = grid(point.X - width / 2), grid(point.X + width / 2)
|
||||
local front, back = grid(point.Z - depth / 2), grid(point.Z + depth / 2)
|
||||
if right == left then left, right = grid(point.X - cell / 2), grid(point.X - cell / 2) + cell end
|
||||
if back == front then front, back = grid(point.Z - cell / 2), grid(point.Z - cell / 2) + cell end
|
||||
local bottom = grid(point.Y)
|
||||
local height = math.max(cell, grid(point.Y + size.Y) - bottom)
|
||||
width, depth = right - left, back - front
|
||||
return Vector3.new((left + right) / 2, bottom, (front + back) / 2),
|
||||
Vector3.new(if rotated then depth else width, height, if rotated then width else depth)
|
||||
end
|
||||
|
||||
local function install(layout: Layout, parent: Instance, asset: string, point: Vector3, rotation: CFrame, dimensions: Vector3?, reserve: boolean?): BasePart
|
||||
local part = template(asset):Clone()
|
||||
local fitted, size = fittedVolume(point, rotation, dimensions or part.Size)
|
||||
part.Size = size
|
||||
part.CFrame = CFrame.new(origin + fitted + Vector3.yAxis * (size.Y / 2)) * rotation
|
||||
part.Parent = parent
|
||||
if reserve then table.insert(layout.bounds, extent(fitted, rotation, size)) end
|
||||
return part
|
||||
end
|
||||
|
||||
local function transformRoute(points: {Vector3}, rotation: CFrame, reversed: boolean): {Vector3}
|
||||
local result: {Vector3} = {}
|
||||
for i = 1, #points do
|
||||
local point = points[if reversed then #points + 1 - i else i]
|
||||
table.insert(result, rotation * point)
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
local flip = CFrame.Angles(0, math.pi, 0)
|
||||
local ninety = CFrame.Angles(0, math.pi / 2, 0)
|
||||
local function path(layout: Layout, name: string, points: {Vector3}, flat: boolean)
|
||||
table.insert(layout.routes, {name = name, points = points, flat = flat})
|
||||
end
|
||||
|
||||
local function accent(parent: Instance, name: string, size: Vector3, pose: CFrame, tint: Color3): Part
|
||||
local part = Instance.new("Part")
|
||||
part.Name, part.Size, part.CFrame = name, size, pose
|
||||
part.Color, part.Material = tint, Enum.Material.Neon
|
||||
part.Anchored, part.CanCollide, part.CanQuery, part.CanTouch, part.CastShadow = true, false, false, false, false
|
||||
part.Parent = parent
|
||||
return part
|
||||
end
|
||||
|
||||
local function routeMarks(parent: Instance, start: Vector3, nextPoint: Vector3, tint: Color3)
|
||||
local dir = (nextPoint - start).Unit
|
||||
local right = dir:Cross(Vector3.yAxis)
|
||||
for i = 0, 1 do
|
||||
local center = origin + start + dir * (i * 4) + Vector3.yAxis * .11
|
||||
local point = center + dir * 1.35
|
||||
for _, side in {-1, 1} do
|
||||
local tail = center - dir + right * (side * 2.5)
|
||||
local glow = accent(parent, "RouteChevron", Vector3.new(.3, .11, (point - tail).Magnitude),
|
||||
CFrame.lookAt((point + tail) / 2, point), tint)
|
||||
glow.Transparency = .2 + i * .08
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function base(layout: Layout, parent: Folder, side: string, rotation: CFrame)
|
||||
local blue = side == "Blue"
|
||||
local color = if blue then Color3.fromRGB(68, 210, 255) else Color3.fromRGB(255, 147, 66)
|
||||
local group = folder(parent, if blue then "BlueBase" else "OrangeBase")
|
||||
local function place(asset: string, x: number, z: number, size: Vector3)
|
||||
return install(layout, group, asset, rotation * localPoint(x, z), rotation, size, true)
|
||||
end
|
||||
for _, x in {-41, 41} do place("Wall", x, -207, Vector3.new(5, 18, 44)) end
|
||||
place("Wall", 0, -229, Vector3.new(85, 18, 4))
|
||||
local cap = install(layout, group, "Foundation", rotation * localPoint(0, -216, 18), rotation, Vector3.new(86, cell, 23), true)
|
||||
accent(group, "BaseCanopyEdge", Vector3.new(cap.Size.X - cell, .62, .48), cap.CFrame * CFrame.new(0, 0, cap.Size.Z / 2 + .25), color)
|
||||
for _, x in {-14.5, 14.5} do
|
||||
local screen = place("Screen", x, -187, Vector3.new(16, 16, 6))
|
||||
local plaque = accent(group, "BaseColor", Vector3.new(9, 1.2, 1),
|
||||
screen.CFrame * CFrame.new(0, screen.Size.Y * .3, -screen.Size.Z / 2 - .45), color)
|
||||
local lamp = Instance.new("PointLight")
|
||||
lamp.Color, lamp.Range, lamp.Brightness = color, 23, 1.15
|
||||
lamp.Parent = plaque
|
||||
end
|
||||
local shield = place("Wall", 0, -166, Vector3.new(24, 17, 7))
|
||||
local nameplate = accent(group, "BaseBeacon", Vector3.new(16, 1, 2),
|
||||
shield.CFrame * CFrame.new(0, shield.Size.Y / 2 + .55, 0), color)
|
||||
local sign = Instance.new("BillboardGui")
|
||||
sign.Name = "BaseName"
|
||||
sign.Size = UDim2.fromOffset(175, 32)
|
||||
sign.StudsOffsetWorldSpace = Vector3.yAxis * 2
|
||||
sign.MaxDistance = 115
|
||||
sign.LightInfluence = 0
|
||||
sign.Parent = nameplate
|
||||
local text = Instance.new("TextLabel")
|
||||
text.Size, text.BackgroundTransparency = UDim2.fromScale(1, 1), 1
|
||||
text.Font, text.TextSize = Enum.Font.GothamBlack, 19
|
||||
text.TextColor3, text.TextStrokeTransparency = color, .2
|
||||
text.Text = if blue then "БАЗА СИНИХ" else "БАЗА ОРАНЖЕВЫХ"
|
||||
text.Parent = sign
|
||||
|
||||
local points: {Vector3} = {}
|
||||
layout.positions[side] = points
|
||||
for row = 1, 2 do
|
||||
for i = 1, 5 do
|
||||
local point = rotation * localPoint((i - 3) * 12, -211 - (row - 1) * 10)
|
||||
local spawn = Instance.new("SpawnLocation")
|
||||
spawn.Name = side .. "_" .. tostring(#points + 1)
|
||||
spawn.Size = Vector3.new(2, 1, 2)
|
||||
spawn.CFrame = CFrame.lookAt(origin + point + Vector3.yAxis * .35, origin + point + Vector3.yAxis * .35 + rotation * Vector3.zAxis)
|
||||
spawn.Transparency, spawn.Duration = 1, 0
|
||||
spawn.CanCollide, spawn.CanTouch, spawn.CanQuery, spawn.Anchored = false, false, false, true
|
||||
spawn.Neutral = false
|
||||
spawn.TeamColor = BrickColor.new(if blue then "Cyan" else "Deep orange")
|
||||
spawn:SetAttribute("ArenaTeam", side)
|
||||
spawn.Parent = layout.markers
|
||||
table.insert(points, point)
|
||||
path(layout, spawn.Name .. "_exit", {point, rotation * localPoint(0, -211)}, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function placeRune(layout: Layout, rune: Model, name: string, frame: CFrame)
|
||||
rune.Name = name
|
||||
rune:SetAttribute("PulseAt", nil)
|
||||
rune:SetAttribute("Phase", (#layout.runes:GetChildren() + 1) * 1.17)
|
||||
rune:PivotTo(frame)
|
||||
rune.Parent = layout.runes
|
||||
end
|
||||
|
||||
local function boostRune(layout: Layout, wedge: MeshPart, toe: Vector3, top: Vector3)
|
||||
local forward = (top - toe).Unit
|
||||
local normal = forward:Cross(wedge.CFrame.LookVector).Unit
|
||||
local position = origin + toe:Lerp(top, .33)
|
||||
local goalWidth = wedge.Size.Z * .41
|
||||
local goalLength = math.min(14, (top - toe).Magnitude * .23)
|
||||
local art, bestScale, bestCoverage = boostArt[1], 1, 0
|
||||
for _, candidate in boostArt do
|
||||
local scale = math.min(goalWidth / candidate.width, goalLength / candidate.length)
|
||||
local coverage = candidate.width * candidate.length * scale * scale
|
||||
if coverage > bestCoverage then art, bestScale, bestCoverage = candidate, scale, coverage end
|
||||
end
|
||||
local rune = art.model:Clone()
|
||||
rune:ScaleTo(art.model:GetScale() * bestScale)
|
||||
rune:SetAttribute("HalfWidth", art.width * bestScale)
|
||||
rune:SetAttribute("HalfLength", art.length * bestScale)
|
||||
placeRune(layout, rune, "Boost " .. layout.ramps, CFrame.lookAt(position, position + forward, normal))
|
||||
layout.boostSurfaces[rune] = wedge
|
||||
end
|
||||
|
||||
local function jumpRune(layout: Layout, name: string, point: Vector3, forward: Vector3)
|
||||
local template = jumpArt
|
||||
assert(template, "Jump rune template is missing")
|
||||
local position = origin + point
|
||||
placeRune(layout, template:Clone(), "Jump " .. name, CFrame.lookAt(position, position + forward))
|
||||
end
|
||||
|
||||
local function ramp(layout: Layout, parent: Folder, asset: string, landing: Vector3, uphill: Vector3, width: number): (Vector3, Vector3)
|
||||
local orientation = CFrame.fromMatrix(Vector3.zero, uphill, Vector3.yAxis, uphill:Cross(Vector3.yAxis))
|
||||
local wedge = install(layout, parent, asset, landing - uphill * (rampRun / 2), orientation, Vector3.new(rampRun, middle, width), true)
|
||||
assert(wedge:IsA("MeshPart"), "Ramp template must be a slope mesh")
|
||||
local center = wedge.Position - origin
|
||||
local toe = center - uphill * (wedge.Size.X / 2) - Vector3.yAxis * (wedge.Size.Y / 2)
|
||||
local top = center + uphill * (wedge.Size.X / 2) + Vector3.yAxis * (wedge.Size.Y / 2)
|
||||
layout.ramps += 1
|
||||
boostRune(layout, wedge, toe, top)
|
||||
-- Check both seams as part of the incline, including the approach and landing.
|
||||
path(layout, "Incline " .. layout.ramps, {toe - uphill * 2, toe, top}, false)
|
||||
return toe, top
|
||||
end
|
||||
|
||||
local function installAssembly(layout: Layout, parent: Instance, key: string, point: Vector3, rotate: CFrame): Model
|
||||
local source = kit:FindFirstChild(key)
|
||||
assert(source and source:IsA("Model"), "Missing structure " .. key)
|
||||
local clone = source:Clone()
|
||||
clone:PivotTo(CFrame.new(origin + point) * rotate)
|
||||
clone.Parent = parent
|
||||
for _, item in clone:GetChildren() do
|
||||
if item:IsA("BasePart") then table.insert(layout.bounds, extent(item.Position - origin, item.CFrame, item.Size)) end
|
||||
end
|
||||
return clone
|
||||
end
|
||||
|
||||
local function light(parent: Instance, point: Vector3, tint: Color3)
|
||||
local strip = accent(parent, "RecessedLight", Vector3.new(5.8, .28, 1.6), CFrame.new(origin + point), tint)
|
||||
local lamp = Instance.new("PointLight")
|
||||
lamp.Color, lamp.Range, lamp.Brightness = tint, 19, 1.5
|
||||
lamp.Parent = strip
|
||||
end
|
||||
|
||||
local amber = Color3.fromRGB(255, 198, 102)
|
||||
local cyan = Color3.fromRGB(107, 236, 255)
|
||||
local violet = Color3.fromRGB(202, 125, 255)
|
||||
|
||||
local function block(layout: Layout, parent: Instance, asset: string, x: number, z: number, bottom: number, size: Vector3)
|
||||
return install(layout, parent, asset, localPoint(x, z, bottom), CFrame.identity, size, true)
|
||||
end
|
||||
|
||||
local function deck(layout: Layout, parent: Instance, x: number, z: number, height: number, width: number, depth: number)
|
||||
local panel = block(layout, parent, "DeckPanel", x, z, height - slab, Vector3.new(width, slab, depth))
|
||||
panel.CanCollide = false
|
||||
-- The overlapping collision margins keep touching deck sections continuously walkable.
|
||||
local surface = Instance.new("Part")
|
||||
surface.Name = "DeckCollision"
|
||||
surface.Size = panel.Size + Vector3.new(.02, 0, .02)
|
||||
surface.CFrame = panel.CFrame
|
||||
surface.Anchored, surface.CanTouch, surface.Transparency, surface.CastShadow = true, false, 1, false
|
||||
surface.Parent = parent
|
||||
end
|
||||
|
||||
local function tunnelLevel(layout: Layout, parent: Folder)
|
||||
local plan = layout.plan
|
||||
local specification = tunnels[plan.tunnels]
|
||||
for _, side in {-1, 1} do
|
||||
local z = side * 30
|
||||
local multiplier = -side * plan.hand
|
||||
local left = -deckHalfX
|
||||
local tint = if side < 0 then cyan else violet
|
||||
for i = 1, #specification.openings do
|
||||
local opening = specification.openings[if multiplier == 1 then i else #specification.openings + 1 - i]
|
||||
local x = opening.x * multiplier
|
||||
local start, finish = x - opening.width / 2, x + opening.width / 2
|
||||
block(layout, parent, "Wall", (left + start) / 2, z, 0, Vector3.new(start - left, middle - slab, 9))
|
||||
left = finish
|
||||
light(parent, localPoint(x, z, middle - slab - .85), tint)
|
||||
path(layout, "Tunnel mouth " .. side .. "/" .. i,
|
||||
{localPoint(0, side * plan.crossing), localPoint(0, side * 47), localPoint(x, side * 47), localPoint(x, 0)}, true)
|
||||
end
|
||||
block(layout, parent, "Wall", (left + deckHalfX) / 2, z, 0, Vector3.new(deckHalfX - left, middle - slab, 9))
|
||||
for _, edge in {-1, 1} do
|
||||
-- End the side piers on the faces of the portal wall, keeping their outer faces continuous.
|
||||
local outerX = edge * (deckHalfX - cell)
|
||||
local first, frontFace, backFace = grid(19), grid(30 - 4.5), grid(30 + 4.5)
|
||||
for _, span in {{first, frontFace}, {backFace, deckHalfZ}} do
|
||||
block(layout, parent, "Wall", outerX, side * (span[1] + span[2]) / 2, 0,
|
||||
Vector3.new(2 * cell, middle - slab, span[2] - span[1]))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function citadel(layout: Layout, parent: Folder, rng: Random)
|
||||
local plan = layout.plan
|
||||
local shape = keeps[plan.keep]
|
||||
local structure = folder(parent, "Citadel")
|
||||
local passages = folder(structure, "Tunnels")
|
||||
local gallery = folder(structure, "MiddleGallery")
|
||||
local summit = folder(structure, "Roof")
|
||||
local inclines = folder(structure, "Ramps")
|
||||
local roof = middle * 2
|
||||
local roofHalfZ = grid(shape.roofHalfZ)
|
||||
local wingDepth = grid(shape.depth)
|
||||
deck(layout, gallery, 0, 0, middle, 2 * deckHalfX, 2 * deckHalfZ)
|
||||
deck(layout, summit, 0, 0, roof, 2 * roofHalfX, 2 * roofHalfZ)
|
||||
tunnelLevel(layout, passages)
|
||||
|
||||
for _, endSide in {-1, 1} do
|
||||
local balconyX = grid(endSide * plan.hand * shape.balconyX)
|
||||
local balconyWidth = if plan.keep == 2 then 39 else 32
|
||||
local balconyDepth = (if plan.keep == 2 then 4 else 3) * cell
|
||||
local balconyZ = endSide * (deckHalfZ + balconyDepth / 2)
|
||||
local launchZ = endSide * (deckHalfZ + balconyDepth + 3 * cell)
|
||||
jumpRune(layout, "Citadel " .. endSide, localPoint(balconyX, launchZ), -Vector3.zAxis * endSide)
|
||||
path(layout, "Citadel jump approach " .. endSide, {localPoint(0, launchZ), localPoint(balconyX, launchZ)}, true)
|
||||
deck(layout, gallery, balconyX, balconyZ, middle, balconyWidth, balconyDepth)
|
||||
block(layout, gallery, "Parapet", balconyX, endSide * (deckHalfZ + balconyDepth - 1.5), middle,
|
||||
Vector3.new(balconyWidth - 3, 4, 3))
|
||||
for _, offset in {-1, 1} do
|
||||
local columnX = balconyX + offset * (balconyWidth / 2 - 4)
|
||||
if math.abs(columnX) >= 13 then
|
||||
block(layout, passages, "Wall", columnX, balconyZ, 0, Vector3.new(7, middle - slab, 8))
|
||||
end
|
||||
end
|
||||
path(layout, "Gallery balcony " .. endSide,
|
||||
{localPoint(-ringX, ringZ * endSide, middle), localPoint(balconyX, ringZ * endSide, middle),
|
||||
localPoint(balconyX, balconyZ, middle)}, true)
|
||||
|
||||
local wingX = endSide * plan.hand * shape.wingX
|
||||
local wingZ = endSide * (roofHalfZ + wingDepth / 2)
|
||||
local wingWalkZ = endSide * (roofHalfZ + math.min(wingDepth / 2, wingDepth - cell - 2.2))
|
||||
deck(layout, summit, wingX, wingZ, roof, shape.width, wingDepth)
|
||||
block(layout, summit, "Parapet", wingX, endSide * (roofHalfZ + wingDepth - 1.5), roof,
|
||||
Vector3.new(shape.width - 2, 4, 3))
|
||||
for _, offset in {-1, 1} do
|
||||
block(layout, gallery, "Wall", offset * 3 * cell, endSide * (roofHalfZ - cell), middle, Vector3.new(2 * cell, middle - slab, 2 * cell))
|
||||
block(layout, gallery, "Wall", wingX + offset * (shape.width / 2 - 4), wingZ, middle,
|
||||
Vector3.new(7, middle - slab, 7))
|
||||
end
|
||||
path(layout, "Roof wing " .. endSide,
|
||||
{localPoint(0, 0, roof), localPoint(wingX, endSide * (roofHalfZ - 3), roof), localPoint(wingX, wingWalkZ, roof)}, true)
|
||||
path(layout, "Gallery crosswalk " .. endSide,
|
||||
{localPoint(-ringX, endSide * ringZ, middle), localPoint(ringX, endSide * ringZ, middle)}, true)
|
||||
end
|
||||
|
||||
local sideZ = rng:NextInteger(6, 7) * cell
|
||||
local endX = rng:NextInteger(9, 10) * cell
|
||||
local upperZ = (if plan.ramps == 1 then 2 elseif plan.ramps == 2 then 3 else 0) * cell
|
||||
for _, side in {-1, 1} do
|
||||
local edgeX = side * ringX
|
||||
if plan.keep == 2 then
|
||||
local wingX = side * (deckHalfX + 13)
|
||||
deck(layout, gallery, wingX, 0, middle, 26, 32)
|
||||
for _, z in {-11, 11} do
|
||||
block(layout, passages, "Wall", wingX, z, 0, Vector3.new(9, middle - slab, 8))
|
||||
end
|
||||
block(layout, gallery, "Parapet", side * (deckHalfX + 24), 0, middle, Vector3.new(4, 4, 29))
|
||||
path(layout, "Side gallery " .. side, {localPoint(edgeX, 0, middle), localPoint(wingX, 0, middle)}, true)
|
||||
end
|
||||
for _, endSide in {-1, 1} do
|
||||
local fromSide = plan.ramps == 1 or (plan.ramps == 3 and side * endSide == plan.hand)
|
||||
local axis = if fromSide then Vector3.xAxis * side else Vector3.zAxis * endSide
|
||||
local landing = if fromSide then localPoint(side * deckHalfX, endSide * sideZ)
|
||||
else localPoint(side * endX, endSide * deckHalfZ)
|
||||
local toe, top = ramp(layout, inclines, "CitadelRamp", landing, -axis, 4 * cell)
|
||||
local entry = toe + axis * 2
|
||||
local junction = if fromSide then localPoint(side * flankX, toe.Z) else localPoint(toe.X, endSide * plan.crossing)
|
||||
local ring = localPoint(edgeX, endSide * ringZ, middle)
|
||||
local turn = if fromSide then localPoint(edgeX, top.Z, middle) else localPoint(top.X, ring.Z, middle)
|
||||
path(layout, "Lower ramp approach " .. side .. "/" .. endSide, {junction, entry}, true)
|
||||
path(layout, "Lower ramp landing " .. side .. "/" .. endSide, {top, turn, ring}, true)
|
||||
end
|
||||
|
||||
local outward = side * Vector3.xAxis
|
||||
local z = side * plan.hand * upperZ
|
||||
local topDock = localPoint(side * roofHalfX, z, middle)
|
||||
local toe, top = ramp(layout, inclines, "CitadelRamp", topDock, -outward, 2 * cell)
|
||||
local entry = toe + outward * 2
|
||||
local across = localPoint(edgeX, 0, middle)
|
||||
path(layout, "Gallery side " .. side,
|
||||
{localPoint(edgeX, -ringZ, middle), across, localPoint(edgeX, ringZ, middle)}, true)
|
||||
path(layout, "Roof ramp approach " .. side, {across, localPoint(edgeX, z, middle), entry}, true)
|
||||
path(layout, "Roof ramp landing " .. side, {top, localPoint(0, z, roof), localPoint(0, 0, roof)}, true)
|
||||
end
|
||||
end
|
||||
|
||||
local function sectorGate(layout: Layout, parent: Folder, point: Vector3, out: number, offset: number)
|
||||
local group = folder(parent, "FlankGate")
|
||||
installAssembly(layout, group, "Gate", point, CFrame.identity)
|
||||
local roof, halfDepth = tile * 3, tile * 2
|
||||
local capX = point.X + out * offset
|
||||
local toward = Vector3.zAxis * math.sign(point.Z)
|
||||
jumpRune(layout, (if out < 0 then "West" else "East") .. " flank " .. math.sign(point.Z), point - toward * (halfDepth + 3 * cell), toward)
|
||||
local tops: {Vector3} = {}
|
||||
local tint = if point.Z < 0 then Color3.fromRGB(73, 220, 255) else Color3.fromRGB(255, 157, 84)
|
||||
for _, endSide in {-1, 1} do
|
||||
local dock = localPoint(capX, point.Z + endSide * halfDepth)
|
||||
local toe, top = ramp(layout, group, "Ramp", dock, -Vector3.zAxis * endSide, 4 * cell)
|
||||
table.insert(tops, top)
|
||||
local entry = toe + Vector3.zAxis * (endSide * 2)
|
||||
local staging = toe + Vector3.zAxis * (endSide * 6)
|
||||
local flank = localPoint(point.X, staging.Z)
|
||||
path(layout, "Flank gate approach", {localPoint(point.X, point.Z), flank, staging, entry}, true)
|
||||
end
|
||||
local middle = point + Vector3.yAxis * roof
|
||||
path(layout, "Flank gate roof", {tops[1], middle, tops[2]}, true)
|
||||
install(layout, group, "LowCover", middle - Vector3.xAxis * (out * 24), ninety, Vector3.new(15, 8, 9), false)
|
||||
install(layout, group, "Parapet", middle + Vector3.xAxis * (out * 38), ninety, Vector3.new(35, 4, 4), false)
|
||||
light(group, point + localPoint(-5, -11, tile * 1.45), tint)
|
||||
light(group, point + localPoint(5, 11, tile * 1.45), tint)
|
||||
end
|
||||
|
||||
local function overlaps(a: Footprint, b: Footprint, padding: number): boolean
|
||||
return math.abs(a.point.X - b.point.X) < a.halfWidth + b.halfWidth + padding
|
||||
and math.abs(a.point.Z - b.point.Z) < a.halfLength + b.halfLength + padding
|
||||
end
|
||||
|
||||
local function reservePaths(layout: Layout): {Vector3}
|
||||
local reserved: {Vector3} = {}
|
||||
for _, route in layout.routes do
|
||||
for i = 2, #route.points do
|
||||
local from, to = route.points[i - 1], route.points[i]
|
||||
if from.Y > .1 or to.Y > .1 then continue end
|
||||
local count = math.max(1, math.ceil((to - from).Magnitude / 3))
|
||||
for j = 0, count do table.insert(reserved, from:Lerp(to, j / count)) end
|
||||
end
|
||||
end
|
||||
return reserved
|
||||
end
|
||||
|
||||
local bays: {{Cover}} = {
|
||||
{{asset = "SquareCover", x = -8, z = -9, turn = 0}, {asset = "LowCover", x = 11, z = 12, turn = 1}},
|
||||
{{asset = "TallCover", x = 7, z = -9, turn = 0}, {asset = "Crate", x = -9, z = 11, turn = 0}},
|
||||
{{asset = "LowCover", x = -10, z = -9, turn = 0}, {asset = "Screen", x = 9, z = 12, turn = 1}},
|
||||
}
|
||||
|
||||
local function furnish(layout: Layout, parent: Folder, rng: Random)
|
||||
local reserved = reservePaths(layout)
|
||||
local function fitsCover(shape: Footprint): boolean
|
||||
local position = shape.point
|
||||
if math.abs(position.X) + shape.halfWidth > halfX - 8 or math.abs(position.Z) + shape.halfLength > halfZ - 8 then
|
||||
return false
|
||||
end
|
||||
for _, bounds in layout.bounds do if overlaps(shape, bounds, 2) then return false end end
|
||||
for _, safe in reserved do
|
||||
if math.abs(position.X - safe.X) <= shape.halfWidth + clearance
|
||||
and math.abs(position.Z - safe.Z) <= shape.halfLength + clearance then return false end
|
||||
end
|
||||
return true
|
||||
end
|
||||
for _, row in {-39, -69, -94, -127, -159, -190, -217} do
|
||||
for _, laneBay in {-206, -141, -76, -45, 45, 76, 141, 206} do
|
||||
local x = laneBay + rng:NextInteger(-5, 5)
|
||||
local z = row + rng:NextInteger(-8, 8)
|
||||
local start = rng:NextInteger(1, #bays)
|
||||
for attempt = 0, #bays - 1 do
|
||||
local pattern = bays[(start + attempt - 1) % #bays + 1]
|
||||
local staged: {{asset: string, point: Vector3, rotation: CFrame, footprint: Footprint}} = {}
|
||||
local fits = true
|
||||
for _, item in pattern do
|
||||
for _, mirror in {-1, 1} do
|
||||
local point = localPoint((x + item.x) * mirror, (z + item.z) * mirror)
|
||||
local angle = if item.turn == 1 then ninety else CFrame.identity
|
||||
local rotation = if mirror == -1 then flip * angle else angle
|
||||
local fitted, size = fittedVolume(point, rotation, template(item.asset).Size)
|
||||
local shape = extent(fitted, rotation, size)
|
||||
if not fitsCover(shape) then fits = false break end
|
||||
for _, other in staged do if overlaps(shape, other.footprint, 2) then fits = false break end end
|
||||
if not fits then break end
|
||||
table.insert(staged, {asset = item.asset, point = point, rotation = rotation, footprint = shape})
|
||||
end
|
||||
if not fits then break end
|
||||
end
|
||||
if fits then
|
||||
local group = folder(parent, "CoverGroup" .. tostring(layout.covers // 4 + 1))
|
||||
for _, item in staged do
|
||||
install(layout, group, item.asset, item.point, item.rotation, nil, true)
|
||||
layout.covers += 1
|
||||
end
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
-- Tight bays may stop fitting after snapping. Fill remaining side pockets with smaller pairs.
|
||||
for _, z in {-23, -54, -85, -111, -145, -174, -202, -235} do
|
||||
for _, x in {-204, -142, -102, -62, 62, 102, 142, 204} do
|
||||
if layout.covers >= 24 then return end
|
||||
local point = localPoint(x + rng:NextInteger(-4, 4), z + rng:NextInteger(-4, 4))
|
||||
local asset = if rng:NextNumber() < .5 then "Crate" else "TallCover"
|
||||
local size = template(asset).Size
|
||||
local first, firstSize = fittedVolume(point, CFrame.identity, size)
|
||||
local second, secondSize = fittedVolume(-point, flip, size)
|
||||
if not fitsCover(extent(first, CFrame.identity, firstSize)) or not fitsCover(extent(second, flip, secondSize)) then continue end
|
||||
install(layout, parent, asset, point, CFrame.identity, nil, true)
|
||||
install(layout, parent, asset, -point, flip, nil, true)
|
||||
layout.covers += 2
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function build(seed: number): Layout
|
||||
local rng = Random.new(seed)
|
||||
local plan = selectPlan(rng)
|
||||
local model = Instance.new("Model")
|
||||
model.Name = "GeneratedLayout"
|
||||
local markers = Instance.new("Folder")
|
||||
markers.Name = "NextSpawns"
|
||||
local layout: Layout = {
|
||||
model = model, markers = markers, routes = {}, bounds = {}, positions = {}, covers = 0, ramps = 0,
|
||||
runes = folder(model, "ArenaRunes"), boostSurfaces = {},
|
||||
variant = keeps[plan.keep].name .. " / " .. tunnels[plan.tunnels].name .. " / " .. rampPlans[plan.ramps], plan = plan,
|
||||
}
|
||||
local foundation = folder(model, "Terrain")
|
||||
install(layout, foundation, "Foundation", localPoint(0, 0, -cell), CFrame.identity, Vector3.new(halfX * 2, cell, halfZ * 2), false)
|
||||
for _, side in {-1, 1} do
|
||||
install(layout, foundation, "Boundary", localPoint(0, side * (halfZ - cell / 2)), CFrame.identity, Vector3.new(halfX * 2, 10 * cell, cell), false)
|
||||
install(layout, foundation, "Boundary", localPoint(side * (halfX - cell / 2), 0), ninety, Vector3.new(2 * (halfZ - cell), 10 * cell, cell), false)
|
||||
end
|
||||
local bases = folder(model, "Bases")
|
||||
base(layout, bases, "Blue", CFrame.identity)
|
||||
base(layout, bases, "Orange", flip)
|
||||
local bend = if rng:NextNumber() < .5 then 22 else -22
|
||||
local center = {localPoint(0, -211), localPoint(0, -183), localPoint(bend, -176), localPoint(bend, -149),
|
||||
localPoint(0, -plan.crossing)}
|
||||
local signs = folder(model, "RouteSigns")
|
||||
path(layout, "Centre", center, true)
|
||||
path(layout, "Centre mirrored", transformRoute(center, flip, true), true)
|
||||
routeMarks(signs, center[4], center[5], cyan)
|
||||
routeMarks(signs, flip * center[4], flip * center[5], cyan)
|
||||
for _, side in {-1, 1} do
|
||||
local flank = {localPoint(0, -211), localPoint(32 * side, -207), localPoint(32 * side, -175),
|
||||
localPoint(89 * side, -191), localPoint(flankX * side, -188), localPoint(flankX * side, 0)}
|
||||
path(layout, "Flank " .. side, flank, true)
|
||||
path(layout, "Flank mirrored " .. side, transformRoute(flank, flip, true), true)
|
||||
routeMarks(signs, flank[5], flank[6], amber)
|
||||
routeMarks(signs, flip * flank[5], flip * flank[6], amber)
|
||||
end
|
||||
for _, z in {-plan.crossing, 0, plan.crossing} do
|
||||
path(layout, "Crosslink " .. z, {localPoint(-flankX, z), localPoint(flankX, z)}, true)
|
||||
end
|
||||
local raised = folder(model, "ElevatedRoutes")
|
||||
citadel(layout, raised, rng)
|
||||
for _, side in {-1, 1} do
|
||||
local gate = localPoint(flankX * side, -rng:NextInteger(29, 30) * cell)
|
||||
local offset = rng:NextInteger(4, 5) * cell
|
||||
sectorGate(layout, raised, gate, side, offset)
|
||||
sectorGate(layout, raised, -gate, -side, offset)
|
||||
end
|
||||
local screens = folder(model, "LaneDividers")
|
||||
for _, side in {-1, 1} do
|
||||
local point = localPoint(112 * side, -rng:NextInteger(79, 96))
|
||||
local size = Vector3.new(13, 23, rng:NextInteger(20, 30))
|
||||
install(layout, screens, "Wall", point, CFrame.identity, size, true)
|
||||
install(layout, screens, "Wall", flip * point, flip, size, true)
|
||||
end
|
||||
furnish(layout, folder(model, "Cover"), rng)
|
||||
return layout
|
||||
end
|
||||
|
||||
local function validate(layout: Layout)
|
||||
assert(layout.covers >= 16 and layout.ramps == 14, "Incomplete cover or upper routes")
|
||||
for _, part in layout.model:GetDescendants() do
|
||||
if not part:IsA("BasePart") or not part.MaterialVariant:match("^HunterArenaGrid") then continue end
|
||||
assert(part:IsA("Part") or part.Name == "Ramp" or part.Name == "CitadelRamp", "Box uses mesh projection: " .. part.Name)
|
||||
local size = part.Size
|
||||
local bbox = extent(part.Position - origin, part.CFrame, size)
|
||||
for _, edge in {bbox.point.X - bbox.halfWidth, bbox.point.X + bbox.halfWidth,
|
||||
bbox.point.Y - size.Y / 2, bbox.point.Y + size.Y / 2,
|
||||
bbox.point.Z - bbox.halfLength, bbox.point.Z + bbox.halfLength} do
|
||||
assert(math.abs(edge - grid(edge)) < .012, "Off-grid volume: " .. part.Name)
|
||||
end
|
||||
end
|
||||
local geometry = RaycastParams.new()
|
||||
geometry.FilterType = Enum.RaycastFilterType.Include
|
||||
geometry.FilterDescendantsInstances = {layout.model}
|
||||
geometry.RespectCanCollide = true
|
||||
local boostCount, jumpCount = 0, 0
|
||||
for _, rune in layout.runes:GetChildren() do
|
||||
assert(rune:IsA("Model") and rune.PrimaryPart, "Missing rune origin")
|
||||
local pose = rune.PrimaryPart.CFrame
|
||||
local support = layout.boostSurfaces[rune]
|
||||
if support then
|
||||
boostCount += 1
|
||||
assert(support.MaterialVariant == template("CitadelRamp").MaterialVariant
|
||||
and math.abs(Vector2.new(support.Size.X, support.Size.Y).Magnitude - 10 * cell) < .01,
|
||||
"Ramp must be amber and span ten cells along the slope")
|
||||
local width = rune:GetAttribute("HalfWidth") :: number
|
||||
local length = rune:GetAttribute("HalfLength") :: number
|
||||
for _, x in {-width, 0, width} do
|
||||
for _, z in {-length, 0, length} do
|
||||
local point = pose:PointToWorldSpace(Vector3.new(x, 0, z))
|
||||
local hit = workspace:Raycast(point + Vector3.yAxis, -Vector3.yAxis * 2, geometry)
|
||||
assert(hit and hit.Instance == support and (hit.Position - point).Magnitude < .12,
|
||||
"Booster does not fit its slope: " .. rune.Name)
|
||||
end
|
||||
end
|
||||
else
|
||||
jumpCount += 1
|
||||
for _, side in {Vector3.zero, Vector3.xAxis, -Vector3.xAxis, Vector3.zAxis, -Vector3.zAxis} do
|
||||
local point = pose.Position + side * (Mobility.JumpRadius + .2)
|
||||
local hit = workspace:Raycast(point + Vector3.yAxis, -Vector3.yAxis * 2, geometry)
|
||||
assert(hit and hit.Normal.Y > .97 and math.abs(hit.Position.Y - point.Y) < .12,
|
||||
"Jump rune needs a flat floor: " .. rune.Name)
|
||||
assert(not workspace:Raycast(point + Vector3.yAxis * .2, Vector3.yAxis * Mobility.JumpRise, geometry),
|
||||
"Jump rune needs open sky: " .. rune.Name)
|
||||
end
|
||||
local target = pose.Position + pose.LookVector * 30
|
||||
local landing = workspace:Raycast(target + Vector3.yAxis * Mobility.JumpRise, -Vector3.yAxis * Mobility.JumpRise, geometry)
|
||||
assert(landing and landing.Normal.Y > .97 and math.abs(landing.Position.Y - target.Y - middle) < .2,
|
||||
"Jump rune needs a nearby high landing: " .. rune.Name)
|
||||
end
|
||||
end
|
||||
assert(boostCount == layout.ramps and jumpCount == 6, "Incomplete mobility runes")
|
||||
local avatar = Vector3.new(3.2, 4.5, 3.2)
|
||||
for _, route in layout.routes do
|
||||
for i = 2, #route.points do
|
||||
local from, to = origin + route.points[i - 1], origin + route.points[i]
|
||||
local steps = math.max(1, math.ceil((to - from).Magnitude / 2))
|
||||
for step = 0, steps do
|
||||
local point = from:Lerp(to, step / steps)
|
||||
local floorHit = workspace:Raycast(point + Vector3.yAxis * .65, -Vector3.yAxis * 1.7, geometry)
|
||||
assert(floorHit and math.abs(floorHit.Position.Y - point.Y) < .35,
|
||||
("Floor gap on %s near %s"):format(route.name, tostring(point - origin)))
|
||||
assert(not workspace:Raycast(point + Vector3.yAxis * .48, Vector3.yAxis * 5.0, geometry),
|
||||
("Headroom on %s near %s"):format(route.name, tostring(point - origin)))
|
||||
end
|
||||
if route.flat and (to - from).Magnitude > .1 then
|
||||
local hit = workspace:Blockcast(CFrame.new(from + Vector3.yAxis * 2.87), avatar, to - from, geometry)
|
||||
assert(not hit, ("Blocked route %s by %s"):format(route.name, if hit then hit.Instance:GetFullName() else ""))
|
||||
end
|
||||
end
|
||||
end
|
||||
local blue, orange = layout.positions.Blue, layout.positions.Orange
|
||||
assert(#blue == 10 and #orange == 10, "Expected ten markers per team")
|
||||
for _, start in blue do
|
||||
for _, finish in orange do
|
||||
local aim = origin + start + Vector3.yAxis * 4.2
|
||||
local delta = finish - start
|
||||
assert(workspace:Raycast(aim, delta, geometry), "Exposed sightline between the bases")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local ProceduralArena = {}
|
||||
function ProceduralArena.regenerate(requestedSeed: number?): number
|
||||
local previous = arena:FindFirstChild("GeneratedLayout")
|
||||
local previousSeed = arena:GetAttribute("Seed")
|
||||
local previousKeep = arena:GetAttribute("CitadelProfile")
|
||||
local previousTunnels = arena:GetAttribute("TunnelProfile")
|
||||
local previousRamps = arena:GetAttribute("RampProfile")
|
||||
local function freshSeed(): number
|
||||
while true do
|
||||
local seed = random:NextInteger(1, 2147483646)
|
||||
local plan = selectPlan(Random.new(seed))
|
||||
if seed ~= previousSeed and plan.keep ~= previousKeep and plan.tunnels ~= previousTunnels and plan.ramps ~= previousRamps
|
||||
and not table.find(recentProfiles, profileKey(plan)) then
|
||||
return seed
|
||||
end
|
||||
end
|
||||
end
|
||||
local seed = requestedSeed or freshSeed()
|
||||
local lastFailure = ""
|
||||
for attempt = 1, if requestedSeed then 1 else 8 do
|
||||
local layout = build(seed)
|
||||
layout.model.Parent = arena
|
||||
local valid, failure = pcall(validate, layout)
|
||||
if valid then
|
||||
if previous then previous:Destroy() end
|
||||
for _, rune in layout.runes:GetChildren() do rune:AddTag(Mobility.ProceduralRuneTag) end
|
||||
spawns:ClearAllChildren()
|
||||
for _, marker in layout.markers:GetChildren() do marker.Parent = spawns end
|
||||
layout.markers:Destroy()
|
||||
arena:SetAttribute("Seed", seed)
|
||||
arena:SetAttribute("LayoutVariant", layout.variant)
|
||||
arena:SetAttribute("CitadelProfile", layout.plan.keep)
|
||||
arena:SetAttribute("TunnelProfile", layout.plan.tunnels)
|
||||
arena:SetAttribute("RampProfile", layout.plan.ramps)
|
||||
if not requestedSeed then
|
||||
table.insert(recentProfiles, profileKey(layout.plan))
|
||||
if #recentProfiles > 5 then table.remove(recentProfiles, 1) end
|
||||
end
|
||||
arena:SetAttribute("CoverCount", layout.covers)
|
||||
arena:SetAttribute("RampCount", layout.ramps)
|
||||
arena:SetAttribute("Levels", 3)
|
||||
arena:SetAttribute("Generation", ((arena:GetAttribute("Generation") :: number?) or 0) + 1)
|
||||
arena:SetAttribute("CheckedRoutes", #layout.routes)
|
||||
return seed
|
||||
end
|
||||
lastFailure = tostring(failure)
|
||||
layout.model:Destroy()
|
||||
layout.markers:Destroy()
|
||||
if attempt < 8 and not requestedSeed then seed = freshSeed() end
|
||||
end
|
||||
error(lastFailure)
|
||||
end
|
||||
|
||||
return ProceduralArena
|
||||
@@ -0,0 +1,294 @@
|
||||
--!strict
|
||||
-- Studio authoring script. Run in Edit to add or refresh the imported arena's runes.
|
||||
local arena = workspace:WaitForChild("HunterMonolithImport") :: Model
|
||||
local center = arena:GetPivot().Position
|
||||
local geometry = RaycastParams.new()
|
||||
geometry.FilterType = Enum.RaycastFilterType.Include
|
||||
geometry.FilterDescendantsInstances = {arena}
|
||||
geometry.RespectCanCollide = true
|
||||
|
||||
local set = Instance.new("Folder")
|
||||
set.Name = "ArenaRunes"
|
||||
local cobalt = Color3.fromRGB(100, 217, 255)
|
||||
local violet = Color3.fromRGB(184, 123, 255)
|
||||
local ice = Color3.fromRGB(216, 239, 255)
|
||||
local dark = Color3.fromRGB(22, 21, 43)
|
||||
local gold = Color3.fromRGB(255, 192, 115)
|
||||
local count = {Guide = 0, Boost = 0, Jump = 0}
|
||||
|
||||
local function walkable(x: number, z: number, ceiling: number): Vector3
|
||||
local hit = workspace:Raycast(Vector3.new(center.X + x, ceiling, center.Z + z), Vector3.new(0, -110, 0), geometry)
|
||||
assert(hit and hit.Normal.Y > .97, string.format("No flat surface at (%d,%d)", x, z))
|
||||
return hit.Position
|
||||
end
|
||||
|
||||
local function flatFootprint(position: Vector3, right: Vector3, forward: Vector3, x: number, z: number)
|
||||
for _, offset in {right * x + forward * z, right * x - forward * z, -right * x + forward * z, -right * x - forward * z} do
|
||||
local test = position + offset
|
||||
local floor = workspace:Raycast(test + Vector3.yAxis, -Vector3.yAxis * 2, geometry)
|
||||
assert(floor and floor.Normal.Y > .96 and math.abs(floor.Position.Y - position.Y) < .20,
|
||||
"Rune footprint needs flat floor: " .. tostring(test))
|
||||
end
|
||||
end
|
||||
|
||||
local function part(parent: Instance, name: string, size: Vector3, pose: CFrame, color: Color3, neon: boolean): Part
|
||||
local p = Instance.new("Part")
|
||||
p.Name, p.Size, p.CFrame, p.Color = name, size, pose, color
|
||||
p.Material = if neon then Enum.Material.Neon else Enum.Material.SmoothPlastic
|
||||
p.Anchored, p.CanCollide, p.CanTouch, p.CanQuery, p.CastShadow = true, false, false, false, false
|
||||
p.Parent = parent
|
||||
return p
|
||||
end
|
||||
|
||||
local function rune(name: string, kind: "Guide" | "Boost" | "Jump", at: CFrame, tint: Color3): (Model, BasePart)
|
||||
local m = Instance.new("Model")
|
||||
m.Name = name
|
||||
m.ModelStreamingMode = Enum.ModelStreamingMode.Atomic
|
||||
m:SetAttribute("Kind", kind)
|
||||
m:SetAttribute("Tint", tint)
|
||||
count[kind] += 1
|
||||
m:SetAttribute("Phase", count[kind] * 1.17)
|
||||
local p = part(m, "Origin", Vector3.new(2, 2, 2), at, tint, false)
|
||||
p.Transparency = 1
|
||||
m.PrimaryPart = p
|
||||
m.Parent = set
|
||||
return m, p
|
||||
end
|
||||
|
||||
local function group(parent: Model, name: string, at: CFrame, motion: string, sequence: number): Model
|
||||
local m = Instance.new("Model")
|
||||
m.Name = name
|
||||
m.WorldPivot = at
|
||||
m:SetAttribute("Motion", motion)
|
||||
m:SetAttribute("Sequence", sequence)
|
||||
m.Parent = parent
|
||||
return m
|
||||
end
|
||||
|
||||
local function bar(parent: Model, name: string, at: CFrame, a: Vector3, b: Vector3, width: number, height: number, color: Color3)
|
||||
local from = at:PointToWorldSpace(a)
|
||||
local to = at:PointToWorldSpace(b)
|
||||
local mid = (from + to) / 2
|
||||
part(parent, name, Vector3.new(width, height, (from - to).Magnitude + .09), CFrame.lookAt(mid, to), color, true)
|
||||
end
|
||||
|
||||
local function floorArrow(parent: Model, at: CFrame, width: number, length: number, tint: Color3, index: number)
|
||||
local arrow = group(parent, "Chevron" .. index, at, "Chase", index)
|
||||
local tip = Vector3.new(0, 0, -length * .45)
|
||||
for _, side in {-1, 1} do
|
||||
bar(arrow, "Wing", at, Vector3.new(width * .5 * side, 0, length * .45), tip, .32, .13, tint)
|
||||
end
|
||||
return arrow
|
||||
end
|
||||
|
||||
local function light(origin: BasePart, tint: Color3, range: number, ambientRate: number)
|
||||
local lamp = Instance.new("PointLight")
|
||||
lamp.Name = "RuneLight"
|
||||
lamp.Color = tint
|
||||
lamp.Brightness = .6
|
||||
lamp.Range = range
|
||||
lamp.Parent = origin
|
||||
local emitter = Instance.new("ParticleEmitter")
|
||||
emitter.Name = "RuneSparks"
|
||||
emitter.Texture = "rbxasset://textures/particles/sparkles_main.dds"
|
||||
emitter.Color = ColorSequence.new(ice, tint)
|
||||
emitter.LightEmission = .86
|
||||
emitter.EmissionDirection = Enum.NormalId.Top
|
||||
emitter.Transparency = NumberSequence.new({
|
||||
NumberSequenceKeypoint.new(0, .58), NumberSequenceKeypoint.new(.22, .23), NumberSequenceKeypoint.new(1, 1),
|
||||
})
|
||||
emitter.Size = NumberSequence.new(.33, .07)
|
||||
emitter.Lifetime = NumberRange.new(.52, .92)
|
||||
emitter.Speed = NumberRange.new(1.7, 3.5)
|
||||
emitter.SpreadAngle = Vector2.new(38, 38)
|
||||
emitter.RotSpeed = NumberRange.new(-50, 50)
|
||||
emitter.Rate = ambientRate
|
||||
local attachment = Instance.new("Attachment")
|
||||
attachment.Name = "SparkSource"
|
||||
attachment.Position = Vector3.new(0, .29, 0)
|
||||
attachment.Parent = origin
|
||||
emitter.Parent = attachment
|
||||
end
|
||||
|
||||
local function ring(parent: Model, at: CFrame, radius: number, tint: Color3, pieces: number, motion: string)
|
||||
local model = group(parent, motion, at, motion, 0)
|
||||
for i = 0, pieces - 1 do
|
||||
local angle = math.pi * 2 * i / pieces
|
||||
local endAngle = angle + math.pi * 2 / pieces * .83
|
||||
local a = Vector3.new(math.cos(angle) * radius, 0, math.sin(angle) * radius)
|
||||
local b = Vector3.new(math.cos(endAngle) * radius, 0, math.sin(endAngle) * radius)
|
||||
bar(model, "Arc", at, a, b, if radius > 4 then .25 else .14, .09, if i % 4 == 0 then ice else tint)
|
||||
end
|
||||
return model
|
||||
end
|
||||
|
||||
local function disc(parent: Model, name: string, at: CFrame, radius: number, thickness: number, tint: Color3, neon: boolean)
|
||||
local p = part(parent, name, Vector3.new(thickness, radius * 2, radius * 2), at * CFrame.Angles(0, 0, math.pi / 2), tint, neon)
|
||||
p.Shape = Enum.PartType.Cylinder
|
||||
end
|
||||
|
||||
local guideSpecs = {
|
||||
{"North cross", 0,-54,0,-18,20},{"South cross",0,54,0,18,20},
|
||||
{"East passage",120,0,85,0,22},{"West passage",-120,0,-85,0,22},
|
||||
{"North gallery approach",24,-149,24,-166,22},{"South gallery approach",-24,149,-24,166,22},
|
||||
{"East gallery approach",150,24,166,24,22},{"West gallery approach",-150,-24,-166,-24,22},
|
||||
{"North ramp",-99,-118,-99,-86,20},{"South ramp",99,118,99,86,20},
|
||||
{"South court bypass",-138,163,-155,177,22},{"North court bypass",138,-163,155,-177,22},
|
||||
{"East upper link",92,-12,79,-12,47},{"West upper link",-92,12,-79,12,47},
|
||||
}
|
||||
for _, spec in guideSpecs do
|
||||
local name, x, z, tx, tz, ceiling = table.unpack(spec :: {any})
|
||||
local position = walkable(x, z, ceiling)
|
||||
local tint = if name:find("gallery") or name:find("upper") then violet else cobalt
|
||||
if name:find("ramp") then tint = gold end
|
||||
local m, origin = rune("Guide · " .. name, "Guide", CFrame.lookAt(position, Vector3.new(center.X + tx, position.Y, center.Z + tz)), tint)
|
||||
flatFootprint(position, origin.CFrame.RightVector, origin.CFrame.LookVector, 2.5, 4.1)
|
||||
for i = 1, 3 do
|
||||
floorArrow(m, origin.CFrame * CFrame.new(0, .16, (2 - i) * 2.65), 4.55, 1.45, tint, i)
|
||||
end
|
||||
end
|
||||
|
||||
local boostColors = {
|
||||
Color3.fromRGB(255, 55, 168),
|
||||
Color3.fromRGB(255, 78, 149),
|
||||
Color3.fromRGB(255, 129, 123),
|
||||
Color3.fromRGB(255, 183, 108),
|
||||
Color3.fromRGB(255, 231, 112),
|
||||
}
|
||||
|
||||
local function triangularInlay(parent: Model, a: Vector3, b: Vector3, c: Vector3, tint: Color3)
|
||||
-- Split along the altitude to the longest edge. Two wedges give the inlay a clean outline.
|
||||
if (c - b).Magnitude > (b - a).Magnitude and (c - b).Magnitude >= (c - a).Magnitude then
|
||||
a, b, c = b, c, a
|
||||
elseif (c - a).Magnitude > (b - a).Magnitude then
|
||||
a, b, c = c, a, b
|
||||
end
|
||||
local edge = (b - a).Unit
|
||||
local corner = a + edge * (c - a):Dot(edge)
|
||||
local rise = c - corner
|
||||
for _, endPoint in {a, b} do
|
||||
local run = endPoint - corner
|
||||
if run.Magnitude < .01 then continue end
|
||||
local y, z = rise.Unit, -run.Unit
|
||||
local wedge = Instance.new("WedgePart")
|
||||
wedge.Name = "LightInlay"
|
||||
wedge.Size = Vector3.new(.08, rise.Magnitude, run.Magnitude)
|
||||
wedge.CFrame = CFrame.fromMatrix(corner + (rise + run) / 2, y:Cross(z), y, z)
|
||||
wedge.Color, wedge.Material, wedge.Transparency = tint, Enum.Material.Neon, .23
|
||||
wedge.Anchored, wedge.CanCollide, wedge.CanTouch, wedge.CanQuery, wedge.CastShadow = true, false, false, false, false
|
||||
wedge.Parent = parent
|
||||
end
|
||||
end
|
||||
|
||||
local function boostChevron(parent: Model, at: CFrame, halfWidth: number, spacing: number, tint: Color3, index: number)
|
||||
local arrow = group(parent, "Chevron" .. index, at, "BoostChase", index)
|
||||
local tip = at.Position + at.LookVector * (spacing * .36)
|
||||
local thickness = -at.LookVector * (spacing * .36)
|
||||
for _, side in {-1, 1} do
|
||||
local wing = at.Position + at.RightVector * (side * halfWidth)
|
||||
triangularInlay(arrow, tip, tip + thickness, wing, tint)
|
||||
triangularInlay(arrow, wing, tip + thickness, wing + thickness, tint)
|
||||
end
|
||||
end
|
||||
|
||||
local function isMainRamp(name: string): boolean
|
||||
return name:match("^A%d+_") ~= nil and (name:find("_ramp_") ~= nil or name:find("_ascent_to_") ~= nil
|
||||
or name:find("^A%d+_Gallery_.+_access_") ~= nil or name:find("_inward_access_") ~= nil
|
||||
or name:find("_terrace_access_") ~= nil)
|
||||
end
|
||||
|
||||
local rampGeometry = RaycastParams.new()
|
||||
rampGeometry.FilterType = Enum.RaycastFilterType.Include
|
||||
rampGeometry.RespectCanCollide = true
|
||||
local ramps: {BasePart} = {}
|
||||
for _, child in arena:GetDescendants() do
|
||||
if child:IsA("BasePart") and child.CanCollide and isMainRamp(child.Name) then table.insert(ramps, child) end
|
||||
end
|
||||
table.sort(ramps, function(a, b) return a.Name < b.Name end)
|
||||
assert(#ramps > 0, "No playable arena ramps found")
|
||||
for _, ramp in ramps do
|
||||
rampGeometry.FilterDescendantsInstances = {ramp}
|
||||
local top = ramp.Position.Y + ramp.Size.Y / 2 + 4
|
||||
local function surfaceAt(point: Vector3): RaycastResult
|
||||
local hit = workspace:Raycast(Vector3.new(point.X, top, point.Z), -Vector3.yAxis * (ramp.Size.Y + 8), rampGeometry)
|
||||
assert(hit and hit.Normal.Y > .6 and hit.Normal.Y < .985, "Expected a ramp slope: " .. ramp.Name)
|
||||
return hit
|
||||
end
|
||||
local mid = surfaceAt(ramp.Position)
|
||||
local normal = mid.Normal
|
||||
local downhill = Vector3.new(normal.X, 0, normal.Z).Unit
|
||||
local alongX = math.abs(downhill.X) > .5
|
||||
local length = if alongX then ramp.Size.X else ramp.Size.Z
|
||||
local width = if alongX then ramp.Size.Z else ramp.Size.X
|
||||
local lower = surfaceAt(mid.Position + downhill * (length * .20))
|
||||
local forward = -downhill * normal.Y + Vector3.yAxis * math.sqrt(1 - normal.Y ^ 2)
|
||||
local at = CFrame.lookAt(lower.Position, lower.Position + forward, normal)
|
||||
local halfWidth = width * .41
|
||||
local halfLength = math.min(14, length / normal.Y * .24)
|
||||
for _, x in {-halfWidth, 0, halfWidth} do
|
||||
for _, z in {-halfLength, 0, halfLength} do
|
||||
local point = at:PointToWorldSpace(Vector3.new(x, 0, z))
|
||||
local hit = workspace:Raycast(point + Vector3.yAxis * 5, -Vector3.yAxis * 6, geometry)
|
||||
assert(hit and hit.Instance == ramp and (hit.Position - point).Magnitude < .10,
|
||||
"Booster does not fit the ramp surface: " .. ramp.Name)
|
||||
end
|
||||
end
|
||||
local m, origin = rune("Boost · " .. ramp.Name, "Boost", at, boostColors[3])
|
||||
m:SetAttribute("HalfWidth", halfWidth)
|
||||
m:SetAttribute("HalfLength", halfLength)
|
||||
local spacing = halfLength * 2 / #boostColors
|
||||
for i, tint in boostColors do
|
||||
local pose = at * CFrame.new(0, .15, (3 - i) * spacing)
|
||||
boostChevron(m, pose, halfWidth * (1 - (i - 1) * .022), spacing, tint, i)
|
||||
end
|
||||
light(origin, boostColors[2], 13, 0)
|
||||
end
|
||||
|
||||
local jumpSpecs = {
|
||||
{"North Gallery",24,-166,0,-1},{"South Gallery",-24,166,0,1},
|
||||
{"East Gallery",166,24,1,0},{"West Gallery",-166,-24,-1,0},
|
||||
{"East Citadel",79,-12,-1,0},{"West Citadel",-79,12,1,0},
|
||||
}
|
||||
for _, spec in jumpSpecs do
|
||||
local name, x, z, dx, dz = table.unpack(spec :: {any})
|
||||
local position = walkable(x, z, 110)
|
||||
local m, origin = rune("Jump · " .. name, "Jump", CFrame.lookAt(position, position + Vector3.new(dx, 0, dz)), violet)
|
||||
local at = origin.CFrame
|
||||
flatFootprint(position, at.RightVector, at.LookVector, 4, 4)
|
||||
disc(m, "RuneSlab", at * CFrame.new(0, .16, 0), 5.2, .24, dark, false)
|
||||
ring(m, at * CFrame.new(0, .31, 0), 4.88, violet, 14, "OuterRing")
|
||||
ring(m, at * CFrame.new(0, .32, 0), 3.35, violet, 8, "InnerRing")
|
||||
for i = 0, 7 do
|
||||
local angle = i * math.pi / 4
|
||||
part(m, "EdgeCrystal", Vector3.new(.39, .16, .39), at * CFrame.new(math.cos(angle) * 4.15, .38, math.sin(angle) * 4.15)
|
||||
* CFrame.Angles(0, angle + math.pi / 4, 0), if i % 2 == 0 then ice else violet, true)
|
||||
end
|
||||
for i = 1, 2 do
|
||||
local pose = at * CFrame.new(0, .75 + i * .72, -.12)
|
||||
local glyph = group(m, "LiftGlyph" .. i, pose, "Lift", i)
|
||||
for _, side in {-1, 1} do
|
||||
bar(glyph, "RisingStroke", pose, Vector3.new(.97 * side, -.33, 0), Vector3.new(0, .34, 0), .19, .15, if i == 1 then violet else ice)
|
||||
end
|
||||
end
|
||||
light(origin, violet, 16, 3)
|
||||
end
|
||||
|
||||
local existing = arena:FindFirstChild(set.Name)
|
||||
if existing then
|
||||
for _, model in existing:GetChildren() do
|
||||
local kind = model:GetAttribute("Kind")
|
||||
if kind == "Boost" or kind == "Landing" then
|
||||
model:Destroy()
|
||||
elseif kind == "Jump" then
|
||||
local destination = model:FindFirstChild("Destination")
|
||||
if destination then destination:Destroy() end
|
||||
end
|
||||
end
|
||||
for _, model in set:GetChildren() do
|
||||
if model:GetAttribute("Kind") == "Boost" or not existing:FindFirstChild(model.Name) then model.Parent = existing end
|
||||
end
|
||||
set:Destroy()
|
||||
else
|
||||
set.Parent = arena
|
||||
end
|
||||
return count
|
||||
@@ -0,0 +1,51 @@
|
||||
-- Studio Edit command: create spawn markers on the already imported arena.
|
||||
local arena = workspace:FindFirstChild("HunterMonolithImport")
|
||||
assert(arena and not arena:FindFirstChild("PlayerSpawns"), "Arena missing or spawns already exist")
|
||||
local ray = RaycastParams.new()
|
||||
ray.FilterType = Enum.RaycastFilterType.Include
|
||||
ray.FilterDescendantsInstances = {arena}
|
||||
ray.RespectCanCollide = true
|
||||
local overlap = OverlapParams.new()
|
||||
overlap.FilterType = Enum.RaycastFilterType.Include
|
||||
overlap.FilterDescendantsInstances = {arena}
|
||||
overlap.RespectCanCollide = true
|
||||
local points = {{-368,-352},{-352,368},{368,352},{352,-368},{-240,-112},{240,112},{112,-240},{-112,240},{0,-320},{0,320},{-320,0},{320,0}}
|
||||
local folder = Instance.new("Folder")
|
||||
folder.Name = "PlayerSpawns"
|
||||
for index, xz in points do
|
||||
local x,z = 1600+xz[1],xz[2]
|
||||
local hit = workspace:Raycast(Vector3.new(x,160,z),Vector3.new(0,-180,0),ray)
|
||||
assert(hit and hit.Normal.Y > .95, "No flat floor at spawn "..index)
|
||||
assert(#workspace:GetPartBoundsInBox(CFrame.new(hit.Position+Vector3.new(0,4.2,0)),Vector3.new(8,8,8),overlap)==0,"Blocked spawn "..index)
|
||||
local spawn = Instance.new("SpawnLocation")
|
||||
spawn.Name = string.format("%02d_%s",index,if index<=8 then "Courtyard" else "Gallery")
|
||||
spawn.Size = Vector3.new(6,2,6)
|
||||
local position = hit.Position-Vector3.new(0,1,0)
|
||||
spawn.CFrame = CFrame.lookAt(position,Vector3.new(1600,position.Y,0))
|
||||
spawn.Transparency = 1
|
||||
spawn.Anchored = true
|
||||
spawn.CanCollide = false
|
||||
spawn.CanTouch = false
|
||||
spawn.CanQuery = false
|
||||
spawn.Neutral = true
|
||||
spawn.Enabled = true
|
||||
spawn.Duration = 3
|
||||
spawn:SetAttribute("FloorY",hit.Position.Y)
|
||||
spawn.Parent = folder
|
||||
end
|
||||
folder.Parent = arena
|
||||
local botChanges = {}
|
||||
for _, marker in workspace.BotSpawns:GetChildren() do
|
||||
if marker:IsA("BasePart") then
|
||||
local old = marker.CFrame
|
||||
local pos = marker.Position
|
||||
if pos.X < 1152 or pos.X > 2048 or math.abs(pos.Z)>432 then pos=Vector3.new(1712,8,-200) end
|
||||
local hit=workspace:Raycast(Vector3.new(pos.X,20,pos.Z),Vector3.new(0,-24,0),ray)
|
||||
assert(hit,"No bot floor: "..marker.Name)
|
||||
marker.CFrame = CFrame.new(hit.Position+Vector3.new(0,marker.Size.Y/2,0))*old.Rotation
|
||||
marker.Anchored=true marker.CanCollide=false marker.CanTouch=false marker.Transparency=1
|
||||
table.insert(botChanges,{name=marker.Name,before={old:GetComponents()},after={marker.CFrame:GetComponents()}})
|
||||
end
|
||||
end
|
||||
return game:GetService("HttpService"):JSONEncode({spawns=#folder:GetChildren(),botChanges=botChanges})
|
||||
|
||||
Reference in new issue
Block a user