+
+ int health = rint(this.m_healthdamage / DAMAGETEXT_PRECISION_MULTIPLIER);
+ int armor = rint(this.m_armordamage / DAMAGETEXT_PRECISION_MULTIPLIER);
+ int total = rint((this.m_healthdamage + this.m_armordamage) / DAMAGETEXT_PRECISION_MULTIPLIER);
+ int potential = rint(this.m_potential_damage / DAMAGETEXT_PRECISION_MULTIPLIER);
+ int potential_health = rint((this.m_potential_damage - this.m_armordamage) / DAMAGETEXT_PRECISION_MULTIPLIER);
+
+ string s = autocvar_cl_damagetext_format;
+ s = strreplace("{armor}", (
+ (this.m_armordamage == 0 && autocvar_cl_damagetext_format_hide_redundant)
+ ? ""
+ : sprintf("%d", armor)
+ ), s);
+ s = strreplace("{potential}", (
+ (this.m_potential_damage == this.m_healthdamage + this.m_armordamage && autocvar_cl_damagetext_format_hide_redundant)
+ ? ""
+ : sprintf("%d", potential)
+ ), s);
+ s = strreplace("{potential_health}", (
+ (this.m_potential_damage - this.m_armordamage == this.m_healthdamage && autocvar_cl_damagetext_format_hide_redundant)
+ ? ""
+ : sprintf("%d", potential_health)
+ ), s);
+
+ s = strreplace("{health}", (
+ (health == potential_health || !autocvar_cl_damagetext_format_verbose)
+ ? sprintf("%d", health)
+ : sprintf("%d (%d)", health, potential_health)
+ ), s);
+ s = strreplace("{total}", (
+ (total == potential || !autocvar_cl_damagetext_format_verbose)
+ ? sprintf("%d", total)
+ : sprintf("%d (%d)", total, potential)
+ ), s);
+
+ // futureproofing: remove any remaining (unknown) format strings in case we add new ones in the future
+ // so players can use them on new servers and still have working damagetext on old ones
+ while (true) {
+ int opening_pos = strstrofs(s, "{", 0);
+ if (opening_pos == -1) break;
+ int closing_pos = strstrofs(s, "}", opening_pos);
+ if (closing_pos == -1 || closing_pos <= opening_pos) break;
+ s = strcat(
+ substring(s, 0, opening_pos),
+ substring_range(s, closing_pos + 1, strlen(s))
+ );
+ }
+
+ if (this.text) strunzone(this.text);
+ this.text = strzone(s);
+
+ float size_range = autocvar_cl_damagetext_size_max - autocvar_cl_damagetext_size_min;
+ float damage_range = autocvar_cl_damagetext_size_max_damage - autocvar_cl_damagetext_size_min_damage;
+ float scale_factor = size_range / damage_range;
+ this.m_size = bound(
+ autocvar_cl_damagetext_size_min,
+ (potential - autocvar_cl_damagetext_size_min_damage) * scale_factor + autocvar_cl_damagetext_size_min,
+ autocvar_cl_damagetext_size_max);