From 40f5bee7905ba76a8a7d810b0fad9a6e9195d2de Mon Sep 17 00:00:00 2001 From: kaadmy Date: Mon, 14 Nov 2016 08:41:47 -0800 Subject: [PATCH] Fix some bugs with achievements thanks to @asl97; fixes #35 --- mods/achievements/init.lua | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/mods/achievements/init.lua b/mods/achievements/init.lua index 32cb8ff..9701d86 100644 --- a/mods/achievements/init.lua +++ b/mods/achievements/init.lua @@ -79,6 +79,20 @@ function achievements.trigger_achievement(player, aname, times) save_achievements() end +-- Load achievements table + +local function on_load() + load_achievements() +end + +-- New player + +local function on_newplayer(player) + achievements.achievements[player:get_player_name()] = {} +end + +-- Interaction callbacks + local function on_craft(itemstack, player, craftgrid, craftinv) for aname, def in pairs(achievements.registered_achievements) do if def.craftitem ~= nil then @@ -128,10 +142,18 @@ local function on_place(pos, newnode, player, oldnode, itemstack, pointed_thing) end end +-- Add callback functions + +minetest.after(0, on_load) + +minetest.register_on_newplayer(on_newplayer) + minetest.register_on_craft(on_craft) minetest.register_on_dignode(on_dig) minetest.register_on_placenode(on_place) +-- Formspecs + local form = default.ui.get_page("core") form = form .. "tableoptions[background=#DDDDDD30]" form = form .. "tablecolumns[text,align=left,width=11;text,align=left,width=28;text,align=left,width=5]" @@ -220,7 +242,6 @@ end minetest.register_on_player_receive_fields(receive_fields) - -- -- Below is the default achievements --