1
0
Fork 0

Change food bar when player is food poisoned

This commit is contained in:
Wuzzy 2017-05-21 01:32:05 +02:00
parent d454aa7745
commit 0167a2f41b
4 changed files with 31 additions and 13 deletions

View File

@ -53,6 +53,15 @@ function mcl_hunger.eat(hp_change, replace_with_item, itemstack, user, pointed_t
return func(itemstack, user, pointed_thing)
end
-- Reset HUD bars after poisoning
local function reset_bars(player)
hb.change_hudbar(player, "health", nil, nil, "hudbars_icon_health.png", nil, "hudbars_bar_health.png")
hb.change_hudbar(player, "hunger", nil, nil, "hbhunger_icon.png", nil, "hbhunger_bar.png")
if mcl_hunger.debug then
hb.change_hudbar(player, "exhaustion", nil, nil, nil, nil, "mcl_hunger_bar_exhaustion.png")
end
end
-- Poison player
local function poisonp(tick, time, time_left, damage, exhaustion, player)
-- First check if player is still there
@ -69,8 +78,7 @@ local function poisonp(tick, time, time_left, damage, exhaustion, player)
else
mcl_hunger.poisonings[player:get_player_name()] = mcl_hunger.poisonings[player:get_player_name()] - 1
if mcl_hunger.poisonings[player:get_player_name()] <= 0 then
-- Reset HUD bar color
hb.change_hudbar(player, "health", nil, nil, "hudbars_icon_health.png", nil, "hudbars_bar_health.png")
reset_bars(player)
end
end
@ -85,7 +93,7 @@ end
-- Immediately stop all poisonings for this player
function mcl_hunger.stop_poison(player)
mcl_hunger.poisonings[player:get_player_name()] = 0
hb.change_hudbar(player, "health", nil, nil, "hudbars_icon_health.png", nil, "hudbars_bar_health.png")
reset_bars(player)
end
local poisonrandomizer = PseudoRandom(os.time())
@ -181,8 +189,16 @@ function mcl_hunger.item_eat(hunger_change, replace_with_item, poisontime, poiso
do_poison = true
end
if do_poison then
-- Set poison bar
hb.change_hudbar(user, "health", nil, nil, "hbhunger_icon_health_poison.png", nil, "hbhunger_bar_health_poison.png")
-- Set poison bars
if poison and poison > 0 then
hb.change_hudbar(user, "health", nil, nil, "hbhunger_icon_health_poison.png", nil, "hbhunger_bar_health_poison.png")
end
if exhaust and exhaust > 0 then
hb.change_hudbar(user, "hunger", nil, nil, "mcl_hunger_icon_foodpoison.png", nil, "mcl_hunger_bar_foodpoison.png")
if mcl_hunger.debug then
hb.change_hudbar(user, "exhaustion", nil, nil, nil, nil, "mcl_hunger_bar_foodpoison.png")
end
end
mcl_hunger.poisonings[name] = mcl_hunger.poisonings[name] + 1
poisonp(1, poisontime, 0, poison, exhaust, user)
end

View File

@ -10,10 +10,12 @@ if minetest.setting_getbool("enable_damage") then
mcl_hunger = {}
mcl_hunger.food = {}
-- Debug Mode. If enabled, saturation and exhaustion are shown as well
local debug = minetest.setting_getbool("mcl_hunger_debug")
if debug == nil then
debug = false
-- Debug Mode. If enabled, saturation and exhaustion are shown as well.
-- NOTE: Read-only. The setting should only be read at the beginning, this mod is not
-- prepared to change this setting later.
mcl_hunger.debug = minetest.setting_getbool("mcl_hunger_debug")
if mcl_hunger.debug == nil then
mcl_hunger.debug = false
end
--[[ Data value format notes:
@ -57,7 +59,7 @@ end
local function init_hud(player)
hb.init_hudbar(player, "hunger", mcl_hunger.get_hunger(player))
if debug then
if mcl_hunger.debug then
hb.init_hudbar(player, "saturation", mcl_hunger.get_saturation(player), mcl_hunger.get_hunger(player)*10)
hb.init_hudbar(player, "exhaustion", mcl_hunger.get_exhaustion(player))
end
@ -65,7 +67,7 @@ end
-- HUD updating functions for Debug Mode. No-op if not in Debug Mode
function mcl_hunger.update_saturation_hud(player, saturation, hunger)
if debug then
if mcl_hunger.debug then
local satulimit
if hunger then
satulimit = hunger * 10
@ -74,7 +76,7 @@ function mcl_hunger.update_saturation_hud(player, saturation, hunger)
end
end
function mcl_hunger.update_exhaustion_hud(player, exhaustion)
if debug then
if mcl_hunger.debug then
hb.change_hudbar(player, "exhaustion", exhaustion)
end
end
@ -83,7 +85,7 @@ dofile(minetest.get_modpath("mcl_hunger").."/hunger.lua")
-- register saturation hudbar
hb.register_hudbar("hunger", 0xFFFFFF, S("Food"), { icon = "hbhunger_icon.png", bgicon = "hbhunger_bgicon.png", bar = "hbhunger_bar.png" }, 20, 20, false)
if debug then
if mcl_hunger.debug then
hb.register_hudbar("saturation", 0xFFFFFF, S("Saturation"), { icon = "mcl_hunger_icon_saturation.png", bgicon = "mcl_hunger_bgicon_saturation.png", bar = "mcl_hunger_bar_saturation.png" }, mcl_hunger.SATURATION_INIT, 200, false, S("%s: %d/%d"))
hb.register_hudbar("exhaustion", 0xFFFFFF, S("Exhaust."), { icon = "mcl_hunger_icon_exhaustion.png", bgicon = "mcl_hunger_bgicon_exhaustion.png", bar = "mcl_hunger_bar_exhaustion.png" }, 0, mcl_hunger.EXHAUST_LVL, false, S("%s: %d/%d"))
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 206 B