Rename global table to “hbhunger”

This commit is contained in:
Wuzzy 2015-02-27 11:17:47 +01:00
parent 867d158645
commit e34e66a989
2 changed files with 39 additions and 39 deletions

View File

@ -1,9 +1,9 @@
-- Keep these for backwards compatibility
function hunger.save_hunger(player)
hunger.set_hunger(player)
function hbhunger.save_hunger(player)
hbhunger.set_hunger(player)
end
function hunger.load_hunger(player)
hunger.get_hunger(player)
function hbhunger.load_hunger(player)
hbhunger.get_hunger(player)
end
-- Poison player
@ -20,19 +20,19 @@ local function poisenp(tick, time, time_left, player)
end
function hunger.item_eat(hunger_change, replace_with_item, poisen, heal)
function hbhunger.item_eat(hunger_change, replace_with_item, poisen, heal)
return function(itemstack, user, pointed_thing)
if itemstack:take_item() ~= nil and user ~= nil then
local name = user:get_player_name()
local h = tonumber(hunger.hunger[name])
local h = tonumber(hbhunger.hunger[name])
local hp = user:get_hp()
-- Saturation
if h < 30 and hunger_change then
h = h + hunger_change
if h > 30 then h = 30 end
hunger.hunger[name] = h
hunger.set_hunger(user)
hbhunger.hunger[name] = h
hbhunger.set_hunger(user)
end
-- Healing
if hp < 20 and heal then
@ -56,7 +56,7 @@ end
local function overwrite(name, hunger_change, replace_with_item, poisen, heal)
local tab = minetest.registered_items[name]
if tab == nil then return end
tab.on_use = hunger.item_eat(hunger_change, replace_with_item, poisen, heal)
tab.on_use = hbhunger.item_eat(hunger_change, replace_with_item, poisen, heal)
minetest.registered_items[name] = tab
end
@ -363,12 +363,12 @@ if minetest.get_modpath("ferns") ~= nil then
end
-- player-action based hunger changes
function hunger.handle_node_actions(pos, oldnode, player, ext)
function hbhunger.handle_node_actions(pos, oldnode, player, ext)
if not player or not player:is_player() then
return
end
local name = player:get_player_name()
local exhaus = hunger.exhaustion[name]
local exhaus = hbhunger.exhaustion[name]
local new = HUNGER_EXHAUST_PLACE
-- placenode event
if not ext then
@ -381,14 +381,14 @@ function hunger.handle_node_actions(pos, oldnode, player, ext)
exhaus = exhaus + new
if exhaus > HUNGER_EXHAUST_LVL then
exhaus = 0
local h = tonumber(hunger.hunger[name])
local h = tonumber(hbhunger.hunger[name])
h = h - 1
if h < 0 then h = 0 end
hunger.hunger[name] = h
hunger.set_hunger(player)
hbhunger.hunger[name] = h
hbhunger.set_hunger(player)
end
hunger.exhaustion[name] = exhaus
hbhunger.exhaustion[name] = exhaus
end
minetest.register_on_placenode(hunger.handle_node_actions)
minetest.register_on_dignode(hunger.handle_node_actions)
minetest.register_on_placenode(hbhunger.handle_node_actions)
minetest.register_on_dignode(hbhunger.handle_node_actions)

View File

@ -1,10 +1,10 @@
if minetest.setting_getbool("enable_damage") then
hunger = {}
hbhunger = {}
-- HUD statbar values
hunger.hunger = {}
hunger.hunger_out = {}
hbhunger.hunger = {}
hbhunger.hunger_out = {}
-- HUD item ids
local hunger_hud = {}
@ -12,7 +12,7 @@ local hunger_hud = {}
HUNGER_HUD_TICK = 0.1
--Some hunger settings
hunger.exhaustion = {} -- Exhaustion is experimental!
hbhunger.exhaustion = {} -- Exhaustion is experimental!
HUNGER_HUNGER_TICK = 800 -- time in seconds after that 1 hunger point is taken
HUNGER_EXHAUST_DIG = 3 -- exhaustion increased this value after digged node
@ -29,7 +29,7 @@ if set then
end
local function custom_hud(player)
hb.init_hudbar(player, "saturation", hunger.get_hunger(player))
hb.init_hudbar(player, "saturation", hbhunger.get_hunger(player))
end
dofile(minetest.get_modpath("hbhunger").."/hunger.lua")
@ -41,15 +41,15 @@ hb.register_hudbar("saturation", 0xFFFFFF, "Saturation", { icon = "hbhunger_icon
local function update_hud(player)
local name = player:get_player_name()
--hunger
local h_out = tonumber(hunger.hunger_out[name])
local h = tonumber(hunger.hunger[name])
local h_out = tonumber(hbhunger.hunger_out[name])
local h = tonumber(hbhunger.hunger[name])
if h_out ~= h then
hunger.hunger_out[name] = h
hbhunger.hunger_out[name] = h
hb.change_hudbar(player, "saturation", h)
end
end
hunger.get_hunger = function(player)
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()
@ -62,10 +62,10 @@ hunger.get_hunger = function(player)
return hgp-1
end
hunger.set_hunger = function(player)
hbhunger.set_hunger = function(player)
local inv = player:get_inventory()
local name = player:get_player_name()
local value = hunger.hunger[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
@ -79,19 +79,19 @@ minetest.register_on_joinplayer(function(player)
local name = player:get_player_name()
local inv = player:get_inventory()
inv:set_size("hunger",1)
hunger.hunger[name] = hunger.get_hunger(player)
hunger.hunger_out[name] = hunger.hunger[name]
hunger.exhaustion[name] = 0
hbhunger.hunger[name] = hbhunger.get_hunger(player)
hbhunger.hunger_out[name] = hbhunger.hunger[name]
hbhunger.exhaustion[name] = 0
custom_hud(player)
hunger.set_hunger(player)
hbhunger.set_hunger(player)
end)
minetest.register_on_respawnplayer(function(player)
-- reset hunger (and save)
local name = player:get_player_name()
hunger.hunger[name] = 20
hunger.set_hunger(player)
hunger.exhaustion[name] = 0
hbhunger.hunger[name] = 20
hbhunger.set_hunger(player)
hbhunger.exhaustion[name] = 0
end)
local main_timer = 0
@ -106,7 +106,7 @@ minetest.register_globalstep(function(dtime)
for _,player in ipairs(minetest.get_connected_players()) do
local name = player:get_player_name()
local h = tonumber(hunger.hunger[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 saturation is > 15 (of 30)
@ -121,8 +121,8 @@ minetest.register_globalstep(function(dtime)
if timer2 > HUNGER_HUNGER_TICK then
if h > 0 then
h = h-1
hunger.hunger[name] = h
hunger.set_hunger(player)
hbhunger.hunger[name] = h
hbhunger.set_hunger(player)
end
end
@ -132,7 +132,7 @@ minetest.register_globalstep(function(dtime)
local controls = player:get_player_control()
-- Determine if the player is walking
if controls.up or controls.down or controls.left or controls.right then
hunger.handle_node_actions(nil, nil, player)
hbhunger.handle_node_actions(nil, nil, player)
end
end
end