InsaneProtestor/mods/ip_destruction_counter/init.lua
2022-11-27 14:08:38 -05:00

68 lines
1.7 KiB
Lua

local modpath = minetest.get_modpath("ip_destruction_counter")
destruction_counter = {}
destruction_counter.nodesDestroyed = 0
destruction_counter.pigsKilled = 0
destruction_counter.peopleKilled = 0
local nodesDestroyedByHand = 0
local idText
local idMeter
minetest.register_on_joinplayer(function(player)
meta = player:get_meta()
player:hud_add({
hud_elem_type = "image",
position = {x = .8, y = .85},
offset = {x = -830, y = 23},
text = "destruction_counter_meter_empty.png",
scale = {x = 4, y = 4},
alignment = {x = 1, y = 0},
})
idMeter = player:hud_add({
hud_elem_type = "image",
position = {x = .8, y = .85},
offset = {x = -830, y = 23},
text = "destruction_counter_meter_full.png",
scale = {x = 0, y = 4},
alignment = {x = 1, y = 0},
})
idText = player:hud_add({
hud_elem_type = "text",
position = {x = 0.3, y = 0.7},
scale = {x = 0.3, y = 0.5},
text = "Destruct-o-meter",
number = 0xff3c0a,
alignment = {x = 1},
offset = {x = 200, y = 46},
})
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
player = minetest.get_player_by_name("singleplayer")
end
local totalDestruction = destruction_counter.nodesDestroyed + destruction_counter.pigsKilled * 20 + destruction_counter.peopleKilled * 10 + math.floor(nodesDestroyedByHand / 10)
local percentage = (totalDestruction / 2000 * 4)
if percentage > 4 then
percentage = 4
end
player:hud_change(idText, "text", "Destruction meter: " .. totalDestruction)
player:hud_change(idMeter, "scale", {x = percentage, y = 4})
end