Commit 0a6cabf2 authored by TenPlus1's avatar TenPlus1

Added mods as pack

parent da890b05
Hudbars mod for Minetest
Hudbars, hbhunger and hbarmor mods for Minetest
This mod adds hud bars to the player's screen for health, hunger and drowning.
These mod adds hud bars to the player's screen for health, hunger, drowning and armor levels.
Mod created by Wuzzy and edited by TenPlus1 for Xanadu server
\ No newline at end of file
Mods created by Wuzzy and edited by TenPlus1 for Xanadu server
\ No newline at end of file
hudbars
3d_armor
hbarmor = {}
-- HUD statbar values
hbarmor.armor = {}
-- Stores if player's HUD bar has been initialized so far.
hbarmor.player_active = {}
-- HUD item ids
local armor_hud = {}
hbarmor.tick = 1 -- 0.1
-- If true, the armor bar is hidden when the player does not wear any armor
hbarmor.autohide = true
local enable_damage = minetest.setting_getbool("enable_damage")
--[[load custom settings
local set = io.open(minetest.get_modpath("hbarmor").."/hbarmor.conf", "r")
if set then
dofile(minetest.get_modpath("hbarmor").."/hbarmor.conf")
set:close()
end--]]
local must_hide = function(playername, arm)
return ((not armor.def[playername].count or armor.def[playername].count == 0) and arm == 0)
end
local arm_printable = function(arm)
return math.ceil(math.floor(arm + 0.5))
end
local function custom_hud(player)
local name = player:get_player_name()
if enable_damage then
local ret = hbarmor.get_armor(player)
if ret == false then
minetest.log("error", "[hbarmor] Call to hbarmor.get_armor in custom_hud returned with false!")
end
local arm = tonumber(hbarmor.armor[name])
if not arm then arm = 0 end
local hide
if hbarmor.autohide then
hide = must_hide(name, arm)
else
hide = false
end
hb.init_hudbar(player, "armor", arm_printable(arm), nil, hide)
end
end
--register and define armor HUD bar
hb.register_hudbar("armor", 0xFFFFFF, "Armor",
{ icon = "hbarmor_icon.png", bar = "hbarmor_bar.png" }, 0, 100, hbarmor.autohide, "%s: %d%%")
--dofile(minetest.get_modpath("hbarmor").."/armor.lua")
-- START armor.lua file
minetest.after(0, function()
if not armor.def then
minetest.after(2,minetest.chat_send_all,
"#Better HUD: Please update your version of 3darmor")
HUD_SHOW_ARMOR = false
end
end)
function hbarmor.get_armor(player)
if not player or not armor.def then
return false
end
local name = player:get_player_name()
local def = armor.def[name] or nil
if def and def.state and def.count then
hbarmor.set_armor(name, def.state, def.count)
else
return false
end
return true
end
function hbarmor.set_armor(player_name, ges_state, items)
local max_items = 4
if items == 5 then
max_items = items
end
local max = max_items * 65535
local lvl = max - ges_state
lvl = lvl / max
if ges_state == 0 and items == 0 then
lvl = 0
end
hbarmor.armor[player_name] = lvl * (items * (100 / max_items))
end
-- END armor.lua
-- update hud elemtens if value has changed
local function update_hud(player)
local name = player:get_player_name()
--armor
local arm = tonumber(hbarmor.armor[name])
if not arm then
arm = 0
hbarmor.armor[name] = 0
end
if hbarmor.autohide then
-- hide armor bar completely when there is none
if must_hide(name, arm) then
hb.hide_hudbar(player, "armor")
else
hb.change_hudbar(player, "armor", arm_printable(arm))
hb.unhide_hudbar(player, "armor")
end
else
hb.change_hudbar(player, "armor", arm_printable(arm))
end
end
minetest.register_on_joinplayer(function(player)
local name = player:get_player_name()
custom_hud(player)
hbarmor.player_active[name] = true
end)
minetest.register_on_leaveplayer(function(player)
local name = player:get_player_name()
hbarmor.player_active[name] = false
end)
local main_timer = 0
--local timer = 0
minetest.register_globalstep(function(dtime)
main_timer = main_timer + dtime
-- timer = timer + dtime
if main_timer > hbarmor.tick then -- or timer > 4 then
if enable_damage then
if main_timer > hbarmor.tick then main_timer = 0 end
for _,player in ipairs(minetest.get_connected_players()) do
local name = player:get_player_name()
if hbarmor.player_active[name] == true then
local ret = hbarmor.get_armor(player)
if ret == false then
minetest.log("error", "[hbarmor] Call to hbarmor.get_armor in globalstep returned with false!")
end
-- update all hud elements
update_hud(player)
end
end
end
end
-- if timer > 4 then timer = 0 end
end)
hudbars
default?
animalmaterials?
bucket?
bushes?
bushes_classic?
cooking?
creatures?
docfarming?
dwarves?
ethereal?
farming?
farming_plus?
ferns?
fishing?
fruit?
glooptest?
jkanimals?
jkfarming?
jkwine?
kpgmobs?
mobfcooking?
mobs?
moretrees?
mtfoods?
mush45?
mushroom?
seaplants?
bakedclay?
\ No newline at end of file
This diff is collapsed.
-- if damage enabled
if minetest.setting_getbool("enable_damage") then
hbhunger = {}
-- HUD statbar values
hbhunger.hunger = {}
hbhunger.hunger_out = {}
-- HUD item ids
local hunger_hud = {}
HUNGER_HUD_TICK = 0.5 -- 0.1
--Some hunger settings
hbhunger.exhaustion = {} -- Exhaustion is experimental!
HUNGER_HUNGER_TICK = 600 -- time in seconds after that 1 hunger point is taken (600)
HUNGER_EXHAUST_DIG = 3 -- exhaustion increased this value after digged node
HUNGER_EXHAUST_PLACE = 1 -- exhaustion increased this value after placed
HUNGER_EXHAUST_MOVE = 0.3 -- exhaustion increased this value if player movement detected
HUNGER_EXHAUST_LVL = 160 -- at what exhaustion player satiation gets lowerd
--[[load custom settings
local set = io.open(minetest.get_modpath("hbhunger").."/hbhunger.conf", "r")
if set then
dofile(minetest.get_modpath("hbhunger").."/hbhunger.conf")
set:close()
end--]]
local function custom_hud(player)
hb.init_hudbar(player, "satiation", hbhunger.get_hunger(player))
end
dofile(minetest.get_modpath("hbhunger").."/hunger.lua")
-- register satiation hudbar
hb.register_hudbar(
"satiation", 0xFFFFFF, "Satiation",
{
icon = "hbhunger_icon.png",
bgicon = "hbhunger_bgicon.png",
bar = "hbhunger_bar.png"
},
20, 30, false
)
-- update hud elemtents if value has changed
local function update_hud(player)
local name = player:get_player_name()
local h_out = tonumber(hbhunger.hunger_out[name])
local h = tonumber(hbhunger.hunger[name])
if h_out ~= h then
hbhunger.hunger_out[name] = h
hb.change_hudbar(player, "satiation", h)
end
end
hbhunger.get_hunger = function(player)
local inv = player:get_inventory()
if not inv then return nil end
local hgp = inv:get_stack("hunger", 1):get_count()
if hgp == 0 then
hgp = 21
inv:set_stack("hunger", 1, ItemStack({name = ":", count = hgp}))
else
hgp = hgp
end
return hgp - 1
end
hbhunger.set_hunger = function(player)
local inv = player:get_inventory()
local name = player:get_player_name()
local value = hbhunger.hunger[name]
if not inv or not value then return nil end
if value > 30 then value = 30 end
if value < 0 then value = 0 end
inv:set_stack("hunger", 1, ItemStack({name = ":", count = value + 1}))
return true
end
minetest.register_on_joinplayer(function(player)
local name = player:get_player_name()
local inv = player:get_inventory()
inv:set_size("hunger", 1)
hbhunger.hunger[name] = hbhunger.get_hunger(player)
hbhunger.hunger_out[name] = hbhunger.hunger[name]
hbhunger.exhaustion[name] = 0
custom_hud(player)
hbhunger.set_hunger(player)
end)
minetest.register_on_respawnplayer(function(player)
-- reset hunger (and save)
local name = player:get_player_name()
hbhunger.hunger[name] = 20
hbhunger.set_hunger(player)
hbhunger.exhaustion[name] = 0
end)
local main_timer = 0
local timer = 0
local timer2 = 0
minetest.register_globalstep(function(dtime)
main_timer = main_timer + dtime
timer = timer + dtime
timer2 = timer2 + dtime
if main_timer > HUNGER_HUD_TICK
or timer > 4
or timer2 > HUNGER_HUNGER_TICK then
if main_timer > HUNGER_HUD_TICK then
main_timer = 0
end
for _,player in ipairs(minetest.get_connected_players()) do
local name = player:get_player_name()
local h = tonumber(hbhunger.hunger[name])
local hp = player:get_hp()
if timer > 4 then
-- heal player by 1 hp if not dead and satiation is > 15
if h > 15
and hp > 0
and player:get_breath() > 0 then
player:set_hp(hp + 1)
-- or damage player by 1 hp if satiation is < 2
elseif h <= 1 then
if hp - 1 >= 0 then
player:set_hp(hp - 1)
end
end
end
-- lower satiation by 1 point after xx seconds
if timer2 > HUNGER_HUNGER_TICK then
if h > 0 then
h = h - 1
hbhunger.hunger[name] = h
hbhunger.set_hunger(player)
end
end
-- update hud elements
update_hud(player)
-- Determine if player is walking
local controls = player:get_player_control()
if controls.up
or controls.down
or controls.left
or controls.right then
hbhunger.handle_node_actions(nil, nil, player)
end
end
end
if timer > 4 then
timer = 0
end
if timer2 > HUNGER_HUNGER_TICK then
timer2 = 0
end
end)
end -- end if damage enabled
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment