From 11b3d7a98902971dc46675638cf9291d1f2db919 Mon Sep 17 00:00:00 2001 From: Martin Taibr Date: Sat, 3 Sep 2016 02:40:30 +0200 Subject: [PATCH] fix damage text rounding errors when accumulating damage --- .../mutators/mutator/damagetext/damagetext.qc | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/qcsrc/common/mutators/mutator/damagetext/damagetext.qc b/qcsrc/common/mutators/mutator/damagetext/damagetext.qc index 88af5496b..3d4288cd2 100644 --- a/qcsrc/common/mutators/mutator/damagetext/damagetext.qc +++ b/qcsrc/common/mutators/mutator/damagetext/damagetext.qc @@ -57,9 +57,9 @@ CLASS(DamageText, Object) if (w != WEP_Null) rgb = w.wpcolor; } string s = autocvar_cl_damagetext_format; - s = strreplace("{health}", sprintf("%d", this.m_damage), s); - s = strreplace("{armor}", sprintf("%d", this.m_armordamage), s); - s = strreplace("{total}", sprintf("%d", this.m_damage + this.m_armordamage), s); + s = strreplace("{health}", sprintf("%d", rint(this.m_damage / 100)), s); + s = strreplace("{armor}", sprintf("%d", rint(this.m_armordamage / 100)), s); + s = strreplace("{total}", sprintf("%d", rint((this.m_damage + this.m_armordamage) / 100)), s); drawcolorcodedstring2_builtin(pos, s, this.m_size * '1 1 0', rgb, this.alpha, DRAWFLAG_NORMAL); } } @@ -108,8 +108,12 @@ MUTATOR_HOOKFUNCTION(damagetext, PlayerDamaged) { ) { msg_entity = it; WriteHeader(MSG_ONE, damagetext); - WriteShort(MSG_ONE, rint(health)); - WriteShort(MSG_ONE, rint(armor)); + + // we need a few decimal places to avoid errors when accumulating damage + // sending them this way saves bandwidth compared to WriteCoord + WriteShort(MSG_ONE, health * 100); + WriteShort(MSG_ONE, armor * 100); + WriteEntity(MSG_ONE, hit); WriteCoord(MSG_ONE, location.x); WriteCoord(MSG_ONE, location.y); -- 2.39.2