From ce58720493a70b3eff28b6a9f1afe1ebaee56a46 Mon Sep 17 00:00:00 2001 From: Beha Date: Sun, 5 Apr 2020 16:00:33 +0000 Subject: [PATCH] Fix group total, fix item increment count argument, add player checks, resize award icon, fix log output --- src/api_awards.lua | 9 +++++++-- src/api_triggers.lua | 6 +++--- src/triggers.lua | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/api_awards.lua b/src/api_awards.lua index 5385d1b..c3cae5a 100644 --- a/src/api_awards.lua +++ b/src/api_awards.lua @@ -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 diff --git a/src/api_triggers.lua b/src/api_triggers.lua index d763a05..11a1391 100644 --- a/src/api_triggers.lua +++ b/src/api_triggers.lua @@ -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) diff --git a/src/triggers.lua b/src/triggers.lua index 2daf6d3..fc260b5 100644 --- a/src/triggers.lua +++ b/src/triggers.lua @@ -141,5 +141,5 @@ minetest.register_on_item_eat(function(_, _, itemstack, player, _) local itemname = itemstack:get_name() itemname = minetest.registered_aliases[itemname] or itemname - awards.notify_eat(player, itemname, itemstack:get_count()) + awards.notify_eat(player, itemname) end)