2013-02-22 18:53:42 +01:00
|
|
|
-- AWARDS
|
|
|
|
-- by Rubenwardy, CC-BY-SA
|
|
|
|
-------------------------------------------------------
|
|
|
|
-- this is the trigger handler file for the awards mod
|
|
|
|
-------------------------------------------------------
|
|
|
|
|
|
|
|
-- Function for Triggers
|
|
|
|
awards.onDig={}
|
|
|
|
awards.onTick={}
|
|
|
|
|
|
|
|
-- Player functions
|
|
|
|
|
|
|
|
-- Trigger Handles
|
|
|
|
minetest.register_on_dignode(function(pos, oldnode, digger)
|
|
|
|
local nodedug = string.split(oldnode.name, ":")
|
|
|
|
|
2013-02-22 19:03:32 +01:00
|
|
|
local mod=nodedug[1]
|
|
|
|
local item=nodedug[2]
|
|
|
|
|
2013-02-22 19:38:09 +01:00
|
|
|
local playern = digger:get_player_name()
|
2013-02-22 19:03:32 +01:00
|
|
|
|
2013-02-22 19:38:09 +01:00
|
|
|
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
|
2013-02-22 18:53:42 +01:00
|
|
|
end
|
|
|
|
|
2013-02-22 19:38:09 +01:00
|
|
|
--check player.count.mod
|
|
|
|
if not player_data[playern]['count'][mod] then
|
|
|
|
player_data[playern]['count'][mod]={}
|
2013-02-22 18:53:42 +01:00
|
|
|
end
|
|
|
|
|
2013-02-22 19:38:09 +01:00
|
|
|
--check player.count.mod.item
|
|
|
|
if not player_data[playern]['count'][mod][item] then
|
|
|
|
player_data[playern]['count'][mod][item]=0
|
2013-02-22 18:53:42 +01:00
|
|
|
end
|
|
|
|
|
2013-02-22 19:38:09 +01:00
|
|
|
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]))
|
2013-02-22 19:03:32 +01:00
|
|
|
|
2013-02-22 19:38:09 +01:00
|
|
|
-- 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
|
|
|
|
|
2013-02-22 20:16:30 +01:00
|
|
|
if res~=nil and (not data['unlocked'][res] or data['unlocked'][res]==res) then
|
|
|
|
data['unlocked'][res]=res
|
2013-02-22 19:38:09 +01:00
|
|
|
minetest.chat_send_player(playern, "Achievement Unlocked: "..res)
|
|
|
|
end
|
|
|
|
end
|
2013-02-22 18:53:42 +01:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
minetest.register_on_newplayer(function(player)
|
2013-02-22 19:38:09 +01:00
|
|
|
--Player data root
|
2013-02-22 18:53:42 +01:00
|
|
|
player_data[player:get_player_name()]={}
|
|
|
|
player_data[player:get_player_name()]['name']=player:get_player_name()
|
2013-02-22 19:38:09 +01:00
|
|
|
|
|
|
|
--The player counter
|
|
|
|
player_data[player:get_player_name()]['count']={}
|
|
|
|
|
|
|
|
--Table to contain achievement records
|
|
|
|
player_data[player:get_player_name()]['unlocked']={}
|
2013-02-22 18:53:42 +01:00
|
|
|
end)
|