AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Need help looping sounds! (https://forums.alliedmods.net/showthread.php?t=49890)

Bad_Bud 01-15-2007 04:09

Need help looping sounds!
 
I have a set_task that is called every 0.01 seconds.

I want to loop a 1 second long sound inside of this set_task.

How would I do this?

dutchmeat 01-15-2007 04:12

Re: Need help looping sounds!
 
You can't, you will have to make a function,
don't know if this is good for you, but it should work.

Code:
new soundloop[33] public plugin_init() {  register_plugin("somesoundplugin","1.0a", "Some strange guy") } public somefunction(id){  soundloop[id] = 1  sound(id)  set_task(1.0,resetloop,id) } public sound(id){ if (soundloop[id] != 1)  return PLUGIN_HANDLED emit_sound(id,CHAN_VOICE,"misc/mysound.wav", 1.0, ATTN_NORM, 0, PITCH_NORM) sound(id) } public resetloop(id){  soundloop[id] = 0 } public plugin_precache() {      precache_sound("misc/mysound.wav")      return PLUGIN_CONTINUE }

Bad_Bud 01-15-2007 04:39

Re: Need help looping sounds!
 
I'm actually kind of wondering why this method won't work:

PHP Code:

new Float:SoundTimer[33]
 
set_task(0.01,"My_0.01_settask",0,"",0,"b")
 
public 
client_putinserver(id)
   
SoundTimer[id]=halflife_time()
 
public 
My_0.01_settask(id)
{
if(
SoundTimer[id]-halflife_time()>1.0)
   {
    
emit_sound(id,CHAN_ITEM,"mysoundloop.wav",1.0,ATTN_NORM,0,PITCH_NORM)
    
SoundTimer[id]=halflife_time()
   }


I could possibly try to mimic having it timed, since theoretically it should go through this task 10 times each sound play, so I could just keep track of it that way, but I'm not sure if that's where the problem is or not.

dutchmeat 01-15-2007 04:43

Re: Need help looping sounds!
 
well first of all, you don't execute 'My_0.01_settask', but the problem is that that function isn't really looped, or executed every frame.
So this check:
if(SoundTimer[id]-halflife_time()>1.0)
is only called one time.

Bad_Bud 01-15-2007 05:05

Re: Need help looping sounds!
 
I was implying that I had a settask looping it. I'll fix that.

dutchmeat 01-15-2007 05:55

Re: Need help looping sounds!
 
you should also put 'public' infront of 'My_0.01_settask(id)'

Bad_Bud 01-15-2007 15:25

Re: Need help looping sounds!
 
...piddly stuff aside, how can I make this work in theory.

XxAvalanchexX 01-15-2007 16:16

Re: Need help looping sounds!
 
SoundTimer[id]-halflife_time() will be a negative value. You want to do this the other way around.

Bad_Bud 01-15-2007 22:35

Re: Need help looping sounds!
 
AH! *gives you 18 flies* :)

Bad_Bud 01-15-2007 22:46

Re: Need help looping sounds!
 
Hmm, well it works great, but I have another question. Is there a way to play only part of a sound? Once you tap your jetpack key once, you're committed to playing the whole one second sound loop, and it's kind of awkward.


All times are GMT -4. The time now is 22:24.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.