From 15e94682e894726ed38bb7939969f188d5c1f5d6 Mon Sep 17 00:00:00 2001 From: Juraj Vajda Date: Sun, 30 Oct 2022 18:55:54 -0400 Subject: [PATCH 1/3] add visible damage points --- api.lua | 64 ++++++++++++++++++++++++++++++++++++++++++++- settingtypes.txt | 3 +++ textures/dmg_0.png | Bin 0 -> 80 bytes textures/dmg_1.png | Bin 0 -> 80 bytes textures/dmg_2.png | Bin 0 -> 85 bytes textures/dmg_3.png | Bin 0 -> 81 bytes textures/dmg_4.png | Bin 0 -> 91 bytes textures/dmg_5.png | Bin 0 -> 83 bytes textures/dmg_6.png | Bin 0 -> 85 bytes textures/dmg_7.png | Bin 0 -> 81 bytes textures/dmg_8.png | Bin 0 -> 80 bytes textures/dmg_9.png | Bin 0 -> 86 bytes 12 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 textures/dmg_0.png create mode 100644 textures/dmg_1.png create mode 100644 textures/dmg_2.png create mode 100644 textures/dmg_3.png create mode 100644 textures/dmg_4.png create mode 100644 textures/dmg_5.png create mode 100644 textures/dmg_6.png create mode 100644 textures/dmg_7.png create mode 100644 textures/dmg_8.png create mode 100644 textures/dmg_9.png 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 0000000000000000000000000000000000000000..a19cd00f10dea03380ee8f1400915de698bf21aa GIT binary patch literal 80 zcmeAS@N?(olHy`uVBq!ia0vp^>_E)P!2%>h0{>|MDREC1$B>G+BGAnC7 eSv0eUhhgOu_E)P!2%>h0{>|MDREC1$B>G+_E)P!2%>h0{>|MDH%@}$B>FS$q5eZ{}(bi3s{T0 j8s?>*P+L5cmx;mPvHH#0gfp{&>KHs-{an^LB{Ts5-|Q7J literal 0 HcmV?d00001 diff --git a/textures/dmg_3.png b/textures/dmg_3.png new file mode 100644 index 0000000000000000000000000000000000000000..dc24c16d8005071ab995228847a1fc657df730b6 GIT binary patch literal 81 zcmeAS@N?(olHy`uVBq!ia0vp^>_E)P!2%>h0{>|MDG5&($B>F!$q5eZ{}UOU1+=HL e9F6d8V_=xnuXCj>Fv<+5hQZU-&t;ucLK6Ur_E)P!3HG%MVKuHQc9jKjv*44lM@tJ|FkpB5t5i> pz{um7!WZUQ;xMb3!%K;oVRM=P#=~>Vg@CFVJYD@<);T3K0RU1|76JeO literal 0 HcmV?d00001 diff --git a/textures/dmg_5.png b/textures/dmg_5.png new file mode 100644 index 0000000000000000000000000000000000000000..3300e985b552bff76324ccebaaeb323558251bf7 GIT binary patch literal 83 zcmeAS@N?(olHy`uVBq!ia0vp^>_E)P!2%>h0{>|MDJf4E$B>G+_E)P!2%>h0{>|MDH%@}$B>F!$q5Ho{wp$cHY>Jk jaf=@~?`kY5$-ppqhvo4@)1_E)P!2%>h0{>|MDG5&($B>F!$q5eZ{~t2=3Rt(Z eSn}vGF)(})RJ_0RpYKkf8U{~SKbLh*2~7Zqi4$`G literal 0 HcmV?d00001 diff --git a/textures/dmg_8.png b/textures/dmg_8.png new file mode 100644 index 0000000000000000000000000000000000000000..6cd88e565548147ef865f6d420398a62f5ed09a9 GIT binary patch literal 80 zcmeAS@N?(olHy`uVBq!ia0vp^>_E)P!2%>h0{>|MDREC1$B>G+BGAkSI doTA~z#-J>1cwXqerxZ{LgQu&X%Q~loCID}o5>NmD literal 0 HcmV?d00001 diff --git a/textures/dmg_9.png b/textures/dmg_9.png new file mode 100644 index 0000000000000000000000000000000000000000..72feaa1969e30b243ccd328cf0b7b144fc91526e GIT binary patch literal 86 zcmeAS@N?(olHy`uVBq!ia0vp^>_E)P!2%>h0{>|MDOpb!$B>F!$q5Ho{vTxMWLD-Z jO00Sq(<0?Fc_JeNgPs0G#aQMHph5;uS3j3^P6 Date: Sun, 30 Oct 2022 19:28:44 -0400 Subject: [PATCH 2/3] add visible damage points --- .luacheckrc | 3 ++- types/math.type.lua | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 types/math.type.lua diff --git a/.luacheckrc b/.luacheckrc index 6d21f31..3dcbf46 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -51,7 +51,8 @@ read_globals = { fields = { "hypot", "sign", - "factorial" + "factorial", + "round", } }, diff --git a/types/math.type.lua b/types/math.type.lua new file mode 100644 index 0000000..4d62d97 --- /dev/null +++ b/types/math.type.lua @@ -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. From 94292e6ac53b37d98ceab8c28a84bfaee2fa5b8e Mon Sep 17 00:00:00 2001 From: Juraj Vajda Date: Sun, 30 Oct 2022 19:39:07 -0400 Subject: [PATCH 3/3] add visible damage points --- README.md | 10 ++++++++++ api.lua | 8 +++++--- textures/{dmg_0.png => x_bows_dmg_0.png} | Bin textures/{dmg_1.png => x_bows_dmg_1.png} | Bin textures/{dmg_2.png => x_bows_dmg_2.png} | Bin textures/{dmg_3.png => x_bows_dmg_3.png} | Bin textures/{dmg_4.png => x_bows_dmg_4.png} | Bin textures/{dmg_5.png => x_bows_dmg_5.png} | Bin textures/{dmg_6.png => x_bows_dmg_6.png} | Bin textures/{dmg_7.png => x_bows_dmg_7.png} | Bin textures/{dmg_8.png => x_bows_dmg_8.png} | Bin textures/{dmg_9.png => x_bows_dmg_9.png} | Bin types/xbows.type.lua | 1 + 13 files changed, 16 insertions(+), 3 deletions(-) rename textures/{dmg_0.png => x_bows_dmg_0.png} (100%) rename textures/{dmg_1.png => x_bows_dmg_1.png} (100%) rename textures/{dmg_2.png => x_bows_dmg_2.png} (100%) rename textures/{dmg_3.png => x_bows_dmg_3.png} (100%) rename textures/{dmg_4.png => x_bows_dmg_4.png} (100%) rename textures/{dmg_5.png => x_bows_dmg_5.png} (100%) rename textures/{dmg_6.png => x_bows_dmg_6.png} (100%) rename textures/{dmg_7.png => x_bows_dmg_7.png} (100%) rename textures/{dmg_8.png => x_bows_dmg_8.png} (100%) rename textures/{dmg_9.png => x_bows_dmg_9.png} (100%) diff --git a/README.md b/README.md index aa3f7a4..cdc3f2a 100644 --- a/README.md +++ b/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 diff --git a/api.lua b/api.lua index 1ac5493..11303a6 100644 --- a/api.lua +++ b/api.lua @@ -2379,13 +2379,15 @@ function XBowsQuiver.hide_3d_quiver(self, player) 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 ----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 @@ -2399,9 +2401,9 @@ function XBows.show_damage_numbers(self, pos, damage, is_crit) for i, value in ipairs(results) do if i == 1 then - texture = texture .. '[combine:' .. 7 * #results .. 'x' .. 9 * #results .. ':0,0=dmg_' .. value .. '.png' + texture = texture .. '[combine:' .. 7 * #results .. 'x' .. 9 * #results .. ':0,0=x_bows_dmg_' .. value .. '.png' else - texture = texture .. ':' .. dmg_nr_offset .. ',0=dmg_' .. value .. '.png' + texture = texture .. ':' .. dmg_nr_offset .. ',0=x_bows_dmg_' .. value .. '.png' end dmg_nr_offset = dmg_nr_offset + 7 diff --git a/textures/dmg_0.png b/textures/x_bows_dmg_0.png similarity index 100% rename from textures/dmg_0.png rename to textures/x_bows_dmg_0.png diff --git a/textures/dmg_1.png b/textures/x_bows_dmg_1.png similarity index 100% rename from textures/dmg_1.png rename to textures/x_bows_dmg_1.png diff --git a/textures/dmg_2.png b/textures/x_bows_dmg_2.png similarity index 100% rename from textures/dmg_2.png rename to textures/x_bows_dmg_2.png diff --git a/textures/dmg_3.png b/textures/x_bows_dmg_3.png similarity index 100% rename from textures/dmg_3.png rename to textures/x_bows_dmg_3.png diff --git a/textures/dmg_4.png b/textures/x_bows_dmg_4.png similarity index 100% rename from textures/dmg_4.png rename to textures/x_bows_dmg_4.png diff --git a/textures/dmg_5.png b/textures/x_bows_dmg_5.png similarity index 100% rename from textures/dmg_5.png rename to textures/x_bows_dmg_5.png diff --git a/textures/dmg_6.png b/textures/x_bows_dmg_6.png similarity index 100% rename from textures/dmg_6.png rename to textures/x_bows_dmg_6.png diff --git a/textures/dmg_7.png b/textures/x_bows_dmg_7.png similarity index 100% rename from textures/dmg_7.png rename to textures/x_bows_dmg_7.png diff --git a/textures/dmg_8.png b/textures/x_bows_dmg_8.png similarity index 100% rename from textures/dmg_8.png rename to textures/x_bows_dmg_8.png diff --git a/textures/dmg_9.png b/textures/x_bows_dmg_9.png similarity index 100% rename from textures/dmg_9.png rename to textures/x_bows_dmg_9.png diff --git a/types/xbows.type.lua b/types/xbows.type.lua index 81ecbdc..d89e2b5 100644 --- a/types/xbows.type.lua +++ b/types/xbows.type.lua @@ -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