onPlace and award description

This commit is contained in:
Rubenwardy 2013-02-22 20:38:01 +00:00
parent aef2e2ae91
commit 6a968c87c5
2 changed files with 86 additions and 5 deletions

@ -36,14 +36,17 @@ dofile(minetest.get_modpath("awards").."/triggers.lua")
-- API Functions -- API Functions
function awards.register_achievement(name,data_table) function awards.register_achievement(name,data_table)
data_table["name"] = name awards['def'][name] = data_table
table.insert(awards.def,data_table);
end end
function awards.register_onDig(func) function awards.register_onDig(func)
table.insert(awards.onDig,func); table.insert(awards.onDig,func);
end end
function awards.register_onPlace(func)
table.insert(awards.onPlace,func);
end
function awards.give_achievement(name,award) function awards.give_achievement(name,award)
local data=player_data[name] local data=player_data[name]
@ -52,9 +55,31 @@ function awards.give_achievement(name,award)
end end
if not data['unlocked'][award] or data['unlocked'][award]~=award then if not data['unlocked'][award] or data['unlocked'][award]~=award then
-- set player_data table
data['unlocked'][award]=award data['unlocked'][award]=award
minetest.chat_send_player(name, "Achievement Unlocked: "..award)
-- define local award data
local title = award
local desc = ""
-- check definition table
if awards['def'][award] and awards['def'][award]['title'] then
title=awards['def'][award]['title']
end
if awards['def'][award] and awards['def'][award]['description'] then
desc=awards['def'][award]['description']
end
-- send award header
minetest.chat_send_player(name, "Achievement Unlocked: "..title)
-- send award content
if desc~="" then
minetest.chat_send_player(name, desc)
end
-- save player_data table
save_playerD() save_playerD()
end end
end end
@ -87,4 +112,14 @@ awards.register_onDig(function(player,data)
if data['count']['default']['mese'] > 0 then if data['count']['default']['mese'] > 0 then
return "award_mesefind" return "award_mesefind"
end end
end)
awards.register_onPlace(function(player,data)
if not data['place']['default'] or not data['place']['default']['mese'] then
return
end
if data['place']['default']['mese'] > 0 then
return "award_meseplace"
end
end) end)

@ -6,6 +6,7 @@
-- Function for Triggers -- Function for Triggers
awards.onDig={} awards.onDig={}
awards.onPlace={}
awards.onTick={} awards.onTick={}
-- Player functions -- Player functions
@ -24,8 +25,6 @@ minetest.register_on_dignode(function(pos, oldnode, digger)
if not player_data[playern] then if not player_data[playern] then
player_data[playern]={} player_data[playern]={}
player_data[playern]['count']={} player_data[playern]['count']={}
player_data[playern]['count']['default']={}
player_data[playern]['count']['default']['dirt']=0
player_data[playern]['name']=playern player_data[playern]['name']=playern
end end
@ -57,13 +56,60 @@ minetest.register_on_dignode(function(pos, oldnode, digger)
end end
end) end)
minetest.register_on_placenode(function(pos, newnode, placer)
local nodedug = string.split(newnode.name, ":")
local mod=nodedug[1]
local item=nodedug[2]
local playern = placer:get_player_name()
if (playern~=nil and nodedug~=nil and mod~=nil and item~=nil) then
--check the player's directory
if not player_data[playern] then
player_data[playern]={}
player_data[playern]['place']={}
player_data[playern]['name']=playern
end
--check player.count.mod
if not player_data[playern]['place'][mod] then
player_data[playern]['place'][mod]={}
end
--check player.count.mod.item
if not player_data[playern]['place'][mod][item] then
player_data[playern]['place'][mod][item]=0
end
player_data[playern]['place'][mod][item]=player_data[playern]['place'][mod][item]+1
print(" - "..mod..":"..item.." 's place is now "..(player_data[playern]['place'][mod][item]))
-- Roll through the onDig functions
local player=placer
local data=player_data[playern]
for i=1,# awards.onPlace do
local res=awards.onPlace[i](player,data)
if res~=nil then
awards.give_achievement(playern,res)
end
end
end
end)
minetest.register_on_newplayer(function(player) minetest.register_on_newplayer(function(player)
minetest.chat_send_player(player:get_player_name(),"[Awards] Registering you now...")
--Player data root --Player data root
player_data[player:get_player_name()]={} player_data[player:get_player_name()]={}
player_data[player:get_player_name()]['name']=player:get_player_name() player_data[player:get_player_name()]['name']=player:get_player_name()
--The player counter --The player counter
player_data[player:get_player_name()]['count']={} player_data[player:get_player_name()]['count']={}
player_data[player:get_player_name()]['place']={}
--Table to contain achievement records --Table to contain achievement records
player_data[player:get_player_name()]['unlocked']={} player_data[player:get_player_name()]['unlocked']={}