diff options
author | Rubenwardy <anjayward@gmail.com> | 2013-02-22 19:35:43 +0000 |
---|---|---|
committer | Rubenwardy <anjayward@gmail.com> | 2013-02-22 19:35:43 +0000 |
commit | 6a982c03be4e52001e0f9b472b05ea27d274e615 (patch) | |
tree | efa55e6d751f3261c466b12dc72c344e8572e7db /init.lua | |
parent | 3b845c0d81ab836647a772732179c4fe6b6f1a17 (diff) |
give achievement function
Diffstat (limited to 'init.lua')
-rw-r--r-- | init.lua | 33 |
1 files changed, 33 insertions, 0 deletions
@@ -14,6 +14,26 @@ awards.def={} -- Load files dofile(minetest.get_modpath("awards").."/triggers.lua") +-- Table Save Load Functions +local function save(table, file) + local file = io:open(file, "w") + if file then + file:write(minetest.serialize(table)) + file:close() + end +end + +local function load(file) + local file = io:open(file, "r") + if file then + local table = minetest.deserialize(file:read("*all")) + if type(table) == "table" then + return table + end + end + return {} +end + -- API Functions function awards.register_achievement(name,data_table) @@ -25,6 +45,19 @@ function awards.register_onDig(func) table.insert(awards.onDig,func); end +function awards.give_achievement(name,award) + local data=player_data[name] + + if not data['unlocked'] then + data['unlocked']={} + end + + if not data['unlocked'][award] or data['unlocked'][award]~=award then + data['unlocked'][award]=award + minetest.chat_send_player(name, "Achievement Unlocked: "..award) + end +end + -- List a player's achievements minetest.register_chatcommand("list_awards", { params = "", |