add support for drawing lifebar above mobs
@ -148,8 +148,11 @@ function fighting.hit(entity,attacker)
|
||||
--push mob back
|
||||
fighting.push_back(entity,dir)
|
||||
|
||||
--update lifebar
|
||||
mobf_lifebar.set(entity.lifebar,entity.object:get_hp()/entity.hp_max)
|
||||
|
||||
-- make it die
|
||||
if entity.object:get_hp() < 1 then
|
||||
if entity.object:get_hp() < 0.5 then
|
||||
--if entity.dynamic_data.generic.health < 1 then
|
||||
local result = entity.data.generic.kill_result
|
||||
if type(entity.data.generic.kill_result) == "function" then
|
||||
@ -187,7 +190,7 @@ function fighting.hit(entity,attacker)
|
||||
dbg_mobf.fighting_lvl2("MOBF: ".. entity.data.name
|
||||
.. " custom on kill handler superseeds generic handling")
|
||||
end
|
||||
|
||||
mobf_lifebar.del(entity.lifebar)
|
||||
return
|
||||
end
|
||||
|
||||
@ -846,6 +849,7 @@ function fighting.self_destruct_handler(entity,now)
|
||||
minetest.log(LOGLEVEL_NOTICE,
|
||||
"MOBF: self destruct without fire isn't really impressive!")
|
||||
end
|
||||
mobf_lifebar.del(entity.lifebar)
|
||||
spawning.remove(entity, "self destruct")
|
||||
return true
|
||||
end
|
||||
@ -1082,6 +1086,7 @@ function fighting.sun_damage_handler(entity,now)
|
||||
..damage .." damage because of sun")
|
||||
|
||||
entity.object:set_hp(entity.object:get_hp() - damage)
|
||||
mobf_lifebar.set(entity.lifebar,entity.object:get_hp()/entity.hp_max)
|
||||
|
||||
if entity.data.sound ~= nil then
|
||||
sound.play(mob_pos,entity.data.sound.sun_damage);
|
||||
@ -1090,6 +1095,7 @@ function fighting.sun_damage_handler(entity,now)
|
||||
if entity.object:get_hp() <= 0 then
|
||||
--if entity.dynamic_data.generic.health <= 0 then
|
||||
dbg_mobf.fighting_lvl2("Mob ".. entity.data.name .. " died of sun")
|
||||
mobf_lifebar.del(entity.lifebar)
|
||||
spawning.remove(entity,"died by sun")
|
||||
return true
|
||||
end
|
||||
|
@ -60,6 +60,7 @@ dofile (mobf_modpath .. "/utils/tracing.lua")
|
||||
dofile (mobf_modpath .. "/utils/geometry.lua")
|
||||
dofile (mobf_modpath .. "/utils/text.lua")
|
||||
dofile (mobf_modpath .. "/utils/permanent_data.lua")
|
||||
dofile (mobf_modpath .. "/lifebar.lua")
|
||||
dofile (mobf_modpath .. "/environment.lua")
|
||||
dofile (mobf_modpath .. "/movement_generic.lua")
|
||||
dofile (mobf_modpath .. "/graphics.lua")
|
||||
@ -158,6 +159,9 @@ function mobf_init_framework()
|
||||
minetest.log(LOGLEVEL_NOTICE,"MOBF: Initialize path handling subsystem..")
|
||||
mobf_path.init()
|
||||
|
||||
minetest.log(LOGLEVEL_NOTICE,"MOBF: Initialize lifebar subsystem..")
|
||||
mobf_lifebar.init()
|
||||
|
||||
minetest.log(LOGLEVEL_NOTICE,"MOBF: Initialize mobf supplied modules..")
|
||||
mobf_init_modules()
|
||||
|
||||
|
148
mobf/lifebar.lua
Normal file
@ -0,0 +1,148 @@
|
||||
-------------------------------------------------------------------------------
|
||||
-- Mob Framework Mod by Sapier
|
||||
--
|
||||
-- You may copy, use, modify or do nearly anything except removing this
|
||||
-- copyright notice.
|
||||
-- And of course you are NOT allow to pretend you have written it.
|
||||
--
|
||||
--! @file lifebar.lua
|
||||
--! @brief mobf_lifebar implementation
|
||||
--! @copyright Sapier
|
||||
--! @author Sapier
|
||||
--! @date 2013-02-14
|
||||
--
|
||||
--! @defgroup mobf_lifebar
|
||||
--! @brief lifebar implements a visible lifebar showing health of a mob abov
|
||||
--! its head
|
||||
--
|
||||
--
|
||||
-- Contact sapier a t gmx net
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
mobf_lifebar = {}
|
||||
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- name: init()
|
||||
--
|
||||
--! @brief register lifebar entity
|
||||
--! @ingroup mobf_lifebar
|
||||
-------------------------------------------------------------------------------
|
||||
function mobf_lifebar.init()
|
||||
print("MOBF: adding lifebar entity")
|
||||
minetest.register_entity(":mobf:lifebar",
|
||||
{
|
||||
physical = false,
|
||||
collisionbox = { 0,0,0,0,0,0 },
|
||||
visual = "sprite",
|
||||
textures = { "mobf_lb_64.png" },
|
||||
visual_size = {x=1,y=0.2},
|
||||
groups = { immortal=1, },
|
||||
is_visible = true,
|
||||
initial_sprite_basepos = {x=0, y=0},
|
||||
|
||||
lifetime = 0,
|
||||
initialized = false,
|
||||
|
||||
on_step = function (self,dtime)
|
||||
if not self.initialized then
|
||||
self.lifetime = self.lifetime + dtime
|
||||
|
||||
if self.lifetime > 1 then
|
||||
print("MOBF: lifebar not attached deleting")
|
||||
self.object:remove()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
})
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- name: add(entity)
|
||||
--
|
||||
--! @brief add a lifebat to an entity
|
||||
--! @ingroup mobf_lifebar
|
||||
--
|
||||
--! @param entity entity to add lifebar
|
||||
--
|
||||
--! @return reference to lifebar added
|
||||
-------------------------------------------------------------------------------
|
||||
function mobf_lifebar.add(entity)
|
||||
local pos = entity.object:getpos()
|
||||
local BS = 10
|
||||
pos.y = pos.y + entity.collisionbox[5] + 0.1
|
||||
|
||||
local lifebar = minetest.env:add_entity(pos,"mobf:lifebar")
|
||||
|
||||
if lifebar ~= nil then
|
||||
|
||||
lifebar:set_attach(entity.object,"",{x=0,y=(entity.collisionbox[5] + 0.1) * BS,z=0},{x=0,y=-90,z=0})
|
||||
|
||||
local luaentity = lifebar:get_luaentity()
|
||||
if luaentity ~= nil then
|
||||
print("MOBF: marking lifebar as initialized")
|
||||
luaentity.initialized = true
|
||||
else
|
||||
print("MOBF: unable to create lifebar entity")
|
||||
end
|
||||
end
|
||||
|
||||
return lifebar
|
||||
end
|
||||
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- name: del(lifebar)
|
||||
--
|
||||
--! @brief delete a lifebar
|
||||
--! @ingroup mobf_lifebar
|
||||
--
|
||||
--! @param lifebar lifebar do telete
|
||||
-------------------------------------------------------------------------------
|
||||
function mobf_lifebar.del(lifebar)
|
||||
if lifebar ~= nil then
|
||||
lifebar:set_detach()
|
||||
lifebar:remove()
|
||||
end
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- name: set(lifebar,value)
|
||||
--
|
||||
--! @brief set value of a lifebar
|
||||
--! @ingroup mobf_lifebar
|
||||
--
|
||||
--! @param lifebar lifebar do update
|
||||
--! @param value (0-1) value of lifebar
|
||||
-------------------------------------------------------------------------------
|
||||
function mobf_lifebar.set(lifebar,value)
|
||||
if lifebar ~= nil then
|
||||
local modifiername = mobf_lifebar.get_imagename(value)
|
||||
print("MOBF: got modifier " .. modifiername .. " for value " .. value)
|
||||
lifebar:settexturemod(modifiername)
|
||||
end
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- name: get_imagename(value)
|
||||
--
|
||||
--! @brief calculate imagename from value
|
||||
--! @ingroup mobf_lifebar
|
||||
--
|
||||
--! @param value to get image for
|
||||
-------------------------------------------------------------------------------
|
||||
function mobf_lifebar.get_imagename(value)
|
||||
|
||||
local number = math.floor((value*32) +0.5)
|
||||
|
||||
print("MOBF: calculated number: " .. number )
|
||||
|
||||
if number < 5 then
|
||||
return "^mobf_lb_0" .. number * 2 .. ".png"
|
||||
else
|
||||
return "^mobf_lb_" .. number * 2 .. ".png"
|
||||
end
|
||||
end
|
@ -407,6 +407,12 @@ function mobf.activate_handler(self,staticdata)
|
||||
self.data.generic.custom_on_activate_handler(self)
|
||||
end
|
||||
|
||||
--add lifebar
|
||||
if minetest.setting_getbool("mobf_lifebar") then
|
||||
self.lifebar = mobf_lifebar.add(self)
|
||||
mobf_lifebar.set(self.lifebar,self.object:get_hp()/self.hp_max)
|
||||
end
|
||||
|
||||
self.dynamic_data.initialized = true
|
||||
end
|
||||
|
||||
|
BIN
mobf/textures/mobf_lb_00.png
Normal file
After Width: | Height: | Size: 260 B |
BIN
mobf/textures/mobf_lb_02.png
Normal file
After Width: | Height: | Size: 267 B |
BIN
mobf/textures/mobf_lb_04.png
Normal file
After Width: | Height: | Size: 270 B |
BIN
mobf/textures/mobf_lb_06.png
Normal file
After Width: | Height: | Size: 270 B |
BIN
mobf/textures/mobf_lb_08.png
Normal file
After Width: | Height: | Size: 270 B |
BIN
mobf/textures/mobf_lb_10.png
Normal file
After Width: | Height: | Size: 270 B |
BIN
mobf/textures/mobf_lb_12.png
Normal file
After Width: | Height: | Size: 270 B |
BIN
mobf/textures/mobf_lb_14.png
Normal file
After Width: | Height: | Size: 270 B |
BIN
mobf/textures/mobf_lb_16.png
Normal file
After Width: | Height: | Size: 270 B |
BIN
mobf/textures/mobf_lb_18.png
Normal file
After Width: | Height: | Size: 270 B |
BIN
mobf/textures/mobf_lb_20.png
Normal file
After Width: | Height: | Size: 270 B |
BIN
mobf/textures/mobf_lb_22.png
Normal file
After Width: | Height: | Size: 271 B |
BIN
mobf/textures/mobf_lb_24.png
Normal file
After Width: | Height: | Size: 271 B |
BIN
mobf/textures/mobf_lb_26.png
Normal file
After Width: | Height: | Size: 270 B |
BIN
mobf/textures/mobf_lb_28.png
Normal file
After Width: | Height: | Size: 270 B |
BIN
mobf/textures/mobf_lb_30.png
Normal file
After Width: | Height: | Size: 269 B |
BIN
mobf/textures/mobf_lb_32.png
Normal file
After Width: | Height: | Size: 269 B |
BIN
mobf/textures/mobf_lb_34.png
Normal file
After Width: | Height: | Size: 270 B |
BIN
mobf/textures/mobf_lb_36.png
Normal file
After Width: | Height: | Size: 270 B |
BIN
mobf/textures/mobf_lb_38.png
Normal file
After Width: | Height: | Size: 271 B |
BIN
mobf/textures/mobf_lb_40.png
Normal file
After Width: | Height: | Size: 271 B |
BIN
mobf/textures/mobf_lb_42.png
Normal file
After Width: | Height: | Size: 270 B |
BIN
mobf/textures/mobf_lb_44.png
Normal file
After Width: | Height: | Size: 270 B |
BIN
mobf/textures/mobf_lb_46.png
Normal file
After Width: | Height: | Size: 270 B |
BIN
mobf/textures/mobf_lb_48.png
Normal file
After Width: | Height: | Size: 270 B |
BIN
mobf/textures/mobf_lb_50.png
Normal file
After Width: | Height: | Size: 270 B |
BIN
mobf/textures/mobf_lb_52.png
Normal file
After Width: | Height: | Size: 270 B |
BIN
mobf/textures/mobf_lb_54.png
Normal file
After Width: | Height: | Size: 270 B |
BIN
mobf/textures/mobf_lb_56.png
Normal file
After Width: | Height: | Size: 270 B |
BIN
mobf/textures/mobf_lb_58.png
Normal file
After Width: | Height: | Size: 270 B |
BIN
mobf/textures/mobf_lb_60.png
Normal file
After Width: | Height: | Size: 270 B |
BIN
mobf/textures/mobf_lb_62.png
Normal file
After Width: | Height: | Size: 266 B |
BIN
mobf/textures/mobf_lb_64.png
Normal file
After Width: | Height: | Size: 262 B |