summaryrefslogtreecommitdiff
path: root/triggers.lua
diff options
context:
space:
mode:
authorRubenwardy <anjayward@gmail.com>2013-02-23 15:13:21 +0000
committerRubenwardy <anjayward@gmail.com>2013-02-23 15:13:21 +0000
commit4cf05cbc47b5ddab616170097673947d69e93a29 (patch)
tree345fc723d8a7797e2021b577578e9996b4065805 /triggers.lua
parent6b031a601d7ba394b61bcbce73c569a74625a913 (diff)
add onDeath
Diffstat (limited to 'triggers.lua')
-rw-r--r--triggers.lua39
1 files changed, 37 insertions, 2 deletions
diff --git a/triggers.lua b/triggers.lua
index 8b51b01..0f985fe 100644
--- a/triggers.lua
+++ b/triggers.lua
@@ -149,12 +149,47 @@ minetest.register_on_placenode(function(pos, newnode, placer)
end
end)
-minetest.register_on_newplayer(function(player)
- minetest.chat_send_player(player:get_player_name(),"[Awards] Registering you now...")
+minetest.register_on_dieplayer(function(player)
+ player_data[player:get_player_name()]['deaths']=player_data[player:get_player_name()]['deaths']+1
+
+ -- Set up the variables
+ local playern=player:get_player_name()
+ local data=player_data[playern]
+
+ -- Roll through the onDeath functions
+ for i=1,# awards.onDeath do
+ local res=nil
+ if type(awards.onDeath[i]) == "function" then
+ -- run the function
+ print(i.." is a function")
+ res=awards.onDeath[i](player,data)
+ elseif type(awards.onDeath[i]) == "table" then
+ -- handle table here
+ print(i.." is a table")
+ if not awards.onDeath[i]['target'] or not awards.onDeath[i]['award'] then
+ -- table running failed!
+ else
+ -- run the table
+
+ if not data['deaths'] then
+ -- table running failed!
+ elseif data['deaths'] > awards.onDeath[i]['target']-1 then
+ res=awards.onDeath[i]['award']
+ end
+ end
+ end
+
+ if res~=nil then
+ awards.give_achievement(playern,res)
+ end
+ end
+end)
+minetest.register_on_newplayer(function(player)
--Player data root
player_data[player:get_player_name()]={}
player_data[player:get_player_name()]['name']=player:get_player_name()
+ player_data[player:get_player_name()]['deaths']=0
--The player counter
player_data[player:get_player_name()]['count']={}