mirror of
https://gitea.your-land.de/Sokomine/yl_speak_up.git
synced 2025-06-20 22:28:02 +02:00
added effects craft and on_failure (but not implemented yet)
This commit is contained in:
parent
86701d5325
commit
6ec65d6a17
@ -20,9 +20,11 @@
|
||||
-- r_node (follows from r_pos)
|
||||
-- r_param2 (follows from r_pos)
|
||||
--
|
||||
-- a craft receipe: TODO
|
||||
-- a craft receipe:
|
||||
-- r_value the expected craft result
|
||||
-- r_craft_grid array containing the stacks in the 9 craft grid fields in string form
|
||||
--
|
||||
-- on_failure: TODO implement
|
||||
-- on_failure:
|
||||
-- r_value alternate target dialog if the action failed
|
||||
--
|
||||
-- Unlike in preconditions, trade (the trade action already happened) and
|
||||
@ -134,7 +136,11 @@ yl_speak_up.show_effect = function(r)
|
||||
minetest.pos_to_string(r.r_pos)..": \""..tostring(r.r_value).."\"?"
|
||||
end
|
||||
elseif(r.r_type == "craft") then
|
||||
return "TODO. Crafting is not yet supported."
|
||||
if(not(r.r_value) or not(r.r_craft_grid)) then
|
||||
return "ERROR: Crafting not configured correctly."
|
||||
end
|
||||
-- TODO: check here if the craft receipe is broken?
|
||||
return "Craft \""..tostring(r.r_value).."\" from "..table.concat(r.r_craft_grid, ", ").."."
|
||||
elseif(r.r_type == "on_failure") then
|
||||
return "If the action (i.e. trade) failed, go to dialog \""..tostring(r.r_value).. "\"."
|
||||
end
|
||||
|
@ -189,6 +189,34 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields,
|
||||
-- we have checked this value earlier on
|
||||
v[ "p_itemstack" ] = data.inv_stack_name
|
||||
end
|
||||
|
||||
-- "NPC crafts soemthing", -- 4
|
||||
-- (only for effects; not for preconditions)
|
||||
elseif(data.what and id_prefix == "r_" and data.what == 4) then
|
||||
local player_inv = player:get_inventory()
|
||||
if(player_inv:get_stack("craftpreview", 1):is_empty()) then
|
||||
yl_speak_up.show_fs(player, "msg", {
|
||||
input_to = "yl_speak_up:"..formspec_input_to,
|
||||
formspec = "size[8,2]"..
|
||||
"label[0.2,0.5;Error: Please prepare your craft grid first!"..
|
||||
"\nYour NPC needs to know what to craft.]"..
|
||||
"button[1.5,1.5;2,0.9;back_from_error_msg;Back]"})
|
||||
return
|
||||
end
|
||||
-- store the craft result (Note: the craft result may change in the future
|
||||
-- if the server changes its craft result, making this craft invalid)
|
||||
v[ "r_value" ] = player_inv:get_stack("craftpreview", 1):to_string()
|
||||
v[ "r_craft_grid"] = {}
|
||||
for i = 1, 9 do
|
||||
-- store all the indigrents of the craft grid
|
||||
table.insert( v[ "r_craft_grid" ],
|
||||
player_inv:get_stack("craft", i):to_string())
|
||||
end
|
||||
|
||||
-- "go to other dialog if the action (i.e. trade) failed", -- 5
|
||||
-- (only for effects; not for preconditions)
|
||||
elseif(data.what and id_prefix == "r_" and data.what == 5) then
|
||||
v[ "r_value" ] = data.on_failure
|
||||
end
|
||||
|
||||
-- only save if something was actually selected
|
||||
@ -250,6 +278,10 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields,
|
||||
elseif(fields.select_operator) then
|
||||
local nr = table.indexof(check_operator, fields.select_operator)
|
||||
yl_speak_up.speak_to[pname][ tmp_data_cache ].operator = nr
|
||||
|
||||
elseif(fields.select_on_failure) then
|
||||
-- in this case we really want the name of the target dialog
|
||||
yl_speak_up.speak_to[pname][ tmp_data_cache ].on_failure = fields.select_on_failure
|
||||
end
|
||||
|
||||
-- the player wants to change/edit a precondition
|
||||
@ -257,6 +289,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.select_variable or fields.select_operator
|
||||
or fields.select_on_failure
|
||||
or fields.back_from_error_msg)) then
|
||||
yl_speak_up.show_fs(player, formspec_input_to)
|
||||
return
|
||||
@ -508,7 +541,33 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
|
||||
-- "NPC crafts soemthing", -- 4
|
||||
-- (craft - only for effects - not for preconditions)
|
||||
elseif(data.what and id_prefix == "r_" and data.what == 4) then
|
||||
-- TODO: implement crafting handling
|
||||
formspec = formspec..
|
||||
"label[8,2.6;Your invnetory:]"..
|
||||
"list[current_player;main;8,3;8,4;]"..
|
||||
"label[1,3.1;Your craft grid:]"..
|
||||
"list[current_player;craft;1,3.5;3,3;]"..
|
||||
"list[current_player;craftpreview;5.8,4.75;1,1;]"..
|
||||
"image[4.6,4.8;1,1;gui_furnace_arrow_bg.png^[transformR270]"..
|
||||
"label[1,8.0;Use your craft grid to show your NPC what to craft "..
|
||||
"and how. Click on \"Save\" to save.]"
|
||||
|
||||
-- "go to other dialog if the action (i.e. trade) failed", -- 5
|
||||
-- (on_failure - only for effects - not for preconditions)
|
||||
elseif(data.what and id_prefix == "r_" and data.what == 5) then
|
||||
local dialog = yl_speak_up.speak_to[pname].dialog
|
||||
local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs)
|
||||
local nr = 1
|
||||
if(not(data) or not(data.on_failure)) then
|
||||
save_button = ""
|
||||
else
|
||||
nr = table.indexof(sorted_dialog_list, data.on_failure)
|
||||
end
|
||||
formspec = formspec..
|
||||
"label[0.2,3.3;If the action *failed* (i.e. the player didn't trade),]"..
|
||||
"label[0.2,3.8;switch to the following dialog:]"..
|
||||
"dropdown[5.0,3.5;6.5,0.6;select_on_failure;"..
|
||||
table.concat(sorted_dialog_list, ",")..";"..
|
||||
tostring(nr)..";]"
|
||||
end
|
||||
|
||||
return formspec..save_button
|
||||
|
Loading…
Reference in New Issue
Block a user