implemented saving of player_offered_item precondition

This commit is contained in:
Sokomine 2022-01-04 04:52:24 +01:00
parent d4e7870c05
commit 42233f59a1

View File

@ -557,15 +557,23 @@ yl_speak_up.save_element_p_or_a_or_e = function(
-- "The NPC gives something to the player (i.e. a quest item).", -- 4
-- "The player is expected to give something to the NPC (i.e. a quest item).", -- 5
-- (only for actions)
elseif((what_type == "npc_gives" or what_type == "npc_wants") and id_prefix == "a_") then
elseif(((what_type == "npc_gives" or what_type == "npc_wants") and id_prefix == "a_")
or (what_type == "player_offered_item" and id_prefix == "p_")) then
local trade_inv_list = what_type
if(id_prefix == "p_") then
trade_inv_list = "npc_wants"
end
local trade_inv = minetest.get_inventory({type="detached", name="yl_speak_up_player_"..pname})
if(not(trade_inv) or trade_inv:is_empty( trade_inv_list )) then
local what = "give to"
if(id_prefix == "p_") then
what = "accept from"
end
yl_speak_up.show_fs(player, "msg", {
input_to = "yl_speak_up:"..formspec_input_to,
formspec = "size[9,2.5]"..
"label[0.2,0.5;Please insert an item first! Your NPC "..
"needs\nto know what it shall give to the player.]"..
"needs\nto know what it shall "..what.." the player.]"..
"button[1.5,2.0;2,0.9;back_from_error_msg;Back]"})
return
end
@ -587,7 +595,8 @@ yl_speak_up.save_element_p_or_a_or_e = function(
return
end
-- is this particular item blacklisted on this server?
if(yl_speak_up.blacklist_action_quest_item[ stack:get_name() ]) then
-- this is only relevant for actions, not for preconditions
if(id_prefix ~= "p_" and yl_speak_up.blacklist_action_quest_item[ stack:get_name() ]) then
yl_speak_up.show_fs(player, "msg", {
input_to = "yl_speak_up:"..formspec_input_to,
formspec = "size[9,2.5]"..
@ -598,10 +607,10 @@ yl_speak_up.save_element_p_or_a_or_e = function(
end
local meta = stack:get_meta()
-- what does the NPC want to give?
v[ "a_value" ] = stack:get_name().." "..stack:get_count()
v[ id_prefix.."value" ] = stack:get_name().." "..stack:get_count()
-- for displaying as a background image
data.item_string = v[ "a_value" ]
if(what_type == "npc_wants") then
data.item_string = v[ id_prefix.."value" ]
if(what_type == "npc_wants" or what_type == "player_offered_item") then
-- try to reconstruct $PLAYER_NAME$ (may not always work)
local item_was_for = meta:get_string("yl_speak_up:quest_item_for")
local new_desc = meta:get_string("description")
@ -617,9 +626,9 @@ yl_speak_up.save_element_p_or_a_or_e = function(
if(what_type == "npc_gives") then
meta:set_string("description", data.item_desc)
end
v[ "a_item_desc" ] = data.item_desc
v[ id_prefix.."item_desc" ] = data.item_desc
end
if(what_type == "npc_wants") then
if(what_type == "npc_wants" or what_type == "player_offers_item") then
data.item_quest_id = meta:get_string("yl_speak_up:quest_id")
end
-- set special ID (optional)
@ -635,7 +644,7 @@ yl_speak_up.save_element_p_or_a_or_e = function(
meta:set_string("yl_speak_up:quest_id",
tostring(n_id).." "..tostring(data.item_quest_id))
end
v[ "a_item_quest_id" ] = data.item_quest_id
v[ id_prefix.."item_quest_id" ] = data.item_quest_id
end
if( v["a_item_quest_id"] and not(v[ "a_item_desc"]) and what_type == "npc_gives") then
yl_speak_up.show_fs(player, "msg", {
@ -648,6 +657,9 @@ yl_speak_up.save_element_p_or_a_or_e = function(
"button[1.5,2.0;2,0.9;back_from_error_msg;Back]"})
return
end
if(data.item_group and data.item_group ~= "") then
v["p_item_group"] = data.item_group
end
local player_inv = player:get_inventory()
if(not(player_inv:room_for_item("main", stack))) then
yl_speak_up.show_fs(player, "msg", {
@ -1320,6 +1332,14 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
data.item_string = e[ "a_value"] -- stack name and count (as string)
data.item_desc = e[ "a_item_desc" ]
data.item_quest_id = e[ "a_item_quest_id" ]
-- player_offered_item precondition
elseif(data.what and id_prefix == "p_" and (data.what == 8)) then
-- data.item_string is used to show a background image
data.item_string = e[ "p_value"] -- stack name and count (as string)
data.item_desc = e[ "p_item_desc" ]
data.item_quest_id = e[ "p_item_quest_id" ]
data.item_group = e[ "p_item_group" ]
end
if(e[ "alternate_text"]) then
@ -2049,14 +2069,15 @@ yl_speak_up.get_fs_edit_option_action_npc_wants_or_accepts = function(
-- get node name without amount
local parts = node_name:split(" ")
local nr = 1
local count = 1
-- prepare group_list
if(data and parts and minetest.registered_items[ parts[1] ]) then
for k,v in pairs(minetest.registered_items[ parts[1] ].groups) do
table.insert(group_list, k)
end
nr = table.indexof(minetest.registered_items[ parts[1] ].groups, data.item_group)
if(nr == -1) then
nr = 1
count = count + 1
if(data.item_group and data.item_group == k) then
nr = count
end
end
end
-- use this for the group selection dialog as well
@ -2074,7 +2095,7 @@ yl_speak_up.get_fs_edit_option_action_npc_wants_or_accepts = function(
"list[detached:yl_speak_up_player_"..pname..";npc_wants;2,3.5;1,1;]"..
"label[3.2,4.0;"..
minetest.formspec_escape(
data.item_node_name
node_name
or "- no item set -").."]"..
"label[0.2,6.1;If you want a special ID and description, create\n"..
"those via the \"NPC gives something to the player\"\n"..