diff --git a/fs_add_quest_steps.lua b/fs_add_quest_steps.lua index 773280b..a008195 100644 --- a/fs_add_quest_steps.lua +++ b/fs_add_quest_steps.lua @@ -8,6 +8,22 @@ local grey_if_zero = function(fs, n) table.insert(fs, minetest.formspec_escape(n)) end + +-- find out in how many quest steps this NPC or location is used; +-- ID can either be n_ or a location p_(x,y,z) +yl_speak_up.count_used_in_quest_steps = function(id, step_data) + local used = 0 + for s, d in pairs(step_data or {}) do + for loc_id, loc in pairs(d.where or {}) do + if(loc and loc.n_id and loc.n_id == id) then + used = used + 1 + end + end + end + return used +end + + -- This order imposed here on the quest steps is the one in which the -- quest steps have to be solved - as far as we can tell (the quest -- may be in the process of beeing created and not logicly complete yet). @@ -341,18 +357,11 @@ yl_speak_up.quest_npc_show_table = function(formspec, table_specs, liste, step_d table.insert(formspec, " description:,#FFFFFF,Owner:,") local tmp = {} for i, n_id in ipairs(liste or {}) do - -- TODO: turn this into a function - -- find out in how many quest steps this NPC is used - local used = 0 - for s, d in pairs(step_data) do - for loc_id, loc in pairs(d.where or {}) do - -- TODO: needs to be diffrent for locations - if(loc and loc.n_id and loc.n_id == "n_"..n_id) then - used = used + 1 - end - end + local full_id = n_id + if(not(is_location_list)) then + full_id = "n_"..tostring(n_id) end - grey_if_zero(tmp, used) + grey_if_zero(tmp, yl_speak_up.count_used_in_quest_steps(full_id, step_data)) -- the n_id of the NPC table.insert(tmp, "#AAFFAA") if(is_location_list) then