Add a chat command to search items

Useful, for example, with /give, this adds a /search_items command which
returns all items where the name contains the given text. Although not
entirely consistent with the purpose of this mod, it makes use of the
same data already pre-cached for the crafting guide.
This commit is contained in:
Ciaran Gultnieks 2014-02-01 07:31:08 +00:00
parent 6bd997ecfc
commit 6b9c00c838

View File

@ -98,6 +98,25 @@ zcg.load_all = function()
print("All crafts loaded !")
end
minetest.register_chatcommand("search_items", {
params = "<text>",
description = "search all craft items",
privs = {},
func = function(name, param)
if zcg.need_load_all then zcg.load_all() end
local found = false
for _, itemname in ipairs(zcg.itemlist) do
if itemname:find(param, 1, true) then
minetest.chat_send_player(name, itemname)
found = true
end
end
if not found then
minetest.chat_send_player(name, "No matching items.")
end
end
})
zcg.formspec = function(pn)
if zcg.need_load_all then zcg.load_all() end
page = zcg.users[pn].page