added d_got_item dialog for accepting items given from player to npc

This commit is contained in:
Sokomine 2022-01-01 21:47:11 +01:00
parent 8a7d6e24b3
commit a1cae79266
5 changed files with 67 additions and 1 deletions

View File

@ -340,6 +340,10 @@ yl_speak_up.show_colored_dialog_text = function(dialog, data, d_id, hypertext_po
if(dialog and dialog.n_dialogs and dialog.n_dialogs[ d_id ]) then
text = dialog.n_dialogs[ d_id ].d_text
end
if(d_id == "d_got_item") then
color = "777777"
text = "[This dialog shall only have automatic options. The text is therefore irrelevant.]"
end
if(data and data.alternate_text and data.alternate_text ~= "") then
add_info_alternate_text = alternate_label_text
-- replace $TEXT$ with the normal dialog text and make the new text yellow

View File

@ -194,7 +194,14 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id, calle
"dropdown[16.0,-0.4;5.3,0.7;option_autoanswer;"..
"by clicking on it,automaticly;"..tostring(autoanswer+1)..";]"
-- (automaticly *by fulfilling the prerequirements*)
if(autoanswer == 0) then
if(d_id == "d_got_item") then
autoanswer = 1
d_option.o_autoanswer = 1
answer_text =
"container[0.0,7.3]"..
"label[0.2,0.0;..this option will be selected automaticly.]"
end
if(autoanswer == 0 and d_id ~= "d_got_item") then
answer_text = answer_text..
"label[1.2,0.8;A:]"..
"field[1.7,0.3;19.6,0.9;text_option_"..minetest.formspec_escape(o_id)..";;"..

View File

@ -63,6 +63,9 @@ end
--###
yl_speak_up.get_number_from_id = function(any_id)
if(any_id == "d_got_item") then
return "0"
end
return string.split(any_id, "_")[2]
end
@ -634,6 +637,25 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
end
end
-- add a "I want to give you something" button to the first dialog if the NPC accepts items
if(active_dialog and active_dialog.d_sort and tonumber(active_dialog.d_sort) == 0) then
local offer_item_add_text = ""
if(edit_mode) then
offer_item_add_text = minetest.formspec_escape("[dialog d_got_item] -> ")
end
-- show this in edit mode and when the NPC actually accepts items
if(edit_mode or dialog.n_dialogs["d_got_item"]) then
h = h + 1
table.insert(formspec, "button[0.5," .. h .. ";53.8,0.9;player_offers_item;]")
table.insert(formspec, "tooltip[player_offers_item;"..
"If you want to give something (items) to this NPC\n"..
"- either because he requested it or as a present -\n"..
"click here. The NPC will return items he doesn't want.]")
table.insert(formspec, "label[0.7,"..(h+0.45)..";"..offer_item_add_text..
"I want to give you something.]")
end
end
-- If in edit mode, add two new menu entries: "add new options" and "end edit mode".
if(edit_mode) then
-- chat option: "Add a new answer/option to this dialog."
@ -1670,6 +1692,29 @@ yl_speak_up.input_talk = function(player, formname, fields)
return
end
-- the player wants to give something to the NPC
if(fields.player_offers_item) then
if(not(edit_mode)) then
-- normal mode: take the item the player wants to offer
yl_speak_up.show_fs(player, "player_offers_item", nil)
else
local dialog = yl_speak_up.speak_to[pname].dialog
local future_d_id = "d_got_item"
-- make sure this dialog exists; create if needed
if(not(dialog.n_dialogs[ future_d_id ])) then
dialog.n_dialogs[future_d_id] = {
d_id = future_d_id,
d_type = "text",
d_text = "",
d_sort = next_id
}
end
-- in edit mode: allow to edit the options
yl_speak_up.show_fs(player, "talk", {n_id = n_id, d_id = future_d_id})
end
return
end
for k, v in pairs(fields) do
local s = string.split(k, "_")

View File

@ -45,6 +45,8 @@ dofile(modpath .. "fs_edit_effects.lua")
dofile(modpath .. "fs_edit_options_dialog.lua")
-- set name, description and owner (owner only with npc_talk_master priv)
dofile(modpath .. "fs_initial_config.lua")
-- inspect and accept items the player gave to the NPC
dofile(modpath .. "fs_player_offers_item.lua")
-- inventory management, trading and handling of quest items:
dofile(modpath .. "inventory.lua")
-- trade one item(stack) against one other item(stack)

View File

@ -30,6 +30,10 @@ minetest.register_on_player_receive_fields( function(player, formname, fields)
elseif formname == "yl_speak_up:trade_list" then
yl_speak_up.input_trade_list(player, formname, fields)
return true
-- handled in fs_player_offers_item.lua
elseif formname == "yl_speak_up:player_offers_item" then
yl_speak_up.input_player_offers_item(player, formname, fields)
return true
-- handled in trade_simple.lua
elseif formname == "yl_speak_up:do_trade_simple" then
yl_speak_up.input_do_trade_simple(player, formname, fields)
@ -230,6 +234,10 @@ yl_speak_up.show_fs = function(player, fs_name, param)
minetest.show_formspec(pname, "yl_speak_up:trade_list",
yl_speak_up.get_fs_trade_list(player, param))
elseif(fs_name == "player_offers_item") then
minetest.show_formspec(pname, "yl_speak_up:player_offers_item",
yl_speak_up.get_fs_player_offers_item(player, param))
elseif(fs_name == "trade_simple") then
-- the optional parameter param is the trade_id
if(not(param) and yl_speak_up.speak_to[pname]) then