diff --git a/fs_edit_general.lua b/fs_edit_general.lua
index 603d1f4..4a843f6 100644
--- a/fs_edit_general.lua
+++ b/fs_edit_general.lua
@@ -1234,7 +1234,7 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
and ((id_prefix == "a_" and data.what == 7)
or (id_prefix == "p_" and data.what == 8)
or (id_prefix == "r_" and data.what == 11))) then
- return yl_speak_up.get_fs_edit_option_action_custom(
+ return yl_speak_up.get_fs_edit_option_all_custom(
pname, dialog, formspec, data, id_prefix, save_button, e)
end
@@ -1247,513 +1247,534 @@ end
-- TODO: text_variable, text_select_operator, values_operator, get_sorted_player_var_list_function
yl_speak_up.get_fs_edit_option_p_and_e_state = function(pname, dialog, formspec, data, id_prefix, save_button, e)
- if(e) then
- data.operator = math.max(1,table.indexof(values_operator, e[ id_prefix.."operator" ]))
- data.var_cmp_value = e[ id_prefix.."var_cmp_value" ]
- data.variable_name = e[ id_prefix.."variable" ]
- local var_list = get_sorted_player_var_list_function(pname)
- data.variable = math.max(1, table.indexof(var_list, e[ id_prefix.."variable"])+1)
- end
- if(not(data.variable) or data.variable < 1) then
- data.variable = 1
- -- not enough selected yet for saving
- save_button = ""
- elseif(not(data.operator) or data.operator == 1) then
- data.operator = 1
- save_button = ""
- end
- local field_for_value = "field[11.2,4.8;7.0,0.6;var_cmp_value;;"..
- minetest.formspec_escape(data.var_cmp_value or "- enter value -").."]"
- -- do not show value input field for unary operators
- -- (unary operators are diffrent for prerequirements and effects)
- if(not(data.operator)
- or (id_prefix == "p_" and (data.operator == 1 or (data.operator>=8 and data.operator<11)))
- -- "unset", "set_to_current_time"
- or (id_prefix == "r_" and (data.operator == 3 or data.operator == 4))) then
- field_for_value = "label[11.2,5.1;- not used for this operator -]"
- end
- -- the list of available variables needs to be extended with the ones
- -- the player has read access to, and the order has to be constant
- -- (because dropdown just returns an index)
+ if(e) then
+ data.operator = math.max(1,table.indexof(values_operator, e[ id_prefix.."operator" ]))
+ data.var_cmp_value = e[ id_prefix.."var_cmp_value" ]
+ data.variable_name = e[ id_prefix.."variable" ]
local var_list = get_sorted_player_var_list_function(pname)
- local var_list_text = "- please select -"
- for i, v in ipairs(var_list) do
- local parts = string.split(v, " ")
- local var_name = v
- if(parts and parts[1] and parts[1] == pname) then
- table.remove(parts, 1)
- var_name = table.concat(parts, " ")
- end
- var_list_text = var_list_text..","..minetest.formspec_escape(tostring(var_name))
+ data.variable = math.max(1, table.indexof(var_list, e[ id_prefix.."variable"])+1)
+ end
+ if(not(data.variable) or data.variable < 1) then
+ data.variable = 1
+ -- not enough selected yet for saving
+ save_button = ""
+ elseif(not(data.operator) or data.operator == 1) then
+ data.operator = 1
+ save_button = ""
+ end
+ local field_for_value = "field[11.2,4.8;7.0,0.6;var_cmp_value;;"..
+ minetest.formspec_escape(data.var_cmp_value or "- enter value -").."]"
+ -- do not show value input field for unary operators
+ -- (unary operators are diffrent for prerequirements and effects)
+ if(not(data.operator)
+ or (id_prefix == "p_" and (data.operator == 1 or (data.operator>=8 and data.operator<11)))
+ -- "unset", "set_to_current_time"
+ or (id_prefix == "r_" and (data.operator == 3 or data.operator == 4))) then
+ field_for_value = "label[11.2,5.1;- not used for this operator -]"
+ end
+ -- the list of available variables needs to be extended with the ones
+ -- the player has read access to, and the order has to be constant
+ -- (because dropdown just returns an index)
+ local var_list = get_sorted_player_var_list_function(pname)
+ local var_list_text = "- please select -"
+ for i, v in ipairs(var_list) do
+ local parts = string.split(v, " ")
+ local var_name = v
+ if(parts and parts[1] and parts[1] == pname) then
+ table.remove(parts, 1)
+ var_name = table.concat(parts, " ")
end
- return
- "label[0.2,3.3;"..text_variable.."]"..
- "label[0.2,4.3;Name of variable:]"..
- "dropdown[0.2,4.8;6.5,0.6;select_variable;"..
- var_list_text..";"..
- tostring(data.variable)..";]"..
- "label[7.0,4.3;"..text_select_operator.."]"..
- "dropdown[7.0,4.8;4.0,0.6;select_operator;"..
- table.concat(check_operator, ",")..";"..
- tostring(data.operator)..";]"..
- "label[11.2,4.3;"..text_select_value.."]"..
- field_for_value..
- "button[0.2,6.0;4.0,0.6;manage_variables;Manage variables]"..
- "hypertext[1.2,7.0;16.0,2.5;some_text;"..
- "Note: Each variable is player-specific and will be set and "..
- "checked for the player that currently talks to your NPC.\n"..
- "Note: You can set a variable to the current time in an effect. "..
- "After that, use a precondition to check if that variable was set \"more "..
- "than x seconds ago\" or \"less than x seconds ago\". This can be "..
- "useful for prevending your NPC from handing out the same quest item again "..
- "too quickly (players are inventive and may use your quest item for their "..
- "own needs).\n]"..
- save_button
+ var_list_text = var_list_text..","..minetest.formspec_escape(tostring(var_name))
+ end
+ return "label[0.2,3.3;"..text_variable.."]"..
+ "label[0.2,4.3;Name of variable:]"..
+ "dropdown[0.2,4.8;6.5,0.6;select_variable;"..
+ var_list_text..";"..
+ tostring(data.variable)..";]"..
+ "label[7.0,4.3;"..text_select_operator.."]"..
+ "dropdown[7.0,4.8;4.0,0.6;select_operator;"..
+ table.concat(check_operator, ",")..";"..
+ tostring(data.operator)..";]"..
+ "label[11.2,4.3;"..text_select_value.."]"..
+ field_for_value..
+ "button[0.2,6.0;4.0,0.6;manage_variables;Manage variables]"..
+ "hypertext[1.2,7.0;16.0,2.5;some_text;"..
+ "Note: Each variable is player-specific and will be set and "..
+ "checked for the player that currently talks to your NPC.\n"..
+ "Note: You can set a variable to the current time in an effect. "..
+ "After that, use a precondition to check if that variable was set \"more "..
+ "than x seconds ago\" or \"less than x seconds ago\". This can be "..
+ "useful for prevending your NPC from handing out the same quest item again "..
+ "too quickly (players are inventive and may use your quest item for their "..
+ "own needs).\n]"..
+ save_button
end
-- TODO: block_pos as parameter?, values_block
yl_speak_up.get_fs_edit_option_p_and_e_block = function(pname, dialog, formspec, data, id_prefix, save_button, e)
- if(e) then
- data.block = math.max(1,table.indexof(values_block, e[ id_prefix.."value" ]))
- data.node_data = {}
- data.node_data.data = e[ id_prefix.."node" ]
- data.node_data.param2 = e[ id_prefix.."param2" ]
- data.block_pos = {x=e[ id_prefix.."pos" ].x,
- y=e[ id_prefix.."pos" ].y,
- z=e[ id_prefix.."pos" ].z}
- -- the block below was punched
- if(id_prefix == "p_" and data.block == 5) then
- data.block_pos.y = data.block_pos.y - 1
+ if(e) then
+ data.block = math.max(1,table.indexof(values_block, e[ id_prefix.."value" ]))
+ data.node_data = {}
+ data.node_data.data = e[ id_prefix.."node" ]
+ data.node_data.param2 = e[ id_prefix.."param2" ]
+ data.block_pos = {x=e[ id_prefix.."pos" ].x,
+ y=e[ id_prefix.."pos" ].y,
+ z=e[ id_prefix.."pos" ].z}
+ -- the block below was punched
+ if(id_prefix == "p_" and data.block == 5) then
+ data.block_pos.y = data.block_pos.y - 1
+ end
+ end
+ local block_pos_str = "- none set -"
+ local node = {name = "- unknown -", param2 = "- unkown -"}
+ if(not(block_pos) and data and data.block_pos) then
+ block_pos = data.block_pos
+ end
+ local error_is_protected = ""
+ if(block_pos) then
+ -- store for later usage
+ data.block_pos = block_pos
+ local tmp_pos = {x=block_pos.x, y=block_pos.y, z=block_pos.z}
+ -- "I can't punch it. The block is as the block *above* the one I punched.",
+ -- (only valid for preconditions; not for effects - because the player and
+ -- his NPC need to be able to build there)
+ if(data.block and id_prefix == "p_" and data.block == 5) then
+ tmp_pos.y = block_pos.y + 1
+ end
+ -- effects (and, likewise, preconditions): the player at least has to be able to
+ -- build at that position - check that
+ if(minetest.is_protected(tmp_pos, pname)) then
+ error_is_protected = "label[0.2,7.8;Error: "..
+ "The position you punched is protected. It cannot be used by "..
+ "your NPC for checks or building. Please select a diffrent block!]"
+ block_pos = nil
+ data.block_pos = nil
+ else
+ block_pos_str = minetest.pos_to_string(tmp_pos)
+ node = minetest.get_node_or_nil(tmp_pos)
+ if(not(node)) then
+ node = {name = "- unknown -", param2 = "- unkown -"}
end
- end
- local block_pos_str = "- none set -"
- local node = {name = "- unknown -", param2 = "- unkown -"}
- if(not(block_pos) and data and data.block_pos) then
- block_pos = data.block_pos
- end
- local error_is_protected = ""
- if(block_pos) then
- -- store for later usage
- data.block_pos = block_pos
- local tmp_pos = {x=block_pos.x, y=block_pos.y, z=block_pos.z}
- -- "I can't punch it. The block is as the block *above* the one I punched.",
- -- (only valid for preconditions; not for effects - because the player and
- -- his NPC need to be able to build there)
- if(data.block and id_prefix == "p_" and data.block == 5) then
- tmp_pos.y = block_pos.y + 1
- end
- -- effects (and, likewise, preconditions): the player at least has to be able to
- -- build at that position - check that
- if(minetest.is_protected(tmp_pos, pname)) then
- error_is_protected = "label[0.2,7.8;Error: "..
- "The position you punched is protected. It cannot be used by "..
- "your NPC for checks or building. Please select a diffrent block!]"
- block_pos = nil
- data.block_pos = nil
- else
- block_pos_str = minetest.pos_to_string(tmp_pos)
- node = minetest.get_node_or_nil(tmp_pos)
- if(not(node)) then
- node = {name = "- unknown -", param2 = "- unkown -"}
- end
- -- "There shall be air instead of this block.",
- -- (only valid for preconditions)
- if(data.block and id_prefix == "p_" and data.block == 3) then
- node = {name = "air", param2 = 0}
- end
- -- cache that (in case a sapling grows or someone else changes it)
- data.node_data = node
+ -- "There shall be air instead of this block.",
+ -- (only valid for preconditions)
+ if(data.block and id_prefix == "p_" and data.block == 3) then
+ node = {name = "air", param2 = 0}
end
+ -- cache that (in case a sapling grows or someone else changes it)
+ data.node_data = node
end
- if(node.name == "- unknown -") then
- save_button = ""
- end
- if(not(data.block) or data.block == 1) then
- data.block = 1
- -- not enough selected yet for saving
- save_button = ""
- end
- return
- "label[0.2,3.3;"..text_block_position.."]"..
- "dropdown[4.0,3.5;16.0,0.6;select_block;"..
- table.concat(check_block, ",")..";"..
- tostring(data.block)..";]"..
- "label[0.2,4.8;Position of the block:]"..
- "label[4.0,4.8;"..minetest.formspec_escape(block_pos_str).."]"..
- "label[0.2,5.8;Name of block:]"..
- "label[4.0,5.8;"..minetest.formspec_escape(node.name).."]"..
- "label[0.2,6.8;Orientation (param2):]"..
- "label[4.0,6.8;"..minetest.formspec_escape(node.param2).."]"..
- "button_exit[10.0,5.5;4.0,0.7;select_block_pos;Set position of block]"..
- "tooltip[select_block_pos;Click on this button to select a block.\n"..
- "This menu will close and you will be asked to punch\n"..
- "the block at the position you want to check or change.\n"..
- "After punching it, you will be returned to this menu.]"..
- error_is_protected..
- save_button
+ end
+ if(node.name == "- unknown -") then
+ save_button = ""
+ end
+ if(not(data.block) or data.block == 1) then
+ data.block = 1
+ -- not enough selected yet for saving
+ save_button = ""
+ end
+ return "label[0.2,3.3;"..text_block_position.."]"..
+ "dropdown[4.0,3.5;16.0,0.6;select_block;"..
+ table.concat(check_block, ",")..";"..
+ tostring(data.block)..";]"..
+ "label[0.2,4.8;Position of the block:]"..
+ "label[4.0,4.8;"..minetest.formspec_escape(block_pos_str).."]"..
+ "label[0.2,5.8;Name of block:]"..
+ "label[4.0,5.8;"..minetest.formspec_escape(node.name).."]"..
+ "label[0.2,6.8;Orientation (param2):]"..
+ "label[4.0,6.8;"..minetest.formspec_escape(node.param2).."]"..
+ "button_exit[10.0,5.5;4.0,0.7;select_block_pos;Set position of block]"..
+ "tooltip[select_block_pos;Click on this button to select a block.\n"..
+ "This menu will close and you will be asked to punch\n"..
+ "the block at the position you want to check or change.\n"..
+ "After punching it, you will be returned to this menu.]"..
+ error_is_protected..
+ save_button
end
yl_speak_up.get_fs_edit_option_precondition_trade = function(pname, dialog, formspec, data, id_prefix, save_button, e)
- if(e) then
- data.trade = math.max(1,table.indexof(values_trade, e[ "p_value" ]))
- end
- if(not(data.trade) or data.trade == 1) then
- data.trade = 1
- -- not enough selected yet for saving
- save_button = ""
- end
- return
- "label[0.2,3.3;If the action is a trade, the following shall be true:]"..
- "dropdown[4.0,3.5;16.0,0.6;select_trade;"..
- table.concat(check_trade, ",")..";"..
- tostring(data.trade)..";]"..
- save_button
+ if(e) then
+ data.trade = math.max(1,table.indexof(values_trade, e[ "p_value" ]))
+ end
+ if(not(data.trade) or data.trade == 1) then
+ data.trade = 1
+ -- not enough selected yet for saving
+ save_button = ""
+ end
+ return "label[0.2,3.3;If the action is a trade, the following shall be true:]"..
+ "dropdown[4.0,3.5;16.0,0.6;select_trade;"..
+ table.concat(check_trade, ",")..";"..
+ tostring(data.trade)..";]"..
+ save_button
end
yl_speak_up.get_fs_edit_option_precondition_inv = function(pname, dialog, formspec, data, id_prefix, save_button, e)
- if(e) then
- data.inv = math.max(1,table.indexof(values_inv, e["p_value"]))
- data.inv_stack_name = e[ "p_itemstack" ]
- end
- if(not(data.inv) or data.inv == 1) then
- data.inv = 1
- -- not enough selected yet for saving
- save_button = ""
- end
- return
- "label[0.2,3.0;The following shall be true about the inventory:]"..
- "dropdown[4.0,3.2;16.0,0.6;select_inv;"..
- table.concat(check_inv, ",")..";"..
- tostring(data.inv)..";]"..
- "label[0.2,4.2;Name of the item(stack):]"..
- "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"..
- "Example: \"default:apple 3\" for three apples,\n"..
- " \"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;]"..
- save_button
+ if(e) then
+ data.inv = math.max(1,table.indexof(values_inv, e["p_value"]))
+ data.inv_stack_name = e[ "p_itemstack" ]
+ end
+ if(not(data.inv) or data.inv == 1) then
+ data.inv = 1
+ -- not enough selected yet for saving
+ save_button = ""
+ end
+ return "label[0.2,3.0;The following shall be true about the inventory:]"..
+ "dropdown[4.0,3.2;16.0,0.6;select_inv;"..
+ table.concat(check_inv, ",")..";"..
+ tostring(data.inv)..";]"..
+ "label[0.2,4.2;Name of the item(stack):]"..
+ "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"..
+ "Example: \"default:apple 3\" for three apples,\n"..
+ " \"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;]"..
+ save_button
end
yl_speak_up.get_fs_edit_option_effect_give_item_or_take_item = function(pname, dialog, formspec, data, id_prefix, save_button, e)
- if(e) then
- data.inv_stack_name = e[ "r_value" ] or ""
- end
- local text = "The following item shall be created out of thin air and added to the "..
- "player's inventory:"
- if(data.what == 8) then
- text = "The following item shall be removed from the player's inventory and "..
- "be destroyed:"
- end
- formspec = formspec..
- "label[0.2,3.0;"..text.."]"..
- "label[0.2,3.5;Note: You can *save* this effect only if you have the "..
- "\"npc_master\" priv!]"..
- "label[0.2,4.2;Name of the item(stack):]"..
- "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"..
- "Example: \"default:apple 3\" for three apples,\n"..
- " \"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;]"..
- save_button
+ if(e) then
+ data.inv_stack_name = e[ "r_value" ] or ""
+ end
+ local text = "The following item shall be created out of thin air and added to the "..
+ "player's inventory:"
+ if(data.what == 8) then
+ text = "The following item shall be removed from the player's inventory and "..
+ "be destroyed:"
+ end
+ return "label[0.2,3.0;"..text.."]"..
+ "label[0.2,3.5;Note: You can *save* this effect only if you have the "..
+ "\"npc_master\" priv!]"..
+ "label[0.2,4.2;Name of the item(stack):]"..
+ "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"..
+ "Example: \"default:apple 3\" for three apples,\n"..
+ " \"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;]"..
+ save_button
end
yl_speak_up.get_fs_edit_option_effect_move = function(pname, dialog, formspec, data, id_prefix, save_button, e)
- if(e) then
- if(e[ "r_value"] and type(e[ "r_value" ]) == "string") then
- local pos = minetest.string_to_pos(e[ "r_value" ])
- if(pos) then
- data.move_to_x = pos.x
- data.move_to_y = pos.y
- data.move_to_z = pos.z
- end
+ if(e) then
+ if(e[ "r_value"] and type(e[ "r_value" ]) == "string") then
+ local pos = minetest.string_to_pos(e[ "r_value" ])
+ if(pos) then
+ data.move_to_x = pos.x
+ data.move_to_y = pos.y
+ data.move_to_z = pos.z
end
end
- return
- "label[0.2,3.0;Move the player to this position:]"..
- "label[0.2,3.5;Note: You can *save* this effect only if you have the "..
- "\"npc_master\" priv!]"..
- "label[0.2,5.3;X:]"..
- "label[3.7,5.3;Y:]"..
- "label[7.2,5.3;Z:]"..
- "field[0.7,5.0;2.0,0.6;move_to_x;;"..(data.move_to_x or "").."]"..
- "field[4.2,5.0;2.0,0.6;move_to_y;;"..(data.move_to_y or "").."]"..
- "field[7.7,5.0;2.0,0.6;move_to_z;;"..(data.move_to_z or "").."]"..
- save_button
+ end
+ return "label[0.2,3.0;Move the player to this position:]"..
+ "label[0.2,3.5;Note: You can *save* this effect only if you have the "..
+ "\"npc_master\" priv!]"..
+ "label[0.2,5.3;X:]"..
+ "label[3.7,5.3;Y:]"..
+ "label[7.2,5.3;Z:]"..
+ "field[0.7,5.0;2.0,0.6;move_to_x;;"..(data.move_to_x or "").."]"..
+ "field[4.2,5.0;2.0,0.6;move_to_y;;"..(data.move_to_y or "").."]"..
+ "field[7.7,5.0;2.0,0.6;move_to_z;;"..(data.move_to_z or "").."]"..
+ save_button
end
-- for "precondition and effect"
yl_speak_up.get_fs_edit_option_p_and_e_function = function(pname, dialog, formspec, data, id_prefix, save_button, e)
- if(e) then
- if(e[ id_prefix.."value"] and e[ id_prefix.."value"] ~= "") then
- data.lua_code = e[ id_prefix.."value" ]
- end
+ if(e) then
+ if(e[ id_prefix.."value"] and e[ id_prefix.."value"] ~= "") then
+ data.lua_code = e[ id_prefix.."value" ]
end
- return
- "label[0.2,3.0;Execute the following Lua code (ought to return true or false):]"..
- "label[0.2,3.5;Note: You can *save* this effect only if you have the "..
- "\"npc_master\" priv!]"..
- "textarea[0.2,4.5;20,4.0;lua_code;;"..
- minetest.formspec_escape(tostring(data.lua_code)).."]"..
- save_button
+ end
+ return "label[0.2,3.0;Execute the following Lua code (ought to return true or false):]"..
+ "label[0.2,3.5;Note: You can *save* this effect only if you have the "..
+ "\"npc_master\" priv!]"..
+ "textarea[0.2,4.5;20,4.0;lua_code;;"..
+ minetest.formspec_escape(tostring(data.lua_code)).."]"..
+ save_button
end
yl_speak_up.get_fs_edit_option_effect_craft = function(pname, dialog, formspec, data, id_prefix, save_button, e)
- if(e) then
- -- those items can at least be shown as background images
- data.craftresult = e[ "r_value" ]
- data.craft_grid = e[ "r_craft_grid"]
- end
- local bg_img = ""
- if(data and data.craftresult and data.craft_grid) then
- bg_img = "item_image[5.95,4.90;0.7,0.7;"..tostring(data.craftresult).."]"
- for i, v in ipairs(data.craft_grid) do
- if(v and v ~= "") then
- bg_img = bg_img.."item_image["..
- tostring(1.15 + ((i-1)%3)*1.25)..","..
- tostring(3.65 + math.floor((i-1)/3)*1.30)..
- ";0.7,0.7;"..tostring(v).."]"
- end
+ if(e) then
+ -- those items can at least be shown as background images
+ data.craftresult = e[ "r_value" ]
+ data.craft_grid = e[ "r_craft_grid"]
+ end
+ local bg_img = ""
+ if(data and data.craftresult and data.craft_grid) then
+ bg_img = "item_image[5.95,4.90;0.7,0.7;"..tostring(data.craftresult).."]"
+ for i, v in ipairs(data.craft_grid) do
+ if(v and v ~= "") then
+ bg_img = bg_img.."item_image["..
+ tostring(1.15 + ((i-1)%3)*1.25)..","..
+ tostring(3.65 + math.floor((i-1)/3)*1.30)..
+ ";0.7,0.7;"..tostring(v).."]"
end
end
- return
- "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.]"..
- bg_img..
- save_button
+ end
+ return "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.]"..
+ bg_img..
+ save_button
end
yl_speak_up.get_fs_edit_option_effect_on_failure = function(pname, dialog, formspec, data, id_prefix, save_button, e)
- if(e) then
- data.on_failure = e[ "r_value" ]
- end
- 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
- local on_failure_dialog = ""
- if(dialog and dialog.n_dialogs and dialog.n_dialogs[ data.on_failure ]) then
- on_failure_dialog =
- "label[0.2,5.5;This will switch to dialog \""..
- minetest.formspec_escape(tostring(data.on_failure)).."\""..
- yl_speak_up.show_colored_dialog_text(
- dialog,
- data,
- data.on_failure,
- "1.2,5.8;18.0,2.0;d_text",
- ", but with the following *modified* text",
- ":]",
- "button_edit_effect_on_failure_text_change")
- end
- return
- "label[0.2,3.3;If the *previous* effect failed,]"..
- "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)..";]"..
- on_failure_dialog..
- save_button
+ if(e) then
+ data.on_failure = e[ "r_value" ]
+ end
+ 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
+ local on_failure_dialog = ""
+ if(dialog and dialog.n_dialogs and dialog.n_dialogs[ data.on_failure ]) then
+ on_failure_dialog =
+ "label[0.2,5.5;This will switch to dialog \""..
+ minetest.formspec_escape(tostring(data.on_failure)).."\""..
+ yl_speak_up.show_colored_dialog_text(
+ dialog,
+ data,
+ data.on_failure,
+ "1.2,5.8;18.0,2.0;d_text",
+ ", but with the following *modified* text",
+ ":]",
+ "button_edit_effect_on_failure_text_change")
+ end
+ return "label[0.2,3.3;If the *previous* effect failed,]"..
+ "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)..";]"..
+ on_failure_dialog..
+ save_button
end
yl_speak_up.get_fs_edit_option_effect_chat_all = function(pname, dialog, formspec, data, id_prefix, save_button, e)
- if(e) then
- data.chat_msg_text = e[ "r_value" ]
- end
- local default_text = "$NPC_NAME$ (owned by $OWNER_NAME$) announces: $PLAYER_NAME$ "..
- "- example; please enter the text -"
- return
- "label[0.2,3.3;Send the following chat message to *all* players:]"..
- "label[0.2,4.1;Message:]"..
- "field[2.0,3.8;16.0,0.6;chat_msg_text;;"..
- minetest.formspec_escape(
- data.chat_msg_text
- or default_text).."]"..
- "label[0.2,5.3;Note: Your chat message needs to contain the following placeholders,"..
- " which will be replaced automaticly like in dialog texts:"..
- "\n$NPC_NAME$, $PLAYER_NAME$ and $OWNER_NAME$.]"..
- save_button
+ if(e) then
+ data.chat_msg_text = e[ "r_value" ]
+ end
+ local default_text = "$NPC_NAME$ (owned by $OWNER_NAME$) announces: $PLAYER_NAME$ "..
+ "- example; please enter the text -"
+ return "label[0.2,3.3;Send the following chat message to *all* players:]"..
+ "label[0.2,4.1;Message:]"..
+ "field[2.0,3.8;16.0,0.6;chat_msg_text;;"..
+ minetest.formspec_escape(
+ data.chat_msg_text
+ or default_text).."]"..
+ "label[0.2,5.3;Note: Your chat message needs to contain the following placeholders,"..
+ " which will be replaced automaticly like in dialog texts:"..
+ "\n$NPC_NAME$, $PLAYER_NAME$ and $OWNER_NAME$.]"..
+ save_button
end
yl_speak_up.get_fs_edit_option_action_trade = function(pname, dialog, formspec, data, id_prefix, save_button, e)
- if(e) then
- data.trade_id = e[ "a_value" ]
- -- use as background images
- if(dialog and dialog.trades and dialog.trades[ data.trade_id ]) then
- data.pay = dialog.trades[ data.trade_id ].pay[1]
- data.buy = dialog.trades[ data.trade_id ].buy[1]
- end
- local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs)
- data.action_failure_dialog = math.max(1,
- table.indexof(sorted_dialog_list, e[ "a_on_failure" ]))
+ if(e) then
+ data.trade_id = e[ "a_value" ]
+ -- use as background images
+ if(dialog and dialog.trades and dialog.trades[ data.trade_id ]) then
+ data.pay = dialog.trades[ data.trade_id ].pay[1]
+ data.buy = dialog.trades[ data.trade_id ].buy[1]
end
- local dialog = yl_speak_up.speak_to[pname].dialog
- local d_id = yl_speak_up.speak_to[pname].d_id
- local o_id = yl_speak_up.speak_to[pname].o_id
- if(not(data.trade_id)) then
- data.trade_id = tostring(d_id).." "..tostring(o_id)
- end
- -- show the player which trade is stored
- local bg_img = ""
- if(data and data.buy and data.pay) then
- bg_img = "item_image[2.15,4.35;0.7,0.7;"..tostring(data.buy).."]"..
- "item_image[5.15,4.35;0.7,0.7;"..tostring(data.pay).."]"
- end
- yl_speak_up.speak_to[pname].trade_id = data.trade_id
- return
- "label[8,2.6;Your invnetory:]"..
- "list[current_player;main;8,3;8,4;]"..
- "label[0.2,3.1;Configure trade with "..minetest.formspec_escape(dialog.n_npc)..":]"..
- "label[0.5,3.8;The customer pays:]"..
- -- show the second slot of the setup inventory in the detached player's inv
- "list[detached:yl_speak_up_player_"..pname..";setup;2,4.2;1,1;]"..
- "image[3.5,4.2;1,1;gui_furnace_arrow_bg.png^[transformR270]"..
- "label[4.0,3.8;"..minetest.formspec_escape(dialog.n_npc or "?").." sells:]"..
- -- show the second slot of said inventory
- "list[detached:yl_speak_up_player_"..pname..";setup;5,4.2;1,1;1]"..
- bg_img..
- yl_speak_up.set_on_action_failure_dialog(pname, data,
- "The player shall trade at least once.")..
- save_button
+ local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs)
+ data.action_failure_dialog = math.max(1,
+ table.indexof(sorted_dialog_list, e[ "a_on_failure" ]))
+ end
+ local dialog = yl_speak_up.speak_to[pname].dialog
+ local d_id = yl_speak_up.speak_to[pname].d_id
+ local o_id = yl_speak_up.speak_to[pname].o_id
+ if(not(data.trade_id)) then
+ data.trade_id = tostring(d_id).." "..tostring(o_id)
+ end
+ -- show the player which trade is stored
+ local bg_img = ""
+ if(data and data.buy and data.pay) then
+ bg_img = "item_image[2.15,4.35;0.7,0.7;"..tostring(data.buy).."]"..
+ "item_image[5.15,4.35;0.7,0.7;"..tostring(data.pay).."]"
+ end
+ yl_speak_up.speak_to[pname].trade_id = data.trade_id
+ return "label[8,2.6;Your invnetory:]"..
+ "list[current_player;main;8,3;8,4;]"..
+ "label[0.2,3.1;Configure trade with "..minetest.formspec_escape(dialog.n_npc)..":]"..
+ "label[0.5,3.8;The customer pays:]"..
+ -- show the second slot of the setup inventory in the detached player's inv
+ "list[detached:yl_speak_up_player_"..pname..";setup;2,4.2;1,1;]"..
+ "image[3.5,4.2;1,1;gui_furnace_arrow_bg.png^[transformR270]"..
+ "label[4.0,3.8;"..minetest.formspec_escape(dialog.n_npc or "?").." sells:]"..
+ -- show the second slot of said inventory
+ "list[detached:yl_speak_up_player_"..pname..";setup;5,4.2;1,1;1]"..
+ bg_img..
+ yl_speak_up.set_on_action_failure_dialog(pname, data,
+ "The player shall trade at least once.")..
+ save_button
end
yl_speak_up.get_fs_edit_option_action_npc_gives = function(pname, dialog, formspec, data, id_prefix, save_button, e)
- local bg_img = ""
- if(data and data.item_string) then
- bg_img = "item_image[2.15,3.65;0.7,0.7;"..tostring(data.item_string).."]"
- end
- return
- "label[8,2.6;Your inventory:]"..
- "list[current_player;main;8,3;8,4;]"..
- "label[1,3.1;"..minetest.formspec_escape(dialog.n_npc or "?").." gives:]"..
- "list[detached:yl_speak_up_player_"..pname..";npc_gives;2,3.5;1,1;]"..
- "label[3.2,4.0;"..
- minetest.formspec_escape(
- data.item_node_name
- or "- no item set -").."]"..
- "label[0.2,5.6;Set a description to turn the item into a special\n"..
- "quest item. Set a special ID (short text) so that\n"..
- "the player cannot create a fake item. Click on \n"..
- "\"Save\" to apply the changes.\n"..
- "You can use placeholders like $PLAYER_NAME$ etc.]"..
- "label[0.2,8.3;Special ID to set:]"..
- "field[3.2,8.0;14.5,0.6;action_item_quest_id;;"..
- minetest.formspec_escape(
- data.item_quest_id
- or "- none set -").."]"..
- "tooltip[action_item_quest_id;"..
- "Set this to a text that helps *you* to remember what this\n"..
- "special quest item is for (i.e. \"quest_deliver_augusts_"..
- "letter\").\n"..
- "The ID will be extended with the ID of the NPC and the\n"..
- "name of the player who got this item from the NPC.]"..
- "label[0.2,9.0;Description to set:]"..
- "field[3.2,8.7;14.5,0.6;action_item_desc;;"..
- minetest.formspec_escape(
- data.item_desc
- or "- no item set -").."]"..
- "tooltip[action_item_desc;"..
- "Set this to a text that helps the *player* to remember what\n"..
- "this special quest item is for (i.e. \"Letter from August to\n"..
- "Frederike\" for a piece of paper).\n"..
- "This description is shown in the inventory on mouseover.]"..
- bg_img..
- yl_speak_up.set_on_action_failure_dialog(pname, data,
- "The player shall take this offered item.")..
- save_button
+ local bg_img = ""
+ if(data and data.item_string) then
+ bg_img = "item_image[2.15,3.65;0.7,0.7;"..tostring(data.item_string).."]"
+ end
+ return "label[8,2.6;Your inventory:]"..
+ "list[current_player;main;8,3;8,4;]"..
+ "label[1,3.1;"..minetest.formspec_escape(dialog.n_npc or "?").." gives:]"..
+ "list[detached:yl_speak_up_player_"..pname..";npc_gives;2,3.5;1,1;]"..
+ "label[3.2,4.0;"..
+ minetest.formspec_escape(
+ data.item_node_name
+ or "- no item set -").."]"..
+ "label[0.2,5.6;Set a description to turn the item into a special\n"..
+ "quest item. Set a special ID (short text) so that\n"..
+ "the player cannot create a fake item. Click on \n"..
+ "\"Save\" to apply the changes.\n"..
+ "You can use placeholders like $PLAYER_NAME$ etc.]"..
+ "label[0.2,8.3;Special ID to set:]"..
+ "field[3.2,8.0;14.5,0.6;action_item_quest_id;;"..
+ minetest.formspec_escape(
+ data.item_quest_id
+ or "- none set -").."]"..
+ "tooltip[action_item_quest_id;"..
+ "Set this to a text that helps *you* to remember what this\n"..
+ "special quest item is for (i.e. \"quest_deliver_augusts_"..
+ "letter\").\n"..
+ "The ID will be extended with the ID of the NPC and the\n"..
+ "name of the player who got this item from the NPC.]"..
+ "label[0.2,9.0;Description to set:]"..
+ "field[3.2,8.7;14.5,0.6;action_item_desc;;"..
+ minetest.formspec_escape(
+ data.item_desc
+ or "- no item set -").."]"..
+ "tooltip[action_item_desc;"..
+ "Set this to a text that helps the *player* to remember what\n"..
+ "this special quest item is for (i.e. \"Letter from August to\n"..
+ "Frederike\" for a piece of paper).\n"..
+ "This description is shown in the inventory on mouseover.]"..
+ bg_img..
+ yl_speak_up.set_on_action_failure_dialog(pname, data,
+ "The player shall take this offered item.")..
+ save_button
end
yl_speak_up.get_fs_edit_option_action_npc_wants = function(pname, dialog, formspec, data, id_prefix, save_button, e)
- local bg_img = ""
- if(data and data.item_string) then
- bg_img = "item_image[2.15,3.65;0.7,0.7;"..tostring(data.item_string).."]"
- end
- return
- "label[8,2.6;Your inventory:]"..
- "list[current_player;main;8,3;8,4;]"..
- "label[1,3.1;"..minetest.formspec_escape(dialog.n_npc or "?").." wants:]"..
- "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
- 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"..
- "menu option first and insert that item here. Don't\n"..
- "use other placeholders than $PLAYER_NAME$ for this!]"..
- "label[0.2,8.3;Expected special ID:]"..
- "label[4.0,8.3;"..
- minetest.formspec_escape(
- data.item_quest_id
- or "- none set -").."]"..
- "label[0.2,9.0;Expected description:]"..
- "label[4.0,9.0;"..
- minetest.formspec_escape(
- data.item_desc
- or "- none set -").."]"..
- bg_img..
- yl_speak_up.set_on_action_failure_dialog(pname, data,
- "The player shall give the NPC this item.")..
- save_button
+ local bg_img = ""
+ if(data and data.item_string) then
+ bg_img = "item_image[2.15,3.65;0.7,0.7;"..tostring(data.item_string).."]"
+ end
+ return "label[8,2.6;Your inventory:]"..
+ "list[current_player;main;8,3;8,4;]"..
+ "label[1,3.1;"..minetest.formspec_escape(dialog.n_npc or "?").." wants:]"..
+ "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
+ 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"..
+ "menu option first and insert that item here. Don't\n"..
+ "use other placeholders than $PLAYER_NAME$ for this!]"..
+ "label[0.2,8.3;Expected special ID:]"..
+ "label[4.0,8.3;"..
+ minetest.formspec_escape(
+ data.item_quest_id
+ or "- none set -").."]"..
+ "label[0.2,9.0;Expected description:]"..
+ "label[4.0,9.0;"..
+ minetest.formspec_escape(
+ data.item_desc
+ or "- none set -").."]"..
+ bg_img..
+ yl_speak_up.set_on_action_failure_dialog(pname, data,
+ "The player shall give the NPC this item.")..
+ save_button
end
yl_speak_up.get_fs_edit_option_action_text_input = function(pname, dialog, formspec, data, id_prefix, save_button, e)
- if(e) then
- data.quest_question = e[ "a_question" ]
- data.quest_answer = e[ "a_value" ]
+ if(e) then
+ data.quest_question = e[ "a_question" ]
+ data.quest_answer = e[ "a_value" ]
+ local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs)
+ data.action_failure_dialog = math.max(1,
+ table.indexof(sorted_dialog_list, e[ "a_on_failure" ]))
+ end
+ return "label[0.2,3.3;What to ask the player and which answer to expect:]"..
+ "label[0.2,4.0;Question to show:]"..
+ "field[4.0,3.8;10.0,0.6;quest_question;;"..
+ minetest.formspec_escape(
+ data.quest_question
+ or "Your answer:").."]"..
+ "label[0.2,5.0;Expected answer:]"..
+ "field[4.0,4.8;10.0,0.6;quest_answer;;"..
+ minetest.formspec_escape(
+ data.quest_answer
+ or "- Insert the correct answer here -").."]"..
+ "tooltip[quest_question;"..
+ "This is just a short text that will be shown to remind\n"..
+ "the player what he is asked for. Most of the question\n"..
+ "ought to be part of the normal dialog of the NPC.]"..
+ "tooltip[quest_answer;"..
+ "The correct answer will not be shown to the player.\n"..
+ "What the player enters will be compared to this\n"..
+ "correct value.]"..
+ "tooltip[select_on_action_failure;"..
+ "If the player gives the wrong answer, you can show him\n"..
+ "a diffrent target dialog (i.e. with text \"No, that answer\n"..
+ "was wrong, but please try again!\"). In such a case the\n"..
+ "effects/results of the current dialog option are *not*\n"..
+ "executed.]"..
+ yl_speak_up.set_on_action_failure_dialog(pname, data,
+ "The player shall enter the correct answer.")..
+ save_button
+end
+
+
+yl_speak_up.get_fs_edit_option_all_custom = function(pname, dialog, formspec, data, id_prefix, save_button, e)
+ if(e) then
+ data.custom_param = e[ id_prefix.."value" ]
+ if(id_prefix == "a_") then
local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs)
data.action_failure_dialog = math.max(1,
- table.indexof(sorted_dialog_list, e[ "a_on_failure" ]))
+ table.indexof(sorted_dialog_list, e[ "a_on_failure" ]))
end
- return
- "label[0.2,3.3;What to ask the player and which answer to expect:]"..
- "label[0.2,4.0;Question to show:]"..
- "field[4.0,3.8;10.0,0.6;quest_question;;"..
- minetest.formspec_escape(
- data.quest_question
- or "Your answer:").."]"..
- "label[0.2,5.0;Expected answer:]"..
- "field[4.0,4.8;10.0,0.6;quest_answer;;"..
- minetest.formspec_escape(
- data.quest_answer
- or "- Insert the correct answer here -").."]"..
- "tooltip[quest_question;"..
- "This is just a short text that will be shown to remind\n"..
- "the player what he is asked for. Most of the question\n"..
- "ought to be part of the normal dialog of the NPC.]"..
- "tooltip[quest_answer;"..
- "The correct answer will not be shown to the player.\n"..
- "What the player enters will be compared to this\n"..
- "correct value.]"..
+ end
+ formspec = formspec..
+ "label[0.2,3.3;Note: Calling a custom function will require direct support "..
+ "from the server.]"..
+ "label[0.2,4.0;Parameter for custom function:]"..
+ "field[6.0,3.7;10.0,0.6;custom_param;;"..
+ minetest.formspec_escape(
+ data.custom_param
+ or "- Insert a text that is passed on to your function here -").."]"..
+ "tooltip[custom_param;"..
+ "The custom parameter may help whoever implements the\n"..
+ "custom function to more easily see what it belongs to.\n"..
+ "Dialog and option ID are also passed as parameters.]"
+ if(id_prefix == "a_") then
+ formspec = formspec..
"tooltip[select_on_action_failure;"..
"If the player gives the wrong answer, you can show him\n"..
"a diffrent target dialog (i.e. with text \"No, that answer\n"..
@@ -1761,49 +1782,14 @@ yl_speak_up.get_fs_edit_option_action_text_input = function(pname, dialog, forms
"effects/results of the current dialog option are *not*\n"..
"executed.]"..
yl_speak_up.set_on_action_failure_dialog(pname, data,
- "The player shall enter the correct answer.")..
- save_button
-end
-
-
-yl_speak_up.get_fs_edit_option_action_custom = function(pname, dialog, formspec, data, id_prefix, save_button, e)
- if(e) then
- data.custom_param = e[ id_prefix.."value" ]
- if(id_prefix == "a_") then
- local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs)
- data.action_failure_dialog = math.max(1,
- table.indexof(sorted_dialog_list, e[ "a_on_failure" ]))
- end
- end
+ "The player shall click on the right button.")
+ else
formspec = formspec..
- "label[0.2,3.3;Note: Calling a custom function will require direct support "..
- "from the server.]"..
- "label[0.2,4.0;Parameter for custom function:]"..
- "field[6.0,3.7;10.0,0.6;custom_param;;"..
- minetest.formspec_escape(
- data.custom_param
- or "- Insert a text that is passed on to your function here -").."]"..
- "tooltip[custom_param;"..
- "The custom parameter may help whoever implements the\n"..
- "custom function to more easily see what it belongs to.\n"..
- "Dialog and option ID are also passed as parameters.]"
- if(id_prefix == "a_") then
- formspec = formspec..
- "tooltip[select_on_action_failure;"..
- "If the player gives the wrong answer, you can show him\n"..
- "a diffrent target dialog (i.e. with text \"No, that answer\n"..
- "was wrong, but please try again!\"). In such a case the\n"..
- "effects/results of the current dialog option are *not*\n"..
- "executed.]"..
- yl_speak_up.set_on_action_failure_dialog(pname, data,
- "The player shall click on the right button.")
- else
- formspec = formspec..
- "label[0.3,5.0;Note: Your custom function has to return either true "..
- "or false.]"
- end
- return formspec..save_button
+ "label[0.3,5.0;Note: Your custom function has to return either true "..
+ "or false.]"
end
+ return formspec..save_button
+end
-- end of formspecs for types of preconditions, actions and effects
----------------------------------------------------------------------------