Skip to content

Commit

Permalink
Add basic reward mod
Browse files Browse the repository at this point in the history
  • Loading branch information
siboehm committed Dec 30, 2023
1 parent e6b4b41 commit 362b3b7
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions mods/reward/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
playerRewardsHUD = {}
playerReturnsHUD = {}

minetest.register_on_joinplayer(function(player)
-- Get the dig and place count from storage, or default to 0
local meta = player:get_meta()
meta:set_int("reward", 0)
meta:set_int("return", 0)

local player_name = player:get_player_name()
local idxReward = player:hud_add({
hud_elem_type = "text",
position = {x = 1, y = 0}, -- right, top
offset = {x=-40, y = 0},
scale = {x = 100, y = 100},
alignment = {x = -1, y = 1}, -- position specifies top right corner position
text = "Reward: " .. meta:get_string("reward"),
name = "reward",
})
local idxReturn = player:hud_add({
hud_elem_type = "text",
position = {x = 1, y = 0}, -- right, top
offset = {x=-40, y = 20},
scale = {x = 100, y = 100},
alignment = {x = -1, y = 1}, -- position specifies top right corner position
text = "Return: " .. meta:get_string("return"),
name = "return",
})
playerRewardsHUD[player_name] = idxReward
playerReturnsHUD[player_name] = idxReturn
end)

minetest.register_globalstep(function(dtime)
local players = minetest.get_connected_players()
for _, player in ipairs(players) do
local name = player:get_player_name()
local meta = player:get_meta()
meta:set_int("reward", 1)
meta:set_int("return", meta:get_int("return") + meta:get_int("reward"))
player:hud_change(playerReturnsHUD[name], "text", "Return: " .. meta:get("return"))
player:hud_change(playerRewardsHUD[name], "text", "Reward: " .. meta:get("reward"))
end
end)

0 comments on commit 362b3b7

Please sign in to comment.