mirror of
https://github.com/LeMagnesium/minetest-mod-metatools.git
synced 2024-11-13 05:40:24 +01:00
Added basic system to set metadata fields
This commit is contained in:
parent
38d211a5eb
commit
c4d9b8aef9
45
init.lua
45
init.lua
|
@ -58,7 +58,7 @@ minetest.register_chatcommand("meta", {
|
|||
minetest.chat_send_player(name," show : show fields at node/depth")
|
||||
minetest.chat_send_player(name," enter name : enter in field name at node/depth")
|
||||
minetest.chat_send_player(name," quit name : quit field name at node/depth")
|
||||
--minetest.chat_send_player(name," set name value : set field name to value at node/depth")
|
||||
minetest.chat_send_player(name," set name value : set field name to value at node/depth")
|
||||
minetest.chat_send_player(name," close : close the current node")
|
||||
|
||||
elseif paramlist[1] == "open" then
|
||||
|
@ -196,19 +196,18 @@ minetest.register_chatcommand("meta", {
|
|||
minetest.log("action","[metatools] Player "..name.." quited stratum "..meta_info[name]["stratum"]+1 .." of node "..minetest.get_node(meta_info[name]["node"]).name.." at pos "..minetest.pos_to_string(meta_info[name]["node"]))
|
||||
return true
|
||||
|
||||
--[[ elseif paramlist[1] == "set" then
|
||||
elseif paramlist[1] == "set" then
|
||||
if not meta_info[name] or not meta_info[name]["node"] then
|
||||
minetest.chat_send_player(name,"- meta::set - You have no node open, use /meta open (x,y,z) to open one")
|
||||
minetest.log("action","[metatools] Player "..name.." failed setting value : no node opened")
|
||||
return false
|
||||
end
|
||||
|
||||
if not paramlist[2] or tonumber(paramlist[2]) == nil then
|
||||
minetest.chat_send_player(name,"- meta::set - You must provide a number of index for the value you want to set")
|
||||
minetest.log("action","[metatools] Player "..name.." failed setting value : no index given")
|
||||
if not paramlist[2] then
|
||||
minetest.chat_send_player(name,"- meta::set - You must provide a variable name for the value you want to set")
|
||||
minetest.log("action","[metatools] Player "..name.." failed setting value : no variable name given")
|
||||
return false
|
||||
end
|
||||
paramlist[2] = tonumber(paramlist[2])
|
||||
|
||||
if not paramlist[3] then
|
||||
minetest.chat_send_player(name,"- meta::set - You must provide a value for the variable you want to set")
|
||||
|
@ -217,29 +216,29 @@ minetest.register_chatcommand("meta", {
|
|||
end
|
||||
|
||||
local i = 4
|
||||
while (i < #paramlist) do
|
||||
paramlist[3] = paramlist[3] .. " " .. paramlist[i]
|
||||
paramlist[i] = nil
|
||||
while (true) do
|
||||
if paramlist[i] ~= nil then
|
||||
paramlist[3] = paramlist[3] .. " " .. paramlist[i]
|
||||
else
|
||||
break
|
||||
end
|
||||
i = i + 1
|
||||
end
|
||||
|
||||
local metalist = meta_info[name]["pointer"]
|
||||
local keyring = 0
|
||||
for key,value in pairs(metalist) do
|
||||
print(keyring .."==".. paramlist[2])
|
||||
if keyring == paramlist[2] and type(value) ~= "table" and type(value) ~= "userdata" then
|
||||
minetest.chat_send_player(name,"- meta::set - Set variable "..key .. " with value "..paramlist[3])
|
||||
value = paramlist[3]
|
||||
minetest.log("action","[metatools] Player "..name .. " set variable ".. paramlist[2] .. " to " .. paramlist[3] .. " at stratum "..meta_info[name]["stratum"]+1 .." of node "..minetest.get_node(meta_info[name]["node"]).name.." at pos "..minetest.pos_to_string(meta_info[name]["node"]))
|
||||
VoxelManip():update_map()
|
||||
return true
|
||||
local meta = minetest.get_meta(meta_info[name]["node"])
|
||||
if tonumber(paramlist[3]) ~= nil then
|
||||
if tonumber(paramlist[3]) % 1 == 0 then
|
||||
meta:set_int(paramlist[2],tonumber(paramlist[3]))
|
||||
else
|
||||
meta:set_float(paramlist[2],tonumber(paramlist[3]))
|
||||
end
|
||||
keyring = keyring + 1
|
||||
elseif type(paramlist[3]) == "string" then
|
||||
meta:set_string(paramlist[2],paramlist[3])
|
||||
end
|
||||
|
||||
minetest.chat_send_player(name,"- meta::set - Variable at "..paramlist[2] .." not found")
|
||||
minetest.log("action","[metatools] Player "..name.." failed setting variable ".. paramlist[2] .." to value ".. paramlist[3] .." in stratum "..meta_info[name]["stratum"].." of node "..minetest.get_node(meta_info[name]["node"]).name.." at pos "..minetest.pos_to_string(meta_info[name]["node"]))
|
||||
return false]]
|
||||
minetest.chat_send_player(name,"- meta::set - Variable set")
|
||||
minetest.log("action","[metatools] Player " .. name .. " set variable " .. paramlist[2] .. " to value " .. paramlist[3] .. " in stratum " .. meta_info[name]["stratum"] .. " of node " .. minetest.get_node(meta_info[name]["node"]).name .. " at pos " .. minetest.pos_to_string(meta_info[name]["node"]))
|
||||
return true
|
||||
else
|
||||
minetest.chat_send_player(name,"- meta - Subcommand " .. paramlist[1] .. " not known. Type /meta help for help")
|
||||
return false
|
||||
|
|
Loading…
Reference in New Issue
Block a user