• CreateSound randomly stops the sound
    5 replies, posted
Hi everybody, I am currently making an addon for TTT which plays music from CSGO after the round ends. It plays the "music/valve_csgo_01/wonround.mp3" when you win and "music/valve_csgo_01/lostround.mp3" when you loose. The code is pretty simple. Here is a part of it: if SERVER then util.AddNetworkString( "RoundEndSound" ) hook.Add( "TTTEndRound", "CS_RoundEndSound", function( result )  net.Start( "RoundEndSound" ) net.WriteFloat( result ) net.Send( player.GetAll() ) end) end if CLIENT then net.Receive( "RoundEndSound", function() local ply = LocalPlayer() local r = net.ReadFloat() if ply:GetRole() == ROLE_INNOCENT || ply:GetRole() == ROLE_DETECTIVE then if r == 3 || r == 4 then if file.Exists( "sound/music/valve_csgo_01/wonround.mp3", "GAME" ) then local song = CreateSound( ply, "music/valve_csgo_01/wonround.mp3" ) song:SetSoundLevel( 0 ) song:Play() else print( "failed" ) end else if file.Exists( "sound/music/valve_csgo_01/lostround.mp3", "GAME" ) then local song = CreateSound( ply, "music/valve_csgo_01/lostround.mp3" ) song:SetSoundLevel( 0 ) song:Play() else print( "failed" ) end end elseif ply:GetRole() == ROLE_TRAITOR then if r == 2 then if file.Exists( "sound/music/valve_csgo_01/wonround.mp3", "GAME" ) then local song = CreateSound( ply, "music/valve_csgo_01/wonround.mp3" ) song:SetSoundLevel( 0 ) song:Play() else print( "failed" ) end else if file.Exists( "sound/music/valve_csgo_01/lostround.mp3", "GAME" ) then local song = CreateSound( ply, "music/valve_csgo_01/lostround.mp3" ) song:SetSoundLevel( 0 ) song:Play() else print( "failed" ) end end end end) end Simple enough right? The problem is that the song randomly stops playing after a few seconds. Sometimes after 5 seconds sometimes after 15. I've tried using this server side but it didn't work either. At first I used surface.PlaySound and it worked fine, but I have to be able to stop the sound. I hope somebody can help me with this.
I've tried it and it didn't work. This is how it's supposed to be: (using surface.PlaySound() ) https://www.youtube.com/watch?v=SuqzUa4irRE and here I'm using CreateSound(): https://www.youtube.com/watch?v=4Umpd_1t4Q0
Just use http://wiki.garrysmod.com/page/surface/PlaySound
Ok I fixed it. It was TTT's fault. TTT stops all sounds at the start of a new round. I thought it would stop the Play() function from running too. But it didn't. I didn't hear anything but the function kept running and thus created this bug. I just have to call Stop() at the start of the round.
Sorry, you need to Log In to post a reply to this thread.