#define MUTATOR_DAMAGETEXT_H
#ifdef MENUQC
-#include "../../../../menu/xonotic/tab.qc"
+#include <menu/xonotic/tab.qh>
#endif
#endif
REGISTER_MUTATOR(damagetext, true);
#if defined(CSQC) || defined(MENUQC)
-AUTOCVAR_SAVE(cl_damagetext, bool, false, _("Draw damage dealt. 0: disabled, 1: enabled"));
-AUTOCVAR_SAVE(cl_damagetext_format, string, "-%3$d", _("How to format the damage text. 1$ is health, 2$ is armor, 3$ is both"));
-AUTOCVAR_SAVE(cl_damagetext_color, vector, '1 1 0', _("Default damage text color"));
-AUTOCVAR_SAVE(cl_damagetext_color_per_weapon, bool, false, _("Damage text uses weapon color"));
-AUTOCVAR_SAVE(cl_damagetext_size, float, 8, _("Damage text font size"));
-AUTOCVAR_SAVE(cl_damagetext_alpha_start, float, 1, _("Damage text initial alpha"));
-AUTOCVAR_SAVE(cl_damagetext_alpha_lifetime, float, 3, _("Damage text lifetime in seconds"));
-AUTOCVAR_SAVE(cl_damagetext_velocity, vector, '0 0 20', _("Damage text move direction"));
-AUTOCVAR_SAVE(cl_damagetext_offset, vector, '0 -40 0', _("Damage text offset"));
-AUTOCVAR_SAVE(cl_damagetext_accumulate_range, float, 30, _("Damage text spawned within this range is accumulated"));
+// no translatable cvar description please
+AUTOCVAR_SAVE(cl_damagetext, bool, false, "Draw damage dealt where you hit the enemy");
+AUTOCVAR_SAVE(cl_damagetext_format, string, "-{total}", "How to format the damage text. {health}, {armor}, {total}");
+STATIC_INIT(DamageText_LegacyFormat) {
+ if (strstrofs(autocvar_cl_damagetext_format, "{", 0) < 0) autocvar_cl_damagetext_format = "-{total}";
+}
+AUTOCVAR_SAVE(cl_damagetext_color, vector, '1 1 0', "Damage text color");
+AUTOCVAR_SAVE(cl_damagetext_color_per_weapon, bool, false, "Damage text uses weapon color");
+AUTOCVAR_SAVE(cl_damagetext_size, float, 8, "Damage text font size");
+AUTOCVAR_SAVE(cl_damagetext_alpha_start, float, 1, "Damage text initial alpha");
+AUTOCVAR_SAVE(cl_damagetext_alpha_lifetime, float, 3, "Damage text lifetime in seconds");
+AUTOCVAR_SAVE(cl_damagetext_velocity, vector, '0 0 20', "Damage text move direction");
+AUTOCVAR_SAVE(cl_damagetext_offset, vector, '0 -40 0', "Damage text offset");
+AUTOCVAR_SAVE(cl_damagetext_accumulate_range, float, 30, "Damage text spawned within this range is accumulated");
+AUTOCVAR_SAVE(cl_damagetext_friendlyfire, bool, true, "Show damage text for friendlyfire too");
+AUTOCVAR_SAVE(cl_damagetext_friendlyfire_color, vector, '1 0 0', "Damage text color for friendlyfire");
#endif
#ifdef CSQC
CLASS(DamageText, Object)
ATTRIB(DamageText, m_color, vector, autocvar_cl_damagetext_color)
+ ATTRIB(DamageText, m_color_friendlyfire, vector, autocvar_cl_damagetext_friendlyfire_color)
ATTRIB(DamageText, m_size, float, autocvar_cl_damagetext_size)
ATTRIB(DamageText, alpha, float, autocvar_cl_damagetext_alpha_start)
ATTRIB(DamageText, fade_rate, float, 1 / autocvar_cl_damagetext_alpha_lifetime)
ATTRIB(DamageText, velocity, vector, autocvar_cl_damagetext_velocity)
ATTRIB(DamageText, m_group, int, 0)
+ ATTRIB(DamageText, m_friendlyfire, bool, false)
ATTRIB(DamageText, m_damage, int, 0)
ATTRIB(DamageText, m_armordamage, int, 0)
ATTRIB(DamageText, m_deathtype, int, 0)
vector pos = project_3d_to_2d(this.origin) + autocvar_cl_damagetext_offset;
if (pos.z >= 0 && this.m_size > 0) {
pos.z = 0;
- vector rgb = this.m_color;
+ vector rgb;
+ if (this.m_friendlyfire) {
+ rgb = this.m_color_friendlyfire;
+ }
+ else {
+ rgb = this.m_color;
+ }
if (autocvar_cl_damagetext_color_per_weapon) {
Weapon w = DEATH_WEAPONOF(this.m_deathtype);
if (w != WEP_Null) rgb = w.wpcolor;
}
- string s = sprintf(autocvar_cl_damagetext_format, this.m_damage, this.m_armordamage, this.m_damage + this.m_armordamage);
- drawcolorcodedstring2(pos, s, this.m_size * '1 1 0', rgb, this.alpha, DRAWFLAG_NORMAL);
+ 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);
+ drawcolorcodedstring2_builtin(pos, s, this.m_size * '1 1 0', rgb, this.alpha, DRAWFLAG_NORMAL);
}
}
ATTRIB(DamageText, draw2d, void(DamageText), DamageText_draw2d)
this.alpha = 1;
}
- CONSTRUCTOR(DamageText, int _group, vector _origin, int _health, int _armor, int _deathtype) {
+ CONSTRUCTOR(DamageText, int _group, vector _origin, int _health, int _armor, int _deathtype, bool _friendlyfire) {
CONSTRUCT(DamageText);
this.m_group = _group;
+ this.m_friendlyfire = _friendlyfire;
DamageText_update(this, _origin, _health, _armor, _deathtype);
}
ENDCLASS(DamageText)
#define SV_DAMAGETEXT_ALL() (autocvar_sv_damagetext >= 3 /* all players */)
MUTATOR_HOOKFUNCTION(damagetext, PlayerDamaged) {
if (SV_DAMAGETEXT_DISABLED()) return;
- const entity attacker = MUTATOR_ARGV(0, entity);
- const entity hit = MUTATOR_ARGV(1, entity); if (hit == attacker) return;
- const int health = MUTATOR_ARGV(0, int);
- const int armor = MUTATOR_ARGV(1, int);
- const int deathtype = MUTATOR_ARGV(2, int);
+ const entity attacker = M_ARGV(0, entity);
+ const entity hit = M_ARGV(1, entity); if (hit == attacker) return;
+ const int health = M_ARGV(2, int);
+ const int armor = M_ARGV(3, int);
+ const int deathtype = M_ARGV(5, int);
const vector location = hit.origin;
- entity e;
- FOR_EACH_REALCLIENT(e) if (
- (SV_DAMAGETEXT_ALL()) ||
- (SV_DAMAGETEXT_PLAYERS() && e == attacker) ||
- (SV_DAMAGETEXT_SPECTATORS_ONLY() && IS_SPEC(e) && e.enemy == attacker) ||
- (SV_DAMAGETEXT_SPECTATORS_ONLY() && IS_OBSERVER(e))
- ) {
- msg_entity = e;
- WriteHeader(MSG_ONE, damagetext);
- WriteShort(MSG_ONE, health);
- WriteShort(MSG_ONE, armor);
- WriteEntity(MSG_ONE, hit);
- WriteCoord(MSG_ONE, location.x);
- WriteCoord(MSG_ONE, location.y);
- WriteCoord(MSG_ONE, location.z);
- WriteInt24_t(MSG_ONE, deathtype);
- }
+ FOREACH_CLIENT(IS_REAL_CLIENT(it), LAMBDA(
+ if (
+ (SV_DAMAGETEXT_ALL()) ||
+ (SV_DAMAGETEXT_PLAYERS() && it == attacker) ||
+ (SV_DAMAGETEXT_SPECTATORS_ONLY() && IS_SPEC(it) && it.enemy == attacker) ||
+ (SV_DAMAGETEXT_SPECTATORS_ONLY() && IS_OBSERVER(it))
+ ) {
+ msg_entity = it;
+ WriteHeader(MSG_ONE, damagetext);
+ WriteShort(MSG_ONE, rint(health));
+ WriteShort(MSG_ONE, rint(armor));
+ WriteEntity(MSG_ONE, hit);
+ WriteCoord(MSG_ONE, location.x);
+ WriteCoord(MSG_ONE, location.y);
+ WriteCoord(MSG_ONE, location.z);
+ WriteInt24_t(MSG_ONE, deathtype);
+ WriteByte(MSG_ONE, SAME_TEAM(hit, attacker));
+ }
+ ));
}
#endif
int group = ReadShort();
vector location = vec3(ReadCoord(), ReadCoord(), ReadCoord());
int deathtype = ReadInt24_t();
+ bool friendlyfire = ReadByte();
return = true;
if (autocvar_cl_damagetext) {
+ if (friendlyfire && !autocvar_cl_damagetext_friendlyfire) {
+ return;
+ }
if (autocvar_cl_damagetext_accumulate_range) {
for (entity e = findradius(location, autocvar_cl_damagetext_accumulate_range); e; e = e.chain) {
if (e.instanceOfDamageText && e.m_group == group) {
}
}
}
- NEW(DamageText, group, location, health, armor, deathtype);
+ NEW(DamageText, group, location, health, armor, deathtype, friendlyfire);
}
}
#endif
#ifdef MENUQC
CLASS(XonoticDamageTextSettings, XonoticTab)
- #include "../../../../menu/gamesettings.qh"
+ #include <menu/gamesettings.qh>
REGISTER_SETTINGS(damagetext, NEW(XonoticDamageTextSettings));
ATTRIB(XonoticDamageTextSettings, title, string, _("Damage text"))
ATTRIB(XonoticDamageTextSettings, intendedWidth, float, 0.9)
METHOD(XonoticDamageTextSettings, showNotify, void(entity this)) { loadAllCvars(this); }
METHOD(XonoticDamageTextSettings, fill, void(entity this))
{
+ entity e;
this.gotoRC(this, 0, 1); this.setFirstColumn(this, this.currentColumn);
this.TD(this, 1, 3, makeXonoticCheckBox(0, "cl_damagetext", _("Draw damage numbers")));
this.TR(this);
- this.TD(this, 1, 1, makeXonoticTextLabel(0, _("Font size:")));
- this.TD(this, 1, 2, makeXonoticSlider(0, 50, 1, "cl_damagetext_size"));
+ this.TD(this, 1, 1, e = makeXonoticTextLabel(0, _("Font size:")));
+ setDependent(e, "cl_damagetext", 1, 1);
+ this.TD(this, 1, 2, e = makeXonoticSlider(0, 50, 1, "cl_damagetext_size"));
+ setDependent(e, "cl_damagetext", 1, 1);
+ this.TR(this);
+ this.TD(this, 1, 1, e = makeXonoticTextLabel(0, _("Accumulate range:")));
+ setDependent(e, "cl_damagetext", 1, 1);
+ this.TD(this, 1, 2, e = makeXonoticSlider(0, 500, 1, "cl_damagetext_accumulate_range"));
+ setDependent(e, "cl_damagetext", 1, 1);
+ this.TR(this);
+ this.TD(this, 1, 1, e = makeXonoticTextLabel(0, _("Lifetime:")));
+ setDependent(e, "cl_damagetext", 1, 1);
+ this.TD(this, 1, 2, e = makeXonoticSlider(0, 10, 1, "cl_damagetext_alpha_lifetime"));
+ setDependent(e, "cl_damagetext", 1, 1);
+ this.TR(this);
+ this.TD(this, 1, 1, e = makeXonoticTextLabel(0, _("Color:")));
+ setDependent(e, "cl_damagetext", 1, 1);
+ this.TD(this, 2, 2, e = makeXonoticColorpickerString("cl_damagetext_color", "cl_damagetext_color"));
+ setDependent(e, "cl_damagetext", 1, 1);
+ this.TR(this);
this.TR(this);
- this.TD(this, 1, 1, makeXonoticTextLabel(0, _("Accumulate range:")));
- this.TD(this, 1, 2, makeXonoticSlider(0, 500, 1, "cl_damagetext_accumulate_range"));
+ // friendly fire
+ this.TD(this, 1, 3, e = makeXonoticCheckBox(0, "cl_damagetext_friendlyfire", _("Draw damage numbers for friendly fire")));
+ setDependent(e, "cl_damagetext", 1, 1);
this.TR(this);
- this.TD(this, 1, 1, makeXonoticTextLabel(0, _("Lifetime:")));
- this.TD(this, 1, 2, makeXonoticSlider(0, 10, 1, "cl_damagetext_alpha_lifetime"));
+ this.TD(this, 1, 1, e = makeXonoticTextLabel(0, _("Color (Friendly Fire):")));
+ setDependentAND(e, "cl_damagetext", 1, 1, "cl_damagetext_friendlyfire", 1, 1);
+ this.TD(this, 2, 2, e = makeXonoticColorpickerString("cl_damagetext_friendlyfire_color", "cl_damagetext_friendlyfire_color"));
+ setDependentAND(e, "cl_damagetext", 1, 1, "cl_damagetext_friendlyfire", 1, 1);
this.TR(this);
- this.TD(this, 1, 1, makeXonoticTextLabel(0, _("Color:")));
- this.TD(this, 2, 2, makeXonoticColorpickerString("cl_damagetext_color", "cl_damagetext_color"));
}
ENDCLASS(XonoticDamageTextSettings)
#endif