tommysticks Posted October 5, 2016 Share Posted October 5, 2016 (edited) Does anyone know how to stop a sound once it has been started? function saber_func() local player = getPlayer(); if player:getPrimaryHandItem():getType() == "lightsaber" and player:getPrimaryHandItem() ~= nil then timeDown = timeDown - 1; if timeDown <= 0 then timeDown = 25; end if timeDown == 24 then local idleSound = ZombRand(2); if idleSound == 1 then getSoundManager():PlayWorldSoundWav('saber_idle_1', false, getPlayer():getSquare(), 0, 4, 1, false); else getSoundManager():PlayWorldSoundWav('saber_idle_2', false, getPlayer():getSquare(), 0, 4, 1, false); end end print(timeDown); else end -- 332 updates in 10 seconds -- 316 ticks in 10 seconds end Events.OnPlayerUpdate.Add(saber_func); In the above code I have it where if you are idle with weapon "lightsaber" in your hand one of 2 random sounds (that are 1.5 seconds*) will play every ~1.4 seconds. This is achieved by a countdown timer but this method sucks because the 2 sounds have to overlap each other and the sound will continue to play even if you un-equip the lightsaber for the remainder of the sound clip. *times are approximate I would rather have a longer idle sound wave that loops when it is finished and stops playing once lightsaber has been un-equipped. Anyone know how to achieve this? If I'm reading the Java Dec correctly, the function PlayWorldSoundWav has a boolean for looping sounds, however, I haven't been able to get any sounds to loop using any function provided: public abstract Audio PlayWorldSoundWav(java.lang.String name, boolean loop, IsoGridSquare source, float pitchVar, float radius, float maxGain, boolean ignoreOutside) Any insight would be appreciated. Thanks. Edited October 5, 2016 by tommysticks Ʀocky 1 Link to comment Share on other sites More sharing options...
nolanri Posted October 19, 2016 Share Posted October 19, 2016 I could not get any sound to loop when I tried as well. I eventually gave up and ended up replaying the sound with a small overlap instead. Ʀocky 1 Link to comment Share on other sites More sharing options...
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