1 REGISTER_MUTATOR(damagetext, true);
4 string autocvar_cl_damagetext_format = "-%3$d";
5 vector autocvar_cl_damagetext_color = '1 1 0';
6 float autocvar_cl_damagetext_size = 8;
7 float autocvar_cl_damagetext_alpha_start = 1;
8 float autocvar_cl_damagetext_alpha_lifetime = 3;
9 vector autocvar_cl_damagetext_velocity = '0 0 20';
10 vector autocvar_cl_damagetext_offset = '0 -40 0';
11 float autocvar_cl_damagetext_accumulate_range = 30;
13 CLASS(DamageText, Object)
14 ATTRIB(DamageText, m_color, vector, autocvar_cl_damagetext_color)
15 ATTRIB(DamageText, m_size, float, autocvar_cl_damagetext_size)
16 ATTRIB(DamageText, alpha, float, autocvar_cl_damagetext_alpha_start)
17 ATTRIB(DamageText, fade_rate, float, 1 / autocvar_cl_damagetext_alpha_lifetime)
18 ATTRIB(DamageText, velocity, vector, autocvar_cl_damagetext_velocity)
19 ATTRIB(DamageText, m_group, int, 0)
20 ATTRIB(DamageText, m_damage, int, 0)
21 ATTRIB(DamageText, m_armordamage, int, 0)
22 ATTRIB(DamageText, time_prev, float, time)
24 void DamageText_draw() {
26 float dt = time - this.time_prev;
27 this.time_prev = time;
28 setorigin(this, this.origin + dt * this.velocity);
29 this.alpha -= dt * this.fade_rate;
30 if (this.alpha < 0) remove(this);
31 vector pos = project_3d_to_2d(this.origin) + autocvar_cl_damagetext_offset;
32 if (pos.z >= 0 && this.m_size > 0) {
34 string s = sprintf(autocvar_cl_damagetext_format, this.m_damage, this.m_armordamage, this.m_damage + this.m_armordamage);
35 drawcolorcodedstring2(pos, s, this.m_size * '1 1 0', this.m_color, this.alpha, DRAWFLAG_NORMAL);
38 ATTRIB(DamageText, draw2d, void(), DamageText_draw)
40 void DamageText_update(DamageText this, vector _origin, int _health, int _armor) {
41 this.m_damage = _health;
42 this.m_armordamage = _armor;
43 setorigin(this, _origin);
47 CONSTRUCTOR(DamageText, int _group, vector _origin, int _health, int _armor) {
48 CONSTRUCT(DamageText);
49 this.m_group = _group;
50 DamageText_update(this, _origin, _health, _armor);
57 MUTATOR_HOOKFUNCTION(damagetext, PlayerDamaged) {
58 const entity attacker = mutator_argv_entity_0;
59 const entity hit = mutator_argv_entity_1; if (hit == attacker) return;
60 const int health = mutator_argv_int_0;
61 const int armor = mutator_argv_int_1;
62 const vector location = hit.origin;
64 FOR_EACH_REALCLIENT(e) if (e == attacker || (IS_SPEC(e) && e.enemy == attacker)) {
66 WriteByte(MSG_ONE, SVC_TEMPENTITY);
67 WriteMutator(MSG_ONE, damagetext);
68 WriteShort(MSG_ONE, health);
69 WriteShort(MSG_ONE, armor);
70 WriteEntity(MSG_ONE, hit);
71 WriteCoord(MSG_ONE, location.x);
72 WriteCoord(MSG_ONE, location.y);
73 WriteCoord(MSG_ONE, location.z);
79 MUTATOR_HOOKFUNCTION(damagetext, CSQC_Parse_TempEntity) {
80 if (MUTATOR_RETURNVALUE) return false;
81 if (!ReadMutatorEquals(mutator_argv_int_0, damagetext)) return false;
82 int health = ReadShort();
83 int armor = ReadShort();
84 int group = ReadShort();
85 vector location = vec3(ReadCoord(), ReadCoord(), ReadCoord());
86 for (entity e = findradius(location, autocvar_cl_damagetext_accumulate_range); e; e = e.chain) {
87 if (e.instanceOfDamageText && e.m_group == group) {
88 DamageText_update(e, location, e.m_damage + health, e.m_armordamage + armor);
92 NEW(DamageText, group, location, health, armor);