-- used by privs.lua -- a chat command to grant or deny or disallow npc these privs; -- it is not checked if the NPC exists minetest.register_chatcommand( 'npc_talk_privs', { description = "Grants or revokes the privilege to the ".. "yl_speak_up-NPC with the ID .\n".. "Call: [grant|revoke] \n".. "If called with parameter [list], all granted privs for all NPC are shown.", privs = {privs = true}, func = function(pname, param) if(not(param) or param == "") then minetest.chat_send_player(pname, "Usage: [grant|revoke|list] \n".. "The following privilege exist:\n\t".. table.concat(yl_speak_up.npc_priv_names, ", ")..".") return end local parts = string.split(param, " ") if(parts[1] == "list") then local text = "This list contains the privs of each NPC in the form of ".. ": " -- create list of all existing extra privs for npc for n_id, v in pairs(yl_speak_up.npc_priv_table) do text = text..".\n"..tostring(n_id)..":" local found = false for priv, w in pairs(v) do text = text.." "..tostring(priv) found = true end if(not(found)) then text = text.." " end end minetest.chat_send_player(pname, text..".") return end if((parts[1] ~= "grant" and parts[1] ~= "revoke") or #parts ~= 3) then minetest.chat_send_player(pname, "Usage: [grant|revoke] ") return end local command = parts[1] local n_id = parts[2] local priv = parts[3] if(table.indexof(yl_speak_up.npc_priv_names, priv) == -1) then minetest.chat_send_player(pname, "Unknown priv \""..tostring(priv).."\".\n".. "The following privilege exist:\n\t".. table.concat(yl_speak_up.npc_priv_names, ", ")..".") return end if(command == "grant" and not(yl_speak_up.npc_priv_table[n_id])) then yl_speak_up.npc_priv_table[n_id] = {} end if(command == "grant") then yl_speak_up.npc_priv_table[n_id][priv] = true elseif(yl_speak_up.npc_priv_table[n_id]) then yl_speak_up.npc_priv_table[n_id][priv] = nil end local text = "New privs of NPC "..tostring(n_id)..":" local found = false if(yl_speak_up.npc_priv_table[n_id]) then for k, v in pairs(yl_speak_up.npc_priv_table[n_id]) do text = text.." "..tostring(k) found = true end end if(not(found)) then text = text.." " yl_speak_up.npc_priv_table[n_id] = nil end minetest.chat_send_player(pname, text..".") yl_speak_up.npc_privs_store() end })