forked from your-land-mirror/yl_speak_up
moved custom precondition functions to custrom_functions_you_can_override.lua
This commit is contained in:
parent
eeb4d3da5d
commit
039d17c8d7
|
@ -1,4 +1,11 @@
|
|||
|
||||
-----------------------------------------------------------------------------
|
||||
-- This can be customized for each server.
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Placeholders (i.e. $NPC_NAME$) in texts
|
||||
-----------------------------------------------------------------------------
|
||||
-- this contains custom functions that you can override on your server
|
||||
-- please take a look at the example code!
|
||||
|
||||
|
@ -37,7 +44,62 @@ yl_speak_up.replace_vars_in_text = function(text, dialog, pname)
|
|||
end
|
||||
|
||||
|
||||
-- a custom precondition;
|
||||
-----------------------------------------------------------------------------
|
||||
-- Custom preconditions
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
-- 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!
|
||||
-- Adding new texts is no problem.
|
||||
yl_speak_up.custom_server_functions.precondition_descriptions = {
|
||||
"(internal) hour of ingame day",
|
||||
"(internal) player's health points",
|
||||
"(internal) player has priv:",
|
||||
}
|
||||
|
||||
-- please return a useful value depending on the function;
|
||||
-- parameter:
|
||||
-- player the player object
|
||||
-- desc entry from yl_speak_up.custom_server_functions.precondition_descriptions above
|
||||
-- precondition contains the data of the precondition for additional information;
|
||||
-- precondition.p_var_cmp_value contains a user-specified value against which
|
||||
-- the return value of this function is checked. This depends on
|
||||
-- precondition.p_operator. Depending on the operator, precondition.p_var_cmp_value
|
||||
-- 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!
|
||||
yl_speak_up.custom_server_functions.precondition_eval = function(player, descr, precondition)
|
||||
|
||||
if(descr == "(internal) hour of ingame day") then
|
||||
-- timeofday is between 0..1; translate to 24 hours
|
||||
return math.floor((minetest.get_timeofday() * 24)+0.5)
|
||||
|
||||
elseif(descr == "(internal) player's health points") then
|
||||
return player:get_hp()
|
||||
|
||||
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"
|
||||
end
|
||||
|
||||
-- if this custom server function does not exist: return false
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- a custom precondition; still works, but less useful than the above method.
|
||||
-- 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!
|
||||
yl_speak_up.precondition_custom = function(player, param)
|
||||
|
@ -48,6 +110,10 @@ yl_speak_up.precondition_custom = function(player, param)
|
|||
end
|
||||
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- 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)
|
||||
|
@ -59,6 +125,10 @@ yl_speak_up.effect_custom = function(player, param)
|
|||
end
|
||||
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Custom actions
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
-- a custom action (the formspec shown to the player);
|
||||
-- overwrite this function on your server with a custom one that shows the formspec
|
||||
-- that you want!
|
||||
|
|
|
@ -1,56 +1,7 @@
|
|||
-- This file contains what is necessary to execute/evaluate a precondition.
|
||||
|
||||
-- some internal ones...
|
||||
yl_speak_up.custom_server_functions = {}
|
||||
|
||||
|
||||
-- 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!
|
||||
-- Adding new texts is no problem.
|
||||
yl_speak_up.custom_server_functions.precondition_descriptions = {
|
||||
"(internal) hour of ingame day",
|
||||
"(internal) player's health points",
|
||||
"(internal) player has priv:",
|
||||
}
|
||||
|
||||
|
||||
-- please return a useful value depending on the function;
|
||||
-- parameter:
|
||||
-- player the player object
|
||||
-- desc entry from yl_speak_up.custom_server_functions.precondition_descriptions
|
||||
-- precondition the data of the precondition for additional information;
|
||||
-- precondition.p_var_cmp_value contains a user-specified value against which
|
||||
-- the return value of this function is checked. This depends on
|
||||
-- precondition.p_operator. Depending on the operator, precondition.p_var_cmp_value
|
||||
-- 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!
|
||||
yl_speak_up.custom_server_functions.precondition_eval = function(player, descr, precondition)
|
||||
|
||||
if(descr == "(internal) hour of ingame day") then
|
||||
-- timeofday is between 0..1; translate to 24 hours
|
||||
return math.floor((minetest.get_timeofday() * 24)+0.5)
|
||||
|
||||
elseif(descr == "(internal) player's health points") then
|
||||
return player:get_hp()
|
||||
|
||||
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"
|
||||
end
|
||||
|
||||
-- if this custom server function does not exist: return false
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- You can add your own custom functions the file:
|
||||
-- in custrom_functions_you_can_override.lua
|
||||
|
||||
-- this is called directly in yl_speak_up.get_fs_talkdialog
|
||||
-- it returns a list of options whose preconditions are fulfilled
|
||||
|
|
4
init.lua
4
init.lua
|
@ -22,6 +22,10 @@ yl_speak_up.speak_to = {}
|
|||
-- ver 3 is what this was developed with and looks best
|
||||
yl_speak_up.fs_version = {}
|
||||
|
||||
-- used for storing custom functions only this server may have
|
||||
yl_speak_up.custom_server_functions = {}
|
||||
|
||||
|
||||
dofile(modpath .. "config.lua")
|
||||
dofile(modpath .. "privs.lua")
|
||||
-- react to right-click etc.
|
||||
|
|
Loading…
Reference in New Issue
Block a user