From 7ac09d90573fce45c10cdd20aad9f4de618ab1aa Mon Sep 17 00:00:00 2001 From: Sokomine Date: Sat, 1 Jul 2023 18:48:00 +0200 Subject: [PATCH] added command /npc_talk_force_edit --- README.md | 7 +++++++ functions.lua | 29 +++++++++++++++++++++++++++++ register_once.lua | 14 ++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/README.md b/README.md index 4365531..76705dd 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,13 @@ and set its name). server will crash - so please test on a test server first! Requires the privs priv. +#### `/npc_talk_force_edit` Toggles edit mode. + From now on (until you issue this command again), all NPC you + talk to will be in edit mode (provided you are allowed to + edit them). This is useful if something's wrong with your NPC + like i.e. you made it select a dialog automaticly and let + that dialog lead to d_end. + ### 3. Terminology diff --git a/functions.lua b/functions.lua index 215dd39..fd9f619 100644 --- a/functions.lua +++ b/functions.lua @@ -513,6 +513,29 @@ yl_speak_up.check_for_disambigous_results = function(n_id, pname) end +-- allow to enter force edit mode (useful when an NPC was broken) +yl_speak_up.force_edit_mode = {} +-- command to enter force edit mode +yl_speak_up.command_npc_talk_force_edit = function(pname, param) + if(not(pname)) then + return + end + if(yl_speak_up.force_edit_mode[pname]) then + yl_speak_up.force_edit_mode[pname] = nil + minetest.chat_send_player(pname, + "Ending force edit mode for NPC. From now on talks ".. + "will no longer start in edit mode.") + else + yl_speak_up.force_edit_mode[pname] = true + minetest.chat_send_player(pname, + "STARTING force edit mode for NPC. From now on talks ".. + "with NPC will always start in edit mode provided ".. + "you are allowed to edit this NPC.\n".. + "In order to end force edit mode, give the command ".. + "/npc_talk_force_edit a second time.") + end +end + -- Make the NPC talk function yl_speak_up.talk(self, clicker) @@ -608,6 +631,12 @@ function yl_speak_up.talk(self, clicker) yl_speak_up.speak_to[pname].may_edit_this_npc = true end + -- are we in force edit mode, and can the player edit this NPC? + if(yl_speak_up.force_edit_mode[pname] + and yl_speak_up.may_edit_npc(clicker, n_id)) then + yl_speak_up.edit_mode[pname] = n_id + end + local dialog = yl_speak_up.speak_to[pname].dialog if(not(dialog.trades)) then dialog.trades = {} diff --git a/register_once.lua b/register_once.lua index 29207eb..4fdf879 100644 --- a/register_once.lua +++ b/register_once.lua @@ -150,6 +150,20 @@ minetest.register_chatcommand( 'npc_talk_reload', { end }) +-- most of the files of this mod can be reloaded without the server having to +-- be restarted; +-- handled in init.lua +minetest.register_chatcommand( 'npc_talk_force_edit', { + description = "Toggles force edit mode. This is helpful if you cut yourself out ".. + "of editing an NPC by breaking it. From now on all NPC you will talk to ".. + "will already be in edit mode (provided you are allowed to edit them).".. + "\nIssuing the command again ends force edit mode.", + privs = {npc_talk_owner = true}, + func = function(pname, param) + return yl_speak_up.command_npc_talk_force_edit(pname, param) + end, +}) + ----------------------------------------------------------------------------- -- some node positions can be set by punching a node -----------------------------------------------------------------------------