mirror of
https://gitlab.com/rubenwardy/awards.git
synced 2024-08-20 10:44:04 +02:00
completed ondig function
This commit is contained in:
parent
7d8aec2423
commit
369b4d1475
21
init.lua
21
init.lua
@ -21,12 +21,8 @@ function awards.register_achievement(name,data_table)
|
|||||||
table.insert(awards.def,data_table);
|
table.insert(awards.def,data_table);
|
||||||
end
|
end
|
||||||
|
|
||||||
function awards.register_onDig(data)
|
function awards.register_onDig(func)
|
||||||
table.insert(awards.onDig,data);
|
table.insert(awards.onDig,func);
|
||||||
end
|
|
||||||
|
|
||||||
function awards:getNodeCount(nodeName)
|
|
||||||
return self.count[nodeName]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -36,9 +32,12 @@ awards.register_achievement("award_mesefind",{
|
|||||||
description = "Found some Mese!",
|
description = "Found some Mese!",
|
||||||
})
|
})
|
||||||
|
|
||||||
awards.register_onDig({
|
awards.register_onDig(function(player,data)
|
||||||
award="",
|
if not data['count']['default'] or not data['count']['default']['mese'] then
|
||||||
func=function(player)
|
return
|
||||||
|
|
||||||
end
|
end
|
||||||
})
|
|
||||||
|
if data['count']['default']['mese'] > 0 then
|
||||||
|
return "award_mesefind"
|
||||||
|
end
|
||||||
|
end)
|
66
triggers.lua
66
triggers.lua
@ -17,43 +17,59 @@ minetest.register_on_dignode(function(pos, oldnode, digger)
|
|||||||
local mod=nodedug[1]
|
local mod=nodedug[1]
|
||||||
local item=nodedug[2]
|
local item=nodedug[2]
|
||||||
|
|
||||||
|
local playern = digger:get_player_name()
|
||||||
|
|
||||||
print (mod)
|
if (playern~=nil and nodedug~=nil and mod~=nil and item~=nil) then
|
||||||
print (item)
|
--check the player's directory
|
||||||
|
if not player_data[playern] then
|
||||||
local player = digger:get_player_name()
|
player_data[playern]={}
|
||||||
|
player_data[playern]['count']={}
|
||||||
print("Awards [Event] - "..player.." has dug a node")
|
player_data[playern]['count']['default']={}
|
||||||
|
player_data[playern]['count']['default']['dirt']=0
|
||||||
if (player~=nil and nodedug~=nil and mod~=nil and item~=nil) then
|
player_data[playern]['name']=playern
|
||||||
if not player_data[player] then
|
|
||||||
player_data[player]={}
|
|
||||||
player_data[player]['count']={}
|
|
||||||
player_data[player]['count']['default']={}
|
|
||||||
player_data[player]['count']['default']['dirt']=0
|
|
||||||
player_data[player]['name']=player
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if not player_data[player]['count'][mod] then
|
--check player.count.mod
|
||||||
player_data[player]['count'][mod]={}
|
if not player_data[playern]['count'][mod] then
|
||||||
|
player_data[playern]['count'][mod]={}
|
||||||
end
|
end
|
||||||
|
|
||||||
if not player_data[player]['count'][mod][item] then
|
--check player.count.mod.item
|
||||||
player_data[player]['count'][mod][item]=0
|
if not player_data[playern]['count'][mod][item] then
|
||||||
|
player_data[playern]['count'][mod][item]=0
|
||||||
end
|
end
|
||||||
|
|
||||||
player_data[player]['count'][mod][item]=player_data[player]['count'][mod][item]+1
|
player_data[playern]['count'][mod][item]=player_data[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 "..(player_data[player]['count'][mod][item]))
|
-- Roll through the onDig functions
|
||||||
else
|
local player=digger
|
||||||
print(player.."'s dig event has been skipped")
|
local data=player_data[playern]
|
||||||
|
|
||||||
|
for i=1,# awards.onDig do
|
||||||
|
local res=awards.onDig[i](player,data)
|
||||||
|
|
||||||
|
if not data['unlocked'] then
|
||||||
|
data['unlocked']={}
|
||||||
|
end
|
||||||
|
|
||||||
|
if res~=nil and (not data['unlocked'][res] or data['unlocked'][res]==false) then
|
||||||
|
data['unlocked'][res]=true
|
||||||
|
minetest.chat_send_player(playern, "Achievement Unlocked: "..res)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_on_newplayer(function(player)
|
minetest.register_on_newplayer(function(player)
|
||||||
|
--Player data root
|
||||||
player_data[player:get_player_name()]={}
|
player_data[player:get_player_name()]={}
|
||||||
player_data[player:get_player_name()]['count']={}
|
|
||||||
player_data[player:get_player_name()]['count']['default']={}
|
|
||||||
player_data[player:get_player_name()]['count']['default']['dirt']=0
|
|
||||||
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
|
||||||
|
player_data[player:get_player_name()]['count']={}
|
||||||
|
|
||||||
|
--Table to contain achievement records
|
||||||
|
player_data[player:get_player_name()]['unlocked']={}
|
||||||
end)
|
end)
|
Loading…
Reference in New Issue
Block a user