forked from Sokomine/yl_speak_up
begin of refactoring of fs_edit_option_related into formspecs for types of preconditions, actions and effects
This commit is contained in:
parent
9d3a08e854
commit
0b9b7d6287
@ -1231,9 +1231,15 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
|
||||
"\"/npc_talk_debug off\".]"
|
||||
end
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- begin of formspecs for types of preconditions, actions and effects
|
||||
|
||||
-- "an internal state (i.e. of a quest)", -- 2
|
||||
-- (state is the second offered option in both preconditions and effects list)
|
||||
if(data.what and data.what == 2 and id_prefix ~= "a_") then
|
||||
|
||||
-- TODO: text_variable, text_select_operator
|
||||
yl_speak_up.get_fs_edit_option_precondition_state = function(pname, dialog, formspec, data, id_prefix, save_button)
|
||||
if(not(data.variable) or data.variable < 1) then
|
||||
data.variable = 1
|
||||
-- not enough selected yet for saving
|
||||
@ -1266,7 +1272,7 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
|
||||
end
|
||||
var_list_text = var_list_text..","..minetest.formspec_escape(tostring(var_name))
|
||||
end
|
||||
formspec = formspec..
|
||||
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;"..
|
||||
@ -1287,11 +1293,16 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
|
||||
"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</normal>]"
|
||||
"own needs).\n</normal>]"..
|
||||
save_button
|
||||
end
|
||||
|
||||
-- "a block somewhere", -- 3
|
||||
-- (block is the third offered option in both preconditions and effects list)
|
||||
elseif(data.what and data.what == 3 and id_prefix ~= "a_") then
|
||||
|
||||
-- TODO: block_pos as parameter?
|
||||
yl_speak_up.get_fs_edit_option_precondition_block = function(pname, dialog, formspec, data, id_prefix, save_button)
|
||||
local block_pos_str = "- none set -"
|
||||
local node = {name = "- unknown -", param2 = "- unkown -"}
|
||||
if(not(block_pos) and data and data.block_pos) then
|
||||
@ -1339,7 +1350,7 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
|
||||
-- not enough selected yet for saving
|
||||
save_button = ""
|
||||
end
|
||||
formspec = formspec..
|
||||
return
|
||||
"label[0.2,3.3;"..text_block_position.."]"..
|
||||
"dropdown[4.0,3.5;16.0,0.6;select_block;"..
|
||||
table.concat(check_block, ",")..";"..
|
||||
@ -1355,32 +1366,40 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
|
||||
"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
|
||||
error_is_protected..
|
||||
save_button
|
||||
end
|
||||
|
||||
-- "a trade", -- 4
|
||||
-- (trade - only for preconditions; effects have something else here)
|
||||
elseif(data.what and id_prefix == "p_" and data.what == 4) then
|
||||
|
||||
yl_speak_up.get_fs_edit_option_precondition_trade = function(pname, dialog, formspec, data, id_prefix, save_button)
|
||||
if(not(data.trade) or data.trade == 1) then
|
||||
data.trade = 1
|
||||
-- not enough selected yet for saving
|
||||
save_button = ""
|
||||
end
|
||||
formspec = formspec..
|
||||
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)..";]"
|
||||
tostring(data.trade)..";]"..
|
||||
save_button
|
||||
end
|
||||
|
||||
-- "the inventory of the player", -- 5
|
||||
-- "the inventory of the NPC", -- 6
|
||||
-- (inventory - only for preconditions; effects have something else here)
|
||||
elseif(data.what and id_prefix == "p_" and data.what >= 5 and data.what <= 6) then
|
||||
|
||||
yl_speak_up.get_fs_edit_option_precondition_inv = function(pname, dialog, formspec, data, id_prefix, save_button)
|
||||
if(not(data.inv) or data.inv == 1) then
|
||||
data.inv = 1
|
||||
-- not enough selected yet for saving
|
||||
save_button = ""
|
||||
end
|
||||
formspec = formspec..
|
||||
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, ",")..";"..
|
||||
@ -1394,11 +1413,14 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
|
||||
"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;]"
|
||||
"list[current_player;main;8,5.3;8,4;]"..
|
||||
save_button
|
||||
|
||||
-- "give item (created out of thin air) to player (requires npc_master priv)", -- 7
|
||||
-- "take item from player and destroy it (requires npc_master priv)", -- 8
|
||||
elseif(data.what and id_prefix == "r_" and (data.what == 7 or data.what == 8)) then
|
||||
|
||||
yl_speak_up.get_fs_edit_option_effect_give_item_or_take_item = function(pname, dialog, formspec, data, id_prefix, save_button)
|
||||
local text = "The following item shall be created out of thin air and added to the "..
|
||||
"player's inventory:"
|
||||
if(data.what == 8) then
|
||||
@ -1418,11 +1440,15 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
|
||||
"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;]"
|
||||
"list[current_player;main;8,5.3;8,4;]"..
|
||||
save_button
|
||||
end
|
||||
|
||||
-- "move the player to a given position (requires npc_master priv)", -- 9
|
||||
elseif(data.what and id_prefix == "r_" and data.what == 9) then
|
||||
formspec = formspec..
|
||||
|
||||
yl_speak_up.get_fs_edit_option_effect_move = function(pname, dialog, formspec, data, id_prefix, save_button)
|
||||
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!]"..
|
||||
@ -1431,21 +1457,29 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
|
||||
"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 "").."]"
|
||||
"field[7.7,5.0;2.0,0.6;move_to_z;;"..(data.move_to_z or "").."]"..
|
||||
save_button
|
||||
end
|
||||
|
||||
-- "execute Lua code (requires npc_master priv)", -- precondition: 7; effect: 10
|
||||
elseif((data.what and id_prefix == "p_" and data.what == 7)
|
||||
or (data.what and id_prefix == "r_" and data.what == 10)) then
|
||||
formspec = formspec..
|
||||
|
||||
-- for "precondition and effect"
|
||||
yl_speak_up.get_fs_edit_option_p_and_e_function = function(pname, dialog, formspec, data, id_prefix, save_button)
|
||||
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)).."]"
|
||||
minetest.formspec_escape(tostring(data.lua_code)).."]"..
|
||||
save_button
|
||||
|
||||
-- "NPC crafts something", -- 4
|
||||
-- (craft - only for effects - not for preconditions)
|
||||
elseif(data.what and id_prefix == "r_" and data.what == 4) then
|
||||
|
||||
yl_speak_up.get_fs_edit_option_effect_craft = function(pname, dialog, formspec, data, id_prefix, save_button)
|
||||
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).."]"
|
||||
@ -1458,7 +1492,7 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
|
||||
end
|
||||
end
|
||||
end
|
||||
formspec = formspec..
|
||||
return
|
||||
"label[8,2.6;Your invnetory:]"..
|
||||
"list[current_player;main;8,3;8,4;]"..
|
||||
"label[1,3.1;Your craft grid:]"..
|
||||
@ -1467,11 +1501,15 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
|
||||
"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
|
||||
bg_img..
|
||||
save_button
|
||||
end
|
||||
|
||||
-- "go to other dialog if the *previous* effect failed", -- 5
|
||||
-- (on_failure - only for effects - not for preconditions)
|
||||
elseif(data.what and id_prefix == "r_" and data.what == 5) then
|
||||
|
||||
yl_speak_up.get_fs_edit_option_effect_on_failure = function(pname, dialog, formspec, data, id_prefix, save_button)
|
||||
local dialog = yl_speak_up.speak_to[pname].dialog
|
||||
local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs)
|
||||
local nr = 1
|
||||
@ -1494,22 +1532,26 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
|
||||
":]",
|
||||
"button_edit_effect_on_failure_text_change")
|
||||
end
|
||||
formspec = formspec..
|
||||
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
|
||||
on_failure_dialog..
|
||||
save_button
|
||||
end
|
||||
|
||||
-- "send a chat message to all players" -- 6
|
||||
elseif(data.what and id_prefix == "r_" and data.what == 6) then
|
||||
|
||||
yl_speak_up.get_fs_edit_option_effect_chat_all = function(pname, dialog, formspec, data, id_prefix, save_button)
|
||||
local default_text = "$NPC_NAME$ (owned by $OWNER_NAME$) announces: $PLAYER_NAME$ "..
|
||||
"- example; please enter the text -"
|
||||
if(not(data)) then
|
||||
data = {}
|
||||
end
|
||||
formspec = formspec..
|
||||
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;;"..
|
||||
@ -1518,10 +1560,14 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
|
||||
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$.]"
|
||||
"\n$NPC_NAME$, $PLAYER_NAME$ and $OWNER_NAME$.]"..
|
||||
save_button
|
||||
end
|
||||
|
||||
-- "Normal trade - one item(stack) for another item(stack).", -- 3
|
||||
elseif(data.what and id_prefix == "a_" and data.what == 3) then
|
||||
|
||||
yl_speak_up.get_fs_edit_option_action_trade = function(pname, dialog, formspec, data, id_prefix, save_button)
|
||||
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
|
||||
@ -1535,7 +1581,7 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
|
||||
"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
|
||||
formspec = formspec..
|
||||
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)..":]"..
|
||||
@ -1548,11 +1594,15 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
|
||||
"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.")
|
||||
"The player shall trade at least once.")..
|
||||
save_button
|
||||
end
|
||||
|
||||
-- "The NPC gives something to the player (i.e. a quest item).", -- 4
|
||||
-- (only for actions)
|
||||
elseif(data.what and id_prefix == "a_" and data.what == 4) then
|
||||
|
||||
yl_speak_up.get_fs_edit_option_action_npc_gives = function(pname, dialog, formspec, data, id_prefix, save_button)
|
||||
if(not(data)) then
|
||||
data = {}
|
||||
end
|
||||
@ -1560,7 +1610,7 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
|
||||
if(data and data.item_string) then
|
||||
bg_img = "item_image[2.15,3.65;0.7,0.7;"..tostring(data.item_string).."]"
|
||||
end
|
||||
formspec = formspec..
|
||||
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:]"..
|
||||
@ -1597,12 +1647,16 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
|
||||
"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.")
|
||||
"The player shall take this offered item.")..
|
||||
save_button
|
||||
end
|
||||
|
||||
|
||||
-- "The player is expected to give something to the NPC (i.e. a quest item).", -- 5
|
||||
-- (only for actions)
|
||||
elseif(data.what and id_prefix == "a_" and data.what == 5) then
|
||||
|
||||
yl_speak_up.get_fs_edit_option_action_npc_wants = function(pname, dialog, formspec, data, id_prefix, save_button)
|
||||
if(not(data)) then
|
||||
data = {}
|
||||
end
|
||||
@ -1610,7 +1664,7 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
|
||||
if(data and data.item_string) then
|
||||
bg_img = "item_image[2.15,3.65;0.7,0.7;"..tostring(data.item_string).."]"
|
||||
end
|
||||
formspec = formspec..
|
||||
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:]"..
|
||||
@ -1635,15 +1689,19 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
|
||||
or "- none set -").."]"..
|
||||
bg_img..
|
||||
yl_speak_up.set_on_action_failure_dialog(pname, data,
|
||||
"The player shall give the NPC this item.")
|
||||
"The player shall give the NPC this item.")..
|
||||
save_button
|
||||
end
|
||||
|
||||
-- "The player has to manually enter a password or passphrase or some other text.", -- 6
|
||||
-- (only for actions)
|
||||
elseif(data.what and id_prefix == "a_" and data.what == 6) then
|
||||
|
||||
yl_speak_up.get_fs_edit_option_action_text_input = function(pname, dialog, formspec, data, id_prefix, save_button)
|
||||
if(not(data)) then
|
||||
data = {}
|
||||
end
|
||||
formspec = formspec..
|
||||
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;;"..
|
||||
@ -1670,7 +1728,9 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
|
||||
"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.")
|
||||
"The player shall enter the correct answer.")..
|
||||
save_button
|
||||
end
|
||||
|
||||
-- "Call custom functions that are supposed to be overridden by the server.", -- 7
|
||||
-- precondition: 8; action: 7; effect: 11
|
||||
@ -1678,6 +1738,8 @@ 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
|
||||
|
||||
yl_speak_up.get_fs_edit_option_action_custom = function(pname, dialog, formspec, data, id_prefix, save_button)
|
||||
if(not(data)) then
|
||||
data = {}
|
||||
end
|
||||
@ -1708,10 +1770,13 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
|
||||
"label[0.3,5.0;Note: Your custom function has to return either true "..
|
||||
"or false.]"
|
||||
end
|
||||
return formspec..save_button
|
||||
end
|
||||
return formspec..save_button
|
||||
end
|
||||
-- return formspec..save_button
|
||||
--end
|
||||
|
||||
-- end of formspecs for types of preconditions, actions and effects
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
-- helper function
|
||||
yl_speak_up.set_on_action_failure_dialog = function(pname, data, instruction)
|
||||
|
Loading…
Reference in New Issue
Block a user