added get_location_id for quests

This commit is contained in:
Sokomine 2023-09-22 02:10:28 +02:00
parent 58fe04cd49
commit af43cc467c

View File

@ -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 <n_id> <d_id> <o_id>"
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