mirror of
https://github.com/TeTpaAka/quests.git
synced 2025-01-22 07:50:49 +01:00
Replace references to deprecated "minetest" global with "core"
This commit is contained in:
parent
094057447d
commit
3baf31ea1a
@ -1,9 +1,9 @@
|
||||
if (cmsg) then
|
||||
function quests.show_message(t, playername, text)
|
||||
if (quests.hud[playername].central_message_enabled) then
|
||||
local player = minetest.get_player_by_name(playername)
|
||||
local player = core.get_player_by_name(playername)
|
||||
cmsg.push_message_player(player, text, quests.colors[t])
|
||||
minetest.sound_play("quests_" .. t, {to_player = playername})
|
||||
core.sound_play("quests_" .. t, {to_player = playername})
|
||||
end
|
||||
end
|
||||
else
|
||||
|
10
core.lua
10
core.lua
@ -1,6 +1,6 @@
|
||||
-- Boilerplate to support localized strings if intllib mod is installed.
|
||||
local S
|
||||
if minetest.get_modpath("intllib") then
|
||||
if core.get_modpath("intllib") then
|
||||
S = intllib.Getter()
|
||||
else
|
||||
-- If you don't use insertions (@1, @2, etc) you can use this:
|
||||
@ -117,12 +117,12 @@ function quests.accept_quest(playername, questname)
|
||||
quests.active_quests[playername][questname].finished = true
|
||||
for _,quest in ipairs(quests.hud[playername].list) do
|
||||
if (quest.name == questname) then
|
||||
local player = minetest.get_player_by_name(playername)
|
||||
local player = core.get_player_by_name(playername)
|
||||
player:hud_change(quest.id, "number", quests.colors.success)
|
||||
end
|
||||
end
|
||||
quests.show_message("success", playername, S("Quest completed:") .. " " .. quests.registered_quests[questname].title)
|
||||
minetest.after(3, function(playername, questname)
|
||||
core.after(3, function(playername, questname)
|
||||
quests.active_quests[playername][questname] = nil
|
||||
quests.update_hud(playername)
|
||||
end, playername, questname)
|
||||
@ -155,12 +155,12 @@ function quests.abort_quest(playername, questname)
|
||||
quests.active_quests[playername][questname].finished = true
|
||||
for _,quest in ipairs(quests.hud[playername].list) do
|
||||
if (quest.name == questname) then
|
||||
local player = minetest.get_player_by_name(playername)
|
||||
local player = core.get_player_by_name(playername)
|
||||
player:hud_change(quest.id, "number", quests.colors.failed)
|
||||
end
|
||||
end
|
||||
quests.show_message("failed", playername, S("Quest failed:") .. " " .. quests.registered_quests[questname].title)
|
||||
minetest.after(3, function(playername, questname)
|
||||
core.after(3, function(playername, questname)
|
||||
quests.active_quests[playername][questname] = nil
|
||||
quests.update_hud(playername)
|
||||
end, playername, questname)
|
||||
|
@ -1,6 +1,6 @@
|
||||
-- Boilerplate to support localized strings if intllib mod is installed.
|
||||
local S
|
||||
if minetest.get_modpath("intllib") then
|
||||
if core.get_modpath("intllib") then
|
||||
S = intllib.Getter()
|
||||
else
|
||||
-- If you don't use insertions (@1, @2, etc) you can use this:
|
||||
@ -141,22 +141,22 @@ function quests.create_info(playername, questname, integrated)
|
||||
end
|
||||
|
||||
-- show the player playername his/her questlog
|
||||
function quests.show_formspec(playername)
|
||||
minetest.show_formspec(playername, "quests:questlog", quests.create_formspec(playername))
|
||||
function quests.show_formspec(playername)
|
||||
core.show_formspec(playername, "quests:questlog", quests.create_formspec(playername))
|
||||
end
|
||||
|
||||
-- chatcommand to see a full list of quests:
|
||||
minetest.register_chatcommand("quests", {
|
||||
core.register_chatcommand("quests", {
|
||||
params = "",
|
||||
description = S("Show all open quests"),
|
||||
func = function(name, param)
|
||||
minetest.show_formspec(name, "quests:questlog", quests.create_formspec(name))
|
||||
core.show_formspec(name, "quests:questlog", quests.create_formspec(name))
|
||||
return true
|
||||
end
|
||||
})
|
||||
|
||||
-- Handle the return fields of the questlog
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
core.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if (player == nil) then
|
||||
return
|
||||
end
|
||||
@ -168,7 +168,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
-- questlog
|
||||
if (fields["quests_header"]) then
|
||||
if (formname == "quests:questlog") then
|
||||
minetest.show_formspec(playername, "quests:questlog", quests.create_formspec(playername, fields["quests_header"]))
|
||||
core.show_formspec(playername, "quests:questlog", quests.create_formspec(playername, fields["quests_header"]))
|
||||
else
|
||||
if (fields["quests_header"] == "1") then
|
||||
unified_inventory.set_inventory_formspec(player, "quests")
|
||||
@ -183,7 +183,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
return
|
||||
end
|
||||
if (fields["quests_questlist"]) then
|
||||
local event = minetest.explode_textlist_event(fields["quests_questlist"])
|
||||
local event = core.explode_textlist_event(fields["quests_questlist"])
|
||||
if (event.type == "CHG") then
|
||||
quests.formspec_lists[playername].id = event.index
|
||||
end
|
||||
@ -194,21 +194,21 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
end
|
||||
quests.abort_quest(playername, quests.formspec_lists[playername]["list"][quests.formspec_lists[playername].id])
|
||||
if (formname == "quests:questlog") then
|
||||
minetest.show_formspec(playername, "quests:questlog", quests.create_formspec(playername))
|
||||
core.show_formspec(playername, "quests:questlog", quests.create_formspec(playername))
|
||||
else
|
||||
unified_inventory.set_inventory_formspec(player, "quests")
|
||||
end
|
||||
end
|
||||
if (fields["quests_config"]) then
|
||||
if (formname == "quests:questlog") then
|
||||
minetest.show_formspec(playername, "quests:config", quests.create_config(playername))
|
||||
core.show_formspec(playername, "quests:config", quests.create_config(playername))
|
||||
else
|
||||
unified_inventory.set_inventory_formspec(player, "quests_config")
|
||||
end
|
||||
end
|
||||
if (fields["quests_info"]) then
|
||||
if (formname == "quests:questlog") then
|
||||
minetest.show_formspec(playername, "quests:info", quests.create_info(playername, quests.formspec_lists[playername].list[quests.formspec_lists[playername].id]))
|
||||
core.show_formspec(playername, "quests:info", quests.create_info(playername, quests.formspec_lists[playername].list[quests.formspec_lists[playername].id]))
|
||||
else
|
||||
unified_inventory.set_inventory_formspec(player, "quests_info")
|
||||
end
|
||||
@ -223,7 +223,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
quests.hide_hud(playername)
|
||||
end
|
||||
if (formname == "quests:config") then
|
||||
minetest.show_formspec(playername, "quests:config", quests.create_config(playername))
|
||||
core.show_formspec(playername, "quests:config", quests.create_config(playername))
|
||||
else
|
||||
unified_inventory.set_inventory_formspec(player, "quests_config")
|
||||
end
|
||||
@ -236,7 +236,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
quests.hud[playername].autohide = false
|
||||
end
|
||||
if (formname == "quests:config") then
|
||||
minetest.show_formspec(playername, "quests:config", quests.create_config(playername))
|
||||
core.show_formspec(playername, "quests:config", quests.create_config(playername))
|
||||
else
|
||||
unified_inventory.set_inventory_formspec(player, "quests_config")
|
||||
end
|
||||
@ -248,7 +248,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
quests.hud[playername].central_message_enabled = false
|
||||
end
|
||||
if (formname == "quests:config") then
|
||||
minetest.show_formspec(playername, "quests:config", quests.create_config(playername))
|
||||
core.show_formspec(playername, "quests:config", quests.create_config(playername))
|
||||
else
|
||||
unified_inventory.set_inventory_formspec(player, "quests_config")
|
||||
end
|
||||
@ -256,7 +256,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
|
||||
if (fields["quests_config_return"]) then
|
||||
if (formname == "quests:config") then
|
||||
minetest.show_formspec(playername, "quests:questlog", quests.create_formspec(playername))
|
||||
core.show_formspec(playername, "quests:questlog", quests.create_formspec(playername))
|
||||
else
|
||||
unified_inventory.set_inventory_formspec(player, "quests")
|
||||
end
|
||||
@ -269,14 +269,14 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
end
|
||||
quests.abort_quest(playername, quests.formspec_lists[playername]["list"][quests.formspec_lists[playername].id])
|
||||
if (formname == "quests:info") then
|
||||
minetest.show_formspec(playername, "quests:questlog", quests.create_formspec(playername))
|
||||
core.show_formspec(playername, "quests:questlog", quests.create_formspec(playername))
|
||||
else
|
||||
unified_inventory.set_inventory_formspec(player, "quests")
|
||||
end
|
||||
end
|
||||
if (fields["quests_info_return"]) then
|
||||
if (formname == "quests:info") then
|
||||
minetest.show_formspec(playername, "quests:questlog", quests.create_formspec(playername))
|
||||
core.show_formspec(playername, "quests:questlog", quests.create_formspec(playername))
|
||||
else
|
||||
unified_inventory.set_inventory_formspec(player, "quests")
|
||||
end
|
||||
|
18
hud.lua
18
hud.lua
@ -1,6 +1,6 @@
|
||||
-- Boilerplate to support localized strings if intllib mod is installed.
|
||||
local S
|
||||
if minetest.get_modpath("intllib") then
|
||||
if core.get_modpath("intllib") then
|
||||
S = intllib.Getter()
|
||||
else
|
||||
-- If you don't use insertions (@1, @2, etc) you can use this:
|
||||
@ -32,18 +32,18 @@ function quests.show_hud(playername, autohide)
|
||||
|
||||
|
||||
|
||||
local player = minetest.get_player_by_name(playername)
|
||||
local player = core.get_player_by_name(playername)
|
||||
if (player == nil) then
|
||||
return false
|
||||
end
|
||||
quests.hud[playername].list = {}
|
||||
table.insert(quests.hud[playername].list, { value=0, id=player:hud_add(hud) })
|
||||
minetest.after(0, quests.update_hud, playername)
|
||||
core.after(0, quests.update_hud, playername)
|
||||
end
|
||||
|
||||
-- call this method to hide the hud
|
||||
function quests.hide_hud(playername)
|
||||
local player = minetest.get_player_by_name(playername)
|
||||
local player = core.get_player_by_name(playername)
|
||||
if (player == nil or quests.hud[playername] == nil or quests.hud[playername].list == nil) then
|
||||
return
|
||||
end
|
||||
@ -80,7 +80,7 @@ function quests.update_hud(playername)
|
||||
end
|
||||
return
|
||||
end
|
||||
local player = minetest.get_player_by_name(playername)
|
||||
local player = core.get_player_by_name(playername)
|
||||
if (player == nil) then
|
||||
return
|
||||
end
|
||||
@ -181,7 +181,7 @@ function quests.update_hud(playername)
|
||||
if (quests.hud[playername].autohide) then
|
||||
if (next(quests.active_quests[playername]) == nil) then
|
||||
player:hud_change(quests.hud[playername].list[1].id, "text", S("No more Quests"))
|
||||
minetest.after(3, function(playername)
|
||||
core.after(3, function(playername)
|
||||
if (next(quests.active_quests[playername]) ~= nil) then
|
||||
player:hud_change(quests.hud[playername].list[1].id, "text", S("Quests:"))
|
||||
else
|
||||
@ -198,14 +198,14 @@ end
|
||||
--for playername,id in pairs(quests.hud) do
|
||||
-- if (id ~= nil) then
|
||||
-- quests.hud[playername] = nil
|
||||
-- minetest.after(10, function(playername)
|
||||
-- core.after(10, function(playername)
|
||||
-- quests.show_hud(playername)
|
||||
-- quests.update_hud(playername)
|
||||
-- end, playername)
|
||||
-- end
|
||||
--end
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
core.register_on_joinplayer(function(player)
|
||||
local playername = player:get_player_name()
|
||||
if (quests.hud[playername] ~= nil) then
|
||||
if (not(quests.hud[playername].first)) then
|
||||
@ -219,7 +219,7 @@ minetest.register_on_joinplayer(function(player)
|
||||
central_message_enabled = central_message_enabled
|
||||
}
|
||||
if (list ~= nil) then
|
||||
minetest.after(1, function(playername)
|
||||
core.after(1, function(playername)
|
||||
quests.show_hud(playername)
|
||||
end, playername)
|
||||
end
|
||||
|
24
init.lua
24
init.lua
@ -1,8 +1,8 @@
|
||||
-- reading previous quests
|
||||
local file = io.open(minetest.get_worldpath().."/quests", "r")
|
||||
local file = io.open(core.get_worldpath().."/quests", "r")
|
||||
if file then
|
||||
minetest.log("action", "Reading quests...")
|
||||
quests = minetest.deserialize(file:read("*all"))
|
||||
core.log("action", "Reading quests...")
|
||||
quests = core.deserialize(file:read("*all"))
|
||||
file:close()
|
||||
end
|
||||
quests = quests or {}
|
||||
@ -29,7 +29,7 @@ quests.colors = {
|
||||
}
|
||||
|
||||
|
||||
local MP = minetest.get_modpath("quests")
|
||||
local MP = core.get_modpath("quests")
|
||||
|
||||
dofile(MP .. "/central_message.lua")
|
||||
dofile(MP .. "/core.lua")
|
||||
@ -37,16 +37,16 @@ dofile(MP .. "/hud.lua")
|
||||
dofile(MP .. "/formspecs.lua")
|
||||
|
||||
-- support for unified_inventory
|
||||
if (minetest.get_modpath("unified_inventory") ~= nil) then
|
||||
dofile(minetest.get_modpath("quests") .. "/unified_inventory.lua")
|
||||
elseif (minetest.get_modpath("inventory_plus") ~= nil) then
|
||||
dofile(minetest.get_modpath("quests") .. "/inventory_plus.lua")
|
||||
if (core.get_modpath("unified_inventory") ~= nil) then
|
||||
dofile(core.get_modpath("quests") .. "/unified_inventory.lua")
|
||||
elseif (core.get_modpath("inventory_plus") ~= nil) then
|
||||
dofile(core.get_modpath("quests") .. "/inventory_plus.lua")
|
||||
end
|
||||
|
||||
|
||||
-- write the quests to file
|
||||
minetest.register_on_shutdown(function()
|
||||
minetest.log("action", "Writing quests to file")
|
||||
core.register_on_shutdown(function()
|
||||
core.log("action", "Writing quests to file")
|
||||
for playername, quest in pairs(quests.active_quests) do
|
||||
for questname, questspecs in pairs(quest) do
|
||||
if (questspecs.finished) then
|
||||
@ -54,9 +54,9 @@ minetest.register_on_shutdown(function()
|
||||
end
|
||||
end
|
||||
end
|
||||
local file = io.open(minetest.get_worldpath().."/quests", "w")
|
||||
local file = io.open(core.get_worldpath().."/quests", "w")
|
||||
if (file) then
|
||||
file:write(minetest.serialize({ --registered_quests = quests.registered_quests,
|
||||
file:write(core.serialize({ --registered_quests = quests.registered_quests,
|
||||
active_quests = quests.active_quests,
|
||||
successfull_quests = quests.successfull_quests,
|
||||
failed_quests = quests.failed_quests,
|
||||
|
@ -1,8 +1,8 @@
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
core.register_on_joinplayer(function(player)
|
||||
inventory_plus.register_button(player, "quests")
|
||||
end)
|
||||
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
core.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if (fields.quests) then
|
||||
quests.show_formspec(player:get_player_name())
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user