summaryrefslogtreecommitdiff
path: root/triggers.lua
diff options
context:
space:
mode:
authorrubenwardy <anjayward@gmail.com>2014-05-02 19:52:25 +0100
committerrubenwardy <anjayward@gmail.com>2014-05-02 19:52:25 +0100
commit442346623a124be9d403d2c83c72dfef21c88b0d (patch)
tree93dd2abb793d94682d4ec6ab35ea91381d6af3a3 /triggers.lua
parent8bd3658d9ee363c55225c63f867a8ebf70c44b6e (diff)
External triggers, on join trigger, intlib
Diffstat (limited to 'triggers.lua')
-rw-r--r--triggers.lua34
1 files changed, 33 insertions, 1 deletions
diff --git a/triggers.lua b/triggers.lua
index b6005be..8bb909e 100644
--- a/triggers.lua
+++ b/triggers.lua
@@ -7,9 +7,9 @@
-- Function and table holders for Triggers
awards.onDig = {}
awards.onPlace = {}
-awards.onTick = {}
awards.onChat = {}
awards.onDeath = {}
+awards.onJoin = {}
-- Trigger Handles
minetest.register_on_dignode(function(pos, oldnode, digger)
@@ -154,6 +154,38 @@ minetest.register_on_dieplayer(function(player)
end
end)
+minetest.register_on_joinplayer(function(player)
+ -- Run checks
+ local name = player:get_player_name()
+ if not player or not name or name=="" then
+ return
+ end
+
+ -- Get player
+ awards.assertPlayer(name)
+ local data = awards.players[name]
+
+ -- Increment counter
+ data.joins = data.joins + 1
+
+ -- Run callbacks and triggers
+ for _,trigger in pairs(awards.onJoin) do
+ local res = nil
+ if type(trigger) == "function" then
+ res = trigger(player,data)
+ elseif type(trigger) == "table" then
+ if trigger.target and trigger.award then
+ if data.joins and data.joins >= trigger.target then
+ res = trigger.award
+ end
+ end
+ end
+ if res ~= nil then
+ awards.give_achievement(name,res)
+ end
+ end
+end)
+
minetest.register_on_chat_message(function(name, message)
-- Run checks
local idx = string.find(message,"/")