657 lines
26 KiB
Luau
657 lines
26 KiB
Luau
--!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 = {}
|
|
local AudioConfig = require(game:GetService("ReplicatedStorage"):WaitForChild("Hunter"):WaitForChild("EffectsConfig") :: ModuleScript)
|
|
local activeCues: {Sound} = {}
|
|
|
|
-- 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 },
|
|
ButtonHover = { id = "rbxassetid://84648433095796", volume = 0.22, speed = 1, near = 0, far = 0, group = "HUD" },
|
|
ButtonPress = { id = "rbxassetid://121882355123711", volume = 0.27, speed = 1, near = 0, far = 0, group = "HUD" },
|
|
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
|
|
}
|
|
local arenaCues: {[string]: boolean} = {}
|
|
local function addCue(name: string, cue: AudioConfig.Cue)
|
|
SOUNDS[name] = {id = cue.id, volume = cue.volume, speed = cue.speed, near = 0, far = 0, group = "HUD"}
|
|
arenaCues[name] = true
|
|
end
|
|
for name, cue in AudioConfig.Cues do addCue(name, cue) end
|
|
for name, target in AudioConfig.Aliases do addCue(name, AudioConfig.Cues[target]) end
|
|
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 = {}
|
|
local seen: {[string]: boolean} = {}
|
|
for _, def in SOUNDS do
|
|
if def.id == "" or seen[def.id] then continue end
|
|
seen[def.id] = true
|
|
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 or def.id == "" 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 limited = arenaCues[name]
|
|
if limited then
|
|
for i = #activeCues, 1, -1 do
|
|
if not activeCues[i].Parent then table.remove(activeCues, i) end
|
|
end
|
|
if #activeCues >= AudioConfig.SoundLimit then
|
|
-- Убираем самый тихий сигнал. Если новый ещё тише, оставляем текущий микс.
|
|
local quietest = 1
|
|
for i = 2, #activeCues do
|
|
if activeCues[i].Volume < activeCues[quietest].Volume then quietest = i end
|
|
end
|
|
if activeCues[quietest].Volume > volume then return nil end
|
|
table.remove(activeCues, quietest):Destroy()
|
|
end
|
|
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
|
|
if limited then table.insert(activeCues, s) end
|
|
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
|