summaryrefslogtreecommitdiff
path: root/api.lua
diff options
context:
space:
mode:
authorrubenwardy <rubenwardy@gmail.com>2018-04-04 16:03:34 +0100
committerrubenwardy <rubenwardy@gmail.com>2018-04-04 16:03:34 +0100
commit8b024accdd7b76229de87eb8b58ee688eb028beb (patch)
treefe0fd2c4070f4ef40a6c96cf4bc8d2fae879bc65 /api.lua
parentdd2a5d2d1f1884f638c9be05c43b1e7966f14dbe (diff)
Add register_trigger_counted for homogenous events
Diffstat (limited to 'api.lua')
-rw-r--r--api.lua26
1 files changed, 26 insertions, 0 deletions
diff --git a/api.lua b/api.lua
index bae9b9e..6230814 100644
--- a/api.lua
+++ b/api.lua
@@ -54,6 +54,32 @@ function awards.register_trigger(name, tfunc)
end
end
+-- Registers a trigger which replies on counting
+function awards.register_trigger_counted(tname, tfunc)
+ awards.register_trigger(tname, tfunc)
+
+ local key = tname .. "s"
+
+ awards["notify_" .. tname] = function(player)
+ assert(player and player.is_player and player:is_player())
+ local name = player:get_player_name()
+
+ awards.assertPlayer(name)
+ local data = awards.players[name]
+
+ -- Increment counter
+ data[key] = data[key] + 1
+ local currentVal = data[key]
+
+ awards.run_trigger_callbacks(player, data, tname, function(entry)
+ if entry.target and entry.award and currentVal and
+ currentVal >= entry.target then
+ return entry.award
+ end
+ end)
+ end
+end
+
function awards.run_trigger_callbacks(player, data, trigger, table_func)
for i = 1, #awards.on[trigger] do
local res = nil