1
0
mirror of https://gitlab.com/rubenwardy/awards.git synced 2024-11-18 16:30:32 +01:00
awards/api_helpers.lua
Wuzzy 38c504e938 Add eat trigger, extend existing triggers, add 9 awards (#35)
* Add eat trigger and 2 new awards
* Add mushroom eating awards
* Add support for counting any eat/dig/craft/place
* Update readme
* Add 4 builder awards
* Update German locale
* Update dependencies
* Fix mistake in German translation
* Revert removal of background
2016-11-15 01:57:01 +01:00

59 lines
1.5 KiB
Lua

function awards.tbv(tb,value,default)
if not default then
default = {}
end
if not tb or type(tb) ~= "table" then
if not value then
value = "[NULL]"
end
minetest.log("error", "awards.tbv - table "..dump(value).." is null, or not a table! Dump: "..dump(tb))
return
end
if not value then
error("[ERROR] awards.tbv was not used correctly!\n"..
"Value: '"..dump(value).."'\n"..
"Dump:"..dump(tb))
return
end
if not tb[value] then
tb[value] = default
end
end
function awards.assertPlayer(playern)
awards.tbv(awards.players, playern)
awards.tbv(awards.players[playern], "name", playern)
awards.tbv(awards.players[playern], "unlocked")
awards.tbv(awards.players[playern], "place")
awards.tbv(awards.players[playern], "count")
awards.tbv(awards.players[playern], "craft")
awards.tbv(awards.players[playern], "eat")
awards.tbv(awards.players[playern], "deaths", 0)
awards.tbv(awards.players[playern], "joins", 0)
awards.tbv(awards.players[playern], "chats", 0)
end
function awards.player(name)
return awards.players[name]
end
function awards._order_awards(name)
local done = {}
local retval = {}
local player = awards.player(name)
if player and player.unlocked then
for _,got in pairs(player.unlocked) do
if awards.def[got] then
done[got] = true
table.insert(retval,{name=got,got=true})
end
end
end
for _,def in pairs(awards.def) do
if not done[def.name] then
table.insert(retval,{name=def.name,got=false})
end
end
return retval
end