This commit is contained in:
Leshyi committed 2026-11-29 19:48:57 +05:00
1 parent 82eecfda06
commit bdf5eca81f
10 files changed
+287 -94

No files matched your search

+24 -19
View File
@@ -4,26 +4,31 @@ local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Sounds = require(ReplicatedStorage:WaitForChild("SniperEffects") :: ModuleScript)
local playerGui = Players.LocalPlayer:WaitForChild("PlayerGui")
local hoverDef = Sounds.SOUNDS.ButtonHover
-- The supplied recording has about 0.38 seconds of silence before the cue.
local HOVER_START_SECONDS = .38
local hover = Instance.new("Sound")
hover.Name = "SniperButtonHover"
hover.SoundId = hoverDef.id
hover.PlaybackSpeed = hoverDef.speed
hover.Parent = game:GetService("SoundService")
script.Destroying:Once(function() hover:Destroy() end)
local function prepareCue(name: string, startSeconds: number): () -> ()
local def = Sounds.SOUNDS[name]
local sound = Instance.new("Sound")
sound.Name = "Sniper" .. name
sound.SoundId = def.id
sound.PlaybackSpeed = def.speed
sound.Parent = game:GetService("SoundService")
script.Destroying:Once(function() sound:Destroy() end)
local function playHover()
if not hover.IsLoaded then return end
local volume = hoverDef.volume * math.max(Sounds.setting("VolMaster", 1), 0)
* math.max(Sounds.setting("Vol" .. hoverDef.group, 1), 0)
if volume <= 0 then return end
hover:Stop()
hover.Volume = volume
hover.TimePosition = HOVER_START_SECONDS
hover:Play()
return function()
if not sound.IsLoaded then return end
local volume = def.volume * math.max(Sounds.setting("VolMaster", 1), 0)
* math.max(Sounds.setting("Vol" .. def.group, 1), 0)
if volume <= 0 then return end
sound:Stop()
sound.Volume = volume
sound.TimePosition = startSeconds
sound:Play()
end
end
-- Start each recording just before its measured onset.
local playHover = prepareCue("ButtonHover", .38)
local playPress = prepareCue("ButtonPress", .035)
local bound: {[GuiButton]: boolean} = setmetatable({}, {__mode = "k"})
local function bindButton(instance: Instance)
@@ -38,7 +43,7 @@ local function bindButton(instance: Instance)
end)
button.Activated:Connect(function()
if button:IsDescendantOf(playerGui) then
Sounds.sound("ButtonPress")
playPress()
end
end)
end