English How to check if the server is playing a sound

30 replies
Goto Page
To the start Previous 1 2 Next To the start
Up
Mami Tomoe
User
Offline Off
Hi I want to make a script that plays sounds but I don't want the sounds to play all together I want it to play by order and the sounds will be chosen randomly so I can't use timers plz help thx bye
It's hard being the best girl in the whole entire world
21.01.17 06:29:46 pm
Up
Masea
Super User
Offline Off
You must use time, second/ms100 hook or anything about time. Do a true parameter whenever sound starts. Save its second duration at another parameter. Then do something like when that duration parameter bigger than 0, reduce it by 1 at second hook. When duration parameter reached to 0, then false the first parameter I said.

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
par1 = false
par2 = 0

function sound_(path)
     if par1 then return end
     parse("sv_sound ...")
     par1 = true
     par2 = SOUND'S SECOND DURATION
end

addhook("second","sec")
function sec()
     if par2 > 0 then
          par2 = par2 - 1
     else
          par1 = false
     end
end

You can do it even using only duration parameter.
Shit your pants: file cs2d Outlast II Mod (29) | Create your UI faster: CS2D UI Framework
21.01.17 07:08:21 pm
Up
THEMUD
User
Offline Off
@user Mami Tomoe: How will the sounds get triggered? By pressing a button or by saying a specific text?
I don't know what I'm doing with my life.
21.01.17 08:40:21 pm
Up
Mami Tomoe
User
Offline Off
By killing and @user Masea: your method is too hard I have like 20 or more sounds and they are all triggered randomly
It's hard being the best girl in the whole entire world
21.01.17 08:54:40 pm
Up
Masea
Super User
Offline Off
Use tables then.
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
SOUNDS = {
     [1] = {
          path = "wada.wav",
          duration = 132, --sec
     },
     [2] = {
          path = "asdasdasd.wav",
          duration = 92, --sec
     }
}

