mirror of
https://github.com/MinetestForFun/quests.git
synced 2025-01-10 10:10:22 +01:00
Ugly fix for MT engine HUD bug, better error reporting
This commit is contained in:
parent
4a93e351f3
commit
0de375a4ab
6
core.lua
6
core.lua
@ -147,7 +147,7 @@ end
|
|||||||
-- @param questname Name of the quest. Should follow the naming conventions: `modname:questname`
|
-- @param questname Name of the quest. Should follow the naming conventions: `modname:questname`
|
||||||
-- @param quest Quest definition `table`
|
-- @param quest Quest definition `table`
|
||||||
-- @return `true` when the quest was successfully registered
|
-- @return `true` when the quest was successfully registered
|
||||||
-- @return `false` when there was already such a quest, or if mandatory info was omitted/corrupt
|
-- @return `false`, <error string> when there was already such a quest, or if mandatory info was omitted/corrupt
|
||||||
function quests.register_quest(questname, quest)
|
function quests.register_quest(questname, quest)
|
||||||
if quests.registered_quests[questname] ~= nil then
|
if quests.registered_quests[questname] ~= nil then
|
||||||
return false -- The quest was not registered since there's already a quest with that name
|
return false -- The quest was not registered since there's already a quest with that name
|
||||||
@ -169,7 +169,7 @@ function quests.register_quest(questname, quest)
|
|||||||
else
|
else
|
||||||
if quest.tasks == nil or type(quest.tasks) ~= "table" then
|
if quest.tasks == nil or type(quest.tasks) ~= "table" then
|
||||||
quests.registered_quests[questname] = nil
|
quests.registered_quests[questname] = nil
|
||||||
return false
|
return false, "No quest.max defined but no tasks either"
|
||||||
end
|
end
|
||||||
new_quest.tasks = {}
|
new_quest.tasks = {}
|
||||||
local tcount = 0
|
local tcount = 0
|
||||||
@ -191,7 +191,7 @@ function quests.register_quest(questname, quest)
|
|||||||
end
|
end
|
||||||
if tcount == 0 then -- No tasks!
|
if tcount == 0 then -- No tasks!
|
||||||
quests.registered_quests[questname] = nil
|
quests.registered_quests[questname] = nil
|
||||||
return false
|
return false, "No quest.max defined but no *valid* tasks either"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
|
41
hud.lua
41
hud.lua
@ -59,7 +59,7 @@ function quests.show_hud(playername, autohide)
|
|||||||
})
|
})
|
||||||
|
|
||||||
quests.hud[playername].list = {}
|
quests.hud[playername].list = {}
|
||||||
minetest.after(0, quests.update_hud, playername)
|
quests.update_hud(playername)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Hide quests HUD to player.
|
--- Hide quests HUD to player.
|
||||||
@ -146,7 +146,7 @@ local function get_hud_list(playername)
|
|||||||
deftable[questname] = get_table(get_quest_hud_string(quest.title, plr_quest.value, quest.max), plr_quest.value, quest.max)
|
deftable[questname] = get_table(get_quest_hud_string(quest.title, plr_quest.value, quest.max), plr_quest.value, quest.max)
|
||||||
counter = counter + 1
|
counter = counter + 1
|
||||||
else
|
else
|
||||||
deftable[questname] = get_table(quest.title, plr_quest.value, quest.max)
|
deftable[questname] = get_table(quest.title)
|
||||||
counter = counter + 0.5
|
counter = counter + 0.5
|
||||||
for taskname, task in pairs(quest.tasks) do
|
for taskname, task in pairs(quest.tasks) do
|
||||||
local plr_task = quests.active_quests[playername][questname][taskname]
|
local plr_task = quests.active_quests[playername][questname][taskname]
|
||||||
@ -158,7 +158,6 @@ local function get_hud_list(playername)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
counter = counter + 0.1
|
|
||||||
end
|
end
|
||||||
if counter >= show_max + 1 then
|
if counter >= show_max + 1 then
|
||||||
break
|
break
|
||||||
@ -252,6 +251,7 @@ function quests.update_hud(playername)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
--[[ Disabled because it had issues with MT engine and too much quests. HUD elements sometimes won't update.
|
||||||
if diff ~= nil then
|
if diff ~= nil then
|
||||||
for questname, hud_elms in pairs(diff) do
|
for questname, hud_elms in pairs(diff) do
|
||||||
if hud_elms == DELETED then
|
if hud_elms == DELETED then
|
||||||
@ -280,27 +280,24 @@ function quests.update_hud(playername)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end]]
|
||||||
|
for questname, hud_elms in pairs(old_hud) do
|
||||||
|
for elm_name, elm_def in pairs(hud_elms) do
|
||||||
|
player:hud_remove(elm_def.id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for questname, hud_elms in pairs(new_hud) do
|
||||||
|
for elm_name, elm_def in pairs(hud_elms) do
|
||||||
|
elm_def.id = player:hud_add(elm_def)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
quests.hud[playername].list = new_hud
|
quests.hud[playername].list = new_hud
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- show the HUDs
|
|
||||||
--for playername,id in pairs(quests.hud) do
|
|
||||||
-- if (id ~= nil) then
|
|
||||||
-- quests.hud[playername] = nil
|
|
||||||
-- minetest.after(10, function(playername)
|
|
||||||
-- quests.show_hud(playername)
|
|
||||||
-- quests.update_hud(playername)
|
|
||||||
-- end, playername)
|
|
||||||
-- end
|
|
||||||
--end
|
|
||||||
|
|
||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
local playername = player:get_player_name()
|
local playername = player:get_player_name()
|
||||||
if (quests.hud[playername] ~= nil) then
|
if quests.hud[playername] ~= nil then
|
||||||
if (not(quests.hud[playername].first)) then
|
if not quests.hud[playername].first then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local list = quests.hud[playername].list
|
local list = quests.hud[playername].list
|
||||||
@ -310,11 +307,6 @@ minetest.register_on_joinplayer(function(player)
|
|||||||
autohide = autohide,
|
autohide = autohide,
|
||||||
central_message_enabled = central_message_enabled
|
central_message_enabled = central_message_enabled
|
||||||
}
|
}
|
||||||
if (list ~= nil) then
|
|
||||||
minetest.after(1, function(playername)
|
|
||||||
quests.show_hud(playername)
|
|
||||||
end, playername)
|
|
||||||
end
|
|
||||||
else -- new player
|
else -- new player
|
||||||
quests.hud[playername] = {
|
quests.hud[playername] = {
|
||||||
autohide = true,
|
autohide = true,
|
||||||
@ -322,4 +314,7 @@ minetest.register_on_joinplayer(function(player)
|
|||||||
}
|
}
|
||||||
quests.active_quests[playername] = {}
|
quests.active_quests[playername] = {}
|
||||||
end
|
end
|
||||||
|
minetest.after(1, function(playername)
|
||||||
|
quests.show_hud(playername)
|
||||||
|
end, playername)
|
||||||
end)
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user