From af43cc467c5b0c692b4002cb5cddeb17857a4575 Mon Sep 17 00:00:00 2001 From: Sokomine Date: Fri, 22 Sep 2023 02:10:28 +0200 Subject: [PATCH] added get_location_id for quests --- quest_api.lua | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/quest_api.lua b/quest_api.lua index 1953c6b..1ec2ff7 100644 --- a/quest_api.lua +++ b/quest_api.lua @@ -954,11 +954,28 @@ yl_speak_up.quest_step_del_quest_step = function(pname, q_id, quest_step_name) end +-- turn a location {n_id=.., d_id=.., c_id=..} or position into a uniq string +yl_speak_up.get_location_id = function(loc) + if(not(loc)) then + return nil + end + if(loc.is_block and loc.n_id and loc.d_id and loc.o_id) then + return "POS "..tostring(loc.n_id).." "..tostring(loc.d_id).." "..tostring(loc.o_id) + -- if it's an NPC: + elseif(loc.n_id and string.sub(loc.n_id, 1, 2) == "n_" and loc.d_id and loc.o_id) then + return "NPC "..tostring(loc.n_id).." "..tostring(loc.d_id).." "..tostring(loc.o_id) + else + return nil + end +end + + -- add an NPC or location to a quest step (quest_step.where = list of such locations) -- Note: This is for NPC and locations that SET this very quest step. They ought to be listed here. -- new_location has to be a table, and new_loc_id an ID to avoid duplicates -- for NPC, new_loc_id ought to look like this: "NPC " -yl_speak_up.quest_step_add_where = function(pname, q_id, quest_step_name, new_location, new_loc_id) local error_msg = yl_speak_up.quest_allow_access(q_id, pname, false) +yl_speak_up.quest_step_add_where = function(pname, q_id, quest_step_name, new_location) + local error_msg = yl_speak_up.quest_allow_access(q_id, pname, false) if(error_msg ~= "OK") then return error_msg end @@ -969,10 +986,13 @@ yl_speak_up.quest_step_add_where = function(pname, q_id, quest_step_name, new_lo if(not(step_data.where)) then step_data.where = {} end - if(step_data.where[new_loc_id]) then - return "OK" + local new_loc_id = yl_speak_up.get_location_id(loc) + if(not(new_loc_id)) then + return "Failed to create location ID for this location." end + -- overwrite existing/old entries yl_speak_up.quests[q_id].step_data[quest_step_name].where[new_loc_id] = new_location + yl_speak_up.save_quest(q_id) -- return OK even if the quest step existed already return "OK" end