Forum

> > CS2D > Scripts > Sv_stopsound
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Sv_stopsound

9 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Sv_stopsound

_Vava_
User Off Offline

Zitieren
Hey Everyone today i have an idea with some Sounds and i want to use sv_stopsound to stop some sounds

1
2
3
4
5
6
7
8
addhook("say","onsay")
function onsay(id,txt)
if txt=="!start" then
parse("sv_sound ZombieCrown/ambience1.wav")
elseif txt=="!stop" then
parse("sv_stopsound ZombieCrown/ambience1.wav 0")
end
end

but it's not working

alt Re: Sv_stopsound

Baloon
GAME BANNED Off Offline

Zitieren
1
2
3
4
5
6
7
8
addhook("say","onsay")
function onsay(id,txt)
if string.sub(txt,1,6)=="!start" then
parse('sv_sound "ZombieCrown/ambience1.wav"')
elseif string.sub(txt,1,5)=="!stop" then
parse('sv_stopsound "ZombieCrown/ambience1.wav" 0')
end
end

alt Re: Sv_stopsound

_Vava_
User Off Offline

Zitieren
Thx @user Baloon:
is there any lua that if start a sound it stop the previous Sound
like that I should not write every time sv_stopsound

alt Re: Sv_stopsound

GeoB99
Moderator Off Offline

Zitieren
No. Once cs2d cmd sv_sound executes its sound file as signed in the parameter you have to wait till the sound stops.

alt Re: Sv_stopsound

MikuAuahDark
User Off Offline

Zitieren
user _Vava_ hat geschrieben
Thx @user Baloon:
is there any lua that if start a sound it stop the previous Sound
like that I should not write every time sv_stopsound


Do you mean something like this?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
local playing_sound_list = {}

local function attempt_stop_sound(player)
	if playing_sound_list[player] then
		parse(string.format("sv_stopsound %q %d", playing_sound_list, player))
		playing_sound_list[player] = nil
	end
end

function play_sound(path, player)
	if type(player) ~= "number" then
		for i = 1, 32 do
			attempt_stop_sound(i)
			playing_sound_list[i] = path
			parse(string.format("sv_sound %q", path))
		end
	else
		attempt_stop_sound(player)
		playing_sound_list[player] = path
		parse(string.format("sv_sound2 %d %q", player, path))
	end
end

Call it like this
1
2
3
play_sound("sfx/path/to/audio.flac", 1)	-- Play only for ID 1
-- other part in your code --
play_sound("sfx/some_sound.ogg")	-- Play for all players and stop previous playing sound for ID 1

alt Re: Sv_stopsound

RIP-HereRestsPlookerbooy
BANNED Off Offline

Zitieren
@user MikuAuahDark:
Change this

1
2
3
4
5
for i = 1, 32 do
     attempt_stop_sound(i)
     playing_sound_list[i] = path
     parse(string.format("sv_sound %q", path))
end

To this

1
2
3
4
5
for _,i in pairs(player(0, "table")) do
     attempt_stop_sound(i)
     playing_sound_list[i] = path
     parse(string.format("sv_sound %q", path))
end

> Prevents some lag atleast...

alt Re: Sv_stopsound

Baloon
GAME BANNED Off Offline

Zitieren
@user _Yank: you may be wrong. Considering pairs is bit slower than ipairs, this looping method
for i = 1,32 do
and this looping method
for _,i in ipairs(player(0,"table"))
are same.

alt Re: Sv_stopsound

_Yank
User Off Offline

Zitieren
@user Baloon: But it is pairs that @user RIP-HereRestsPlookerbooy used on his post. Even if it wasn't, the ipairs method still slower than the for one because it relies on a function (thus additional delays for it being called and for it to produce the return value may be included). And still, only in LuaJIT that ipairs method is as fast as the for one when dealing with arrays.

Anyways, you shouldn't care too much about this, the difference is very very VERY minimal and should only be noticeable on much bigger and/or complex cases.
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht