diff --git a/custom_functions_you_can_override.lua b/custom_functions_you_can_override.lua index c4e739c..50233ac 100644 --- a/custom_functions_you_can_override.lua +++ b/custom_functions_you_can_override.lua @@ -2,6 +2,9 @@ ----------------------------------------------------------------------------- -- This can be customized for each server. ----------------------------------------------------------------------------- +-- But please not in this file. Write your own one and re-define these +-- functions here if needed! +----------------------------------------------------------------------------- ----------------------------------------------------------------------------- -- Placeholders (i.e. $NPC_NAME$) in texts @@ -45,8 +48,10 @@ end ----------------------------------------------------------------------------- --- Custom preconditions +-- Custom preconditions without parameters - the simple way ----------------------------------------------------------------------------- +-- Unlike the more advanced custom preconditions, actions and effects below, +-- these ones here take *no* custom parameters when beeing used. -- When you change an existing texts NPC that make use of that precondition will no -- longer be able to recognize it. You have to reconfigure all those NPC! @@ -68,6 +73,7 @@ yl_speak_up.custom_server_functions.precondition_descriptions = { -- may also be used as a parameter to this function. -- Just make sure to tell your users what return values they shall expect and which -- operators make sense! +-- Note: This function will be called often. Make it efficient! yl_speak_up.custom_server_functions.precondition_eval = function(player, descr, precondition) if(descr == "(internal) hour of ingame day") then @@ -77,6 +83,8 @@ yl_speak_up.custom_server_functions.precondition_eval = function(player, descr, elseif(descr == "(internal) player's health points") then return player:get_hp() + -- this is something that is better handled by a custom precondition + -- with a parameter (see below - preconditions of type "evaluate"!) elseif(descr == "(internal) player has priv:") then -- the name of the priv is derived from the parameter local ret = minetest.check_player_privs(player, @@ -96,30 +104,6 @@ yl_speak_up.custom_server_functions.precondition_eval = function(player, descr, end --- Custom preconditions are deprecated. --- Please use --- yl_speak_up.custom_server_functions.precondition_descriptions = {..} --- and --- 1yl_speak_up.custom_server_functions.precondition_eval(player, descr, precondition) --- instead! --- has to return either true (=precondition is fulfilled) or false (=precondition is not fulfilled) --- Note: This function will be called often. Make it efficient! - - ------------------------------------------------------------------------------ --- Custom effects ------------------------------------------------------------------------------ - --- a custom effect; --- has to return true (=effect was executed successfully) or false (=effect failed for some reason) -yl_speak_up.effect_custom = function(player, param) - minetest.chat_send_player(player:get_player_name(), - "Executing custom effect with parameter \""..tostring(param).."\"..") - -- return true if your effect executed successfuly, and false if not - -- (only relevant for following on_failure effects) - return true -end - ----------------------------------------------------------------------------- -- Custom actions @@ -182,25 +166,48 @@ yl_speak_up.input_fs_action_custom = function(player, formname, fields) "button[2,0.5;1.5,0.9;back_from_error_msg;Back]"}) end +-- actions: (not yet used) +yl_speak_up.custom_functions_a_ = {} + ----------------------------------------------------------------------------- -- Custom preconditions and effects (functions; they have the type "evaluate") ----------------------------------------------------------------------------- --- each entry in the table has the following format: --- key: for display in edit options dialog and dropdown menu, --- function_name: name of the function that shall be called --- description: long description of what the function does, --- param1_text: label for the input field for param1 (if empty, no input field is offered) --- param1_desc: mouseover text for the input field for param1 +-- General structure: +-- Each entry in the table +-- yl_speak_up.custom_functions_*_ (with * beeing p, a or r) +-- has the following format: +-- key: Short uniq name for the function. +-- description: Long description of what the function does +-- param1_text: Label for the input field for param1 (if empty, no input field is offered) +-- param1_desc: Mouseover text for the input field for param1 -- ... --- param9_text: label for the input field for param1 --- param9_desc: mouseover text for the input field for param1 +-- param9_text: Label for the input field for param1 +-- param9_desc: Mouseover text for the input field for param1 +-- code: The actual implementation of the function that is to be called. + +----------------------------------------------------------------------------- +-- Custom preconditions (of type "evaluate") +----------------------------------------------------------------------------- +-- The function has to have the following structure: -- --- preconditions: +-- code = function(player, n_id, p) +-- -- do something +-- return result +-- end, +-- +-- The return value is compared to the given value with the given +-- comperator operation. +-- +-- Please keep in mind that preconditions are called *often*. They need to be +-- fast and efficient. +-- +-- Parameters: +-- The acting player object. +-- The NPC ID of the given NPC. +--

The precondition. Contains the parameters in p.p_param. +-- +-- Table for storing the custom preconditions: yl_speak_up.custom_functions_p_ = {} --- actions: (not yet used) -yl_speak_up.custom_functions_a_ = {} --- results: -yl_speak_up.custom_functions_r_ = {} -- example function for preconditions: yl_speak_up.custom_functions_p_[ "example function" ] = { @@ -239,6 +246,11 @@ yl_speak_up.custom_functions_p_[ "example function" ] = { end, } +-- get the XP the player has collected (provided the xp_redo mod is installed); +-- returns 0 if the mod isn't installed +-- Note: This could also have been handled by the old/above "Custom preconditions +-- without parameters - the simple way" method. +-- Please use this version instead of the old above! yl_speak_up.custom_functions_p_[ "get_xp_of_player" ] = { description = "Get the xp the player has achieved (requires xp_redo).", code = function(player, n_id, p) @@ -250,27 +262,39 @@ yl_speak_up.custom_functions_p_[ "get_xp_of_player" ] = { end } - -- TODO: actually implement these as examples -yl_speak_up.custom_functions_r_[ "set_variable_to_random_number" ] = { - description = "Set a variable to a random number.", - param1_text = "Name of the variable:", - param1_desc = "Which variable do you want to set to a random number?", - param2_text = "Minimum value:", - param2_desc = "Which is the MINIMUM value the varible might be set to?", - param3_text = "Maximum value:", - param3_desc = "Which is the MAXIMUM value the varible might be set to?", -} - -yl_speak_up.custom_functions_r_[ "set_variable_to_random_value_from_list" ] = { - description = "Set a variable to a random value from a list.", - param1_text = "Name of the variable:", - param1_desc = "Which variable do you want to set to a random value from your list?", - param2_text = "Possible values:", - param2_desc = "Enter all the possible values/texts for your variable here.\n".. - "Seperate the entires by \"|\", i.e.: \"entry1|entry2|entry3\".", +yl_speak_up.custom_functions_p_[ "compare_variable_against_variable" ] = { + description = "Compare a variable against another variable.", + param1_text = "Name of the first variable:", + param1_desc = "Which variables do you want to compare?", + param2_text = "Name of the second variable:", + param2_desc = "Which variables do you want to compare?", + param3_text = "Operator (i.e. >=, <, ==, ~=, ..):", + param3_text = "Please state which operator shall be used.", } +----------------------------------------------------------------------------- +-- Custom effects (of type "evaluate") +----------------------------------------------------------------------------- +-- The function has to have the following structure: +-- +-- code = function(player, n_id, r) +-- -- do something +-- return result +-- end, +-- +-- The return value has to be either (if the function was +-- successful) or if it encountered an error. +-- +-- Functions used in/as effects usually change something, i.e. a variable. +-- +-- Parameters: +-- The acting player object. +-- The NPC ID of the given NPC. +-- The effect/result. Contains the parameters in r.r_param. +-- +-- Table for storing the custom results/effects: +yl_speak_up.custom_functions_r_ = {} -- example function for results/effects: yl_speak_up.custom_functions_r_[ "example function" ] = { @@ -310,6 +334,26 @@ yl_speak_up.custom_functions_r_[ "example function" ] = { end, } +-- TODO: actually implement these as examples +yl_speak_up.custom_functions_r_[ "set_variable_to_random_number" ] = { + description = "Set a variable to a random number.", + param1_text = "Name of the variable:", + param1_desc = "Which variable do you want to set to a random number?", + param2_text = "Minimum value:", + param2_desc = "Which is the MINIMUM value the varible might be set to?", + param3_text = "Maximum value:", + param3_desc = "Which is the MAXIMUM value the varible might be set to?", +} + +yl_speak_up.custom_functions_r_[ "set_variable_to_random_value_from_list" ] = { + description = "Set a variable to a random value from a list.", + param1_text = "Name of the variable:", + param1_desc = "Which variable do you want to set to a random value from your list?", + param2_text = "Possible values:", + param2_desc = "Enter all the possible values/texts for your variable here.\n".. + "Seperate the entires by \"|\", i.e.: \"entry1|entry2|entry3\".", +} + ----------------------------------------------------------------------------- -- Custom handling of special properties ----------------------------------------------------------------------------- diff --git a/fs_edit_general.lua b/fs_edit_general.lua index a4ee3ab..0f0faf6 100644 --- a/fs_edit_general.lua +++ b/fs_edit_general.lua @@ -1712,7 +1712,7 @@ yl_speak_up.get_fs_edit_option_p_and_e_evaluate = function( end local operator_list = {} for i, v in ipairs(check_operator) do - v2 = values_operator[i] + local v2 = values_operator[i] if( v2 ~= "quest_step_done" and v2 ~= "quest_step_not_done" and v2 ~= "true_for_param" and v2 ~= "false_for_param") then table.insert(operator_list, v)