Forum

> > CS2D > Scripts > How to check if the server is playing a sound
Forums overviewCS2D overview Scripts overviewLog in to reply

English How to check if the server is playing a sound

30 replies
Page
To the start Previous 1 2 Next To the start

old Re: How to check if the server is playing a sound

Zeik
User Off Offline

Quote
I forgot to change queueSound:
1
2
3
function queueSound(id, queue, sound)
  List.push(queue[id], sound)
end

It should work now:
More >

old Sound durations

VADemon
User Off Offline

Quote
That's a quick and simple way to make a list with sound durations:
Code >

• Download ffmpeg's "ffprobe.exe" and put it to CS2D root folder (ffmpeg package for Linux)
• Put the script to autorun/
• Start in-game server and type this in console: "lua soundtime.export()"
• Wait 2-10 minutes
∗ cs2d/soundtime.lua will contain the sound times

° Some files will not return a duration because ffmpeg thinks they're corrupt

Load this list with:
1
local longtablenamesmakemytaillonger = dofile("soundtime.lua")

The table consists of
["sound path"] = "duration in seconds"

old Re: How to check if the server is playing a sound

Mami Tomoe
User Off Offline

Quote
@user Zeik: One error has left:
1
2
3
4
5
6
LUA ERROR: sys/lua/cool stuff/play.lua:27: attempt to index local 'list' (a nil value)
 -> sys/lua/cool stuff/play.lua:27: in function 'push'
 -> sys/lua/cool stuff/play.lua:61: in function 'queueSound'
 -> sys/lua/cool stuff/main.lua:4: in main chunk
 -> [C]: in function 'dofile'
 -> sys/lua/server.lua:2: in main chunk

I have a question how to call
sv_sound
and how to call
sv_sound2
?
is it
queueSound(0,queue,sound[1])
for all and change 0 to id for one?

I also sometimes get this in console is that normal?
1
FATAL ERROR [UNHANDLED EXCEPTION]: CreateSoundBuffer failed (87)

old Re: How to check if the server is playing a sound

Zeik
User Off Offline

Quote
@user Mami Tomoe: You have to create the queue like this:
1
queue = Array.newLists(32)
Are you doing it that way?



You call queueSound with 0 when the sound is for all:
1
queueSound(0, queue, sounds[1])

And with id when it's private:
1
queueSound(id, queue, sounds[1])

old Re: How to check if the server is playing a sound

Mami Tomoe
User Off Offline

Quote
Yeah I have exactly the code you gave me in that more tag all I changed was the table for sounds

Isn't the list meant to be List?

When I put l
ua queueSound(0,queue,sounds[1])
in console I get this thing:
1
FATAL ERROR [UNHANDLED EXCEPTION]: CreateSoundBuffer failed (87)
And after a few seconds CS2D stops responding
edited 3×, last 24.01.17 03:28:04 pm

old Re: How to check if the server is playing a sound

Zeik
User Off Offline

Quote
EDIT: Okay I debugged it and found out this:
1
2
3
function killSound(id)
  isSoundRunning[id] = false
end
The timer function was sending a id string and I forgot to convert it to number so it actually never "killed" the sound.

Here's the completely functional script with an example:
More >
edited 2×, last 24.01.17 06:41:28 pm

old Re: How to check if the server is playing a sound

Mami Tomoe
User Off Offline

Quote
I have fixed a few bugs and now the script works but after a few seconds the script stops working with no errors at all so I did some debugging and I found this:

isSoundRunning[1]
is true even though there is no sound running.
Setting
isSoundRunning[1]
to false manually prints that:
1
FATAL ERROR [UNHANDLED EXCEPTION]: CreateSoundBuffer failed (87)
and will leave the isSoundRunning[1] as true unless I enter it a few more times.

old Re: How to check if the server is playing a sound

Zeik
User Off Offline

Quote
I pointed out the solution in the comment just before yours

I tested it and it works perfectly. So if it doesn't work then you're doing something wrong with it.

PS: If you don't understand how it works or don't mind understanding it, then I'd recommend you to leave it as it is so you don't break anything.
Just modify this with your own sounds:
1
sounds = {{"fun/doublekill.wav",1000}, {"fun/firstblood.wav",1000}}
And then play a sound using only this function call changing the id argument for 0 if its a global sound or with a number between 1 and 32 to play it for a specific player only:
1
queueSound(id, queue, sounds[1])
If you change anything else in the script then you may mess up and it's up to you to fix it.

old Re: How to check if the server is playing a sound

Mami Tomoe
User Off Offline

Quote
Thank you it all works now!
One last problem though is that when both functions are being used then both sounds will play, like the following:

1
2
queueSound(0,queue,sounds[2])
queueSound(id,queue,sounds[3])

In this case
id
will hear both sounds while other players only one
id
should be able to hear both sounds though
edited 1×, last 25.01.17 02:02:51 pm

old Re: How to check if the server is playing a sound

Zeik
User Off Offline

Quote
If you want it like that then just change queueSound for this:

1
2
3
4
5
6
7
8
9
function queueSound(id, queue, sound)
  if (id ~= 0) then
    List.push(queue[id], sound)
  else
    for i in ipairs(queue) do
      List.push(queue[i], sound)
    end
  end
end
To the start Previous 1 2 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview