From e3eb8c7ac81714e5d7fad9804ea7854f528e2593 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Fri, 5 Mar 2021 16:37:56 +0100 Subject: [PATCH] add /playsound command --- mods/MISC/mcl_commands/init.lua | 1 + mods/MISC/mcl_commands/sound.lua | 48 ++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 mods/MISC/mcl_commands/sound.lua diff --git a/mods/MISC/mcl_commands/init.lua b/mods/MISC/mcl_commands/init.lua index c078e5872..7a9fe4868 100644 --- a/mods/MISC/mcl_commands/init.lua +++ b/mods/MISC/mcl_commands/init.lua @@ -10,5 +10,6 @@ dofile(modpath.."/seed.lua") dofile(modpath.."/summon.lua") dofile(modpath.."/say.lua") dofile(modpath.."/list.lua") +dofile(modpath.."/sound.lua") dofile(modpath.."/alias.lua") \ No newline at end of file diff --git a/mods/MISC/mcl_commands/sound.lua b/mods/MISC/mcl_commands/sound.lua new file mode 100644 index 000000000..934abb80e --- /dev/null +++ b/mods/MISC/mcl_commands/sound.lua @@ -0,0 +1,48 @@ +local S = minetest.get_translator("mcl_commands") + +minetest.register_chatcommand("playsound",{ + params = S(" "), --TODO:add source + description = S("Play a sound. Arguments: : name of the sound. : Target."), + privs = {server = true}, + func = function(name, params) + local P = {} + local i = 0 + for str in string.gmatch(params, "([^ ]+)") do + i = i + 1 + P[i] = str + end + + local params = {} + if P[1] == tostring(P[1]) then + params.name = P[1] + else + return false, S("Sound name is invalid!") --TODO: add mc chat message + end + + if P[2] == tostring(P[2]) and minetest.player_exists(P[2]) then + params.target = P[2] + else + return false, S("Target is invalid!!") + end + + -- if P[3] then + -- params.pos = nil --TODO:position + -- else + -- params.pos = nil + -- end + + -- if P[4] == tonumber(P[4]) then + -- params.gain = P[4] + -- else + -- params.gain = 1.0 + -- end + + -- if P[5] == tonumber(P[5]) then + -- params.pitch = P[5] + -- else + -- params.pitch = 1.0 + -- end + minetest.sound_play({name = params.name}, {to_player = params.target}, true) --TODO: /stopsound + return true + end, +}) \ No newline at end of file