mirror of
https://github.com/TeTpaAka/quests.git
synced 2024-12-23 01:00:40 +01:00
Add metadata to quests
This commit is contained in:
parent
2c4468f3ac
commit
f69ca0062d
10
README
10
README
@ -1,4 +1,4 @@
|
|||||||
quests 0.8
|
quests 0.9
|
||||||
|
|
||||||
quests is a simple quest framework for minetest that lets you define your own quests and handels the representation.
|
quests is a simple quest framework for minetest that lets you define your own quests and handels the representation.
|
||||||
|
|
||||||
@ -28,6 +28,7 @@ quests.register_quest(questname,quest)
|
|||||||
-- max, -- is the desired maximum. If max is 1, no maximum is displayed. defaults to 1
|
-- max, -- is the desired maximum. If max is 1, no maximum is displayed. defaults to 1
|
||||||
-- autoaccept, -- is true or false, wether the result of the quest should be dealt by this mode or the registering mod.
|
-- autoaccept, -- is true or false, wether the result of the quest should be dealt by this mode or the registering mod.
|
||||||
-- callback -- when autoaccept is true, at the end of the quest, it gets removed and callback is called.
|
-- callback -- when autoaccept is true, at the end of the quest, it gets removed and callback is called.
|
||||||
|
-- -- function(playername, questname, metadata)
|
||||||
-- }
|
-- }
|
||||||
--
|
--
|
||||||
-- returns true, when the quest was successfully registered
|
-- returns true, when the quest was successfully registered
|
||||||
@ -38,6 +39,7 @@ quests.start_quest(playername, questname)
|
|||||||
--
|
--
|
||||||
-- playername - the name of the player
|
-- playername - the name of the player
|
||||||
-- questname - the name of the quest, which was registered with quests.register_quest
|
-- questname - the name of the quest, which was registered with quests.register_quest
|
||||||
|
-- metadata - optional additional data
|
||||||
--
|
--
|
||||||
-- returns false on failure
|
-- returns false on failure
|
||||||
-- returns true if the quest was started
|
-- returns true if the quest was started
|
||||||
@ -72,3 +74,9 @@ quests.hide_hud(playername)
|
|||||||
|
|
||||||
quests.show_formspec(playername)
|
quests.show_formspec(playername)
|
||||||
-- shows the player playername his/her questlog
|
-- shows the player playername his/her questlog
|
||||||
|
|
||||||
|
quests.get_metadata(playername, questname)
|
||||||
|
-- get metadata of the quest if the quest exists, else return nil
|
||||||
|
|
||||||
|
quests.set_metadata(playername, questname, metadata)
|
||||||
|
-- set metadata of the quest
|
||||||
|
25
core.lua
25
core.lua
@ -19,6 +19,7 @@ end
|
|||||||
-- max, -- is the desired maximum. If max is 1, no maximum is displayed. defaults to 1
|
-- max, -- is the desired maximum. If max is 1, no maximum is displayed. defaults to 1
|
||||||
-- autoaccept, -- is true or false, wether the result of the quest should be dealt by this mode or the registering mod.
|
-- autoaccept, -- is true or false, wether the result of the quest should be dealt by this mode or the registering mod.
|
||||||
-- callback -- when autoaccept is true, at the end of the quest, it gets removed and callback is called.
|
-- callback -- when autoaccept is true, at the end of the quest, it gets removed and callback is called.
|
||||||
|
-- -- function(playername, questname, metadata)
|
||||||
-- }
|
-- }
|
||||||
--
|
--
|
||||||
-- returns true, when the quest was successfully registered
|
-- returns true, when the quest was successfully registered
|
||||||
@ -40,10 +41,11 @@ end
|
|||||||
--
|
--
|
||||||
-- playername - the name of the player
|
-- playername - the name of the player
|
||||||
-- questname - the name of the quest, which was registered with quests.register_quest
|
-- questname - the name of the quest, which was registered with quests.register_quest
|
||||||
|
-- metadata - optional additional data
|
||||||
--
|
--
|
||||||
-- returns false on failure
|
-- returns false on failure
|
||||||
-- returns true if the quest was started
|
-- returns true if the quest was started
|
||||||
function quests.start_quest(playername, questname)
|
function quests.start_quest(playername, questname, metadata)
|
||||||
if (quests.registered_quests[questname] == nil) then
|
if (quests.registered_quests[questname] == nil) then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@ -53,7 +55,7 @@ function quests.start_quest(playername, questname)
|
|||||||
if (quests.active_quests[playername][questname] ~= nil) then
|
if (quests.active_quests[playername][questname] ~= nil) then
|
||||||
return false -- the player has already this quest
|
return false -- the player has already this quest
|
||||||
end
|
end
|
||||||
quests.active_quests[playername][questname] = {value = 0}
|
quests.active_quests[playername][questname] = {value = 0, metadata = metadata}
|
||||||
|
|
||||||
quests.update_hud(playername)
|
quests.update_hud(playername)
|
||||||
quests.show_message("new", playername, S("New quest: ") .. quests.registered_quests[questname].title)
|
quests.show_message("new", playername, S("New quest: ") .. quests.registered_quests[questname].title)
|
||||||
@ -65,6 +67,7 @@ end
|
|||||||
-- questname is the quest which gets updated
|
-- questname is the quest which gets updated
|
||||||
-- the quest gets updated by value
|
-- the quest gets updated by value
|
||||||
-- this method calls a previously specified callback if autoaccept is true
|
-- this method calls a previously specified callback if autoaccept is true
|
||||||
|
--
|
||||||
-- returns true if the quest is finished
|
-- returns true if the quest is finished
|
||||||
-- returns false if there is no such quest or the quest continues
|
-- returns false if there is no such quest or the quest continues
|
||||||
function quests.update_quest(playername, questname, value)
|
function quests.update_quest(playername, questname, value)
|
||||||
@ -85,7 +88,8 @@ function quests.update_quest(playername, questname, value)
|
|||||||
quests.active_quests[playername][questname]["value"] = quests.registered_quests[questname]["max"]
|
quests.active_quests[playername][questname]["value"] = quests.registered_quests[questname]["max"]
|
||||||
if (quests.registered_quests[questname]["autoaccept"]) then
|
if (quests.registered_quests[questname]["autoaccept"]) then
|
||||||
if (quests.registered_quests[questname]["callback"] ~= nil) then
|
if (quests.registered_quests[questname]["callback"] ~= nil) then
|
||||||
quests.registered_quests[questname]["callback"](playername, questname)
|
quests.registered_quests[questname]["callback"](playername, questname,
|
||||||
|
quests.active_quests[playername][questname].metadata)
|
||||||
end
|
end
|
||||||
quests.accept_quest(playername,questname)
|
quests.accept_quest(playername,questname)
|
||||||
quests.update_hud(playername)
|
quests.update_hud(playername)
|
||||||
@ -162,4 +166,19 @@ function quests.abort_quest(playername, questname)
|
|||||||
end, playername, questname)
|
end, playername, questname)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- get metadata of the quest if the quest exists, else return nil
|
||||||
|
function quests.get_metadata(playername, questname)
|
||||||
|
if (quests.active_quests[playername] == nil or quests.active_quests[playername][questname] == nil) then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
return quests.active_quests[playername][questname].metadata
|
||||||
|
end
|
||||||
|
|
||||||
|
-- set metadata of the quest
|
||||||
|
function quests.set_metadata(playername, questname, metadata)
|
||||||
|
if (quests.active_quests[playername] == nil or quests.active_quests[playername][questname] == nil) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
quests.active_quests[playername][questname].metadata = metadata
|
||||||
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user