add visible damage points

This commit is contained in:
Juraj Vajda 2022-10-30 18:55:54 -04:00
parent bfde48768e
commit 15e94682e8
12 changed files with 66 additions and 1 deletions

64
api.lua
View File

@ -44,7 +44,8 @@ XBows = {
registered_entities = {},
player_bow_sneak = {},
settings = {
x_bows_attach_arrows_to_entities = minetest.settings:get_bool('x_bows_attach_arrows_to_entities', false)
x_bows_attach_arrows_to_entities = minetest.settings:get_bool('x_bows_attach_arrows_to_entities', false),
x_bows_show_damage_numbers = minetest.settings:get_bool('x_bows_show_damage_numbers', false)
},
charge_sound_after_job = {},
fallback_quiver = not minetest.global_exists('sfinv') and not minetest.global_exists('unified_inventory') and not minetest.global_exists('i3')
@ -1119,6 +1120,8 @@ function XBowsEntityDef.on_step(self, selfObj, dtime)
selfObj._caused_damage = _damage
selfObj._caused_knockback = knockback
XBows:show_damage_numbers(selfObj.object:get_pos(), _damage, selfObj._is_critical_hit)
-- already dead (entity)
if not pointed_thing.ref:get_luaentity() and not pointed_thing.ref:is_player() then
selfObj.object:remove()
@ -2375,3 +2378,62 @@ function XBowsQuiver.hide_3d_quiver(self, player)
player_api.set_textures(player, player_textures)
end
end
local function split(str)
if #str > 0 then
return str:sub(1,1), split(str:sub(2))
end
end
---Show damage numbers
function XBows.show_damage_numbers(self, pos, damage, is_crit)
if not pos or not self.settings.x_bows_show_damage_numbers then
return
end
---get damage texture
local dmgstr = tostring(math.round(damage))
local results = {split(dmgstr)}
local texture = ''
local dmg_nr_offset = 0
for i, value in ipairs(results) do
if i == 1 then
texture = texture .. '[combine:' .. 7 * #results .. 'x' .. 9 * #results .. ':0,0=dmg_' .. value .. '.png'
else
texture = texture .. ':' .. dmg_nr_offset .. ',0=dmg_' .. value .. '.png'
end
dmg_nr_offset = dmg_nr_offset + 7
end
if texture and texture ~= '' then
local size = 7
if is_crit then
size = 14
texture = texture .. '^[colorize:#FF0000:255'
else
texture = texture .. '^[colorize:#FFFF00:127'
end
---show damage texture
minetest.add_particlespawner({
amount = 1,
time = 0.01,
minpos = {x = pos.x, y = pos.y + 1, z = pos.z},
maxpos = {x = pos.x, y = pos.y + 2, z = pos.z},
minvel = {x = math.random(-1, 1), y = 5, z = math.random(-1, 1)},
maxvel = {x = math.random(-1, 1), y = 5, z = math.random(-1, 1)},
minacc = {x = math.random(-1, 1), y = -7, z = math.random(-1, 1)},
maxacc = {x = math.random(-1, 1), y = -7, z = math.random(-1, 1)},
minexptime = 2,
maxexptime = 2,
minsize = size,
maxsize = size,
texture = texture,
collisiondetection = true,
glow = 10
})
end
end

View File

@ -1,2 +1,5 @@
# Disabled per default due to inconsistent mob models scaling (visual_size). This will scale the arrows unproportionally and looks bad. If you have mobs with no scaling you can enable this setting.
x_bows_attach_arrows_to_entities (Attach arrows to entities) bool false
# Shows caused damage number flying out from the hit object/player.
x_bows_show_damage_numbers (Show damage caused) bool false

BIN
textures/dmg_0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 B

BIN
textures/dmg_1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 B

BIN
textures/dmg_2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 B

BIN
textures/dmg_3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 B

BIN
textures/dmg_4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 91 B

BIN
textures/dmg_5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 B

BIN
textures/dmg_6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 B

BIN
textures/dmg_7.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 B

BIN
textures/dmg_8.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 B

BIN
textures/dmg_9.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 B