forked from Sokomine/yl_speak_up
moved chat command npc_talk_debug into extra file
This commit is contained in:
parent
428b11afd6
commit
8bfc59a9a2
75
command_npc_talk_debug.lua
Normal file
75
command_npc_talk_debug.lua
Normal file
@ -0,0 +1,75 @@
|
||||
|
||||
|
||||
-- store which player is monitoring the NPC (for preconditions and
|
||||
-- effects)
|
||||
yl_speak_up.debug_mode_set_by_player = {}
|
||||
|
||||
-- for sending debug information about preconditions and effects to
|
||||
-- the player who is monitoring the NPC
|
||||
-- (sometimes it is not easy/obvious to see why something failed)
|
||||
yl_speak_up.debug_msg = function(player, n_id, o_id, text)
|
||||
local dname = yl_speak_up.debug_mode_set_by_player[ n_id ]
|
||||
-- nobody cares
|
||||
if(not(dname)) then
|
||||
return
|
||||
end
|
||||
local pname = player:get_player_name()
|
||||
local d_id = yl_speak_up.speak_to[pname].d_id
|
||||
minetest.chat_send_player(dname, "[NPC "..tostring(n_id)..": "..
|
||||
tostring(pname).."] <"..tostring(d_id).." "..tostring(o_id)..
|
||||
"> "..tostring(text))
|
||||
end
|
||||
|
||||
|
||||
-- a chat command for entering and leaving debug mode; needs to be a chat command
|
||||
-- because the player may have wandered off from his NPC and get too many messages
|
||||
-- without a quick way to get rid of them otherwise
|
||||
minetest.register_chatcommand( 'npc_talk_debug', {
|
||||
description = "Sets you as debugger for the yl_speak_up-NPC with the ID <n_id>.\n"..
|
||||
" <list> lists the NPC you are currently debugging.\n"..
|
||||
" <off> turns debug mode off again.",
|
||||
privs = {npc_talk_owner = true},
|
||||
func = function(pname, param)
|
||||
if(param and param == "off") then
|
||||
local count = 0
|
||||
for k, v in pairs(yl_speak_up.debug_mode_set_by_player) do
|
||||
if(v and v == pname) then
|
||||
yl_speak_up.debug_mode_set_by_player[ k ] = nil
|
||||
count = count + 1
|
||||
minetest.chat_send_player(pname, "You are no longer "..
|
||||
"debugging the NPC with the ID "..tostring(k)..".")
|
||||
end
|
||||
end
|
||||
minetest.chat_send_player(pname, "Removed you as debugger of "..
|
||||
tostring(count).." NPCs.")
|
||||
return
|
||||
elseif(not(param) or param == "" or param == "list") then
|
||||
local count = 0
|
||||
local text = "You are currently debugging the NPCs with the following IDs:\n"
|
||||
for k, v in pairs(yl_speak_up.debug_mode_set_by_player) do
|
||||
if(v and v == pname) then
|
||||
count = count + 1
|
||||
text = text.." "..tostring(k)
|
||||
end
|
||||
end
|
||||
if(count == 0) then
|
||||
text = text.." - none -"
|
||||
else
|
||||
text = text.."\nTo turn debugging off, call this command with the "..
|
||||
"parameter <off>."
|
||||
end
|
||||
minetest.chat_send_player(pname, text)
|
||||
return
|
||||
elseif(not(yl_speak_up.may_edit_npc(minetest.get_player_by_name(pname), param))) then
|
||||
minetest.chat_send_player(pname, "You do not have the necessary privs to "..
|
||||
"edit that NPC.")
|
||||
return
|
||||
else
|
||||
yl_speak_up.debug_mode_set_by_player[ param ] = pname
|
||||
minetest.chat_send_player(pname, "You are now receiving debug information "..
|
||||
"for NPC "..tostring(param)..".\nTo turn that off, type "..
|
||||
"\"/npc_talk_debug off\".")
|
||||
end
|
||||
end
|
||||
});
|
||||
|
@ -1,78 +1,4 @@
|
||||
|
||||
-- store which player is monitoring the NPC (for preconditions and
|
||||
-- effects)
|
||||
yl_speak_up.debug_mode_set_by_player = {}
|
||||
|
||||
-- for sending debug information about preconditions and effects to
|
||||
-- the player who is monitoring the NPC
|
||||
-- (sometimes it is not easy/obvious to see why something failed)
|
||||
yl_speak_up.debug_msg = function(player, n_id, o_id, text)
|
||||
local dname = yl_speak_up.debug_mode_set_by_player[ n_id ]
|
||||
-- nobody cares
|
||||
if(not(dname)) then
|
||||
return
|
||||
end
|
||||
local pname = player:get_player_name()
|
||||
local d_id = yl_speak_up.speak_to[pname].d_id
|
||||
minetest.chat_send_player(dname, "[NPC "..tostring(n_id)..": "..
|
||||
tostring(pname).."] <"..tostring(d_id).." "..tostring(o_id)..
|
||||
"> "..tostring(text))
|
||||
end
|
||||
|
||||
|
||||
-- a chat command for entering and leaving debug mode; needs to be a chat command
|
||||
-- because the player may have wandered off from his NPC and get too many messages
|
||||
-- without a quick way to get rid of them otherwise
|
||||
minetest.register_chatcommand( 'npc_talk_debug', {
|
||||
description = "Sets you as debugger for the yl_speak_up-NPC with the ID <n_id>.\n"..
|
||||
" <list> lists the NPC you are currently debugging.\n"..
|
||||
" <off> turns debug mode off again.",
|
||||
privs = {npc_talk_owner = true},
|
||||
func = function(pname, param)
|
||||
if(param and param == "off") then
|
||||
local count = 0
|
||||
for k, v in pairs(yl_speak_up.debug_mode_set_by_player) do
|
||||
if(v and v == pname) then
|
||||
yl_speak_up.debug_mode_set_by_player[ k ] = nil
|
||||
count = count + 1
|
||||
minetest.chat_send_player(pname, "You are no longer "..
|
||||
"debugging the NPC with the ID "..tostring(k)..".")
|
||||
end
|
||||
end
|
||||
minetest.chat_send_player(pname, "Removed you as debugger of "..
|
||||
tostring(count).." NPCs.")
|
||||
return
|
||||
elseif(not(param) or param == "" or param == "list") then
|
||||
local count = 0
|
||||
local text = "You are currently debugging the NPCs with the following IDs:\n"
|
||||
for k, v in pairs(yl_speak_up.debug_mode_set_by_player) do
|
||||
if(v and v == pname) then
|
||||
count = count + 1
|
||||
text = text.." "..tostring(k)
|
||||
end
|
||||
end
|
||||
if(count == 0) then
|
||||
text = text.." - none -"
|
||||
else
|
||||
text = text.."\nTo turn debugging off, call this command with the "..
|
||||
"parameter <off>."
|
||||
end
|
||||
minetest.chat_send_player(pname, text)
|
||||
return
|
||||
elseif(not(yl_speak_up.may_edit_npc(minetest.get_player_by_name(pname), param))) then
|
||||
minetest.chat_send_player(pname, "You do not have the necessary privs to "..
|
||||
"edit that NPC.")
|
||||
return
|
||||
else
|
||||
yl_speak_up.debug_mode_set_by_player[ param ] = pname
|
||||
minetest.chat_send_player(pname, "You are now receiving debug information "..
|
||||
"for NPC "..tostring(param)..".\nTo turn that off, type "..
|
||||
"\"/npc_talk_debug off\".")
|
||||
end
|
||||
end
|
||||
});
|
||||
|
||||
|
||||
-- helper function; get a formspec with the inventory of the player (for selecting items)
|
||||
yl_speak_up.fs_your_inventory_select_item = function(pname, data)
|
||||
return "label[0.2,4.2;Name of the item(stack):]"..
|
||||
|
2
init.lua
2
init.lua
@ -60,6 +60,8 @@ dofile(modpath .. "print_as_table.lua")
|
||||
dofile(modpath .. "formspec_helpers.lua")
|
||||
-- handle alternate text for dialogs
|
||||
dofile(modpath .. "fs_alternate_text.lua")
|
||||
-- implementation of chat command npc_talk_debug:
|
||||
dofile(modpath .. "command_npc_talk_debug.lua")
|
||||
-- common functions for editing preconditions and effects
|
||||
dofile(modpath .. "fs_edit_general.lua")
|
||||
-- edit preconditions (can be reached through edit options dialog)
|
||||
|
Loading…
Reference in New Issue
Block a user