moved adding npc/locations to quest steps into quest_api

This commit is contained in:
Sokomine 2023-10-28 17:32:07 +02:00
parent 6f8dde7e61
commit 1dd6c587c7
2 changed files with 22 additions and 16 deletions

View File

@ -324,17 +324,6 @@ yl_speak_up.input_fs_add_quest_steps = function(player, formname, fields)
else else
return show_error_fs(player, "Failed to update NPC.") return show_error_fs(player, "Failed to update NPC.")
end end
-- make sure quest.npcs or quest.locations contains this entry
if(string.sub(n_id, 1, 2) == "n_") then
-- only npcs that are not yet added (and we store IDs without n_ prefix)
local id = tonumber(string.sub(n_id, 3))
if(id and table.indexof(quest.npcs or {}, id) == -1) then
table.insert(yl_speak_up.quests[q_id].npcs, id)
end
elseif(string.sub(n_id, 1, 1) == "p"
and table.indexof(quest.locations or {}, n_id) == -1) then
table.insert(yl_speak_up.quests[q_id].locations, n_id)
end
-- show the newly created or selected step -- show the newly created or selected step
yl_speak_up.speak_to[pname].quest_step = work_step yl_speak_up.speak_to[pname].quest_step = work_step
return yl_speak_up.show_fs(player, "manage_quest_steps", work_step) return yl_speak_up.show_fs(player, "manage_quest_steps", work_step)

View File

@ -994,10 +994,22 @@ yl_speak_up.quest_step_add_where = function(pname, q_id, quest_step_name, new_lo
end end
local new_loc_id = yl_speak_up.get_location_id(new_location) local new_loc_id = yl_speak_up.get_location_id(new_location)
if(not(new_loc_id)) then if(not(new_loc_id)) then
return "Failed to create location ID for this location." return "Failed to create location ID for this location/NPC."
end end
-- overwrite existing/old entries -- overwrite existing/old entries
yl_speak_up.quests[q_id].step_data[quest_step_name].where[new_loc_id] = new_location yl_speak_up.quests[q_id].step_data[quest_step_name].where[new_loc_id] = new_location
-- make sure quest.npcs or quest.locations contains this entry
local n_id = new_location.n_id or "?"
if(string.sub(n_id, 1, 2) == "n_") then
-- only npcs that are not yet added (and we store IDs without n_ prefix)
local id = tonumber(string.sub(n_id, 3))
if(id and table.indexof(yl_speak_up.quests[q_id].npcs or {}, id) == -1) then
table.insert(yl_speak_up.quests[q_id].npcs, id)
end
elseif(string.sub(n_id, 1, 1) == "p"
and table.indexof(yl_speak_up.quests[q_id].locations or {}, n_id) == -1) then
table.insert(yl_speak_up.quests[q_id].locations, n_id)
end
yl_speak_up.save_quest(q_id) yl_speak_up.save_quest(q_id)
-- return OK even if the quest step existed already -- return OK even if the quest step existed already
return "OK" return "OK"
@ -1005,7 +1017,7 @@ end
-- delete a quest step location with the id location_id -- delete a quest step location with the id location_id
yl_speak_up.quest_step_del_where = function(pname, q_id, quest_step_name, location_id) yl_speak_up.quest_step_del_where = function(pname, q_id, quest_step_name, old_location)
local error_msg = yl_speak_up.quest_allow_access(q_id, pname, false) local error_msg = yl_speak_up.quest_allow_access(q_id, pname, false)
if(error_msg ~= "OK") then if(error_msg ~= "OK") then
return error_msg return error_msg
@ -1014,11 +1026,16 @@ yl_speak_up.quest_step_del_where = function(pname, q_id, quest_step_name, locati
if(not(quest_step)) then if(not(quest_step)) then
return "Quest step \""..tostring(quest_step_name).."\" does not exist." return "Quest step \""..tostring(quest_step_name).."\" does not exist."
end end
if(not(step_data.where)) then local loc_id = yl_speak_up.get_location_id(old_location)
step_data.where = {} if(not(loc_id)) then
return "Failed to create location ID for this location/NPC."
end
if(not(yl_speak_up.quests[q_id].step_data[quest_step_name])) then
yl_speak_up.quests[q_id].step_data[quest_step_name].where = {}
end end
-- delete the quest step location -- delete the quest step location
yl_speak_up.quests[q_id].step_data[quest_step_name].where[location_id] = nil yl_speak_up.quests[q_id].step_data[quest_step_name].where[loc_id] = nil
yl_speak_up.save_quest(q_id)
return "OK" return "OK"
end end