-
-
Save ronoaldo/348eea9db83c2d16fe04fc7960321958 to your computer and use it in GitHub Desktop.
Daily reward mod prototype
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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