Add central messages and sounds for quest actions
This commit is contained in:
parent
e63d4e6d15
commit
c6fbf683f2
8
README
8
README
|
@ -1,8 +1,12 @@
|
|||
quests 0.7
|
||||
quests 0.8
|
||||
|
||||
quests is a simple quest framework for minetest that lets you define your own quests and handels the representation.
|
||||
|
||||
Dependencies: none
|
||||
Dependencies:
|
||||
intllib (optional)
|
||||
unified_inventory or inventory_plus (optional)
|
||||
central_message (optional)
|
||||
|
||||
License: WTFPL
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
|
12
central_message.lua
Normal file
12
central_message.lua
Normal file
|
@ -0,0 +1,12 @@
|
|||
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)
|
||||
cmsg.push_message_player(player, text, quests.colors[t])
|
||||
minetest.sound_play("quests_" .. t, {to_player = playername})
|
||||
end
|
||||
end
|
||||
else
|
||||
function quests.show_message(...)
|
||||
end
|
||||
end
|
7
core.lua
7
core.lua
|
@ -56,6 +56,7 @@ function quests.start_quest(playername, questname)
|
|||
quests.active_quests[playername][questname] = {value = 0}
|
||||
|
||||
quests.update_hud(playername)
|
||||
quests.show_message("new", playername, S("New quest: ") .. quests.registered_quests[questname].title)
|
||||
return true
|
||||
end
|
||||
|
||||
|
@ -113,9 +114,10 @@ function quests.accept_quest(playername, questname)
|
|||
for _,quest in ipairs(quests.hud[playername].list) do
|
||||
if (quest.name == questname) then
|
||||
local player = minetest.get_player_by_name(playername)
|
||||
player:hud_change(quest.id, "number", 0x00AD00)
|
||||
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)
|
||||
quests.active_quests[playername][questname] = nil
|
||||
quests.update_hud(playername)
|
||||
|
@ -150,9 +152,10 @@ function quests.abort_quest(playername, questname)
|
|||
for _,quest in ipairs(quests.hud[playername].list) do
|
||||
if (quest.name == questname) then
|
||||
local player = minetest.get_player_by_name(playername)
|
||||
player:hud_change(quest.id, "number", 0xAD0000)
|
||||
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)
|
||||
quests.active_quests[playername][questname] = nil
|
||||
quests.update_hud(playername)
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
intllib?
|
||||
unified_inventory?
|
||||
inventory_plus?
|
||||
central_message?
|
||||
|
|
|
@ -63,21 +63,27 @@ function quests.create_config(playername, integrated)
|
|||
local formspec = ""
|
||||
if (not integrated) then
|
||||
formspec = formspec .. "size[7,3]"
|
||||
end
|
||||
formspec = formspec .. "checkbox[.25,.25;quests_config_enable;" .. S("Enable HUD") .. ";"
|
||||
if(quests.hud[playername] ~= nil and quests.hud[playername].list ~= nil) then
|
||||
end
|
||||
formspec = formspec .. "checkbox[.25,.25;quests_config_enable;" .. S("Enable HUD") .. ";"
|
||||
if(quests.hud[playername] ~= nil and quests.hud[playername].list ~= nil) then
|
||||
formspec = formspec .. "true"
|
||||
else
|
||||
formspec = formspec .. "false"
|
||||
end
|
||||
formspec = formspec .. "]checkbox[.25,.75;quests_config_autohide;" .. S("Autohide HUD") .. ";"
|
||||
if(quests.hud[playername] ~= nil and quests.hud[playername].autohide) then
|
||||
formspec = formspec .. "true"
|
||||
else
|
||||
formspec = formspec .. "false"
|
||||
end
|
||||
formspec = formspec .. "]checkbox[.25,.75;quests_config_autohide;" .. S("Autohide HUD") .. ";"
|
||||
if(quests.hud[playername] ~= nil and quests.hud[playername].autohide) then
|
||||
formspec = formspec .. "]checkbox[.25,1.25;quests_config_central_message;" .. S("Central messages") .. ";"
|
||||
if(quests.hud[playername] ~= nil and quests.hud[playername].central_message_enabled) then
|
||||
formspec = formspec .. "true"
|
||||
else
|
||||
formspec = formspec .. "false"
|
||||
end
|
||||
formspec = formspec .. "]"..
|
||||
"button[.25,1.75;3,.7;quests_config_return;" .. S("Return") .. "]"
|
||||
end
|
||||
formspec = formspec .. "]" ..
|
||||
"button[.25,2.25;3,.7;quests_config_return;" .. S("Return") .. "]"
|
||||
return formspec
|
||||
end
|
||||
|
||||
|
@ -204,6 +210,19 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
unified_inventory.set_inventory_formspec(player, "quests_config")
|
||||
end
|
||||
end
|
||||
if (fields["quests_config_central_message"]) then
|
||||
if (fields["quests_config_central_message"] == "true") then
|
||||
quests.hud[playername].central_message_enabled = true
|
||||
else
|
||||
quests.hud[playername].central_message_enabled = false
|
||||
end
|
||||
if (formname == "quests:config") then
|
||||
minetest.show_formspec(playername, "quests:config", quests.create_config(playername))
|
||||
else
|
||||
unified_inventory.set_inventory_formspec(player, "quests_config")
|
||||
end
|
||||
end
|
||||
|
||||
if (fields["quests_config_return"]) then
|
||||
if (formname == "quests:config") then
|
||||
minetest.show_formspec(playername, "quests:questlog", quests.create_formspec(playername))
|
||||
|
|
20
hud.lua
20
hud.lua
|
@ -11,7 +11,7 @@ local show_max = 10 -- the maximum visible quests.
|
|||
|
||||
local hud_config = { position = {x = 1, y = 0.2},
|
||||
offset = { x = -200, y = 0},
|
||||
number = 0xAAAA00 }
|
||||
number = quests.colors.new }
|
||||
|
||||
-- call this function to enable the HUD for the player that shows his quests
|
||||
-- the HUD can only show up to show_max quests
|
||||
|
@ -106,7 +106,7 @@ function quests.update_hud(playername)
|
|||
player:hud_change(hud_element.id_background, "offset", { x= hud_config.offset.x, y=hud_config.offset.y + (i-1) *40 + 22})
|
||||
end
|
||||
if (hud_element.id_bar ~= nil) then
|
||||
player:hud_change(hud_element.id_bar, "offset", { x= hud_config.offset.x, y=hud_config.offset.y + (i-1) *40 + 24})
|
||||
player:hud_change(hud_element.id_bar, "offset", { x= hud_config.offset.x + 2, y=hud_config.offset.y + (i-1) *40 + 24})
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -150,12 +150,14 @@ function quests.update_hud(playername)
|
|||
if (quests.registered_quests[questname].max ~= 1) then
|
||||
id_background = player:hud_add({ hud_elem_type = "image",
|
||||
scale = { x = 1, y = 1 },
|
||||
size = { x = 2, y = 4 },
|
||||
alignment = { x = 1, y = 1 },
|
||||
position = { x = hud_config.position.x, y = hud_config.position.y },
|
||||
offset = { x = hud_config.offset.x, y = hud_config.offset.y + counter * 40 + 22 },
|
||||
text = "quests_questbar_background.png" })
|
||||
id_bar = player:hud_add({hud_elem_type = "statbar",
|
||||
scale = { x = 1, y = 1 },
|
||||
-- size = { x = 2, y = 4 },
|
||||
alignment = { x = 1, y = 1 },
|
||||
position = { x = hud_config.position.x, y = hud_config.position.y },
|
||||
offset = { x = hud_config.offset.x + 2, y = hud_config.offset.y + counter * 40 + 24 },
|
||||
|
@ -209,16 +211,22 @@ minetest.register_on_joinplayer(function(player)
|
|||
return
|
||||
end
|
||||
local list = quests.hud[playername].list
|
||||
print(dump(list))
|
||||
local autohide = quests.hud[playername].autohide
|
||||
quests.hud[playername] = { autohide = autohide }
|
||||
local central_message_enabled = quests.hud[playername].central_message_enabled
|
||||
quests.hud[playername] = {
|
||||
autohide = autohide,
|
||||
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
|
||||
quests.hud[playername] = {autohide = true}
|
||||
else -- new player
|
||||
quests.hud[playername] = {
|
||||
autohide = true,
|
||||
central_message_enabled = true
|
||||
}
|
||||
quests.active_quests[playername] = {}
|
||||
end
|
||||
end)
|
||||
|
|
15
init.lua
15
init.lua
|
@ -22,10 +22,19 @@ function quests.round(num, n)
|
|||
return math.floor(num * mult + .5) / mult
|
||||
end
|
||||
|
||||
quests.colors = {
|
||||
new = "0xAAAA00",
|
||||
success = "0x00AD00",
|
||||
failed = "0xAD0000"
|
||||
}
|
||||
|
||||
dofile(minetest.get_modpath("quests") .. "/core.lua")
|
||||
dofile(minetest.get_modpath("quests") .. "/hud.lua")
|
||||
dofile(minetest.get_modpath("quests") .. "/formspecs.lua")
|
||||
|
||||
local MP = minetest.get_modpath("quests")
|
||||
|
||||
dofile(MP .. "/central_message.lua")
|
||||
dofile(MP .. "/core.lua")
|
||||
dofile(MP .. "/hud.lua")
|
||||
dofile(MP .. "/formspecs.lua")
|
||||
|
||||
-- support for unified_inventory
|
||||
if (minetest.get_modpath("unified_inventory") ~= nil) then
|
||||
|
|
BIN
sounds/quests_failed.ogg
Normal file
BIN
sounds/quests_failed.ogg
Normal file
Binary file not shown.
BIN
sounds/quests_new.ogg
Normal file
BIN
sounds/quests_new.ogg
Normal file
Binary file not shown.
BIN
sounds/quests_success.ogg
Normal file
BIN
sounds/quests_success.ogg
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user