added operator 'is true/false when called with parameter:'

This commit is contained in:
Sokomine 2022-01-17 03:42:15 +01:00
parent 039d17c8d7
commit 75cc01904e
3 changed files with 24 additions and 11 deletions

View File

@ -79,13 +79,15 @@ yl_speak_up.custom_server_functions.precondition_eval = function(player, descr,
elseif(descr == "(internal) player has priv:") then
-- the name of the priv is derived from the parameter
if(minetest.check_player_privs(player,
minetest.string_to_privs(tostring(precondition.p_var_cmp_value)))) then
-- TODO: change to true/false when new operator is available
return tostring(precondition.p_var_cmp_value)
else
return "false"
local ret = minetest.check_player_privs(player,
minetest.string_to_privs(tostring(precondition.p_var_cmp_value)))
-- evaluate the parameter directly
if(not(ret) or precondition.p_operator == "true_for_param"
or precondition.p_operator == "false_for_param") then
return ret
end
-- return the parameter for == / != comparison
return tostring(precondition.p_var_cmp_value)
-- if this custom server function does not exist: return false
else

View File

@ -101,6 +101,11 @@ yl_speak_up.eval_precondition = function(player, n_id, p, other_options_true_or_
-- evaluate it
var_val = yl_speak_up.custom_server_functions.precondition_eval(
player, p.p_variable, p)
if(p.p_operator == "true_for_param") then
return var_val
elseif(p.p_operator == "false_for_param") then
return not(var_val)
end
else
local pname = player:get_player_name()
local owner = yl_speak_up.npc_owner[ n_id ]

View File

@ -1,6 +1,3 @@
-- TODO: check inscription of a sign?
-- TODO: check mesecons related things?
--
-- This file contains what is necessary to add/edit a precondition.
--
-- Which diffrent types of preconditions are available?
@ -140,12 +137,14 @@ local check_operator = {
"less than x seconds ago", -- 12
"has completed quest step", -- 13
"quest step *not* completed", -- 14
"is true for parameter:", -- 15
"is false for parameter:", -- 16
}
-- how to store these as p_value (the actual variable is stored in p_variable, and the value in p_cmp_value):
local values_operator = {"", "==", "~=", ">=", ">", "<=", "<", "not", "is_set", "is_unset",
"more_than_x_seconds_ago","less_than_x_seconds_ago",
"quest_step_done", "quest_step_not_done"}
"quest_step_done", "quest_step_not_done", "true_for_param", "false_for_param"}
@ -206,6 +205,12 @@ yl_speak_up.show_precondition = function(p, pname)
elseif(p.p_operator == "quest_step_not_done") then
return var_name.." shows: player has not yet completed quest step \""..
tostring(p.p_var_cmp_value).."\""
elseif(p.p_operator == "true_for_param") then
return var_name.." is true if called with parameter: \""..
tostring(p.p_var_cmp_value).."\""
elseif(p.p_operator == "false_for_param") then
return var_name.." is false if called with parameter: \""..
tostring(p.p_var_cmp_value).."\""
end
if(p.p_var_cmp_value == "") then
return var_name.." "..tostring(p.p_operator).." \"\""
@ -327,7 +332,8 @@ yl_speak_up.get_fs_edit_preconditions = function(player, table_click_result)
-- show one precondition element
yl_speak_up.show_precondition,
"table_of_preconditions",
"The following expression shall be true:", "Operator:", "Value to compare with:",
"The following expression shall be true:", "Operator:",
"Value to compare with (in some cases parameter):",
"The following shall be true about the block:"
)
end