forked from Sokomine/yl_speak_up
76 lines
2.5 KiB
Lua
76 lines
2.5 KiB
Lua
-- 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 <priv> to the "..
|
|
"yl_speak_up-NPC with the ID <n_id>.\n"..
|
|
"Call: [grant|revoke] <n_id> <priv>\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_id> <priv>\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 "..
|
|
"<npc_name>: <list of privs>"
|
|
-- 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.." <none>"
|
|
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] <n_id> <priv>")
|
|
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.." <none>"
|
|
yl_speak_up.npc_priv_table[n_id] = nil
|
|
end
|
|
minetest.chat_send_player(pname, text..".")
|
|
yl_speak_up.npc_privs_store()
|
|
end
|
|
})
|