Play countdown sound to spectators, too

This commit is contained in:
Wuzzy 2024-07-11 10:59:23 +02:00
parent 31c3af484f
commit 7468cf59cf

View File

@ -118,24 +118,35 @@ arena_lib.on_time_tick("tnttag", function(arena)
end
-- Play warning sound each second to players when time is running out
elseif wavetimeleft <= COUNTDOWN_SECONDS then
local tagger_names, nontagger_names = {}, {}
local play_alert_to, play_countdown_to = {}, {}
for p_name in pairs(arena.players) do
-- Loud "alert" sound for tagger
if arena.players[p_name].tagged then
tagger_names[p_name] = true
play_alert_to[p_name] = true
-- Short subtle bleep sound for everyone else
else
nontagger_names[p_name] = true
play_countdown_to[p_name] = true
end
end
-- Also play sound to spectators
for p_name in pairs(arena.spectators) do
local target = arena_lib.get_spectated_target(p_name)
if target and target.type == "player" then
if arena.players[target.name].tagged then
play_alert_to[p_name] = true
else
play_countdown_to[p_name] = true
end
end
end
if has_audio_lib then
audio_lib.play_sound("tnttag_timer", {to_players=tagger_names})
audio_lib.play_sound("tnttag_timer_nontagger", {to_players=nontagger_names})
audio_lib.play_sound("tnttag_timer", {to_players=play_alert_to})
audio_lib.play_sound("tnttag_timer_nontagger", {to_players=play_countdown_to})
else
for p_name, _ in pairs(tagger_names) do
for p_name, _ in pairs(play_alert_to) do
minetest.sound_play({name="tnttag_timer", gain=GAIN_TIMER}, {to_player=p_name}, true)
end
for p_name, _ in pairs(nontagger_names) do
for p_name, _ in pairs(play_countdown_to) do
minetest.sound_play({name="tnttag_timer", gain=GAIN_TIMER}, {to_player=p_name}, true)
end
end