63 lines
1.5 KiB
Lua
Raw Normal View History

2022-11-21 16:12:22 -05:00
local modpath = minetest.get_modpath("destruction_counter")
destruction_counter = {}
destruction_counter.nodesDestroyed = 0
local nodesDestroyedByHand = 0
local idText
local idMeter
minetest.register_on_joinplayer(function(player)
meta = player:get_meta()
2022-11-21 20:06:10 -05:00
2022-11-21 16:12:22 -05:00
player:hud_add({
hud_elem_type = "image",
2022-11-21 20:06:10 -05:00
position = {x = .8, y = .85},
offset = {x = -830, y = 23},
text = "destruction_counter_meter_empty.png",
scale = {x = 4, y = 4},
2022-11-21 16:12:22 -05:00
alignment = {x = 1, y = 0},
})
idMeter = player:hud_add({
hud_elem_type = "image",
2022-11-21 20:06:10 -05:00
position = {x = .8, y = .85},
offset = {x = -830, y = 23},
text = "destruction_counter_meter_full.png",
scale = {x = 0, y = 4},
2022-11-21 16:12:22 -05:00
alignment = {x = 1, y = 0},
})
2022-11-21 20:06:10 -05:00
idText = player:hud_add({
hud_elem_type = "text",
position = {x = 0.3, y = 0.7},
scale = {x = 0.3, y = 0.5},
2022-11-22 15:54:42 -05:00
text = "Destruct-o-meter",
2022-11-21 20:06:10 -05:00
number = 0xff3c0a,
alignment = {x = 1},
2022-11-22 15:54:42 -05:00
offset = {x = 200, y = 46},
2022-11-21 20:06:10 -05:00
})
2022-11-21 16:12:22 -05:00
end)
minetest.register_on_dignode(function(pos, oldnode, digger)
nodesDestroyedByHand = nodesDestroyedByHand + 1
destruction_counter.updateCounter(digger)
end)
function destruction_counter.updateCounter(player)
if not player then
return
end
local totalDestruction = destruction_counter.nodesDestroyed + math.floor(nodesDestroyedByHand / 10)
local percentage = (totalDestruction / 1000 * 4)
if percentage > 100 then
percentage = 100
end
player:hud_change(idText, "text", "Destruction meter: " .. totalDestruction)
player:hud_change(idMeter, "scale", {x = percentage, y = 4})
end