actions of type custom can now be created

This commit is contained in:
Sokomine 2021-06-16 02:59:10 +02:00
parent 7fe9f18791
commit 7045842359
2 changed files with 53 additions and 9 deletions

View File

@ -30,12 +30,12 @@ local check_what = {
"The NPC gives something to the player (i.e. a quest item).", -- 4
"The player is expected to give something to the NPC (i.e. a quest item).", -- 5
"The player has to manually enter a password or passphrase or some other text.", -- 6
"The player has to move virtual items in a virtual inventory to the right position.", -- 7
"Call custom functions that are supposed to be overridden by the server.", -- 8
"Call custom functions that are supposed to be overridden by the server.", -- 7
-- "The player has to move virtual items in a virtual inventory to the right position.", -- 8
}
-- how to store these as a_type in the action:
local values_what = {"", "none", "trade", "npc_gives", "npc_wants", "text_input", "puzzle", "custom"}
local values_what = {"", "none", "trade", "npc_gives", "npc_wants", "text_input", "custom", "puzzle"}
-- monitor changes to the npc_gives and npc_wants slots (in particular when editing actions)
@ -85,7 +85,8 @@ yl_speak_up.action_inv_changed = function(inv, listname, index, stack, player, h
end
-- show the updated formspec to the player
yl_speak_up.show_fs(player, "edit_actions", nil)
-- TODO: implement
-- no need to check anything more here; the real checks need to be done
-- when the player presses the save/store/execute button
end
@ -107,10 +108,11 @@ yl_speak_up.show_action = function(a)
"with ID \""..tostring(a.a_item_quest_id or "- no special ID -").."\"."
elseif(a.a_type == "text_input") then
return "Q: \""..tostring(a.a_question).."\" A:\""..tostring(a.a_value).."\"."
elseif(a.a_type == "puzzle") then
return "puzzle:" -- TODO show ation text
-- puzzle is unused; better do that via custom
-- elseif(a.a_type == "puzzle") then
-- return "puzzle:"
elseif(a.a_type == "custom") then
return "custom:" -- TODO show ation text
return "Call custom function with param: \""..tostring(a.a_value).."\"."
end
-- fallback
return tostring(a.a_value)
@ -118,12 +120,12 @@ end
yl_speak_up.execute_all_actions = function(player, actions, o_id)
-- TODO: implement
-- TODO: implement execute_all_actions
end
yl_speak_up.execute_action = function(player, n_id, o_id, r)
-- TODO: implement. boils down to showing formspecs
-- TODO: implement execute_action. boils down to showing formspecs
-- fallback: unkown type
return false
end

View File

@ -251,6 +251,11 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields,
and data and data.what and data.what == 6 and id_prefix == "r_") then
data.chat_msg_text = fields.chat_msg_text
elseif(fields.custom_param
and fields.custom_param ~= "- Insert a text that is passed on to your function here -"
and fields.custom_param ~= "") then
data.custom_param = fields.custom_param
elseif(fields.action_item_quest_id
and fields.action_item_quest_id ~= ""
and fields.action_item_quest_id ~= "- none set -"
@ -608,6 +613,12 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields,
local dialog = yl_speak_up.speak_to[pname].dialog
local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs)
v[ "a_on_failure" ] = sorted_dialog_list[ data.action_failure_dialog ]
-- "Call custom functions that are supposed to be overridden by the server.", -- 7
elseif(data.what and id_prefix == "a_" and data.what == 7) then
v[ "a_value" ] = data.custom_param
local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs)
v[ "a_on_failure" ] = sorted_dialog_list[ data.action_failure_dialog ]
end
-- only save if something was actually selected
@ -1177,6 +1188,37 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
"effects/results of the current dialog option are *not*\n"..
"executed.]"
-- "Call custom functions that are supposed to be overridden by the server.", -- 7
-- (only for actions)
elseif(data.what and id_prefix == "a_" and data.what == 7) then
local custom_param = "- Insert a text that is passed on to your function here -"
if(data and data.custom_param) then
custom_param = data.custom_param
end
local nr = 1
if(data and data.action_failure_dialog) then
nr = data.action_failure_dialog + 1
end
local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs)
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;;"..tostring(custom_param).."]"..
"label[0.2,5.0;If the player fails at it, go to dialog:]"..
"dropdown[6.0,4.7;2.8,0.6;select_on_action_failure;"..
"- current one -,"..
table.concat(sorted_dialog_list, ",")..";"..tostring(nr)..";]"..
"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.]"..
"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.]"
end
return formspec..save_button
end