forked from Sokomine/yl_speak_up
make editing alternate_text for timer/limitation failure possible
This commit is contained in:
parent
1b480edfb7
commit
632d7d6895
@ -72,10 +72,10 @@ yl_speak_up.chat_all_color = "#AAAAFF"
|
|||||||
-- it's possible to prevent players from trying actions (i.e. npc_gives, text_input, ..) too often;
|
-- it's possible to prevent players from trying actions (i.e. npc_gives, text_input, ..) too often;
|
||||||
-- if no special text is set, this one will be shown (tab "Limit guessing:" in edit options menu)
|
-- if no special text is set, this one will be shown (tab "Limit guessing:" in edit options menu)
|
||||||
yl_speak_up.standard_text_if_action_failed_too_often = "You have tried so many times. I'm tired! "..
|
yl_speak_up.standard_text_if_action_failed_too_often = "You have tried so many times. I'm tired! "..
|
||||||
"Come back when you know the answer - but not before tomorrow."
|
"Come back when you really know the answer - but not too soon.\n $TEXT$"
|
||||||
-- it's also possible to prevent players from successfully executing actions too often (after all the
|
-- it's also possible to prevent players from successfully executing actions too often (after all the
|
||||||
-- quest items are created from the finite NPC's inventory); this is the standard text that will be
|
-- quest items are created from the finite NPC's inventory); this is the standard text that will be
|
||||||
-- shown by default (tab "Limit repeating:" in edit options menu)
|
-- shown by default (tab "Limit repeating:" in edit options menu)
|
||||||
yl_speak_up.standard_text_if_action_repeated_too_soon = "I don't have infinite ressources. If you lost "..
|
yl_speak_up.standard_text_if_action_repeated_too_soon = "I don't have infinite ressources. If you lost "..
|
||||||
"something I gave you - come back tomorrow and we may talk again."
|
"something I gave you - come back later and we may talk again.\n$TEXT$"
|
||||||
|
|
||||||
|
@ -112,11 +112,86 @@ yl_speak_up.handle_edit_actions_alternate_text = function(
|
|||||||
})
|
})
|
||||||
-- showing new formspec - the calling function shall return as well
|
-- showing new formspec - the calling function shall return as well
|
||||||
return true
|
return true
|
||||||
|
|
||||||
|
-- edit alternate text for when the player has failed to do the action too many times
|
||||||
|
elseif(fields.button_edit_limit_action_failed_repeat) then
|
||||||
|
local timer_name = "timer_on_failure_"..tostring(d_id).."_"..tostring(o_id)
|
||||||
|
local timer_data = yl_speak_up.get_variable_metadata( timer_name, "parameter", true)
|
||||||
|
local alternate_text = yl_speak_up.standard_text_if_action_failed_too_often
|
||||||
|
if(timer_data and timer_data["alternate_text"]) then
|
||||||
|
alternate_text = timer_data["alternate_text"]
|
||||||
|
end
|
||||||
|
-- remember what we're working at
|
||||||
|
yl_speak_up.speak_to[pname].edit_alternate_text_for = "timer_on_failure"
|
||||||
|
yl_speak_up.show_fs(player, "msg", {
|
||||||
|
input_to = "yl_speak_up:"..formspec_input_to,
|
||||||
|
formspec = yl_speak_up.get_fs_edit_dialog_modification(
|
||||||
|
dialog, d_id, alternate_text,
|
||||||
|
"if the player failed to complete the action "..
|
||||||
|
"\" of option \""..tostring(o_id)..
|
||||||
|
"\" of dialog \""..tostring(d_id)..
|
||||||
|
"\" too many times",
|
||||||
|
true) -- forbid_turn_into_new_dialog
|
||||||
|
})
|
||||||
|
-- showing new formspec - the calling function shall return as well
|
||||||
|
return true
|
||||||
|
-- edit alternate text whent he player has to wait a bit until he's allowed to repeat the
|
||||||
|
-- action (to avoid i.e. unlimited quest item handout)
|
||||||
|
elseif(fields.button_edit_limit_action_success_repeat) then
|
||||||
|
local timer_name = "timer_on_success_"..tostring(d_id).."_"..tostring(o_id)
|
||||||
|
local timer_data = yl_speak_up.get_variable_metadata( timer_name, "parameter", true)
|
||||||
|
local alternate_text = yl_speak_up.standard_text_if_action_repeated_too_soon
|
||||||
|
if(timer_data and timer_data["alternate_text"]) then
|
||||||
|
alternate_text = timer_data["alternate_text"]
|
||||||
|
end
|
||||||
|
-- remember what we're working at
|
||||||
|
yl_speak_up.speak_to[pname].edit_alternate_text_for = "timer_on_success"
|
||||||
|
yl_speak_up.show_fs(player, "msg", {
|
||||||
|
input_to = "yl_speak_up:"..formspec_input_to,
|
||||||
|
formspec = yl_speak_up.get_fs_edit_dialog_modification(
|
||||||
|
dialog, d_id, alternate_text,
|
||||||
|
"if the player has complete the action "..
|
||||||
|
"\" of option \""..tostring(o_id)..
|
||||||
|
"\" of dialog \""..tostring(d_id)..
|
||||||
|
"\" just not long enough ago",
|
||||||
|
true) -- forbid_turn_into_new_dialog
|
||||||
|
})
|
||||||
|
-- showing new formspec - the calling function shall return as well
|
||||||
|
return true
|
||||||
|
|
||||||
-- save the changes
|
-- save the changes
|
||||||
elseif(fields.save_dialog_modification) then
|
elseif(fields.save_dialog_modification) then
|
||||||
local old_text = "-none-"
|
local old_text = "-none-"
|
||||||
local target_element = yl_speak_up.speak_to[pname].edit_alternate_text_for
|
local target_element = yl_speak_up.speak_to[pname].edit_alternate_text_for
|
||||||
if(target_element) then
|
if(target_element
|
||||||
|
and (target_element == "timer_on_failure" or target_element == "timer_on_success")) then
|
||||||
|
-- we're changing a timer (both can be handled the same way here)
|
||||||
|
local timer_name = target_element.."_"..tostring(d_id).."_"..tostring(o_id)
|
||||||
|
local timer_data = yl_speak_up.get_variable_metadata( timer_name, "parameter", true)
|
||||||
|
local alternate_text = yl_speak_up.standard_text_if_action_failed_too_often
|
||||||
|
if(target_element == "timer_on_success") then
|
||||||
|
alternate_text = yl_speak_up.standard_text_if_action_repeated_too_soon
|
||||||
|
end
|
||||||
|
if(timer_data and timer_data["alternate_text"]) then
|
||||||
|
alternate_text = timer_data["alternate_text"]
|
||||||
|
end
|
||||||
|
-- store the modified alternate text
|
||||||
|
if(fields.d_text_new and fields.d_text_new ~= ""
|
||||||
|
and fields.d_text_new ~= alternate_text) then
|
||||||
|
-- make sure the variable exists
|
||||||
|
if(yl_speak_up.add_time_based_variable(timer_name)) then
|
||||||
|
yl_speak_up.set_variable_metadata(timer_name, nil, "parameter",
|
||||||
|
"alternate_text", fields.d_text_new)
|
||||||
|
-- log the change
|
||||||
|
yl_speak_up.log_change(pname, n_id,
|
||||||
|
"Dialog "..d_id..", option "..tostring(o_id)..
|
||||||
|
": The text displayed for "..tostring(target_element)..
|
||||||
|
" was changed from "..
|
||||||
|
"["..tostring(alternate_text).."] to ["..
|
||||||
|
tostring(fields.d_text_new).."].")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
elseif(target_element) then
|
||||||
data = target_element
|
data = target_element
|
||||||
id_prefix = "a_"
|
id_prefix = "a_"
|
||||||
if(target_element.r_id) then
|
if(target_element.r_id) then
|
||||||
@ -314,7 +389,13 @@ end
|
|||||||
-- this allows to edit modifications of a dialog that are applied when a given option
|
-- this allows to edit modifications of a dialog that are applied when a given option
|
||||||
-- is choosen - i.e. when the NPC wants to answer some questions - but those answers
|
-- is choosen - i.e. when the NPC wants to answer some questions - but those answers
|
||||||
-- do not warrant their own dialog
|
-- do not warrant their own dialog
|
||||||
yl_speak_up.get_fs_edit_dialog_modification = function(dialog, d_id, alternate_dialog_text, explanation)
|
yl_speak_up.get_fs_edit_dialog_modification = function(dialog, d_id, alternate_dialog_text, explanation,
|
||||||
|
forbid_turn_into_new_dialog)
|
||||||
|
|
||||||
|
local nd = "button[9.0,12.3;6,0.7;turn_alternate_text_into_new_dialog;Turn this into a new dialog]"
|
||||||
|
if(forbid_turn_into_new_dialog) then
|
||||||
|
nd = ""
|
||||||
|
end
|
||||||
return "formspec_version[3]"..
|
return "formspec_version[3]"..
|
||||||
"size[20,13.5]"..
|
"size[20,13.5]"..
|
||||||
"label[6.0,0.5;Edit alternate text]"..
|
"label[6.0,0.5;Edit alternate text]"..
|
||||||
@ -337,7 +418,7 @@ yl_speak_up.get_fs_edit_dialog_modification = function(dialog, d_id, alternate_d
|
|||||||
minetest.formspec_escape(alternate_dialog_text or "$TEXT$").."]"..
|
minetest.formspec_escape(alternate_dialog_text or "$TEXT$").."]"..
|
||||||
"button[3.0,12.3;1,0.7;back_from_edit_dialog_modification;Abort]"..
|
"button[3.0,12.3;1,0.7;back_from_edit_dialog_modification;Abort]"..
|
||||||
"button[6.0,12.3;1,0.7;save_dialog_modification;Save]"..
|
"button[6.0,12.3;1,0.7;save_dialog_modification;Save]"..
|
||||||
"button[9.0,12.3;6,0.7;turn_alternate_text_into_new_dialog;Turn this into a new dialog]"
|
nd
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -71,6 +71,8 @@ yl_speak_up.input_edit_option_dialog = function(player, formname, fields)
|
|||||||
if(fields.button_edit_action_failed_dialog
|
if(fields.button_edit_action_failed_dialog
|
||||||
or fields.button_edit_action_success_dialog
|
or fields.button_edit_action_success_dialog
|
||||||
or fields.save_dialog_modification
|
or fields.save_dialog_modification
|
||||||
|
or fields.button_edit_limit_action_failed_repeat
|
||||||
|
or fields.button_edit_limit_action_success_repeat
|
||||||
or fields.turn_alternate_text_into_new_dialog) then
|
or fields.turn_alternate_text_into_new_dialog) then
|
||||||
if( yl_speak_up.handle_edit_actions_alternate_text(
|
if( yl_speak_up.handle_edit_actions_alternate_text(
|
||||||
-- x_id, id_prefix, target_element and tmp_data_cache are nil here
|
-- x_id, id_prefix, target_element and tmp_data_cache are nil here
|
||||||
|
Loading…
Reference in New Issue
Block a user