Limited health

pull/37/head
Brandon 2016-06-03 22:33:11 -05:00
parent 0f686c981e
commit d8e87a8775
6 changed files with 45 additions and 18 deletions

View File

@ -35,15 +35,15 @@ local function adventuretest_die_player(player)
end end
bones_on_dieplayer(player) bones_on_dieplayer(player)
skills_on_dieplayer(player) skills_on_dieplayer(player)
hunger.update_hunger(player, 20) hunger.update_hunger(player, 20)
affects.player_died(player) affects.player_died(player)
player:set_hp(20) if sethome_respawnplayer(player) == false then
if sethome_respawnplayer(player) == false then mg_villages.spawnplayer(player)
mg_villages.spawnplayer(player) end
end energy.respawnplayer(player)
energy.respawnplayer(player) pd.increment(name,STAT_DIED,1)
pd.increment(name,STAT_DIED,1) player:set_hp(pd.get_number(name,"max_hp"))
return true return true
end end
minetest.register_on_dieplayer(adventuretest_die_player) minetest.register_on_dieplayer(adventuretest_die_player)
@ -51,7 +51,7 @@ minetest.register_on_dieplayer(adventuretest_die_player)
local function adventuretest_dignode(pos, node, digger) local function adventuretest_dignode(pos, node, digger)
--print("on_dignode") --print("on_dignode")
-- going to try to consolidate all on_dignode calls here so there is only one function call -- going to try to consolidate all on_dignode calls here so there is only one function call
local name = digger:get_player_name()
-- ON DIG NODE FOR MONEY MOD -- ON DIG NODE FOR MONEY MOD
for k,v in pairs(money.convert_items) do for k,v in pairs(money.convert_items) do
if ( node.name == money.convert_items[k].dig_block ) then if ( node.name == money.convert_items[k].dig_block ) then
@ -126,9 +126,19 @@ minetest.register_on_generated(on_generated)
local function on_join(player) local function on_join(player)
pd.load_player(player:get_player_name()) pd.load_player(player:get_player_name())
local name = player:get_player_name()
if minetest.setting_getbool("enable_damage") then if minetest.setting_getbool("enable_damage") then
hunger_join_player(player) hunger_join_player(player)
end end
-- for backward compatibility if player was created before max hp was added
if pd.get_number(name,"max_hp") == 0 then
local l = pd.get(name,"level")
local hp = 6 + (( math.floor(l.level / 2) ) * 2)
if hp > 20 then
hp = 20
end
pd.set(name,"max_hp",hp)
end
end end
minetest.register_on_joinplayer(on_join) minetest.register_on_joinplayer(on_join)
@ -151,6 +161,8 @@ local function on_new(player)
pd.set(name,"jump",1) pd.set(name,"jump",1)
pd.set(name,"gravity",1) pd.set(name,"gravity",1)
pd.set(name,"level", {level=1,exp=0}) pd.set(name,"level", {level=1,exp=0})
pd.set(name,"max_health",6)
player:set_hp(6)
skills.set_default_skills(name) skills.set_default_skills(name)
pd.save_player(name) pd.save_player(name)
mg_villages.on_newplayer(player) mg_villages.on_newplayer(player)

View File

@ -17,11 +17,15 @@ function energy.update_energy(p,name,dtime)
if math.random(0,4) == 1 then if math.random(0,4) == 1 then
minetest.sound_play("default_snore",{object=p}) minetest.sound_play("default_snore",{object=p})
end end
p:set_hp(p:get_hp()+2) if p:get_hp() < pd.get_number(name,"max_hp") then
p:set_hp(p:get_hp()+2)
end
end end
if anim.animation == "sit" then if anim.animation == "sit" then
adj = adj + 0.5 adj = adj + 0.5
p:set_hp(p:get_hp()+1) if p:get_hp() < pd.get_number(name,"max_hp") then
p:set_hp(p:get_hp()+1)
end
end end
-- adjust their energy -- adjust their energy

View File

@ -32,7 +32,7 @@ if damage_enabled then
number = 20, number = 20,
alignment = {x = -1, y = -1}, alignment = {x = -1, y = -1},
offset = HUD_HEALTH_OFFSET, offset = HUD_HEALTH_OFFSET,
background = "hud_heart_bg.png", --background = "hud_heart_bg.png",
events = { events = {
{ {
type = "damage", type = "damage",

View File

@ -94,11 +94,13 @@ function do_health_tick(player,name,dtime)
-- 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 lvl > HUNGER_HEAL_LVL and air > 0 then if lvl > HUNGER_HEAL_LVL and air > 0 then
player:set_hp(hp + HUNGER_HEAL) if hp < pd.get_number(name,"max_hp") then
player:set_hp(hp + HUNGER_HEAL)
end
end end
-- or damage player by 1 hp if saturation is < 2 (of 30) -- or damage player by 1 hp if saturation is < 2 (of 30)
if lvl < HUNGER_STARVE_LVL then if lvl < HUNGER_STARVE_LVL then
player:set_hp(hp - HUNGER_STARVE) player:set_hp(hp - HUNGER_STARVE)
end end
end end
@ -148,6 +150,7 @@ function hunger.item_eat(hunger_change, replace_with_item, poisen, heal, sound)
local name = user:get_player_name() local name = user:get_player_name()
local sat = pd.get_number(name,"hunger_lvl") local sat = pd.get_number(name,"hunger_lvl")
local hp = user:get_hp() local hp = user:get_hp()
local max_hp = pd.get_number(name,"max_hp")
-- Saturation -- Saturation
if sat < HUNGER_MAX and hunger_change then if sat < HUNGER_MAX and hunger_change then
sat = sat + hunger_change sat = sat + hunger_change
@ -157,10 +160,10 @@ function hunger.item_eat(hunger_change, replace_with_item, poisen, heal, sound)
end end
end end
-- Healing -- Healing
if hp < 20 and heal then if hp < max_hp and heal then
hp = hp + heal hp = hp + heal
if hp > 20 then if hp > max_hp then
hp = 20 hp = max_hp
end end
user:set_hp(hp) user:set_hp(hp)
end end

View File

@ -144,6 +144,9 @@ armor.update_armor = function(self, player)
self.def[name].state = state self.def[name].state = state
self.def[name].count = items self.def[name].count = items
if heal_max > math.random(100) then if heal_max > math.random(100) then
if self.player_hp[name] > pd.get_number(name,"max_hp") then
self.player_hp[name] = pd.get_number(name,"max_hp")
end
player:set_hp(self.player_hp[name]) player:set_hp(self.player_hp[name])
return return
end end

View File

@ -72,6 +72,11 @@ function skills.add_exp(name, exp)
gain = 10.0, gain = 10.0,
}) })
pd.set(name,"level",l) pd.set(name,"level",l)
local hp = 6 + (( math.floor(l.level / 2) ) * 2)
if hp > 20 then
hp = 20
end
pd.set(name,"max_hp",hp)
end end
end end