mirror of
git://repo.or.cz/minetest_hbhunger.git
synced 2024-12-24 00:40:20 +01:00
Make entire mod a no-op if damage is disabled
This commit is contained in:
parent
8ec358cbfd
commit
f1f33a7fc4
29
init.lua
29
init.lua
@ -1,3 +1,5 @@
|
|||||||
|
if minetest.setting_getbool("enable_damage") then
|
||||||
|
|
||||||
hunger = {}
|
hunger = {}
|
||||||
|
|
||||||
-- HUD statbar values
|
-- HUD statbar values
|
||||||
@ -27,10 +29,7 @@ if set then
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function custom_hud(player)
|
local function custom_hud(player)
|
||||||
if minetest.setting_getbool("enable_damage") then
|
|
||||||
--hunger
|
|
||||||
hb.init_hudbar(player, "saturation", hunger.get_hunger(player))
|
hb.init_hudbar(player, "saturation", hunger.get_hunger(player))
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
dofile(minetest.get_modpath("hunger").."/hunger.lua")
|
dofile(minetest.get_modpath("hunger").."/hunger.lua")
|
||||||
@ -109,36 +108,34 @@ minetest.after(2.5, function()
|
|||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
|
|
||||||
-- only proceed if damage is enabled
|
-- only proceed if damage is enabled
|
||||||
if minetest.setting_getbool("enable_damage") then
|
local h = tonumber(hunger.hunger[name])
|
||||||
local h = tonumber(hunger.hunger[name])
|
local hp = player:get_hp()
|
||||||
local hp = player:get_hp()
|
if timer > 4 then
|
||||||
if timer > 4 then
|
|
||||||
-- heal player by 1 hp if not dead and saturation is > 15 (of 30)
|
-- heal player by 1 hp if not dead and saturation is > 15 (of 30)
|
||||||
if h > 15 and hp > 0 and player:get_breath() > 0 then
|
if h > 15 and hp > 0 and player:get_breath() > 0 then
|
||||||
player:set_hp(hp+1)
|
player:set_hp(hp+1)
|
||||||
-- or damage player by 1 hp if saturation is < 2 (of 30)
|
-- or damage player by 1 hp if saturation is < 2 (of 30)
|
||||||
elseif h <= 1 and minetest.setting_getbool("enable_damage") then
|
elseif h <= 1 then
|
||||||
if hp-1 >= 0 then player:set_hp(hp-1) end
|
if hp-1 >= 0 then player:set_hp(hp-1) end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- lower saturation by 1 point after xx seconds
|
-- lower saturation by 1 point after xx seconds
|
||||||
if timer2 > HUNGER_HUNGER_TICK then
|
if timer2 > HUNGER_HUNGER_TICK then
|
||||||
if h > 0 then
|
if h > 0 then
|
||||||
h = h-1
|
h = h-1
|
||||||
hunger.hunger[name] = h
|
hunger.hunger[name] = h
|
||||||
hunger.set_hunger(player)
|
hunger.set_hunger(player)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- update all hud elements
|
-- update all hud elements
|
||||||
update_hud(player)
|
update_hud(player)
|
||||||
|
|
||||||
local controls = player:get_player_control()
|
local controls = player:get_player_control()
|
||||||
-- Determine if the player is walking
|
-- Determine if the player is walking
|
||||||
if controls.up or controls.down or controls.left or controls.right then
|
if controls.up or controls.down or controls.left or controls.right then
|
||||||
hunger.handle_node_actions(nil, nil, player)
|
hunger.handle_node_actions(nil, nil, player)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -146,3 +143,5 @@ minetest.after(2.5, function()
|
|||||||
if timer2 > HUNGER_HUNGER_TICK then timer2 = 0 end
|
if timer2 > HUNGER_HUNGER_TICK then timer2 = 0 end
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user