Forum
CS2D Scripts How to check if the server is playing a soundHow to check if the server is playing a sound
30 replies1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
1
2
3
4
5
6
7
8
9
10
11
12
13
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)
1
2
3
4
5
6
7
8
9
10
11
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")
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 @ DC: or anyyyy @ Omghelpme:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
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().
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.
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! )
1
2
3
4
5
6
7
8
9
10
11
12
13
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
sv_sound2because the code only supports
sv_sound
Here's the complete code:
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
The previous code worked I just need a function that will send it to a single player
I need support for
sv_soundand
sv_sound2
plz
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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 timer and just put the player ID in as parameter:
1
timer(soundDuration, "callbackFunction", playerID)