diff --git a/mods/CORE/mcl_commands/API.md b/mods/CORE/mcl_commands/API.md index 95dcdd77d7..013fb0809d 100644 --- a/mods/CORE/mcl_commands/API.md +++ b/mods/CORE/mcl_commands/API.md @@ -71,3 +71,4 @@ If not specified, a value will be by default with the word pattern. TODO: * color value must be a color string or a valid named color +* nodename value must be a valid node name diff --git a/mods/MISC/mcl_basic_commands/setblock.lua b/mods/MISC/mcl_basic_commands/setblock.lua index 30d68b74fa..a092dfe69e 100644 --- a/mods/MISC/mcl_basic_commands/setblock.lua +++ b/mods/MISC/mcl_basic_commands/setblock.lua @@ -1,22 +1,21 @@ local S = minetest.get_translator("mcl_commands") -minetest.register_chatcommand("setblock", { - params = S(",, "), - description = S("Set node at given position"), - privs = {give=true, interact=true}, - func = function(name, param) - local p = {} - local nodestring = nil - p.x, p.y, p.z, nodestring = param:match("^([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+) +(.+)$") - p.x, p.y, p.z = tonumber(p.x), tonumber(p.y), tonumber(p.z) - if p.x and p.y and p.z and nodestring then - local itemstack = ItemStack(nodestring) - if itemstack:is_empty() or not minetest.registered_nodes[itemstack:get_name()] then - return false, S("Invalid node") - end - minetest.set_node(p, {name=nodestring}) - return true, S("@1 spawned.", nodestring) - end - return false, S("Invalid parameters (see /help setblock)") +mcl_commands.register_command("setblock", { + func = function(cmd) + cmd:sub(":pos:pos :node:text", { --TODO:replace by upcomming nodename type + func = function(name) + local itemstack = ItemStack(nodestring) + if itemstack:is_empty() or not minetest.registered_nodes[itemstack:get_name()] then + return false, S("Invalid node") --workaround + end + minetest.set_node(p, {name=nodestring}) + return true, S("@1 spawned.", nodestring) + --return false, S("Invalid parameters (see /help setblock)") + end, + privs = {}, + }) end, + description = S("Set node at given position"), + params = S(",, "), + privs = {give=true, interact=true}, }) \ No newline at end of file diff --git a/mods/MISC/mcl_basic_commands/sound.lua b/mods/MISC/mcl_basic_commands/sound.lua index 934abb80eb..490a2eae7e 100644 --- a/mods/MISC/mcl_basic_commands/sound.lua +++ b/mods/MISC/mcl_basic_commands/sound.lua @@ -1,48 +1,19 @@ 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 +mcl_commands.register_command("playsound", { + func = function(cmd) + cmd:sub(":sound:word :target:username", { --TODO:replace by upcomming types + func = function(name, sound, target) + if minetest.player_exists(target) then + minetest.sound_play({name = sound}, {to_player = target}, true) --TODO:add source, gain, pitch + else + return false, S("Target is invalid!!") --TODO: add mc chat message + end + end, + privs = {}, + }) end, + description = S("Play a sound. Arguments: : name of the sound. : Target."), + params = S(" "), + privs = {server = true}, }) \ No newline at end of file