Index sounds to be played.

So I am working on a multi-Kill and Kill streak announcement system and both sets use sounds. The sounds can be called at the same time which will cause them to over lap. I was wondering how I could set a up system that would insert the sounds into a table then play them one after the other in the order they were inserted.

I have a rough idea on how to go about it but I am not completely sure.

[lua]local index = 1
local TabeldSounds = {
}

function KIndexSound(um)
table.insert(TabeldSounds,index,um:ReadString())
index = index + 1
end
usermessage.Hook(“ksendsound”,KIndexSound)[/lua]

This is what I have at the moment. Not sure how to continue from here.

[lua]

local beingPlayed = { }

function KIndexSound(um)

local length = um:ReadFloat()

table.insert( beingPlayed, um:ReadString() )

KPlaySound( um:ReadString() )

timer.Simple( length, function() table.remove( beingPlayed, 1 ) end )

end

usermessage.Hook(“ksendsound”,KIndexSound)

function KPlaySound( sound )

 if #beingPlayed > 1 then

      timer.Simple( 1, function() KPlaySound( sound ) end )

 else

      --play your damn sound son

 end

end

[/lua]

Try this, not sure if it’ll work well though.

You need to know the sound length in seconds though and send it through the usermessage.

There appears to be something weird going on with the string during all of this

http://puu.sh/5EzsP.png

Make sure your files have english letters only in them.

They all do. They worked fine before.

Uh I didn’t notice you were using umsgs, post the code you are using, both sending and receiving.

Here is the sending

[lua]function SendSound(Sound,ply)
umsg.Start(“ksendsound”,ply)
umsg.String(Sound)
umsg.Float(SoundDuration(Sound))
umsg.End()
end
[/lua]

The receiving is exactly how it is in arcaneex’s code above.

You must read the variables in the same order you send them. So,


usermessage.Hook("ksendsound",function (um)

local snd = um:ReadString()
local length = um:ReadFloat()

table.insert( beingPlayed, snd )

KPlaySound( snd )

timer.Simple( length, function() table.remove( beingPlayed, 1 ) end ) -- This isn't going to work.

end )


Alright, I wasn’t sure about that. I know that’s not going to work. I could already tell by the pattern of the sound errors.

What are you talking about?

Your comment in the code about the timer not going to work. I knew that already because of the pattern and frequency that the “could not find sound” errors were given.

I spent a few hours fucking around and ended up creating one.

woot I guess.