mirror of
https://gitlab.com/rubenwardy/awards.git
synced 2024-12-27 11:10:41 +01:00
give achievement function
This commit is contained in:
parent
3b845c0d81
commit
6a982c03be
33
init.lua
33
init.lua
@ -14,6 +14,26 @@ awards.def={}
|
|||||||
-- Load files
|
-- Load files
|
||||||
dofile(minetest.get_modpath("awards").."/triggers.lua")
|
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
|
-- API Functions
|
||||||
function awards.register_achievement(name,data_table)
|
function awards.register_achievement(name,data_table)
|
||||||
@ -25,6 +45,19 @@ function awards.register_onDig(func)
|
|||||||
table.insert(awards.onDig,func);
|
table.insert(awards.onDig,func);
|
||||||
end
|
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
|
-- List a player's achievements
|
||||||
minetest.register_chatcommand("list_awards", {
|
minetest.register_chatcommand("list_awards", {
|
||||||
params = "",
|
params = "",
|
||||||
|
@ -50,13 +50,8 @@ minetest.register_on_dignode(function(pos, oldnode, digger)
|
|||||||
for i=1,# awards.onDig do
|
for i=1,# awards.onDig do
|
||||||
local res=awards.onDig[i](player,data)
|
local res=awards.onDig[i](player,data)
|
||||||
|
|
||||||
if not data['unlocked'] then
|
if res~=nil then
|
||||||
data['unlocked']={}
|
awards.give_achievement(playern,res)
|
||||||
end
|
|
||||||
|
|
||||||
if res~=nil and (not data['unlocked'][res] or data['unlocked'][res]~=res) then
|
|
||||||
data['unlocked'][res]=res
|
|
||||||
minetest.chat_send_player(playern, "Achievement Unlocked: "..res)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user