Change food bar when player is food poisoned
This commit is contained in:
parent
d454aa7745
commit
0167a2f41b
|
@ -53,6 +53,15 @@ function mcl_hunger.eat(hp_change, replace_with_item, itemstack, user, pointed_t
|
||||||
return func(itemstack, user, pointed_thing)
|
return func(itemstack, user, pointed_thing)
|
||||||
end
|
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
|
-- Poison player
|
||||||
local function poisonp(tick, time, time_left, damage, exhaustion, player)
|
local function poisonp(tick, time, time_left, damage, exhaustion, player)
|
||||||
-- First check if player is still there
|
-- First check if player is still there
|
||||||
|
@ -69,8 +78,7 @@ local function poisonp(tick, time, time_left, damage, exhaustion, player)
|
||||||
else
|
else
|
||||||
mcl_hunger.poisonings[player:get_player_name()] = mcl_hunger.poisonings[player:get_player_name()] - 1
|
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
|
if mcl_hunger.poisonings[player:get_player_name()] <= 0 then
|
||||||
-- Reset HUD bar color
|
reset_bars(player)
|
||||||
hb.change_hudbar(player, "health", nil, nil, "hudbars_icon_health.png", nil, "hudbars_bar_health.png")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -85,7 +93,7 @@ end
|
||||||
-- Immediately stop all poisonings for this player
|
-- Immediately stop all poisonings for this player
|
||||||
function mcl_hunger.stop_poison(player)
|
function mcl_hunger.stop_poison(player)
|
||||||
mcl_hunger.poisonings[player:get_player_name()] = 0
|
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
|
end
|
||||||
|
|
||||||
local poisonrandomizer = PseudoRandom(os.time())
|
local poisonrandomizer = PseudoRandom(os.time())
|
||||||
|
@ -181,8 +189,16 @@ function mcl_hunger.item_eat(hunger_change, replace_with_item, poisontime, poiso
|
||||||
do_poison = true
|
do_poison = true
|
||||||
end
|
end
|
||||||
if do_poison then
|
if do_poison then
|
||||||
-- Set poison bar
|
-- Set poison bars
|
||||||
hb.change_hudbar(user, "health", nil, nil, "hbhunger_icon_health_poison.png", nil, "hbhunger_bar_health_poison.png")
|
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
|
mcl_hunger.poisonings[name] = mcl_hunger.poisonings[name] + 1
|
||||||
poisonp(1, poisontime, 0, poison, exhaust, user)
|
poisonp(1, poisontime, 0, poison, exhaust, user)
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,10 +10,12 @@ if minetest.setting_getbool("enable_damage") then
|
||||||
mcl_hunger = {}
|
mcl_hunger = {}
|
||||||
mcl_hunger.food = {}
|
mcl_hunger.food = {}
|
||||||
|
|
||||||
-- Debug Mode. If enabled, saturation and exhaustion are shown as well
|
-- Debug Mode. If enabled, saturation and exhaustion are shown as well.
|
||||||
local debug = minetest.setting_getbool("mcl_hunger_debug")
|
-- NOTE: Read-only. The setting should only be read at the beginning, this mod is not
|
||||||
if debug == nil then
|
-- prepared to change this setting later.
|
||||||
debug = false
|
mcl_hunger.debug = minetest.setting_getbool("mcl_hunger_debug")
|
||||||
|
if mcl_hunger.debug == nil then
|
||||||
|
mcl_hunger.debug = false
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[ Data value format notes:
|
--[[ Data value format notes:
|
||||||
|
@ -57,7 +59,7 @@ end
|
||||||
|
|
||||||
local function init_hud(player)
|
local function init_hud(player)
|
||||||
hb.init_hudbar(player, "hunger", mcl_hunger.get_hunger(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, "saturation", mcl_hunger.get_saturation(player), mcl_hunger.get_hunger(player)*10)
|
||||||
hb.init_hudbar(player, "exhaustion", mcl_hunger.get_exhaustion(player))
|
hb.init_hudbar(player, "exhaustion", mcl_hunger.get_exhaustion(player))
|
||||||
end
|
end
|
||||||
|
@ -65,7 +67,7 @@ end
|
||||||
|
|
||||||
-- HUD updating functions for Debug Mode. No-op if not in Debug Mode
|
-- HUD updating functions for Debug Mode. No-op if not in Debug Mode
|
||||||
function mcl_hunger.update_saturation_hud(player, saturation, hunger)
|
function mcl_hunger.update_saturation_hud(player, saturation, hunger)
|
||||||
if debug then
|
if mcl_hunger.debug then
|
||||||
local satulimit
|
local satulimit
|
||||||
if hunger then
|
if hunger then
|
||||||
satulimit = hunger * 10
|
satulimit = hunger * 10
|
||||||
|
@ -74,7 +76,7 @@ function mcl_hunger.update_saturation_hud(player, saturation, hunger)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function mcl_hunger.update_exhaustion_hud(player, exhaustion)
|
function mcl_hunger.update_exhaustion_hud(player, exhaustion)
|
||||||
if debug then
|
if mcl_hunger.debug then
|
||||||
hb.change_hudbar(player, "exhaustion", exhaustion)
|
hb.change_hudbar(player, "exhaustion", exhaustion)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -83,7 +85,7 @@ dofile(minetest.get_modpath("mcl_hunger").."/hunger.lua")
|
||||||
|
|
||||||
-- register saturation hudbar
|
-- 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)
|
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("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"))
|
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
|
end
|
||||||
|
|
BIN
mods/PLAYER/mcl_hunger/textures/mcl_hunger_bar_foodpoison.png
Normal file
BIN
mods/PLAYER/mcl_hunger/textures/mcl_hunger_bar_foodpoison.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 72 B |
BIN
mods/PLAYER/mcl_hunger/textures/mcl_hunger_icon_foodpoison.png
Normal file
BIN
mods/PLAYER/mcl_hunger/textures/mcl_hunger_icon_foodpoison.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 206 B |
Loading…
Reference in New Issue
Block a user