From 15e94682e894726ed38bb7939969f188d5c1f5d6 Mon Sep 17 00:00:00 2001 From: Juraj Vajda Date: Sun, 30 Oct 2022 18:55:54 -0400 Subject: [PATCH] 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