forked from Sokomine/yl_speak_up
implemented deal_with_offered_item effect (only editing, not effect yet)
This commit is contained in:
parent
031fda8411
commit
3c52cfeae6
@ -48,6 +48,7 @@ local check_what = {
|
||||
"put item from the NPC's inventory into a chest etc.", -- 4
|
||||
"take item from a chest etc. and put it into the NPC's inventory",
|
||||
-- 5
|
||||
"an item the player offered to the NPC",
|
||||
"NPC crafts something", -- 6
|
||||
"go to other dialog if the previous effect failed", -- 7
|
||||
"send a chat message to all players", -- 8
|
||||
@ -62,6 +63,8 @@ local check_what = {
|
||||
local values_what = {"", "state", "block",
|
||||
-- interact with the inventory of blocks on the map
|
||||
"put_into_block_inv", "take_from_block_inv",
|
||||
-- the player gave an item to the NPC; now deal with it somehow
|
||||
"deal_with_offered_item",
|
||||
-- crafting, handling failure, send chat message to all
|
||||
"craft", "on_failure", "chat_all",
|
||||
-- the following require the npc_master priv:
|
||||
@ -101,6 +104,17 @@ local values_operator = {"", "set_to", "unset", "set_to_current_time",
|
||||
"quest_step", "maximum", "minimum", "increment", "decrement"}
|
||||
|
||||
|
||||
-- for "deal_with_offered_item", used i.e. in yl_speak_up.get_fs_edit_option_effect_deal_with_offered_item
|
||||
yl_speak_up.dropdown_list_deal_with_offered_item = {
|
||||
minetest.formspec_escape("- please select -"),
|
||||
"Take the expected part of the offered item(s) and put them in the NPC's inventory.",
|
||||
"Accept all of the offered item(s) and put them in the NPC's inventory.",
|
||||
"Refuse and give the item(s) back."
|
||||
}
|
||||
-- the values that will be stored for yl_speak_up.dropdown_list_deal_with_offered_item above
|
||||
yl_speak_up.dropdown_values_deal_with_offered_item = {
|
||||
"do_nothing", "take_as_wanted", "take_all", "refuse_all"}
|
||||
|
||||
-- get the list of variables the player has *write* access to
|
||||
yl_speak_up.get_sorted_player_var_list_write_access = function(pname)
|
||||
local var_list = {}
|
||||
@ -256,6 +270,14 @@ yl_speak_up.show_effect = function(r, pname)
|
||||
minetest.pos_to_string(r.r_pos)..
|
||||
" out of inventory list \""..tostring(r.r_inv_list_name)..
|
||||
"\" and put it into the NPC's inventory."
|
||||
elseif(r.r_type == "deal_with_offered_item") then
|
||||
local nr = 1
|
||||
if(r.r_value) then
|
||||
nr = math.max(1, table.indexof(yl_speak_up.dropdown_values_deal_with_offered_item,
|
||||
r.r_value))
|
||||
return yl_speak_up.dropdown_list_deal_with_offered_item[ nr ]
|
||||
end
|
||||
return "ERROR: Missing subtype r.r_value: \""..tostring(r.r_value).."\""
|
||||
end
|
||||
-- fallback
|
||||
return tostring(r.r_value)
|
||||
|
@ -713,6 +713,17 @@ yl_speak_up.save_element_p_or_a_or_e = function(
|
||||
local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs)
|
||||
v[ "a_on_failure" ] = sorted_dialog_list[ data.action_failure_dialog ]
|
||||
|
||||
elseif(what_type == "deal_with_offered_item" and id_prefix == "r_") then
|
||||
if(not(data.select_deal_with_offered_item) or data.select_deal_with_offered_item < 2) then
|
||||
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;Error: Please select what the NPC shall do!]"..
|
||||
"button[1.5,2.0;2,0.9;back_from_error_msg;Back]"})
|
||||
return
|
||||
end
|
||||
v[ "r_value" ] = yl_speak_up.dropdown_values_deal_with_offered_item[data.select_deal_with_offered_item]
|
||||
|
||||
-- "Call custom functions that are supposed to be overridden by the server.", --
|
||||
-- precondition: 9; action: 7; effect: 13
|
||||
elseif((id_prefix == "a_" and what_type == "custom")
|
||||
@ -904,6 +915,11 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields,
|
||||
return
|
||||
end
|
||||
|
||||
elseif(fields.select_deal_with_offered_item and fields.select_deal_with_offered_item ~= "") then
|
||||
data.select_deal_with_offered_item = table.indexof(
|
||||
yl_speak_up.dropdown_list_deal_with_offered_item,
|
||||
fields.select_deal_with_offered_item)
|
||||
|
||||
elseif(fields.select_accept_group and fields.select_accept_group ~= ""
|
||||
and data and data.what and what_type == "player_offered_item" and id_prefix == "p_") then
|
||||
data.item_group = fields.select_accept_group
|
||||
@ -1171,6 +1187,7 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields,
|
||||
and (fields.change_element or fields.select_what or fields.select_trade
|
||||
or fields.select_inv or fields.select_block
|
||||
or fields.inv_list_name
|
||||
or fields.select_deal_with_offered_item
|
||||
or fields.select_accept_group
|
||||
or fields.select_match_stack_size
|
||||
or fields.select_variable or fields.select_operator
|
||||
@ -1427,6 +1444,10 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
|
||||
pname, dialog, formspec, data, id_prefix, save_button, e,
|
||||
values_inv, check_inv, values_block)
|
||||
|
||||
elseif(data.what and id_prefix == "r_" and what_type == "deal_with_offered_item") then
|
||||
return yl_speak_up.get_fs_edit_option_effect_deal_with_offered_item(
|
||||
pname, dialog, formspec, data, id_prefix, save_button, e)
|
||||
|
||||
-- "give item (created out of thin air) to player (requires npc_master priv)", -- 9
|
||||
-- "take item from player and destroy it (requires npc_master priv)", -- 10
|
||||
elseif(data.what and id_prefix == "r_" and (what_type == "give_item" or what_type=="take_item")) then
|
||||
@ -1789,6 +1810,28 @@ yl_speak_up.get_fs_edit_option_precondition_inv = function(
|
||||
end
|
||||
|
||||
|
||||
-- "an item the player offered to the NPC"
|
||||
yl_speak_up.get_fs_edit_option_effect_deal_with_offered_item = function(
|
||||
pname, dialog, formspec, data, id_prefix, save_button, e)
|
||||
if(e) then
|
||||
data.select_deal_with_offered_item = table.indexof(
|
||||
yl_speak_up.dropdown_values_deal_with_offered_item,
|
||||
e[ "r_value" ])
|
||||
end
|
||||
if(not(data) or not(data.select_deal_with_offered_item)
|
||||
or data.select_deal_with_offered_item < 2) then
|
||||
save_button = ""
|
||||
data.select_deal_with_offered_item = 1
|
||||
end
|
||||
return formspec..
|
||||
"label[0.2,3.3;The NPC shall:]"..
|
||||
"dropdown[4.0,3.0;15.0,0.7;select_deal_with_offered_item;"..
|
||||
table.concat(yl_speak_up.dropdown_list_deal_with_offered_item, ",")..";"..
|
||||
tostring(data.select_deal_with_offered_item)..";]"..
|
||||
save_button
|
||||
end
|
||||
|
||||
|
||||
-- "give item (created out of thin air) to player (requires npc_master priv)", -- 9
|
||||
-- "take item from player and destroy it (requires npc_master priv)", -- 10
|
||||
yl_speak_up.get_fs_edit_option_effect_give_item_or_take_item = function(
|
||||
@ -2073,7 +2116,7 @@ yl_speak_up.get_fs_edit_option_action_npc_wants_or_accepts = function(
|
||||
node_name = tostring(data.item_node_name or data.item_string)
|
||||
bg_img = "item_image[1.15,3.65;0.7,0.7;"..node_name.."]"
|
||||
end
|
||||
info_text = ""
|
||||
local info_text = ""
|
||||
if(id_prefix == "p_") then
|
||||
local group_list = {minetest.formspec_escape("- no, just this one item -")}
|
||||
-- get node name without amount
|
||||
|
Loading…
Reference in New Issue
Block a user