From 282ae84c81e3223dee6a7f1e57472f5f32f7f2f1 Mon Sep 17 00:00:00 2001 From: Sokomine Date: Fri, 22 Apr 2022 03:18:49 +0200 Subject: [PATCH] npc privs have to match for the npc or for the generic npc who provides a functionality --- README.md | 5 ++++- exec_apply_effects.lua | 8 ++++---- exec_eval_preconditions.lua | 2 +- privs.lua | 11 ++++++++++- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 6c6518d..0bf7289 100644 --- a/README.md +++ b/README.md @@ -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 =========== diff --git a/exec_apply_effects.lua b/exec_apply_effects.lua index 277a13d..820e3df 100644 --- a/exec_apply_effects.lua +++ b/exec_apply_effects.lua @@ -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 diff --git a/exec_eval_preconditions.lua b/exec_eval_preconditions.lua index f866606..f6cf487 100644 --- a/exec_eval_preconditions.lua +++ b/exec_eval_preconditions.lua @@ -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; diff --git a/privs.lua b/privs.lua index 287619e..a494a3f 100644 --- a/privs.lua +++ b/privs.lua @@ -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(