diff --git a/api.lua b/api.lua index c7ec19d..1ac5493 100644 --- a/api.lua +++ b/api.lua @@ -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 diff --git a/settingtypes.txt b/settingtypes.txt index f4842e4..29aabaf 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -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 diff --git a/textures/dmg_0.png b/textures/dmg_0.png new file mode 100644 index 0000000..a19cd00 Binary files /dev/null and b/textures/dmg_0.png differ diff --git a/textures/dmg_1.png b/textures/dmg_1.png new file mode 100644 index 0000000..6702c8d Binary files /dev/null and b/textures/dmg_1.png differ diff --git a/textures/dmg_2.png b/textures/dmg_2.png new file mode 100644 index 0000000..8b35f55 Binary files /dev/null and b/textures/dmg_2.png differ diff --git a/textures/dmg_3.png b/textures/dmg_3.png new file mode 100644 index 0000000..dc24c16 Binary files /dev/null and b/textures/dmg_3.png differ diff --git a/textures/dmg_4.png b/textures/dmg_4.png new file mode 100644 index 0000000..f603d7c Binary files /dev/null and b/textures/dmg_4.png differ diff --git a/textures/dmg_5.png b/textures/dmg_5.png new file mode 100644 index 0000000..3300e98 Binary files /dev/null and b/textures/dmg_5.png differ diff --git a/textures/dmg_6.png b/textures/dmg_6.png new file mode 100644 index 0000000..8da46e5 Binary files /dev/null and b/textures/dmg_6.png differ diff --git a/textures/dmg_7.png b/textures/dmg_7.png new file mode 100644 index 0000000..d01881f Binary files /dev/null and b/textures/dmg_7.png differ diff --git a/textures/dmg_8.png b/textures/dmg_8.png new file mode 100644 index 0000000..6cd88e5 Binary files /dev/null and b/textures/dmg_8.png differ diff --git a/textures/dmg_9.png b/textures/dmg_9.png new file mode 100644 index 0000000..72feaa1 Binary files /dev/null and b/textures/dmg_9.png differ