forked from Sokomine/yl_speak_up
stored input from text_input action in yl_speak_up.last_text_input[pname] and added function to examine that input as precondition of type evaluate
This commit is contained in:
parent
e7e097ea20
commit
d7f0abb841
@ -228,6 +228,30 @@ yl_speak_up.custom_functions_p_[ "compare_variable_against_variable" ] = {
|
||||
}
|
||||
|
||||
|
||||
yl_speak_up.custom_functions_p_[ "text_contained_these_words" ] = {
|
||||
description = "Check if what the player entered in the last text_input action contains\n"..
|
||||
"all these words here.",
|
||||
param1_text = "List (seperated by space) of words:",
|
||||
param1_desc = "The text the player entered during the last text_input action is examined.\n"..
|
||||
"If it contains all the words you enter here, then this function here will return true.\n"..
|
||||
"Note: All input will be converted to lower case. Word order does not matter.",
|
||||
code = function(player, n_id, p)
|
||||
local pname = player:get_player_name()
|
||||
if(not(yl_speak_up.last_text_input[pname])) then
|
||||
return false
|
||||
end
|
||||
local input_words = string.split(string.lower(yl_speak_up.last_text_input[pname]), " ")
|
||||
local word_list = string.split(string.lower(p["p_param1"] or ""), " ")
|
||||
for i, word in ipairs(word_list) do
|
||||
if(table.indexof(input_words, word) == -1) then
|
||||
return -1
|
||||
end
|
||||
end
|
||||
return true
|
||||
end,
|
||||
}
|
||||
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Custom actions (of type "evaluate")
|
||||
-----------------------------------------------------------------------------
|
||||
|
@ -685,6 +685,8 @@ yl_speak_up.input_fs_action_text_input = function(player, formname, fields)
|
||||
" "..tostring(yl_speak_up.speak_to[pname].d_id)..
|
||||
": Answer is correct.")
|
||||
end
|
||||
-- store what the player entered so that it can be examined by other functions
|
||||
yl_speak_up.last_text_input[pname] = fields.quest_answer:trim()
|
||||
-- the action was a either a success or failure
|
||||
yl_speak_up.execute_next_action(player, a_id, success)
|
||||
return
|
||||
|
@ -27,10 +27,13 @@ yl_speak_up.npc_owner = {}
|
||||
-- store the current trade between player and npc in case it gets edited in the meantime
|
||||
yl_speak_up.trade = {}
|
||||
|
||||
-- store what the player last entered in an text_input action
|
||||
yl_speak_up.last_text_input = {}
|
||||
|
||||
yl_speak_up.reset_vars_for_player = function(pname, reset_fs_version)
|
||||
yl_speak_up.speak_to[pname] = nil
|
||||
yl_speak_up.edit_mode[pname] = nil
|
||||
yl_speak_up.last_text_input[pname] = nil
|
||||
-- when just stopping editing: don't reset the fs_version
|
||||
if(reset_fs_version) then
|
||||
yl_speak_up.fs_version[pname] = nil
|
||||
|
Loading…
Reference in New Issue
Block a user