From 058baca37b07a6057f27eb7dfdabb283527f09cc Mon Sep 17 00:00:00 2001 From: Sokomine Date: Sun, 10 Apr 2022 20:43:41 +0200 Subject: [PATCH] added npc_talk_style command --- README.md | 11 +++++++++++ fs_talkdialog.lua | 49 +++++++++++++++++++++++++++++++++++++---------- 2 files changed, 50 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 0944928..efa1d94 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,17 @@ This mod allows to set RPG-like texts for NPC where the NPC "says" something to the player and the player can reply with a selection of given replies - which most of the time lead to the next dialog. +Chat commands +============= + +/npc_talk_style Allows to select the formspec version: + 1: Very rudamentary. Not recommended. + 2: Shows additional buttons for up and down. + 3: Default (recommended) version. + +/npc_talk_debug Allows to debug dialogs. + + Terminology =========== dialog A text said by the NPC, with diffrent replys the player can diff --git a/fs_talkdialog.lua b/fs_talkdialog.lua index 5a0f045..2c41ae8 100644 --- a/fs_talkdialog.lua +++ b/fs_talkdialog.lua @@ -481,16 +481,16 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec owner_info = "\n\n(owned by "..minetest.formspec_escape(yl_speak_up.npc_owner[ n_id ])..")" end - local fs_version = 1 - if formspec_v >= 4 then - fs_version = 3 - elseif formspec_v >= 2 then - fs_version = 2 - else - fs_version = 1 - end - -- store which formspec version the player has - if(not(yl_speak_up.fs_version[pname])) then + local fs_version = yl_speak_up.fs_version[pname] + if(not(fs_version)) then + if formspec_v >= 4 then + fs_version = 3 + elseif formspec_v >= 2 then + fs_version = 2 + else + fs_version = 1 + end + -- store which formspec version the player has yl_speak_up.fs_version[pname] = fs_version end formspec = { @@ -955,3 +955,32 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec return table.concat(formspec, "") 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_style', { + description = "This command sets your formspec version ".. + "for the yl_speak_up NPC to value .\n".. + " Version 1: For very old clients. Not recommended.\n".. + " Version 2: Adds extra scroll buttons. Perhaps you like this more.\n".. + " Version 3: Default version.", + privs = {}, + func = function(pname, param) + if(param and param == "1") then + yl_speak_up.fs_version[pname] = 1 + elseif(param and param == "2") then + yl_speak_up.fs_version[pname] = 2 + elseif(param and param == "3") then + yl_speak_up.fs_version[pname] = 3 + else + minetest.chat_send_player(pname, "This command sets your formspec version ".. + "for the yl_speak_up NPC to value .\n".. + " Version 1: For very old clients. Not recommended.\n".. + " Version 2: Adds extra scroll buttons. Perhaps you like this more.\n".. + " Version 3: Default version.") + end + minetest.chat_send_player(pname, "Your formspec version for the yl_speak_up NPC ".. + "has been set to version "..tostring(yl_speak_up.fs_version[pname]).. + " for this session.") + end + })