I am trying to create a script where if the player is sprinting, then it will play my sounds in an random order with a one second delay between each sound.
Example: "huff" wait a sec "puff" wait a sec "huff"
Here is what I have so far:
hook.Add( "PlayerTick", "vSoundBreath", BreathingSounds1)
local function BreathingSounds1(ply, mv)
sound.Add( {
name = "breathsound1",
channel = CHAN_STATIC,
volume = 1.0,
level = 80,
pitch = 100 * GetConVarNumber("host_timescale"),
sound = "michael_breathing/breath"..math.random(1,18)..".wav"
} )
//local pitch = 100 * GetConVarNumber("host_timescale")
//local volume = 300
for k,v in pairs(player.GetAll()) do
if v:Health() <= 0 then return end
if ply:IsSprinting() == true then
ply:EmitSound( "breathsound1" )
end
if ply:IsSprinting() == false then
ply:StopSound( "breathsound1" )
end
end
end
It works, but the only problem I am having is that when I sprint it plays a crap ton of sounds at once.
Is there maybe a better hook for this?
EDIT: I've kinda got it working with this
hook.Add( "PlayerTick", "vSoundBreath", BreathingSounds1)
local function BreathingSounds1(ply)
timer.Create( "breathtimer1", 1, 0, function ()
sound.Add( {
name = "breathsound1",
channel = CHAN_STATIC,
volume = 0.5,
level = 40,
pitch = 100 * GetConVarNumber("host_timescale"),
sound = "michael_breathing/breath"..math.random(1,18)..".wav"
} )
for k,v in pairs(player.GetAll()) do
if v:Health() <= 0 then return end
if ply:Alive() then
if ply:IsSprinting() == true then
ply:EmitSound( "breathsound1" )
end
if ply:IsSprinting() == false then
ply:StopSound( "breathsound1" )
end
end
end
end )
end
The only issue is that it adds a new sound each time. And if I put the timer outside of it, it won't randomize the sound. Anyone know how I can prevent it from doing that?
Move sound creation out from hook and timer.
In main chunk make a for loop from 1 to 18 and add all of these sound.
Then play them randomly in the hook
Sorry, I forgot to reply back.
I just used audacity to mix the sound files and have 0.5 second delays between each sound then made it one sound file.
Thanks for the help though, and I'm sure someone will find these methods handy 👍
It's a yeet
Sorry, you need to Log In to post a reply to this thread.