check if npcs and locations can be removed from quests

This commit is contained in:
Sokomine 2023-09-30 19:14:49 +02:00
parent f12f778b06
commit 94df301302

View File

@ -215,10 +215,20 @@ yl_speak_up.input_fs_add_quest_steps = function(player, formname, fields)
elseif(fields.delete_from_npc_list) then
-- remove an NPC from the list of contributors
-- TODO: check if it *can* be removed
local selected = minetest.explode_table_event(fields.delete_from_npc_list)
local liste = (res.quest.npcs or {})
if(selected and selected.row and selected.row > 1 and selected.row <= #liste + 1) then
-- *can* it be removed, or is it needed somewhere?
local full_id = "n_"..tostring(liste[selected_row - 1])
if(yl_speak_up.count_used_in_quest_steps(full_id, step_data) > 0) then
yl_speak_up.show_fs(player, "msg", {
input_to = "yl_speak_up:add_quest_steps",
formspec = "size[9,2]"..
"label[0.2,0.0;Error:\n"..
"This NPC is needed for setting a quest step.]"..
"button[1.5,1.5;2,0.9;back_from_error_msg;Back]"})
return
end
table.remove(yl_speak_up.quests[q_id].npcs, selected.row - 1)
end
yl_speak_up.save_quest(q_id)
@ -226,10 +236,20 @@ yl_speak_up.input_fs_add_quest_steps = function(player, formname, fields)
elseif(fields.delete_from_location_list) then
-- remove a location from the list of contributors
-- TODO: check if it *can* be removed
local selected = minetest.explode_table_event(fields.delete_from_location_list)
local liste = (res.quest.locations or {})
if(selected and selected.row and selected.row > 1 and selected.row <= #liste + 1) then
-- *can* it be removed, or is it needed somewhere?
local full_id = liste[selected_row - 1]
if(yl_speak_up.count_used_in_quest_steps(full_id, step_data) > 0) then
yl_speak_up.show_fs(player, "msg", {
input_to = "yl_speak_up:add_quest_steps",
formspec = "size[9,2]"..
"label[0.2,0.0;Error:\n"..
"This location is needed for setting a quest step.]"..
"button[1.5,1.5;2,0.9;back_from_error_msg;Back]"})
return
end
table.remove(yl_speak_up.quests[q_id].locations, selected.row - 1)
end
yl_speak_up.save_quest(q_id)