From 50591119c72adbfed8d4d30a5a0c4dc2750b3884 Mon Sep 17 00:00:00 2001 From: Sokomine Date: Tue, 4 May 2021 19:14:52 +0200 Subject: [PATCH] show who owns the npc; limit length of name and description to 40 characters --- functions.lua | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/functions.lua b/functions.lua index 8dcb15c..3524755 100644 --- a/functions.lua +++ b/functions.lua @@ -1155,6 +1155,11 @@ local function get_fs_talkdialog(player, n_id, d_id) local formspec = {} local h + -- show who owns the NPC (and is thus more or less responsible for what it says) + local owner_info = "" + if(yl_speak_up.npc_owner[ n_id ]) then + owner_info = "\n\n(owned by "..minetest.formspec_escape(yl_speak_up.npc_owner[ n_id ])..")" + end if formspec_v >= 4 then formspec = { "formspec_version[3]", @@ -1202,7 +1207,7 @@ local function get_fs_talkdialog(player, n_id, d_id) minetest.formspec_escape(dialog.n_npc), "]", "label[0.3,1.8;", - minetest.formspec_escape(dialog.n_description), + minetest.formspec_escape(dialog.n_description)..owner_info, "]", "image[15.5,0.5;4,4;", portrait, @@ -1221,7 +1226,6 @@ local function get_fs_talkdialog(player, n_id, d_id) -- display the window with the text the NPC is saying -- TODO: make name and description likewise editable? -- TODO: make name of dialog and sort option editable? - -- TODO: show who owns the npc/is responsible for its talks? if(edit_mode) then -- TODO: sort by name? @@ -2344,6 +2348,11 @@ minetest.register_on_player_receive_fields( minetest.chat_send_player(pname, "Please provide a description of your NPC!") return end + -- sensible length limit + if(string.len(fields.n_npc)>40 or string.len(fields.n_description)>40) then + minetest.chat_send_player(pname, "The name and description of your NPC cannot be longer than 40 characters.") + return + end -- give the NPC its first dialog local f = {} -- create a new dialog