summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRubenwardy <anjayward@gmail.com>2013-02-22 18:38:09 +0000
committerRubenwardy <anjayward@gmail.com>2013-02-22 18:38:09 +0000
commit369b4d147575a1525ba81dd691394dad08ea34d6 (patch)
tree0e82f129c5c278d3c1b8dabc90fc3de06c9e2700
parent7d8aec2423636bf2e3f5cfa2bccbf2d42a777388 (diff)
completed ondig function
-rw-r--r--init.lua19
-rw-r--r--triggers.lua66
2 files changed, 50 insertions, 35 deletions
diff --git a/init.lua b/init.lua
index f88c74b..f6cddfe 100644
--- a/init.lua
+++ b/init.lua
@@ -21,12 +21,8 @@ function awards.register_achievement(name,data_table)
table.insert(awards.def,data_table);
end
-function awards.register_onDig(data)
- table.insert(awards.onDig,data);
-end
-
-function awards:getNodeCount(nodeName)
- return self.count[nodeName]
+function awards.register_onDig(func)
+ table.insert(awards.onDig,func);
end
@@ -36,9 +32,12 @@ awards.register_achievement("award_mesefind",{
description = "Found some Mese!",
})
-awards.register_onDig({
- award="",
- func=function(player)
+awards.register_onDig(function(player,data)
+ if not data['count']['default'] or not data['count']['default']['mese'] then
+ return
+ end
+ if data['count']['default']['mese'] > 0 then
+ return "award_mesefind"
end
-}) \ No newline at end of file
+end) \ No newline at end of file
diff --git a/triggers.lua b/triggers.lua
index a2074f8..0536ec6 100644
--- a/triggers.lua
+++ b/triggers.lua
@@ -17,43 +17,59 @@ minetest.register_on_dignode(function(pos, oldnode, digger)
local mod=nodedug[1]
local item=nodedug[2]
+ local playern = digger:get_player_name()
- print (mod)
- print (item)
-
- local player = digger:get_player_name()
-
- print("Awards [Event] - "..player.." has dug a node")
-
- if (player~=nil and nodedug~=nil and mod~=nil and item~=nil) then
- if not player_data[player] then
- player_data[player]={}
- player_data[player]['count']={}
- player_data[player]['count']['default']={}
- player_data[player]['count']['default']['dirt']=0
- player_data[player]['name']=player
+ if (playern~=nil and nodedug~=nil and mod~=nil and item~=nil) then
+ --check the player's directory
+ if not player_data[playern] then
+ player_data[playern]={}
+ player_data[playern]['count']={}
+ player_data[playern]['count']['default']={}
+ player_data[playern]['count']['default']['dirt']=0
+ player_data[playern]['name']=playern
end
- if not player_data[player]['count'][mod] then
- player_data[player]['count'][mod]={}
+ --check player.count.mod
+ if not player_data[playern]['count'][mod] then
+ player_data[playern]['count'][mod]={}
end
- if not player_data[player]['count'][mod][item] then
- player_data[player]['count'][mod][item]=0
+ --check player.count.mod.item
+ if not player_data[playern]['count'][mod][item] then
+ player_data[playern]['count'][mod][item]=0
end
- player_data[player]['count'][mod][item]=player_data[player]['count'][mod][item]+1
+ player_data[playern]['count'][mod][item]=player_data[playern]['count'][mod][item]+1
+
+ print(" - "..mod..":"..item.." 's count is now "..(player_data[playern]['count'][mod][item]))
- print(mod..":"..item.." 's count is now "..(player_data[player]['count'][mod][item]))
- else
- print(player.."'s dig event has been skipped")
+ -- Roll through the onDig functions
+ local player=digger
+ local data=player_data[playern]
+
+ for i=1,# awards.onDig do
+ local res=awards.onDig[i](player,data)
+
+ if not data['unlocked'] then
+ data['unlocked']={}
+ end
+
+ if res~=nil and (not data['unlocked'][res] or data['unlocked'][res]==false) then
+ data['unlocked'][res]=true
+ minetest.chat_send_player(playern, "Achievement Unlocked: "..res)
+ end
+ end
end
end)
minetest.register_on_newplayer(function(player)
+ --Player data root
player_data[player:get_player_name()]={}
- player_data[player:get_player_name()]['count']={}
- player_data[player:get_player_name()]['count']['default']={}
- player_data[player:get_player_name()]['count']['default']['dirt']=0
player_data[player:get_player_name()]['name']=player:get_player_name()
+
+ --The player counter
+ player_data[player:get_player_name()]['count']={}
+
+ --Table to contain achievement records
+ player_data[player:get_player_name()]['unlocked']={}
end) \ No newline at end of file