1 REGISTER_MUTATOR(damagetext, true);
4 vector autocvar_cl_damagetext_color = '1 1 0';
5 float autocvar_cl_damagetext_size = 8;
6 float autocvar_cl_damagetext_alpha_start = 1;
7 float autocvar_cl_damagetext_alpha_lifetime = 3;
8 vector autocvar_cl_damagetext_velocity = '0 0 20';
9 vector autocvar_cl_damagetext_offset = '0 -40 0';
10 float autocvar_cl_damagetext_accumulate_range = 300;
12 CLASS(DamageText, Object)
13 ATTRIB(DamageText, m_color, vector, autocvar_cl_damagetext_color)
14 ATTRIB(DamageText, m_size, float, autocvar_cl_damagetext_size)
15 ATTRIB(DamageText, alpha, float, autocvar_cl_damagetext_alpha_start)
16 ATTRIB(DamageText, fade_rate, float, 1 / autocvar_cl_damagetext_alpha_lifetime)
17 ATTRIB(DamageText, velocity, vector, autocvar_cl_damagetext_velocity)
18 ATTRIB(DamageText, m_damage, int, 0)
19 ATTRIB(DamageText, m_armordamage, int, 0)
20 ATTRIB(DamageText, time_prev, float, time)
22 void DamageText_draw() {
24 float dt = time - this.time_prev;
25 this.time_prev = time;
26 setorigin(this, this.origin + dt * this.velocity);
27 this.alpha -= dt * this.fade_rate;
28 if (this.alpha < 0) remove(this);
29 vector pos = project_3d_to_2d(this.origin) + autocvar_cl_damagetext_offset;
30 if (pos.z >= 0 && this.m_size > 0) {
32 string s = sprintf("-%d", this.m_damage + this.m_armordamage);
33 drawstring(pos, s, this.m_size * '1 1 0', this.m_color, this.alpha, DRAWFLAG_NORMAL);
36 ATTRIB(DamageText, draw2d, void(), DamageText_draw)
38 void DamageText_update(DamageText this, vector _origin, int _health, int _armor) {
39 this.m_damage = _health;
40 this.m_armordamage = _armor;
41 setorigin(this, _origin);
45 CONSTRUCTOR(DamageText, vector _origin, int _health, int _armor) {
46 CONSTRUCT(DamageText);
47 DamageText_update(this, _origin, _health, _armor);
54 MUTATOR_HOOKFUNCTION(damagetext, PlayerDamaged) {
55 const entity me = mutator_argv_entity_0; if (!IS_REAL_CLIENT(me)) return;
56 const entity hit = mutator_argv_entity_1; if (hit == me) return;
57 const int health = mutator_argv_int_0;
58 const int armor = mutator_argv_int_1;
59 const vector location = hit.origin;
61 WriteByte(MSG_ONE, SVC_TEMPENTITY);
62 WriteMutator(MSG_ONE, damagetext);
63 WriteShort(MSG_ONE, health);
64 WriteShort(MSG_ONE, armor);
65 WriteCoord(MSG_ONE, location.x);
66 WriteCoord(MSG_ONE, location.y);
67 WriteCoord(MSG_ONE, location.z);
72 MUTATOR_HOOKFUNCTION(damagetext, CSQC_Parse_TempEntity) {
73 if (MUTATOR_RETURNVALUE) return false;
74 if (!ReadMutatorEquals(mutator_argv_int_0, damagetext)) return false;
75 int health = ReadShort();
76 int armor = ReadShort();
77 vector location = vec3(ReadCoord(), ReadCoord(), ReadCoord());
78 for (entity e = findradius(location, autocvar_cl_damagetext_accumulate_range); e; e = e.chain) {
79 if (e.instanceOfDamageText) {
80 DamageText_update(e, location, e.m_damage + health, e.m_armordamage + armor);
84 NEW(DamageText, location, health, armor);