mirror of
https://gitea.your-land.de/Sokomine/yl_speak_up.git
synced 2025-06-25 08:38:03 +02:00
allow to use item slot to describe stack for preconditions
This commit is contained in:
parent
228faed97d
commit
c24cce74b1
@ -216,27 +216,51 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields,
|
|||||||
-- are we talking about an inventory?
|
-- are we talking about an inventory?
|
||||||
-- (inventory only applies to preconditions; not effects)
|
-- (inventory only applies to preconditions; not effects)
|
||||||
local data = yl_speak_up.speak_to[pname][ tmp_data_cache ]
|
local data = yl_speak_up.speak_to[pname][ tmp_data_cache ]
|
||||||
if(fields.inv_stack_name and fields.inv_stack_name ~= ""
|
if(((fields.inv_stack_name and fields.inv_stack_name ~= "")
|
||||||
|
or (fields.store_item_name and fields.store_item_name ~= ""))
|
||||||
and id_prefix == "p_"
|
and id_prefix == "p_"
|
||||||
and data and data.what and data.what >= 5 and data.what <= 6) then
|
and data and data.what and data.what >= 5 and data.what <= 6) then
|
||||||
local parts = fields.inv_stack_name:split(" ")
|
local wanted = ""
|
||||||
local size = 1
|
local wanted_name = ""
|
||||||
if(parts and #parts > 1) then
|
if(not(fields.store_item_name)) then
|
||||||
size = tonumber(parts[2])
|
local parts = fields.inv_stack_name:split(" ")
|
||||||
if(not(size) or size < 1) then
|
local size = 1
|
||||||
size = 1
|
if(parts and #parts > 1) then
|
||||||
|
size = tonumber(parts[2])
|
||||||
|
if(not(size) or size < 1) then
|
||||||
|
size = 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
wanted = parts[1].." "..tostring(size)
|
||||||
|
wanted_name = parts[1]
|
||||||
|
else
|
||||||
|
local trade_inv = minetest.get_inventory({type="detached",
|
||||||
|
name="yl_speak_up_player_"..pname})
|
||||||
|
if(not(trade_inv) or trade_inv:is_empty("npc_wants", 1)) then
|
||||||
|
-- show error message
|
||||||
|
yl_speak_up.show_fs(player, "msg", {
|
||||||
|
input_to = "yl_speak_up:"..formspec_input_to,
|
||||||
|
formspec = "size[8,2]"..
|
||||||
|
"label[0.2,0.0;Please put an item(stack) into the slot "..
|
||||||
|
"next to the\n\"Store\" button first!]"..
|
||||||
|
"button[1.5,1.5;2,0.9;back_from_error_msg;Back]"})
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local stack = trade_inv:get_stack("npc_wants", 1)
|
||||||
|
wanted = stack:get_name().." "..stack:get_count()
|
||||||
|
wanted_name = stack:get_name()
|
||||||
end
|
end
|
||||||
-- does the item exist?
|
-- does the item exist?
|
||||||
if(minetest.registered_items[ parts[1] ]) then
|
if(minetest.registered_items[ wanted_name ]) then
|
||||||
data.inv_stack_name = parts[1].." "..tostring(size)
|
data.inv_stack_name = wanted
|
||||||
|
fields.inv_stack_name = wanted
|
||||||
else
|
else
|
||||||
-- show error message
|
-- show error message
|
||||||
yl_speak_up.show_fs(player, "msg", {
|
yl_speak_up.show_fs(player, "msg", {
|
||||||
input_to = "yl_speak_up:"..formspec_input_to,
|
input_to = "yl_speak_up:"..formspec_input_to,
|
||||||
formspec = "size[8,2]"..
|
formspec = "size[8,2]"..
|
||||||
"label[0.2,0.5;Error: \""..
|
"label[0.2,0.5;Error: \""..
|
||||||
minetest.formspec_escape(fields.inv_stack_name)..
|
minetest.formspec_escape(wanted)..
|
||||||
"\" is not a valid item(stack).]"..
|
"\" is not a valid item(stack).]"..
|
||||||
"button[1.5,1.5;2,0.9;back_from_error_msg;Back]"})
|
"button[1.5,1.5;2,0.9;back_from_error_msg;Back]"})
|
||||||
return
|
return
|
||||||
@ -665,7 +689,7 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields,
|
|||||||
|
|
||||||
-- select a general direction/type first
|
-- select a general direction/type first
|
||||||
-- but *not* when enter was pressed (enter sends them all)
|
-- but *not* when enter was pressed (enter sends them all)
|
||||||
if(fields.select_what and not(fields.key_enter)) then
|
if(fields.select_what and not(fields.key_enter) and not(fields.store_item_name)) then
|
||||||
local nr = table.indexof(check_what, fields.select_what)
|
local nr = table.indexof(check_what, fields.select_what)
|
||||||
yl_speak_up.speak_to[pname][ tmp_data_cache ] = { what = nr }
|
yl_speak_up.speak_to[pname][ tmp_data_cache ] = { what = nr }
|
||||||
end
|
end
|
||||||
@ -728,6 +752,7 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields,
|
|||||||
or fields.select_on_failure
|
or fields.select_on_failure
|
||||||
or fields.select_on_action_failure
|
or fields.select_on_action_failure
|
||||||
or fields.back_from_error_msg
|
or fields.back_from_error_msg
|
||||||
|
or fields.store_item_name
|
||||||
or was_changed
|
or was_changed
|
||||||
or fields.key_enter
|
or fields.key_enter
|
||||||
or fields.quit
|
or fields.quit
|
||||||
@ -946,7 +971,7 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
|
|||||||
|
|
||||||
if(id_prefix ~= "a_") then
|
if(id_prefix ~= "a_") then
|
||||||
formspec = formspec..
|
formspec = formspec..
|
||||||
"label[1,9.0;If you are unsure if your setup of pre(C)onditions and (Ef)fects "..
|
"label[1,10.5;If you are unsure if your setup of pre(C)onditions and (Ef)fects "..
|
||||||
"works as intended,\ntype \"/npc_talk_debug "..tostring(n_id).."\" "..
|
"works as intended,\ntype \"/npc_talk_debug "..tostring(n_id).."\" "..
|
||||||
"in chat in order to enter debug mode. You can leave it with "..
|
"in chat in order to enter debug mode. You can leave it with "..
|
||||||
"\"/npc_talk_debug off\".]"
|
"\"/npc_talk_debug off\".]"
|
||||||
@ -1096,15 +1121,20 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
|
|||||||
save_button = ""
|
save_button = ""
|
||||||
end
|
end
|
||||||
formspec = formspec..
|
formspec = formspec..
|
||||||
"label[0.2,3.3;The following shall be true about the inventory:]"..
|
"label[0.2,3.0;The following shall be true about the inventory:]"..
|
||||||
"dropdown[4.0,3.5;16.0,0.6;select_inv;"..
|
"dropdown[4.0,3.2;16.0,0.6;select_inv;"..
|
||||||
table.concat(check_inv, ",")..";"..
|
table.concat(check_inv, ",")..";"..
|
||||||
tostring(data.inv)..";]"..
|
tostring(data.inv)..";]"..
|
||||||
"label[0.2,4.5;Name of the item(stack):]"..
|
"label[0.2,4.2;Name of the item(stack):]"..
|
||||||
"field[4.0,4.3;16.0,0.6;inv_stack_name;;"..(data.inv_stack_name or "").."]"..
|
"field[4.0,4.0;16.0,0.6;inv_stack_name;;"..(data.inv_stack_name or "").."]"..
|
||||||
"tooltip[inv_stack_name;Enter name of the block and amount.\n"..
|
"tooltip[inv_stack_name;Enter name of the block and amount.\n"..
|
||||||
"Example: \"default:apple 3\" for three apples,\n"..
|
"Example: \"default:apple 3\" for three apples,\n"..
|
||||||
" \"farming:bread\" for a bread.]"
|
" \"farming:bread\" for a bread.]"..
|
||||||
|
"label[0.2,5.7;Or put the item in here\nand click on \"Store\":]"..
|
||||||
|
"button[5.5,5.5;1.5,0.9;store_item_name;Store]"..
|
||||||
|
"list[detached:yl_speak_up_player_"..pname..";npc_wants;4.0,5.5;1,1;]"..
|
||||||
|
"label[8,4.9;Your inventory:]"..
|
||||||
|
"list[current_player;main;8,5.3;8,4;]"
|
||||||
|
|
||||||
-- "NPC crafts something", -- 4
|
-- "NPC crafts something", -- 4
|
||||||
-- (craft - only for effects - not for preconditions)
|
-- (craft - only for effects - not for preconditions)
|
||||||
|
Loading…
Reference in New Issue
Block a user