1
2
3
4
5
6
7
8
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
Scripts
Sv_stopsound
Sv_stopsound
1

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
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
Baloon:
sv_sound executes its sound file as signed in the parameter you have to wait till the sound stops.
_Vava_ has written
Baloon: 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
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
MikuAuahDark:for i = 1, 32 do
attempt_stop_sound(i)
playing_sound_list[i] = path
parse(string.format("sv_sound %q", path))
end
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...
RIP-HereRestsPlookerbooy: Actually, @
MikuAuahDark's method is faster, the only problem is that it doesn't check wether the player exists.
_Yank: you may be wrong. Considering pairs is bit slower than ipairs, this looping method for i = 1,32 doand this looping method
for _,i in ipairs(player(0,"table"))are same.
Baloon: But it is pairs that @
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.
_Yank has written
RIP-HereRestsPlookerbooy: Actually, @
MikuAuahDark's method is faster, the only problem is that it doesn't check wether the player exists.
sv_sound2 and
sv_stopsound does that.
1