local randomsound = math.random(1,#SOUNDS)
parse('sv_sound '..SOUNDS[randomsound].path)

Trust me, this is not hard...
Shit your pants: file cs2d Outlast II Mod (29) | Create your UI faster: CS2D UI Framework
21.01.17 09:50:55 pm
Up
Mami Tomoe
User
Offline Off
Yeah but each kill triggers a random sound and has a chance to trigger even more sounds like double kill + godlike and other players might kill as well and this will also show images on screen so I really need to check if it's playing a sound...
It's hard being the best girl in the whole entire world
21.01.17 09:53:41 pm
Up
THEMUD
User
Offline Off
@user Mami Tomoe: Try this code, I'm not sure if this is what you are demanding.
Code:
1
2
3
4
5
6
7
8
9
10
11
sounds = {
     [1] = "sfx/NAME1.wav";
     [2] = "sfx/NAME2.wav";
     [3] = "sfx/NAME3.wav";
};

function _kill(id)
     parse("sv_sound "..sounds[math.random(1, #sounds)]);
end

addhook("kill", "_kill")

You can put more sound files in the table by providing its name, extension and path.
I don't know what I'm doing with my life.
21.01.17 09:57:35 pm
Up
Mami Tomoe
User
Offline Off
Kill has a chance to play a sound or more
For example:
Double kill!
Legendary!

and other players might kill as well so I don't want the sounds to play all together so plz is there a way to just CHECK if a sound is being played?? plz @user DC: or anyyyy @user Omghelpme:
It's hard being the best girl in the whole entire world
21.01.17 10:08:22 pm
Up
THEMUD
User
Offline Off
@user Mami Tomoe: What about if the sound plays only for the killer? Will that solve your issue?
I don't know what I'm doing with my life.
21.01.17 11:41:40 pm
Up
Masea
Super User
Offline Off
@user Mami Tomoe: Don't forget my first post dude. I did what you've wanted from us already.
Shit your pants: file cs2d Outlast II Mod (29) | Create your UI faster: CS2D UI Framework
22.01.17 10:22:27 am
Up
Bowlinghead
User
Offline Off
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
--untested
-- edit it.
sounds = {"mysound1", "mysound2"}
times = {3000, 5000} -- first song is 3 secs long, 2nd is 5secs long

isSoundRunning = false

function killSound()
     isSoundRunning = false
end

function playSound(id)
     if (isSoundRunning == false) then
          parse("sound "..sounds[id]) 
          timer(times[id], "killSound")  
          isSoundRunning = true
     end
end

cs2d lua cmd timer

Do you want to hear the ignored sounds after the current sound has ended?
(Example: while "doublekill" is playing, someone did a tripple kill so after "doublekill" has ended, youll hear a "tripplekill")

autor has written:
so plz is there a way to just CHECK if a sound is being played?

Yes, if you keep track of the time. You can make a function like getCurrentSound().
Share time limited free games here
22.01.17 09:14:33 pm
Up
Zeik
User
Offline Off
I edited @user Bowlinghead:'s code so it uses a queue:

More >

The kill hook is just an example. You call the queueSound function whenever you need to play a sound, and then the ms100 hook will take care of playing the sounds in order.

PS: not tested.
PS 2: Queueing many sounds in short intervals will cause a total mess. So be careful.
23.01.17 04:05:39 pm
Up
Mami Tomoe
User
Offline Off
@user Zeik: Thank you! It seems like it might work

Hello!!! < This is an edit!

I added this function because I need it to play sometimes to one player only

But when I use it the game freeze ( stuck in while! )
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
function playSound2(id, sfx)
     local temp=false
     while temp==false do
          if (isSoundRunning == false) then
               if (not List.isEmpty(queue)) then
                    isSoundRunning = true
                    parse("sv_sound2 "..id.." "..sfx[1])
                    timer(sfx[2], "killSound")
                    temp=true
               end
          end
     end
end


plz help thx
edited 1×, last 23.01.17 05:14:32 pm
It's hard being the best girl in the whole entire world
23.01.17 06:26:55 pm
Up
Zeik
User
Offline Off
@user Mami Tomoe: I don't know what you're trying to do but it won't work like that because the while loop will only end when isSoundRunning is false (is the only if block that changes temp state). So when it's true it's an infinite loop, thus the game freezes.
23.01.17 08:03:18 pm
Up
Mami Tomoe
User
Offline Off
I need a function that will
sv_sound2
because the code only supports
sv_sound
It's hard being the best girl in the whole entire world
23.01.17 09:20:05 pm
Up
Zeik
User
Offline Off
I don't know how costly it is to have a private queue for each player but it's what you're needing.

Here's the complete code:
More >


Again, it's not tested.

PS: Basically, 0 is for global sound, and the rest are private.
edited 1×, last 23.01.17 09:31:04 pm
23.01.17 09:36:17 pm
Up
Mami Tomoe
User
Offline Off
It does a lot of errors just spamming red

The previous code worked I just need a function that will send it to a single player

I need support for
sv_sound
and
sv_sound2


plz
It's hard being the best girl in the whole entire world
23.01.17 09:56:39 pm
Up
Zeik
User
Offline Off
@user Mami Tomoe: You should post the errors otherwise I can't help much...
23.01.17 10:27:11 pm
Up
Mami Tomoe
User
Offline Off
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
LUA ERROR: sys/lua/cool stuff/play.lua:27: attempt to perform arithmetic on field 'first' (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
LUA ERROR: sys/lua/cool stuff/play.lua:38: attempt to compare two nil values
 -> sys/lua/cool stuff/play.lua:38: in function 'isEmpty'
 -> sys/lua/cool stuff/play.lua:66: in function 'playSound'
 -> sys/lua/cool stuff/play.lua:82: in function <sys/lua/cool stuff/play.lua:81>
LUA ERROR: sys/lua/cool stuff/play.lua:38: attempt to compare two nil values
 -> sys/lua/cool stuff/play.lua:38: in function 'isEmpty'
 -> sys/lua/cool stuff/play.lua:66: in function 'playSound'
 -> sys/lua/cool stuff/play.lua:82: in function <sys/lua/cool stuff/play.lua:81>


main is the main script that makes cool hooks
play is the script you gave me
score is the script that sends sound commands to play
It's hard being the best girl in the whole entire world
23.01.17 10:51:51 pm
Up
DC
Admin
Offline Off
There is no Lua command to check if CS2D is still playing a sound. That's because Lua only runs on the server and the server does not render anything or play any sounds at all if it's a headless dedicated server.

In fact this functionality is completely removed from dedicated servers because it's not needed and it might even lead to issues because servers commonly don't have audio and video drivers at all. Therefore the server does not even know the length of the used audio files.

So the only thing you can do is to - like already suggested - save the duration of all audio samples somehow and check the duration manually.

To solve the issue with the per-player sound you could use cs2d lua cmd timer and just put the player ID in as parameter:
Code:
1
timer(soundDuration, "callbackFunction", playerID)
This value can then be used in the function called by the timer to play the next sound for the player with that particular ID.
www.UnrealSoftware.de | www.CS2D.com | www.CarnageContest.com | Use the forum & avoid PMs!
To the start Previous 1 2 Next To the start