Limited health
This commit is contained in:
parent
0f686c981e
commit
d8e87a8775
@ -35,15 +35,15 @@ local function adventuretest_die_player(player)
|
||||
end
|
||||
bones_on_dieplayer(player)
|
||||
skills_on_dieplayer(player)
|
||||
hunger.update_hunger(player, 20)
|
||||
affects.player_died(player)
|
||||
player:set_hp(20)
|
||||
if sethome_respawnplayer(player) == false then
|
||||
mg_villages.spawnplayer(player)
|
||||
end
|
||||
energy.respawnplayer(player)
|
||||
pd.increment(name,STAT_DIED,1)
|
||||
return true
|
||||
hunger.update_hunger(player, 20)
|
||||
affects.player_died(player)
|
||||
if sethome_respawnplayer(player) == false then
|
||||
mg_villages.spawnplayer(player)
|
||||
end
|
||||
energy.respawnplayer(player)
|
||||
pd.increment(name,STAT_DIED,1)
|
||||
player:set_hp(pd.get_number(name,"max_hp"))
|
||||
return true
|
||||
end
|
||||
|
||||
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)
|
||||
--print("on_dignode")
|
||||
-- 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
|
||||
for k,v in pairs(money.convert_items) do
|
||||
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)
|
||||
pd.load_player(player:get_player_name())
|
||||
local name = player:get_player_name()
|
||||
if minetest.setting_getbool("enable_damage") then
|
||||
hunger_join_player(player)
|
||||
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
|
||||
minetest.register_on_joinplayer(on_join)
|
||||
|
||||
@ -151,6 +161,8 @@ local function on_new(player)
|
||||
pd.set(name,"jump",1)
|
||||
pd.set(name,"gravity",1)
|
||||
pd.set(name,"level", {level=1,exp=0})
|
||||
pd.set(name,"max_health",6)
|
||||
player:set_hp(6)
|
||||
skills.set_default_skills(name)
|
||||
pd.save_player(name)
|
||||
mg_villages.on_newplayer(player)
|
||||
|
@ -17,11 +17,15 @@ function energy.update_energy(p,name,dtime)
|
||||
if math.random(0,4) == 1 then
|
||||
minetest.sound_play("default_snore",{object=p})
|
||||
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
|
||||
if anim.animation == "sit" then
|
||||
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
|
||||
|
||||
-- adjust their energy
|
||||
|
@ -32,7 +32,7 @@ if damage_enabled then
|
||||
number = 20,
|
||||
alignment = {x = -1, y = -1},
|
||||
offset = HUD_HEALTH_OFFSET,
|
||||
background = "hud_heart_bg.png",
|
||||
--background = "hud_heart_bg.png",
|
||||
events = {
|
||||
{
|
||||
type = "damage",
|
||||
|
@ -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)
|
||||
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
|
||||
|
||||
-- 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)
|
||||
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 sat = pd.get_number(name,"hunger_lvl")
|
||||
local hp = user:get_hp()
|
||||
local max_hp = pd.get_number(name,"max_hp")
|
||||
-- Saturation
|
||||
if sat < HUNGER_MAX and hunger_change then
|
||||
sat = sat + hunger_change
|
||||
@ -157,10 +160,10 @@ function hunger.item_eat(hunger_change, replace_with_item, poisen, heal, sound)
|
||||
end
|
||||
end
|
||||
-- Healing
|
||||
if hp < 20 and heal then
|
||||
if hp < max_hp and heal then
|
||||
hp = hp + heal
|
||||
if hp > 20 then
|
||||
hp = 20
|
||||
if hp > max_hp then
|
||||
hp = max_hp
|
||||
end
|
||||
user:set_hp(hp)
|
||||
end
|
||||
|
@ -144,6 +144,9 @@ armor.update_armor = function(self, player)
|
||||
self.def[name].state = state
|
||||
self.def[name].count = items
|
||||
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])
|
||||
return
|
||||
end
|
||||
|
@ -72,6 +72,11 @@ function skills.add_exp(name, exp)
|
||||
gain = 10.0,
|
||||
})
|
||||
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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user