Merge pull request 'playerbound music toggle' (#3658) from playerMusicToggle into master
Reviewed-on: https://git.minetest.land/MineClone2/MineClone2/pulls/3658 Reviewed-by: 𝕵𝖔𝖍𝖆𝖓𝖓𝖊𝖘 𝕱𝖗𝖎𝖙𝖟 <mrrar@noreply.git.minetest.land>mobs_armor
commit
6c99a63419
|
@ -1,3 +1,5 @@
|
||||||
|
local S = minetest.get_translator(minetest.get_current_modname())
|
||||||
|
|
||||||
local modname = minetest.get_current_modname()
|
local modname = minetest.get_current_modname()
|
||||||
local modpath = minetest.get_modpath(modname)
|
local modpath = minetest.get_modpath(modname)
|
||||||
|
|
||||||
|
@ -46,7 +48,7 @@ local function pick_track(dimension, underground)
|
||||||
minetest.log("action", "[mcl_music] Playing track: " .. chosen_track .. ", for context: " .. track_key)
|
minetest.log("action", "[mcl_music] Playing track: " .. chosen_track .. ", for context: " .. track_key)
|
||||||
return chosen_track
|
return chosen_track
|
||||||
else
|
else
|
||||||
--?
|
-- ?
|
||||||
end
|
end
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -102,6 +104,7 @@ local function play()
|
||||||
|
|
||||||
local day_count = minetest.get_day_count()
|
local day_count = minetest.get_day_count()
|
||||||
for _, player in pairs(minetest.get_connected_players()) do
|
for _, player in pairs(minetest.get_connected_players()) do
|
||||||
|
if not player:get_meta():get("mcl_music:disable") then
|
||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
local hp = player:get_hp()
|
local hp = player:get_hp()
|
||||||
local pos = player:get_pos()
|
local pos = player:get_pos()
|
||||||
|
@ -116,7 +119,7 @@ local function play()
|
||||||
local old_dimension = listener and listener.dimension
|
local old_dimension = listener and listener.dimension
|
||||||
local is_dimension_changed = old_dimension and (old_dimension ~= dimension) or false
|
local is_dimension_changed = old_dimension and (old_dimension ~= dimension) or false
|
||||||
|
|
||||||
--minetest.log("handle: " .. dump (handle))
|
-- minetest.log("handle: " .. dump (handle))
|
||||||
if is_dimension_changed then
|
if is_dimension_changed then
|
||||||
stop_music_for_listener_name(player_name)
|
stop_music_for_listener_name(player_name)
|
||||||
if not listeners[player_name] then
|
if not listeners[player_name] then
|
||||||
|
@ -136,6 +139,7 @@ local function play()
|
||||||
--minetest.log("else")
|
--minetest.log("else")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
minetest.after(7, play)
|
minetest.after(7, play)
|
||||||
end
|
end
|
||||||
|
@ -149,6 +153,10 @@ if music_enabled then
|
||||||
stop_music_for_listener_name(player_name)
|
stop_music_for_listener_name(player_name)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
minetest.register_on_leaveplayer(function(player, timed_out)
|
||||||
|
listeners[player:get_player_name()] = nil
|
||||||
|
end)
|
||||||
|
|
||||||
minetest.register_on_respawnplayer(function(player)
|
minetest.register_on_respawnplayer(function(player)
|
||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
stop_music_for_listener_name(player_name)
|
stop_music_for_listener_name(player_name)
|
||||||
|
@ -156,3 +164,59 @@ if music_enabled then
|
||||||
else
|
else
|
||||||
minetest.log("action", "[mcl_music] In-game music is deactivated")
|
minetest.log("action", "[mcl_music] In-game music is deactivated")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
minetest.register_chatcommand("music", {
|
||||||
|
params = "[on|off|invert [<player name>]]",
|
||||||
|
description = S("Turns music for yourself or another player on or off."),
|
||||||
|
func = function(sender_name, params)
|
||||||
|
local argtable = {}
|
||||||
|
for str in string.gmatch(params, "([^%s]+)") do
|
||||||
|
table.insert(argtable, str)
|
||||||
|
end
|
||||||
|
|
||||||
|
local action = argtable[1]
|
||||||
|
local playername = argtable[2]
|
||||||
|
|
||||||
|
local sender = minetest.get_player_by_name(sender_name)
|
||||||
|
local target_player = nil
|
||||||
|
|
||||||
|
if not action or action == "" then action = "invert" end
|
||||||
|
|
||||||
|
if not playername or playername == "" or sender_name == playername then
|
||||||
|
target_player = sender
|
||||||
|
playername =sender_name
|
||||||
|
elseif not minetest.check_player_privs(sender, "debug") then -- Self-use handled above
|
||||||
|
minetest.chat_send_player(sender_name, S("You need the debug privilege in order to turn ingame music on or off for somebody else!"))
|
||||||
|
return
|
||||||
|
else -- Admin
|
||||||
|
target_player = minetest.get_player_by_name(playername)
|
||||||
|
end
|
||||||
|
|
||||||
|
if not target_player then
|
||||||
|
minetest.chat_send_player(sender_name, S("Couldn't find player @1!", playername))
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local meta = target_player:get_meta()
|
||||||
|
local display_new_state = "unknown" -- Should never be displayed -> no translation
|
||||||
|
|
||||||
|
if action == "invert" then
|
||||||
|
if not meta:get("mcl_music:disable") then
|
||||||
|
meta:set_int("mcl_music:disable", 1)
|
||||||
|
display_new_state = S("off")
|
||||||
|
else
|
||||||
|
meta:set_string("mcl_music:disable", "") -- This deletes the meta value!
|
||||||
|
display_new_state = S("on")
|
||||||
|
end
|
||||||
|
elseif action == "on" then
|
||||||
|
meta:set_string("mcl_music:disable", "") -- Delete
|
||||||
|
display_new_state = S("on")
|
||||||
|
else
|
||||||
|
meta:set_int("mcl_music:disable", 1)
|
||||||
|
display_new_state = S("off")
|
||||||
|
end
|
||||||
|
|
||||||
|
stop_music_for_listener_name(playername)
|
||||||
|
minetest.chat_send_player(sender_name, S("Set music for @1 to: @2", playername, display_new_state))
|
||||||
|
end,
|
||||||
|
})
|
|
@ -0,0 +1,7 @@
|
||||||
|
# textdomain: mcl_music
|
||||||
|
You need the debug privilege in order to turn ingame music on or off for somebody else!=Sie benötigen das „debug“ Privileg, um die Musik (im Spiel) für jemand anders ein oder aus zu schalten!
|
||||||
|
Couldn't find player @1!= Spieler @1 konnte nicht gefunden werden!
|
||||||
|
Set music for @1 to: @2=Musik für @1 auf @2 gesetzt
|
||||||
|
Turns music for yourself or another player on or off.=Schaltet die Musik für Sie selbst oder jemand anders ein oder aus.
|
||||||
|
on=an
|
||||||
|
off=aus
|
|
@ -0,0 +1,7 @@
|
||||||
|
# textdomain: mcl_music
|
||||||
|
You need the debug privilege in order to turn ingame music on or off for somebody else!=
|
||||||
|
Couldn't find player @1!=
|
||||||
|
Set music for @1 to: @2=
|
||||||
|
Turns music for yourself or another player on or off.=
|
||||||
|
on=
|
||||||
|
off=
|
Loading…
Reference in New Issue