Merge remote-tracking branch 'upstream/master' into nalc-1.2-dev

This commit is contained in:
Sys Quatre 2020-06-16 20:49:49 +02:00
commit 8702b6cdd8
6 changed files with 35 additions and 20 deletions

View File

@ -16,7 +16,11 @@ dofile(minetest.get_modpath("awards").."/src/api_triggers.lua")
dofile(minetest.get_modpath("awards").."/src/chat_commands.lua")
dofile(minetest.get_modpath("awards").."/src/gui.lua")
dofile(minetest.get_modpath("awards").."/src/triggers.lua")
-- Optionally add default awards.
if minetest.settings:get_bool("awards.add_defaults", true) then
dofile(minetest.get_modpath("awards").."/src/awards.lua")
end
awards.load()
minetest.register_on_shutdown(awards.save)

2
settingtypes.txt Normal file
View File

@ -0,0 +1,2 @@
# Add default achievements from the awards mod
awards.add_defaults (Add Default Achievements) bool true

View File

@ -43,6 +43,11 @@ end
-- name - the name of the player
-- award - the name of the award to give
function awards.unlock(name, award)
-- Ensure the player is online.
if not minetest.get_player_by_name(name) then
return
end
-- Access Player Data
local data = awards.player(name)
local awdef = awards.registered_awards[award]
@ -60,7 +65,7 @@ function awards.unlock(name, award)
end
-- Unlock Award
minetest.log("action", name.." has unlocked award "..name)
minetest.log("action", name.." has unlocked award "..award)
data.unlocked[award] = award
awards.save()
@ -91,7 +96,7 @@ function awards.unlock(name, award)
local title = awdef.title or award
local desc = awdef.description or ""
local background = awdef.background or "awards_bg_default.png"
local icon = awdef.icon or "awards_unknown.png"
local icon = (awdef.icon or "awards_unknown.png") .. "^[resize:32x32"
local sound = awdef.sound
if sound == nil then
-- Explicit check for nil because sound could be `false` to disable it

View File

@ -144,8 +144,8 @@ function awards.register_trigger(tname, tdef)
if tdef.key_is_item and key:sub(1, 6) ~= "group:" then
local itemdef = minetest.registered_items[key]
if itemdef then
for groupname, _ in pairs(itemdef.groups or {}) do
if tdef.watched_groups[groupname] then
for groupname,rating in pairs(itemdef.groups or {}) do
if rating ~= 0 and tdef.watched_groups[groupname] then
tdef.notify(player, "group:" .. groupname, n)
end
end
@ -160,8 +160,9 @@ function awards.register_trigger(tname, tdef)
data[tname] = data[tname] or {}
local currentVal = (data[tname][key] or 0) + n
data[tname][key] = currentVal
data[tname].__total = (data[tname].__total or 0)
if key:sub(1, 6) ~= "group:" then
data[tname].__total = (data[tname].__total or 0) + n
data[tname].__total = data[tname].__total + n
end
tdef:run_callbacks(player, data, function(entry)
@ -173,7 +174,6 @@ function awards.register_trigger(tname, tdef)
else
return
end
if current >= entry.target then
return entry.award
end
@ -201,7 +201,7 @@ end
function awards.increment_item_counter(data, field, itemname, count)
itemname = minetest.registered_aliases[itemname] or itemname
data[field][itemname] = (data[field][itemname] or 0) + 1
data[field][itemname] = (data[field][itemname] or 0) + (count or 1)
end
function awards.get_item_count(data, field, itemname)

View File

@ -89,7 +89,7 @@ if minetest.get_modpath("fire") then
secret = true,
})
awards.register_on_death(function(player,data)
local pos = player:getpos()
local pos = player:get_pos()
if pos and minetest.find_node_near(pos, 2, "fire:basic_flame") ~= nil then
return "award_burn"
end
@ -115,7 +115,7 @@ awards.register_award("award_deep_down", {
secret = true,
})
awards.register_on_death(function(player,data)
local pos = player:getpos()
local pos = player:get_pos()
if pos and pos.y < -10000 then
return "award_deep_down"
end
@ -129,7 +129,7 @@ awards.register_award("award_no_screen", {
secret = true,
})
awards.register_on_death(function(player,data)
local pos = player:getpos()
local pos = player:get_pos()
if pos and pos.y > 10000 then
return "award_no_screen"
end
@ -767,7 +767,7 @@ if minetest.get_modpath("default") then
secret = true,
})
awards.register_on_death(function(player,data)
local pos = player:getpos()
local pos = player:get_pos()
if pos and (minetest.find_node_near(pos, 2, "default:lava_flowing") ~= nil or
minetest.find_node_near(pos, 2, "default:lava_source") ~= nil) then
return "award_in_the_flow"
@ -782,7 +782,7 @@ if minetest.get_modpath("default") then
secret = true,
})
awards.register_on_death(function(player,data)
local pos = player:getpos()
local pos = player:get_pos()
if pos and minetest.find_node_near(pos, 5, "default:stone_with_diamond") ~= nil then
return "award_this_is_sad"
end
@ -798,7 +798,7 @@ if minetest.get_modpath("bones") then
secret = true,
})
awards.register_on_death(function(player,data)
local pos = player:getpos()
local pos = player:get_pos()
if pos and minetest.find_node_near(pos, 5, "bones:bones") ~= nil then
return "award_the_stack"
end

View File

@ -14,6 +14,10 @@
-- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
--
-- Check if a player object is valid for awards.
local function player_ok(player)
return player and player.is_player and player:is_player() and not player.is_fake_player
end
awards.register_trigger("chat", {
type = "counted",
@ -22,7 +26,7 @@ awards.register_trigger("chat", {
})
minetest.register_on_chat_message(function(name, message)
local player = minetest.get_player_by_name(name)
if not player or string.find(message, "/") then
if not player_ok(player) or string.find(message, "/") then
return
end
@ -68,7 +72,7 @@ awards.register_trigger("dig", {
key_is_item = true,
})
minetest.register_on_dignode(function(pos, node, player)
if not player or not pos or not node then
if not player_ok(player) or not pos or not node then
return
end
@ -89,7 +93,7 @@ awards.register_trigger("place", {
key_is_item = true,
})
minetest.register_on_placenode(function(pos, node, player)
if not player or not pos or not node then
if not player_ok(player) or not pos or not node then
return
end
@ -110,7 +114,7 @@ awards.register_trigger("craft", {
key_is_item = true,
})
--minetest.register_on_craft(function(itemstack, player, old_craft_grid, craft_inv)
-- if not player or itemstack:is_empty() then
-- if not player_ok(player) or itemstack:is_empty() then
-- return
-- end
--
@ -131,11 +135,11 @@ awards.register_trigger("eat", {
key_is_item = true,
})
minetest.register_on_item_eat(function(_, _, itemstack, player, _)
if not player or itemstack:is_empty() then
if not player_ok(player) or itemstack:is_empty() then
return
end
local itemname = itemstack:get_name()
itemname = minetest.registered_aliases[itemname] or itemname
awards.notify_craft(player, itemname, itemstack:get_count())
awards.notify_eat(player, itemname)
end)