Fix HUD issues and use hudbars
This commit is contained in:
parent
e84f5949db
commit
1faee08282
@ -4,11 +4,7 @@ local damage_enabled = minetest.settings:get_bool("enable_damage")
|
|||||||
|
|
||||||
if damage_enabled then
|
if damage_enabled then
|
||||||
|
|
||||||
-- Position of thirst HUD
|
hb.register_hudbar("thirst", 0xFFFFFF, "Thirst", { icon = "thirst_hud_icon.png", bgicon = "thirst_hud_bg.png", bar = "" }, 20, 30, false)
|
||||||
local hud_position = {x = 0.5, y = 1}
|
|
||||||
|
|
||||||
-- Offset of thirst HUD
|
|
||||||
local hud_offset = {x = -197, y = -90}
|
|
||||||
|
|
||||||
-- Maximum thirst value, and default for new players.
|
-- Maximum thirst value, and default for new players.
|
||||||
local max_thirst = 20
|
local max_thirst = 20
|
||||||
@ -16,9 +12,6 @@ if damage_enabled then
|
|||||||
-- Global table for the API.
|
-- Global table for the API.
|
||||||
thirst = {}
|
thirst = {}
|
||||||
|
|
||||||
-- Used to store HUD indexes for each player.
|
|
||||||
thirst.hud = {}
|
|
||||||
|
|
||||||
-- Every x seconds, the player thirst is decreased by 1 if they're in water.
|
-- Every x seconds, the player thirst is decreased by 1 if they're in water.
|
||||||
thirst.water_quench_rate = 2
|
thirst.water_quench_rate = 2
|
||||||
|
|
||||||
@ -31,28 +24,6 @@ if damage_enabled then
|
|||||||
-- Every x seconds, thirst data is saved.
|
-- Every x seconds, thirst data is saved.
|
||||||
thirst.data_storage_rate = 10
|
thirst.data_storage_rate = 10
|
||||||
|
|
||||||
-- Default thirst HUD def
|
|
||||||
thirst.hud_def = {
|
|
||||||
hud_elem_type = "statbar",
|
|
||||||
position = hud_position,
|
|
||||||
text = "thirst_hud_icon.png",
|
|
||||||
scale = {x = 1, y = 1},
|
|
||||||
offset = hud_offset,
|
|
||||||
number = 20,
|
|
||||||
}
|
|
||||||
|
|
||||||
-- Gets HUD definition with <amount> thirst, or full thirst if no amount specified.
|
|
||||||
thirst.get_hud_def = function(amount)
|
|
||||||
|
|
||||||
amount = amount or 20
|
|
||||||
|
|
||||||
def = thirst.hud_def
|
|
||||||
|
|
||||||
def.number = amount
|
|
||||||
|
|
||||||
return def
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Returns the thirst a player has, or nil if the player does not exist.
|
-- Returns the thirst a player has, or nil if the player does not exist.
|
||||||
thirst.get_player_thirst = function(name)
|
thirst.get_player_thirst = function(name)
|
||||||
|
|
||||||
@ -77,23 +48,6 @@ if damage_enabled then
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Sets a player's HUD to a certain thirst level
|
|
||||||
thirst.set_player_hud_def = function(name, amount)
|
|
||||||
|
|
||||||
local player = minetest.get_player_by_name(name)
|
|
||||||
|
|
||||||
local idx = thirst.hud[name]
|
|
||||||
|
|
||||||
if idx then
|
|
||||||
|
|
||||||
player:hud_change(idx, "number", amount)
|
|
||||||
|
|
||||||
else
|
|
||||||
|
|
||||||
thirst.hud[name] = player:hud_add(thirst.get_hud_def(amount))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Sets player thirst to a value.
|
-- Sets player thirst to a value.
|
||||||
thirst.set_player_thirst = function(name, amount)
|
thirst.set_player_thirst = function(name, amount)
|
||||||
|
|
||||||
@ -113,7 +67,7 @@ if damage_enabled then
|
|||||||
|
|
||||||
meta:set_int("thirst", amount)
|
meta:set_int("thirst", amount)
|
||||||
|
|
||||||
thirst.set_player_hud_def(name, amount)
|
hb.change_hudbar(player, "thirst", amount, max_thirst, "thirst_hud_icon.png", "thirst_hud_bg.png", "", "Thirst", 0xFFFF)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -147,18 +101,9 @@ if damage_enabled then
|
|||||||
|
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
|
|
||||||
thirst.set_player_hud_def(name, thirst.get_player_thirst(name))
|
hb.init_hudbar(player, "thirst", thirst.get_player_thirst(name), max_thirst, false)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_chatcommand("set_thirst", {
|
|
||||||
params = "",
|
|
||||||
func = function(name, params)
|
|
||||||
amount = tonumber(params)
|
|
||||||
thirst.set_player_thirst(name, amount)
|
|
||||||
minetest.chat_send_all("Current thirst data:\n" .. dump(thirst.players))
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
|
||||||
-- Reset player thirst on die.
|
-- Reset player thirst on die.
|
||||||
minetest.register_on_respawnplayer(function(player)
|
minetest.register_on_respawnplayer(function(player)
|
||||||
|
|
||||||
|
2
mods/thirst/mod.conf
Normal file
2
mods/thirst/mod.conf
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
name = thirst
|
||||||
|
depends = hudbars
|
Loading…
x
Reference in New Issue
Block a user