npc privs have to match for the npc or for the generic npc who provides a functionality

This commit is contained in:
Sokomine 2022-04-22 03:18:49 +02:00
parent 6442335931
commit 282ae84c81
4 changed files with 19 additions and 7 deletions

View File

@ -9,7 +9,7 @@ Chat commands
/npc_talk_style Allows to select the formspec version:
1: Very rudamentary. Not recommended.
2: Shows additional buttons for up and down.
3: Default (recommended) version.
3: Default (recommended) version. Scroll via mouse wheel.
/npc_talk_debug Allows to debug dialogs.
@ -19,6 +19,9 @@ Chat commands
/npc_talk_privs grant n_3 effect_exec_lua
grants NPC n_3 the right to execute
lua code as an effect/result
Note: If a precondition or effect originates from a generic
NPC, the priv will be considered granted if the
executing NPC or the the generic NPC has the priv.
Terminology
===========

View File

@ -307,7 +307,7 @@ yl_speak_up.execute_effect = function(player, n_id, o_id, r)
return true
elseif(r.r_type == "function") then
-- this can only be set and edited with the staff
if(not(yl_speak_up.npc_has_priv(n_id, "effect_exec_lua"))) then
if(not(yl_speak_up.npc_has_priv(n_id, "effect_exec_lua", r.r_is_generic))) then
return false
end
return yl_speak_up.eval_and_execute_function(player, r, "r_")
@ -316,7 +316,7 @@ yl_speak_up.execute_effect = function(player, n_id, o_id, r)
if(not(r.r_value)) then
return false
end
if(not(yl_speak_up.npc_has_priv(n_id, "effect_give_item"))) then
if(not(yl_speak_up.npc_has_priv(n_id, "effect_give_item", r.r_is_generic))) then
return false
end
local item = ItemStack(r.r_value)
@ -334,7 +334,7 @@ yl_speak_up.execute_effect = function(player, n_id, o_id, r)
return true
-- this can only be set and edited with the staff
elseif(r.r_type == "take_item") then
if(not(yl_speak_up.npc_has_priv(n_id, "effect_take_item"))) then
if(not(yl_speak_up.npc_has_priv(n_id, "effect_take_item", r.r_is_generic))) then
return false
end
if(not(r.r_value)) then
@ -355,7 +355,7 @@ yl_speak_up.execute_effect = function(player, n_id, o_id, r)
return true
-- this can only be set and edited with the staff
elseif(r.r_type == "move") then
if(not(yl_speak_up.npc_has_priv(n_id, "effect_move_player"))) then
if(not(yl_speak_up.npc_has_priv(n_id, "effect_move_player", r.r_is_generic))) then
return false
end
-- copeid/moved here from AliasAlreadyTakens code in functions.lua

View File

@ -87,7 +87,7 @@ yl_speak_up.eval_precondition = function(player, n_id, p, other_options_true_or_
-- a precondition set by using the staff; kept for compatibility
return true
elseif(p.p_type == "function") then
if(not(yl_speak_up.npc_has_priv(n_id, "precon_exec_lua"))) then
if(not(yl_speak_up.npc_has_priv(n_id, "precon_exec_lua", p.p_is_generic))) then
return false
end
-- a precondition set by using the staff;

View File

@ -42,11 +42,20 @@ yl_speak_up.npc_priv_names = {
"effect_exec_lua", "effect_give_item", "effect_take_item", "effect_move_player",
}
yl_speak_up.npc_has_priv = function(n_id, priv_name)
-- either the npc with n_id *or* if generic_npc_id is set the generic npc with the
-- id generic_npc_id needs to have been granted priv_name
yl_speak_up.npc_has_priv = function(n_id, priv_name, generic_npc_id)
-- fallback: disallow
if(not(n_id) or not(priv_name)) then
return false
end
-- if the precondition or effect come from a generic_npc and that
-- generic npc has the desired priv, then the priv has been granted
if(generic_npc_id
and yl_speak_up.npc_priv_table[generic_npc_id]
and yl_speak_up.npc_priv_table[generic_npc_id][priv_name]) then
return true
end
if(not(yl_speak_up.npc_priv_table[n_id])
or not(yl_speak_up.npc_priv_table[n_id][priv_name])) then
minetest.log(