'LinKin Posted March 12, 2014 Share Posted March 12, 2014 Hello, I'm using playSound function. So it plays a sound when something happens in game, but, there exists the possibility that 2 events are triggered with a veery small difference of time, so I think that the sounds would mix up. Meaning that the player will not hear clearly. How could I avoid this? Like, just when it finishes playing the first sound, it starts to play the other one. Thanks. Link to comment
Moderators Citizen Posted March 13, 2014 Moderators Share Posted March 13, 2014 Try this: local soundQueue = {} local currentSound local canPlay = true function playLatentSound( path ) if not path or type( path ) ~= "string" then return end local snd = playSound( path ) if not canPlay then setSoundPaused( snd, true ) table.insert( soundQueue, snd ) else currentSound = snd canPlay = false end end function whenSoundStops ( ) if source ~= currentSound or #soundQueue < 1 then return end local nextSnd = soundQueue[1] if nextSnd and getElementType( nextSnd ) == "sound" then setSoundPaused( nextSnd, false ) table.remove( soundQueue, 1 ) currentSound = nextSound else canPlay = true end end addEventHandler( "onClientSoundStop", root, whenSoundStops) Use playSoundLatent instead of playSound. Note that this system obviously won't support the looped argument. (I wrote everything from my phone. Took me a lot of time but I hope it will work.) I just got another idea if you need to prevent the sound mixing for all sounds (even those that are coming from other resources. Link to comment
'LinKin Posted March 13, 2014 Author Share Posted March 13, 2014 (edited) Thanks. Got the idea but look. This is the event to use, and it's only from 1.4 ONWARDS. onClientSoundStopping Hmm, I will try another way. I will tell you if it works Edited March 13, 2014 by Guest Link to comment
Castillo Posted March 13, 2014 Share Posted March 13, 2014 The wiki is wrong, the event "onClientSoundStopped" is available on MTA 1.3.5, I just tested. Link to comment
'LinKin Posted March 13, 2014 Author Share Posted March 13, 2014 Oh well, Ok But I've done it this way: And I think it's pretty the same.. addEventHandler("onClientElementDestroy", root, function() if source == currentSound then canPlay = true if #soundQueue >= 1 then local nextSnd = soundQueue[1] if nextSnd and getElementType( nextSnd ) == "sound" then setSoundPaused( nextSnd, false ) table.remove( soundQueue, 1 ) currentSound = nextSnd end end end end) Took it from here: https://forum.multitheftauto.com/viewtopic.php?f ... 3&p=398931 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now