Skip to content

Instantly share code, notes, and snippets.

@ronoaldo
Last active August 24, 2021 03:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ronoaldo/348eea9db83c2d16fe04fc7960321958 to your computer and use it in GitHub Desktop.
Save ronoaldo/348eea9db83c2d16fe04fc7960321958 to your computer and use it in GitHub Desktop.
Daily reward mod prototype
local LAST_CLAIM = "dailyreward_last_claim"
dailyreward = {}
dailyreward.items = {
ItemStack("default:diamondblock 1"),
ItemStack("default:mese 1"),
}
function dailyreward.claim(player)
local inv = player:get_inventory()
for _, itemstack in ipairs(dailyreward.items) do
-- TODO(ronoaldo): handle left overs
inv:add_item(itemstack)
end
local now = os.time()
player:get_meta().set_int(LAST_CLAIM, now)
end
function dailyreward.can_claim(player)
local meta = player:get_meta()
local last_claim = meta:get_int(LAST_CLAIM)
local now = os.time()
if now - last_claim > 24*60*60 then
return false
end
return true
end
function dailyreward.callback(player)
if dailyreward.can_claim(player) then
dailyreward.claim(player)
end
end
minetest.register_on_join_player(dailyreward.callback)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment