forked from your-land-mirror/yl_speak_up
proceeded with refactoring; functions are now functions again
This commit is contained in:
parent
f2bba9b270
commit
73ac297b98
@ -1231,12 +1231,105 @@ 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
|
||||
return yl_speak_up.get_fs_edit_option_precondition_state(
|
||||
pname, dialog, formspec, data, id_prefix, save_button)
|
||||
|
||||
-- "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
|
||||
return yl_speak_up.get_fs_edit_option_precondition_block(
|
||||
pname, dialog, formspec, data, id_prefix, save_button)
|
||||
|
||||
-- "a trade", -- 4
|
||||
-- (trade - only for preconditions; effects have something else here)
|
||||
elseif(data.what and id_prefix == "p_" and data.what == 4) then
|
||||
return yl_speak_up.get_fs_edit_option_precondition_trade(
|
||||
pname, dialog, formspec, data, id_prefix, save_button)
|
||||
|
||||
-- "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
|
||||
return yl_speak_up.get_fs_edit_option_precondition_inv(
|
||||
pname, dialog, formspec, data, id_prefix, 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
|
||||
return yl_speak_up.get_fs_edit_option_effect_give_item_or_take_item(
|
||||
pname, dialog, formspec, data, id_prefix, save_button)
|
||||
|
||||
-- "move the player to a given position (requires npc_master priv)", -- 9
|
||||
elseif(data.what and id_prefix == "r_" and data.what == 9) then
|
||||
return yl_speak_up.get_fs_edit_option_effect_move(
|
||||
pname, dialog, formspec, data, id_prefix, save_button)
|
||||
|
||||
-- "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
|
||||
return yl_speak_up.get_fs_edit_option_p_and_e_function(
|
||||
pname, dialog, formspec, data, id_prefix, 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
|
||||
return yl_speak_up.get_fs_edit_option_effect_craft(
|
||||
pname, dialog, formspec, data, id_prefix, save_button)
|
||||
|
||||
-- "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
|
||||
return yl_speak_up.get_fs_edit_option_effect_on_failure(
|
||||
pname, dialog, formspec, data, id_prefix, save_button)
|
||||
|
||||
-- "send a chat message to all players" -- 6
|
||||
elseif(data.what and id_prefix == "r_" and data.what == 6) then
|
||||
return yl_speak_up.get_fs_edit_option_effect_chat_all(
|
||||
pname, dialog, formspec, data, id_prefix, save_button)
|
||||
|
||||
-- "Normal trade - one item(stack) for another item(stack).", -- 3
|
||||
elseif(data.what and id_prefix == "a_" and data.what == 3) then
|
||||
return yl_speak_up.get_fs_edit_option_action_trade(
|
||||
pname, dialog, formspec, data, id_prefix, save_button)
|
||||
|
||||
-- "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
|
||||
return yl_speak_up.get_fs_edit_option_action_npc_gives(
|
||||
pname, dialog, formspec, data, id_prefix, save_button)
|
||||
|
||||
-- "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
|
||||
return yl_speak_up.get_fs_edit_option_action_npc_wants(
|
||||
pname, dialog, formspec, data, id_prefix, save_button)
|
||||
|
||||
-- "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
|
||||
return yl_speak_up.get_fs_edit_option_action_text_input(
|
||||
pname, dialog, formspec, data, id_prefix, save_button)
|
||||
|
||||
-- "Call custom functions that are supposed to be overridden by the server.", -- 7
|
||||
-- precondition: 8; action: 7; effect: 11
|
||||
elseif(data.what
|
||||
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(
|
||||
pname, dialog, formspec, data, id_prefix, save_button)
|
||||
end
|
||||
|
||||
return "ERROR"
|
||||
end
|
||||
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- begin of formspecs for types of preconditions, actions and effects
|
||||
|
||||
-- TODO: text_variable, text_select_operator
|
||||
yl_speak_up.get_fs_edit_option_precondition_state = function(pname, dialog, formspec, data, id_prefix, save_button)
|
||||
@ -1297,9 +1390,6 @@ yl_speak_up.get_fs_edit_option_precondition_state = function(pname, dialog, form
|
||||
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)
|
||||
@ -1370,9 +1460,6 @@ yl_speak_up.get_fs_edit_option_precondition_block = function(pname, dialog, form
|
||||
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
|
||||
@ -1388,10 +1475,6 @@ yl_speak_up.get_fs_edit_option_precondition_trade = function(pname, dialog, form
|
||||
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
|
||||
@ -1415,10 +1498,8 @@ yl_speak_up.get_fs_edit_option_precondition_inv = function(pname, dialog, formsp
|
||||
"label[8,4.9;Your inventory:]"..
|
||||
"list[current_player;main;8,5.3;8,4;]"..
|
||||
save_button
|
||||
end
|
||||
|
||||
-- "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 "..
|
||||
@ -1444,8 +1525,6 @@ yl_speak_up.get_fs_edit_option_effect_give_item_or_take_item = function(pname, d
|
||||
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
|
||||
|
||||
yl_speak_up.get_fs_edit_option_effect_move = function(pname, dialog, formspec, data, id_prefix, save_button)
|
||||
return
|
||||
@ -1461,9 +1540,6 @@ yl_speak_up.get_fs_edit_option_effect_move = function(pname, dialog, formspec, d
|
||||
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
|
||||
|
||||
-- for "precondition and effect"
|
||||
yl_speak_up.get_fs_edit_option_p_and_e_function = function(pname, dialog, formspec, data, id_prefix, save_button)
|
||||
@ -1474,10 +1550,8 @@ yl_speak_up.get_fs_edit_option_p_and_e_function = function(pname, dialog, formsp
|
||||
"textarea[0.2,4.5;20,4.0;lua_code;;"..
|
||||
minetest.formspec_escape(tostring(data.lua_code)).."]"..
|
||||
save_button
|
||||
end
|
||||
|
||||
-- "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 = ""
|
||||
@ -1505,9 +1579,6 @@ yl_speak_up.get_fs_edit_option_effect_craft = function(pname, dialog, formspec,
|
||||
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
|
||||
@ -1542,8 +1613,6 @@ yl_speak_up.get_fs_edit_option_effect_on_failure = function(pname, dialog, forms
|
||||
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$ "..
|
||||
@ -1561,8 +1630,6 @@ yl_speak_up.get_fs_edit_option_effect_chat_all = function(pname, dialog, formspe
|
||||
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
|
||||
@ -1595,9 +1662,6 @@ yl_speak_up.get_fs_edit_option_action_trade = function(pname, dialog, formspec,
|
||||
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)
|
||||
local bg_img = ""
|
||||
@ -1646,10 +1710,6 @@ yl_speak_up.get_fs_edit_option_action_npc_gives = function(pname, dialog, formsp
|
||||
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)
|
||||
local bg_img = ""
|
||||
if(data and data.item_string) then
|
||||
@ -1684,9 +1744,6 @@ yl_speak_up.get_fs_edit_option_action_npc_wants = function(pname, dialog, formsp
|
||||
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)
|
||||
return
|
||||
@ -1720,12 +1777,6 @@ yl_speak_up.get_fs_edit_option_action_text_input = function(pname, dialog, forms
|
||||
save_button
|
||||
end
|
||||
|
||||
-- "Call custom functions that are supposed to be overridden by the server.", -- 7
|
||||
-- precondition: 8; action: 7; effect: 11
|
||||
elseif(data.what
|
||||
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)
|
||||
formspec = formspec..
|
||||
@ -1757,8 +1808,6 @@ yl_speak_up.get_fs_edit_option_action_custom = function(pname, dialog, formspec,
|
||||
end
|
||||
return formspec..save_button
|
||||
end
|
||||
-- return formspec..save_button
|
||||
--end
|
||||
|
||||
-- end of formspecs for types of preconditions, actions and effects
|
||||
----------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user