Add visible damage points
|
@ -51,7 +51,8 @@ read_globals = {
|
|||
fields = {
|
||||
"hypot",
|
||||
"sign",
|
||||
"factorial"
|
||||
"factorial",
|
||||
"round",
|
||||
}
|
||||
},
|
||||
|
||||
|
|
10
README.md
|
@ -130,6 +130,16 @@ Modified by SaKeL:
|
|||
- x_bows_quiver_empty_mesh.png
|
||||
- x_bows_quiver_blank_mesh.png
|
||||
- x_bows_quiver_slot.png
|
||||
- x_bows_dmg_0.png
|
||||
- x_bows_dmg_1.png
|
||||
- x_bows_dmg_2.png
|
||||
- x_bows_dmg_3.png
|
||||
- x_bows_dmg_4.png
|
||||
- x_bows_dmg_5.png
|
||||
- x_bows_dmg_6.png
|
||||
- x_bows_dmg_7.png
|
||||
- x_bows_dmg_8.png
|
||||
- x_bows_dmg_9.png
|
||||
|
||||
### Sounds
|
||||
|
||||
|
|
66
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,64 @@ function XBowsQuiver.hide_3d_quiver(self, player)
|
|||
player_api.set_textures(player, player_textures)
|
||||
end
|
||||
end
|
||||
|
||||
---string split to characters
|
||||
---@param str string
|
||||
---@return string[] | nil
|
||||
local function split(str)
|
||||
if #str > 0 then
|
||||
return str:sub(1,1), split(str:sub(2))
|
||||
end
|
||||
end
|
||||
|
||||
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=x_bows_dmg_' .. value .. '.png'
|
||||
else
|
||||
texture = texture .. ':' .. dmg_nr_offset .. ',0=x_bows_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
|
||||
|
|
|
@ -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
|
||||
|
|
After Width: | Height: | Size: 80 B |
After Width: | Height: | Size: 80 B |
After Width: | Height: | Size: 85 B |
After Width: | Height: | Size: 81 B |
After Width: | Height: | Size: 91 B |
After Width: | Height: | Size: 83 B |
After Width: | Height: | Size: 85 B |
After Width: | Height: | Size: 81 B |
After Width: | Height: | Size: 80 B |
After Width: | Height: | Size: 86 B |
|
@ -0,0 +1,7 @@
|
|||
---https://github.com/sumneko/lua-language-server/wiki
|
||||
|
||||
---@alias mathlib mathlib|MathAbstract
|
||||
|
||||
---Math helpers
|
||||
---@class MathAbstract
|
||||
---@field round fun(x: number): number Returns `x` rounded to the nearest integer. At a multiple of 0.5, rounds away from zero.
|
|
@ -32,6 +32,7 @@
|
|||
---@field open_quiver fun(self: XBowsQuiver, itemstack: ItemStack, user: ObjectRef): ItemStack Open quiver
|
||||
---@field uuid fun(): string Creates UUID
|
||||
---@field fallback_quiver boolean If no invenotory mod is detected then fallback solution will be used
|
||||
---@field show_damage_numbers fun(self: XBows, pos: Vector, damaga: number, is_crit?: boolean): nil Builds textures and shows textures in particle spawner
|
||||
|
||||
|
||||
---XBowsQuiver class extended from XBows
|
||||
|
|