summaryrefslogtreecommitdiff
path: root/api.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 /api.lua
parent8bd3658d9ee363c55225c63f867a8ebf70c44b6e (diff)
External triggers, on join trigger, intlib
Diffstat (limited to 'api.lua')
-rw-r--r--api.lua40
1 files changed, 40 insertions, 0 deletions
diff --git a/api.lua b/api.lua
index 71ddd2f..650c127 100644
--- a/api.lua
+++ b/api.lua
@@ -64,6 +64,7 @@ function awards.assertPlayer(playern)
awards.tbv(awards.players[playern], "place")
awards.tbv(awards.players[playern], "count")
awards.tbv(awards.players[playern], "deaths", 0)
+ awards.tbv(awards.players[playern], "joins", 0)
awards.tbv(awards.players[playern], "chats", 0)
end
@@ -72,6 +73,32 @@ dofile(minetest.get_modpath("awards").."/triggers.lua")
dofile(minetest.get_modpath("awards").."/config.txt")
-- API Functions
+function awards._additional_triggers(name, data_table)
+ -- To add triggers in another mod, you should override this function
+ -- If the code can't handle the trigger passed, then call the last value of _additional_triggers
+ --[[
+ local add_trig = awards._additional_triggers
+ awards._additional_triggers = function(name, data_table)
+ if data_table.trigger.type == "trigger" then
+ local tmp = {
+ award = name,
+ node = data_table.trigger.node,
+ target = data_table.trigger.target,
+ }
+ table.insert(awards.onTrigger,tmp)
+ elseif data_table.trigger.type == "trigger2" then
+ local tmp = {
+ award = name,
+ node = data_table.trigger.node,
+ target = data_table.trigger.target,
+ }
+ table.insert(awards.onTrigger2,tmp)
+ else
+ add_trig(name, data_table)
+ end
+ end
+ ]]--
+end
function awards.register_achievement(name,data_table)
-- see if a trigger is defined in the achievement definition
if data_table.trigger and data_table.trigger.type then
@@ -101,6 +128,14 @@ function awards.register_achievement(name,data_table)
target = data_table.trigger.target,
}
table.insert(awards.onChat,tmp)
+ elseif data_table.trigger.type == "join" then
+ local tmp = {
+ award = name,
+ target = data_table.trigger.target,
+ }
+ table.insert(awards.onJoin,tmp)
+ else
+ awards._additional_triggers(name, data_table)
end
end
@@ -140,6 +175,11 @@ function awards.register_onChat(func)
table.insert(awards.onChat,func)
end
+-- run a function when a player joins
+function awards.register_onJoin(func)
+ table.insert(awards.onJoin,func)
+end
+
-- This function is called whenever a target condition is met.
-- It checks if a player already has that achievement, and if they do not,
-- it gives it to them