re-check player hp before healing
parent
209c8cfc39
commit
0df522a11e
32
mobs_api.lua
32
mobs_api.lua
|
@ -115,6 +115,38 @@ mobs.npcs.message_on_rightclick = function(self,player,data)
|
|||
mobs.npcs.send_chat_message(playername,msg,mobname)
|
||||
end
|
||||
|
||||
local function heal_loop(player,hp_max,c)
|
||||
|
||||
local hp = player:get_hp()
|
||||
local hp = hp + 1
|
||||
if hp > hp_max then hp = hp_max end
|
||||
-- Set new hp
|
||||
player:set_hp(hp)
|
||||
|
||||
-- Start couning in case to avoid endless loop in case the player is hurting while healing...
|
||||
if not c then
|
||||
c = 1
|
||||
else
|
||||
c = c+1
|
||||
end
|
||||
|
||||
-- Start again if health is not maxed
|
||||
-- And loop as not reached its limit (30)
|
||||
if ( c <= 30 ) and ( hp < hp_max ) then
|
||||
minetest.after(1,heal_loop,player,hp_max,c)
|
||||
end
|
||||
end
|
||||
|
||||
mobs.npcs.heal_on_rightclick = function(self,player,data)
|
||||
|
||||
|
||||
-- Get current HP and HP_MAX
|
||||
-- local hp = player:get_hp()
|
||||
local hp_max = player:get_properties().hp_max
|
||||
-- Calculate new hp
|
||||
heal_loop(player,hp_max)
|
||||
mobs.npcs.message_on_rightclick(self,player,data)
|
||||
end
|
||||
|
||||
|
||||
-- Register messages
|
||||
|
|
|
@ -121,7 +121,16 @@ mobs.npcs.interactions = {
|
|||
},
|
||||
on_rightclick = mobs.npcs.message_on_rightclick,
|
||||
},
|
||||
|
||||
-- TODO: Set a timeout between heals with a different message too
|
||||
-- TODO: Or set a limit per player per days
|
||||
heal = {
|
||||
icon = icprefix..'healer.png',
|
||||
desc = S("Heal the player"),
|
||||
formfields = {
|
||||
{'textarea','message','',4},
|
||||
},
|
||||
on_rightclick = mobs.npcs.heal_on_rightclick,
|
||||
},
|
||||
-- Following actions are planned but do not exist at the moment
|
||||
--
|
||||
dialog = {
|
||||
|
@ -139,11 +148,6 @@ mobs.npcs.interactions = {
|
|||
desc = S("Open a special inventory where the player can give item and received some transformed output"),
|
||||
disabled = true,
|
||||
},
|
||||
heal = {
|
||||
icon = icprefix..'healer.png',
|
||||
desc = S("Heal the player"),
|
||||
disabled = true,
|
||||
},
|
||||
give = {
|
||||
icon = icprefix..'giver.png',
|
||||
desc = S("Give something to the player"),
|
||||
|
@ -170,10 +174,10 @@ mob_def._spawner_pos = nil
|
|||
local textures_string
|
||||
|
||||
-- Get textures
|
||||
local textures = mobs.npcs.get_textures_array("character_lambda_",modname)
|
||||
if textures then
|
||||
mob_def.textures = textures
|
||||
end
|
||||
-- local textures = mobs.npcs.get_textures_array("character_lambda_",modname)
|
||||
-- if textures then
|
||||
-- mob_def.textures = textures
|
||||
-- end
|
||||
|
||||
|
||||
|
||||
|
@ -414,7 +418,7 @@ mobs.npcs.update_cmob_properties = function(pos, player, mob)
|
|||
-- Register to global table
|
||||
set_mob_data(pos,data)
|
||||
|
||||
print(dump(self))
|
||||
-- print(dump(self))
|
||||
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue