From 14e0902cf11d64566371f2c98f6b495e8480d718 Mon Sep 17 00:00:00 2001 From: Sokomine Date: Thu, 8 Jul 2021 23:30:27 +0200 Subject: [PATCH] combined list of read and write acces in quest api --- quest_api.lua | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/quest_api.lua b/quest_api.lua index 69b5415..79bcacf 100644 --- a/quest_api.lua +++ b/quest_api.lua @@ -111,40 +111,45 @@ yl_speak_up.get_quest_variable_value = function(player_name, variable_name) end --- which variables can player pname read and use in preconditions? --- returns a sorted list -yl_speak_up.get_quest_variables_with_read_access = function(pname) +yl_speak_up.get_quest_variables = function(pname, has_write_access) if(not(pname)) then return {} end local liste = {} + -- first: list the variables owned by the player for k, v in pairs(yl_speak_up.player_vars) do local parts = string.split(k, " ") if(parts and parts[1] and parts[1] == "$" and parts[2] and parts[2] == pname) then table.insert(liste, k) end end + -- if the player has the right privs: allow to access all other variables as well + if( minetest.check_player_privs(pname, {npc_master=true}) + or minetest.check_player_privs(pname, {npc_talk_master=true})) then + for k, v in pairs(yl_speak_up.player_vars) do + local parts = string.split(k, " ") + -- variables owned by *other* players + if(parts and parts[1] and parts[1] == "$" and parts[2] and parts[2] ~= pname) then + table.insert(liste, k) + end + end + end -- TODO: insert those vars owned by other players where this one has read access to table.sort(liste) return liste end +-- which variables can player pname read and use in preconditions? +-- returns a sorted list +yl_speak_up.get_quest_variables_with_read_access = function(pname) + return yl_speak_up.get_quest_variables(pname, false) +end + + -- which variables can player pname write and use in effects/results? yl_speak_up.get_quest_variables_with_write_access = function(pname) - if(not(pname)) then - return {} - end - local liste = {} - for k, v in pairs(yl_speak_up.player_vars) do - local parts = string.split(k, " ") - if(parts and parts[1] and parts[1] == "$" and parts[2] and parts[2] == pname) then - table.insert(liste, k) - end - end - -- TODO: insert those vars owned by other players where this one has write access to - table.sort(liste) - return liste + return yl_speak_up.get_quest_variables(pname, true) end