refine some commands to match last changes

This commit is contained in:
AFCMS 2021-03-09 00:47:01 +01:00
parent f90243f6e5
commit a22188ccf4
3 changed files with 33 additions and 62 deletions

View File

@ -71,3 +71,4 @@ If not specified, a value will be by default with the word pattern.
TODO: TODO:
* color value must be a color string or a valid named color * color value must be a color string or a valid named color
* nodename value must be a valid node name

View File

@ -1,22 +1,21 @@
local S = minetest.get_translator("mcl_commands") local S = minetest.get_translator("mcl_commands")
minetest.register_chatcommand("setblock", { mcl_commands.register_command("setblock", {
params = S("<X>,<Y>,<Z> <NodeString>"), func = function(cmd)
description = S("Set node at given position"), cmd:sub(":pos:pos :node:text", { --TODO:replace by upcomming nodename type
privs = {give=true, interact=true}, func = function(name)
func = function(name, param) local itemstack = ItemStack(nodestring)
local p = {} if itemstack:is_empty() or not minetest.registered_nodes[itemstack:get_name()] then
local nodestring = nil return false, S("Invalid node") --workaround
p.x, p.y, p.z, nodestring = param:match("^([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+) +(.+)$") end
p.x, p.y, p.z = tonumber(p.x), tonumber(p.y), tonumber(p.z) minetest.set_node(p, {name=nodestring})
if p.x and p.y and p.z and nodestring then return true, S("@1 spawned.", nodestring)
local itemstack = ItemStack(nodestring) --return false, S("Invalid parameters (see /help setblock)")
if itemstack:is_empty() or not minetest.registered_nodes[itemstack:get_name()] then end,
return false, S("Invalid node") privs = {},
end })
minetest.set_node(p, {name=nodestring})
return true, S("@1 spawned.", nodestring)
end
return false, S("Invalid parameters (see /help setblock)")
end, end,
description = S("Set node at given position"),
params = S("<X>,<Y>,<Z> <NodeString>"),
privs = {give=true, interact=true},
}) })

View File

@ -1,48 +1,19 @@
local S = minetest.get_translator("mcl_commands") local S = minetest.get_translator("mcl_commands")
minetest.register_chatcommand("playsound",{ mcl_commands.register_command("playsound", {
params = S("<sound> <target>"), --TODO:add source func = function(cmd)
description = S("Play a sound. Arguments: <sound>: name of the sound. <target>: Target."), cmd:sub(":sound:word :target:username", { --TODO:replace by upcomming types
privs = {server = true}, func = function(name, sound, target)
func = function(name, params) if minetest.player_exists(target) then
local P = {} minetest.sound_play({name = sound}, {to_player = target}, true) --TODO:add source, gain, pitch
local i = 0 else
for str in string.gmatch(params, "([^ ]+)") do return false, S("Target is invalid!!") --TODO: add mc chat message
i = i + 1 end
P[i] = str end,
end privs = {},
})
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, end,
description = S("Play a sound. Arguments: <sound>: name of the sound. <target>: Target."),
params = S("<sound> <target>"),
privs = {server = true},
}) })