Nextbot, play a series of sounds, or pause/sleep functions?

So, i’m trying to make a Metrocop Nextbot, and as you may know, when the normal NPC Metrocop dies, sometimes the Dispatcher will say something like “Lost Biosignal from Protection Team Unit, Patrol 6” after the Metrocop plays its death sound.

I’m trying to do that with my bot; make it emit a series of sounds that do not interrupt each other, but i can’t seem to find out how to get the function to pause or sleep in any feasible way.

I can’t use coroutine.wait, because it only works in the RunBehave function, and i need this to run in the OnKilled Function

I can’t use a busywait, because that pauses the ENTIRE GAME for the given time.

timer.Simple dosen’t seem to work without a function inside it, and it doesn’t seem to like functions that contain “self” anywhere in them, but i’m not sure i’m using them correctly.

Anyone know a way to play a series of sounds, or to make a function pause or sleep for a given time?

Nextbots fire On take damage hooks, so you shouldn’t have an issue with it playing more than once unless you’re firing it somewhere else and not detecting death shot. Nextbots also have a hook for death which is OnKilled:

Not to be rude, but did you read my post?
I know what those hooks are.

My problem is that i want to be able to pause them, so i can play a series of sounds back-to-back without them overlapping.

Ah, my bad… I thought you had the issue where it was spamming the same sound…

You could set up a sound-queue, and Pop sounds as they are to be played. Use SoundDuration, or GetLength ( for GMOD Audio ) to get the duration of the sounds. You could use timers to pop and play the next sound, or a think.

It wouldn’t be too difficult to set up a system to manage this. If you do use Think to control it, I’d recommend activating the hook when the first sound is added, and remove it after the last sound is played.

If SoundDuration or GetLength fails, you can GetState to see if it is playing ( GMOD Audio ), or IsPlaying will work for other sounds. You should also check to make sure the sound isn’t set to loop, otherwise the IsPlaying / GetState == playing will always return true.