From 6405b26d65a6289ada84fa21a604f1111ab8b86d Mon Sep 17 00:00:00 2001 From: Rubenwardy Date: Wed, 6 Nov 2013 18:38:55 +0000 Subject: [PATCH] Move playerdata table around --- api.lua | 13 ++++++++----- triggers.lua | 54 ++++++++++++++++++++++++++-------------------------- 2 files changed, 35 insertions(+), 32 deletions(-) diff --git a/api.lua b/api.lua index bc975ca..94756ff 100644 --- a/api.lua +++ b/api.lua @@ -8,7 +8,7 @@ function save_playerD() local file = io.open(minetest.get_worldpath().."/awards.txt", "w") if file then - file:write(minetest.serialize(player_data)) + file:write(minetest.serialize(awards.players)) file:close() end end @@ -26,7 +26,10 @@ end -- The global award namespace awards={} -player_data=load_playerD() +awards.players=load_playerD() +function awards.player(name) + return awards.players[player] +end -- A table of award definitions awards.def={} @@ -114,7 +117,7 @@ end -- award - the name of the award to give function awards.give_achievement(name,award) -- Access Player Data - local data=player_data[name] + local data=awards.players[name] -- Perform checks if not data then @@ -181,13 +184,13 @@ minetest.register_chatcommand("list_awards", { params = "", description = "list_awards: list your awards", func = function(name, param) - if not player_data[name] then + if not awards.players[name] then minetest.chat_send_player(name, "Unable to find your award listings!") end minetest.chat_send_player(name, name.."'s awards:") - for _, str in pairs(player_data[name].unlocked) do + for _, str in pairs(awards.players[name].unlocked) do minetest.chat_send_player(name, str); end end, diff --git a/triggers.lua b/triggers.lua index 4b99786..63fb9dc 100644 --- a/triggers.lua +++ b/triggers.lua @@ -29,19 +29,19 @@ minetest.register_on_dignode(function(pos, oldnode, digger) end -- Run checks - awards.tbv(player_data, playern ) - awards.tbv(player_data[playern], "count" ) - awards.tbv(player_data[playern], "name", playern ) - awards.tbv(player_data[playern].count, mod) - awards.tbv(player_data[playern].count[mod], item, 0 ) + awards.tbv(awards.players, playern ) + awards.tbv(awards.players[playern], "count" ) + awards.tbv(awards.players[playern], "name", playern ) + awards.tbv(awards.players[playern].count, mod) + awards.tbv(awards.players[playern].count[mod], item, 0 ) -- Increment counder - 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])) + awards.players[playern].count[mod][item]=awards.players[playern].count[mod][item]+1 + print(" - "..mod..":"..item.." 's count is now "..(awards.players[playern].count[mod][item])) -- Run callbacks and triggers local player=digger - local data=player_data[playern] + local data=awards.players[playern] for i=1,# awards.onDig do local res = nil @@ -91,19 +91,19 @@ minetest.register_on_placenode(function(pos,node,digger) if (not playern or not nodedug or not mod or not item) then return end - awards.tbv(player_data, playern ) - awards.tbv(player_data[playern], "place" ) - awards.tbv(player_data[playern], "name", playern ) - awards.tbv(player_data[playern].place, mod) - awards.tbv(player_data[playern].place[mod], item, 0 ) + awards.tbv(awards.players, playern ) + awards.tbv(awards.players[playern], "place" ) + awards.tbv(awards.players[playern], "name", playern ) + awards.tbv(awards.players[playern].place, mod) + awards.tbv(awards.players[playern].place[mod], item, 0 ) -- Increment counder - player_data[playern].place[mod][item] = player_data[playern].place[mod][item]+1 - print(" - "..mod..":"..item.." 's count is now "..(player_data[playern].place[mod][item])) + awards.players[playern].place[mod][item] = awards.players[playern].place[mod][item]+1 + print(" - "..mod..":"..item.." 's count is now "..(awards.players[playern].place[mod][item])) -- Run callbacks and triggers local player = digger - local data = player_data[playern] + local data = awards.players[playern] for i=1,# awards.onPlace do local res = nil if type(awards.onPlace[i]) == "function" then @@ -140,16 +140,16 @@ minetest.register_on_dieplayer(function(player) if not player or not player:get_player_name() or player:get_player_name()=="" then return end - awards.tbv(player_data, playern ) - awards.tbv(player_data[playern], "name", playern ) - awards.tbv(player_data[playern], "deaths", 0 ) + awards.tbv(awards.players, playern ) + awards.tbv(awards.players[playern], "name", playern ) + awards.tbv(awards.players[playern], "deaths", 0 ) -- Increment counter - player_data[player:get_player_name()].deaths = player_data[player:get_player_name()].deaths + 1 + awards.players[player:get_player_name()].deaths = awards.players[player:get_player_name()].deaths + 1 -- Run callbacks and triggers local playern=player:get_player_name() - local data=player_data[playern] + local data=awards.players[playern] for i=1,# awards.onDeath do local res=nil if type(awards.onDeath[i]) == "function" then @@ -179,12 +179,12 @@ minetest.register_on_dieplayer(function(player) end) minetest.register_on_newplayer(function(player) - awards.tbv(player_data, player:get_player_name()) - awards.tbv(player_data[playern], "name", player:get_player_name()) - awards.tbv(player_data[playern], "unlocked") - awards.tbv(player_data[playern], "place") - awards.tbv(player_data[playern], "count") - awards.tbv(player_data[playern], "deaths", 0) + awards.tbv(awards.players, player:get_player_name()) + awards.tbv(awards.players[playern], "name", player:get_player_name()) + awards.tbv(awards.players[playern], "unlocked") + awards.tbv(awards.players[playern], "place") + awards.tbv(awards.players[playern], "count") + awards.tbv(awards.players[playern], "deaths", 0) end) minetest.register_on_shutdown(function()