hunger_ng support

This commit is contained in:
tacotexmex 2018-02-25 22:15:18 +01:00
parent c51ac933ba
commit 4861806fd5
2 changed files with 20 additions and 5 deletions

View File

@ -1,3 +1,4 @@
player_monoids? player_monoids?
hudbars? hudbars?
hbhunger? hbhunger?
hunger_ng?

View File

@ -20,8 +20,16 @@ local stamina_timer = 0
local breath_timer = 0 local breath_timer = 0
local hudbars = minetest.get_modpath("hudbars") or false local hudbars = minetest.get_modpath("hudbars") or false
local starve = minetest.get_modpath("hbhunger") or false
local monoids = minetest.get_modpath("player_monoids") or false local monoids = minetest.get_modpath("player_monoids") or false
local starve
if minetest.get_modpath("hbhunger") then
starve = "hbhunger"
elseif minetest.get_modpath("hunger_ng") then
starve = "hunger_ng"
--starve_drain = starve_drain * -1
else
starve = false
end
-- Functions -- Functions
@ -71,8 +79,13 @@ end
local function drain_hunger(player, hunger, name) local function drain_hunger(player, hunger, name)
if hunger > 0 then if hunger > 0 then
hbhunger.hunger[name] = hunger - starve_drain local newhunger = hunger - starve_drain
hbhunger.set_hunger_raw(player) if starve == "hbhunger" then
hbhunger.hunger[name] = newhunger
hbhunger.set_hunger_raw(player)
elseif starve == "hunger_ng" then
player:set_attribute("hunger_ng:hunger", newhunger)
end
end end
end end
@ -141,7 +154,6 @@ minetest.register_globalstep(function(dtime)
elseif key == "Use" and not dir then elseif key == "Use" and not dir then
key_press = ctrl.aux1 key_press = ctrl.aux1
end end
-- if key == "W" and dir then -- if key == "W" and dir then
-- key_press = ctrl.aux1 and ctrl.up or key_press and ctrl.up -- key_press = ctrl.aux1 and ctrl.up or key_press and ctrl.up
-- elseif key == "W" then -- elseif key == "W" then
@ -155,8 +167,10 @@ minetest.register_globalstep(function(dtime)
local ground = minetest.get_node_or_nil({x=pos.x, y=pos.y-1, z=pos.z}) local ground = minetest.get_node_or_nil({x=pos.x, y=pos.y-1, z=pos.z})
local walkable = false local walkable = false
local player_stamina = tonumber(player:get_attribute("stamina")) local player_stamina = tonumber(player:get_attribute("stamina"))
if starve then if starve == "hbhunger" then
hunger = tonumber(hbhunger.hunger[name]) hunger = tonumber(hbhunger.hunger[name])
elseif starve == "hunger_ng" then
hunger = tonumber(player:get_attribute("hunger_ng:hunger"))
end end
if ground ~= nil then if ground ~= nil then
walkable = minetest.registered_nodes[ground.name].walkable walkable = minetest.registered_nodes[ground.name].walkable