mirror of
https://gitlab.com/rubenwardy/awards.git
synced 2024-11-30 03:03:44 +01:00
Move playerdata table around
This commit is contained in:
parent
773f799320
commit
6405b26d65
13
api.lua
13
api.lua
@ -8,7 +8,7 @@
|
|||||||
function save_playerD()
|
function save_playerD()
|
||||||
local file = io.open(minetest.get_worldpath().."/awards.txt", "w")
|
local file = io.open(minetest.get_worldpath().."/awards.txt", "w")
|
||||||
if file then
|
if file then
|
||||||
file:write(minetest.serialize(player_data))
|
file:write(minetest.serialize(awards.players))
|
||||||
file:close()
|
file:close()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -26,7 +26,10 @@ end
|
|||||||
|
|
||||||
-- The global award namespace
|
-- The global award namespace
|
||||||
awards={}
|
awards={}
|
||||||
player_data=load_playerD()
|
awards.players=load_playerD()
|
||||||
|
function awards.player(name)
|
||||||
|
return awards.players[player]
|
||||||
|
end
|
||||||
|
|
||||||
-- A table of award definitions
|
-- A table of award definitions
|
||||||
awards.def={}
|
awards.def={}
|
||||||
@ -114,7 +117,7 @@ end
|
|||||||
-- award - the name of the award to give
|
-- award - the name of the award to give
|
||||||
function awards.give_achievement(name,award)
|
function awards.give_achievement(name,award)
|
||||||
-- Access Player Data
|
-- Access Player Data
|
||||||
local data=player_data[name]
|
local data=awards.players[name]
|
||||||
|
|
||||||
-- Perform checks
|
-- Perform checks
|
||||||
if not data then
|
if not data then
|
||||||
@ -181,13 +184,13 @@ minetest.register_chatcommand("list_awards", {
|
|||||||
params = "",
|
params = "",
|
||||||
description = "list_awards: list your awards",
|
description = "list_awards: list your awards",
|
||||||
func = function(name, param)
|
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!")
|
minetest.chat_send_player(name, "Unable to find your award listings!")
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.chat_send_player(name, name.."'s awards:")
|
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);
|
minetest.chat_send_player(name, str);
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
54
triggers.lua
54
triggers.lua
@ -29,19 +29,19 @@ minetest.register_on_dignode(function(pos, oldnode, digger)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Run checks
|
-- Run checks
|
||||||
awards.tbv(player_data, playern )
|
awards.tbv(awards.players, playern )
|
||||||
awards.tbv(player_data[playern], "count" )
|
awards.tbv(awards.players[playern], "count" )
|
||||||
awards.tbv(player_data[playern], "name", playern )
|
awards.tbv(awards.players[playern], "name", playern )
|
||||||
awards.tbv(player_data[playern].count, mod)
|
awards.tbv(awards.players[playern].count, mod)
|
||||||
awards.tbv(player_data[playern].count[mod], item, 0 )
|
awards.tbv(awards.players[playern].count[mod], item, 0 )
|
||||||
|
|
||||||
-- Increment counder
|
-- Increment counder
|
||||||
player_data[playern].count[mod][item]=player_data[playern].count[mod][item]+1
|
awards.players[playern].count[mod][item]=awards.players[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 "..(awards.players[playern].count[mod][item]))
|
||||||
|
|
||||||
-- Run callbacks and triggers
|
-- Run callbacks and triggers
|
||||||
local player=digger
|
local player=digger
|
||||||
local data=player_data[playern]
|
local data=awards.players[playern]
|
||||||
|
|
||||||
for i=1,# awards.onDig do
|
for i=1,# awards.onDig do
|
||||||
local res = nil
|
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
|
if (not playern or not nodedug or not mod or not item) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
awards.tbv(player_data, playern )
|
awards.tbv(awards.players, playern )
|
||||||
awards.tbv(player_data[playern], "place" )
|
awards.tbv(awards.players[playern], "place" )
|
||||||
awards.tbv(player_data[playern], "name", playern )
|
awards.tbv(awards.players[playern], "name", playern )
|
||||||
awards.tbv(player_data[playern].place, mod)
|
awards.tbv(awards.players[playern].place, mod)
|
||||||
awards.tbv(player_data[playern].place[mod], item, 0 )
|
awards.tbv(awards.players[playern].place[mod], item, 0 )
|
||||||
|
|
||||||
-- Increment counder
|
-- Increment counder
|
||||||
player_data[playern].place[mod][item] = player_data[playern].place[mod][item]+1
|
awards.players[playern].place[mod][item] = awards.players[playern].place[mod][item]+1
|
||||||
print(" - "..mod..":"..item.." 's count is now "..(player_data[playern].place[mod][item]))
|
print(" - "..mod..":"..item.." 's count is now "..(awards.players[playern].place[mod][item]))
|
||||||
|
|
||||||
-- Run callbacks and triggers
|
-- Run callbacks and triggers
|
||||||
local player = digger
|
local player = digger
|
||||||
local data = player_data[playern]
|
local data = awards.players[playern]
|
||||||
for i=1,# awards.onPlace do
|
for i=1,# awards.onPlace do
|
||||||
local res = nil
|
local res = nil
|
||||||
if type(awards.onPlace[i]) == "function" then
|
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
|
if not player or not player:get_player_name() or player:get_player_name()=="" then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
awards.tbv(player_data, playern )
|
awards.tbv(awards.players, playern )
|
||||||
awards.tbv(player_data[playern], "name", playern )
|
awards.tbv(awards.players[playern], "name", playern )
|
||||||
awards.tbv(player_data[playern], "deaths", 0 )
|
awards.tbv(awards.players[playern], "deaths", 0 )
|
||||||
|
|
||||||
-- Increment counter
|
-- 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
|
-- Run callbacks and triggers
|
||||||
local playern=player:get_player_name()
|
local playern=player:get_player_name()
|
||||||
local data=player_data[playern]
|
local data=awards.players[playern]
|
||||||
for i=1,# awards.onDeath do
|
for i=1,# awards.onDeath do
|
||||||
local res=nil
|
local res=nil
|
||||||
if type(awards.onDeath[i]) == "function" then
|
if type(awards.onDeath[i]) == "function" then
|
||||||
@ -179,12 +179,12 @@ minetest.register_on_dieplayer(function(player)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_on_newplayer(function(player)
|
minetest.register_on_newplayer(function(player)
|
||||||
awards.tbv(player_data, player:get_player_name())
|
awards.tbv(awards.players, player:get_player_name())
|
||||||
awards.tbv(player_data[playern], "name", player:get_player_name())
|
awards.tbv(awards.players[playern], "name", player:get_player_name())
|
||||||
awards.tbv(player_data[playern], "unlocked")
|
awards.tbv(awards.players[playern], "unlocked")
|
||||||
awards.tbv(player_data[playern], "place")
|
awards.tbv(awards.players[playern], "place")
|
||||||
awards.tbv(player_data[playern], "count")
|
awards.tbv(awards.players[playern], "count")
|
||||||
awards.tbv(player_data[playern], "deaths", 0)
|
awards.tbv(awards.players[playern], "deaths", 0)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_on_shutdown(function()
|
minetest.register_on_shutdown(function()
|
||||||
|
Loading…
Reference in New Issue
Block a user