+
+void Ent_DamageEffect()
+{
+ float type, specnum1, specnum2, entnumber, body;
+ vector org;
+ string specstr, effectnum;
+ entity e;
+
+ type = ReadByte(); // damage weapon
+ specnum1 = ReadByte(); // player species
+ entnumber = ReadByte(); // player entnum
+ body = ReadByte(); // is dead body / gibbed
+ org_x = ReadCoord();
+ org_y = ReadCoord();
+ org_z = ReadCoord();
+
+ if not(autocvar_cl_damageeffect)
+ return;
+ if(autocvar_cl_gentle || autocvar_cl_gentle_damage)
+ return;
+
+ e = get_weaponinfo(type);
+
+ specnum2 = (specnum1 & 0x78) / 8; // blood type: using four bits (0..7, bit indexes 3,4,5)
+ specstr = species_prefix(specnum2);
+
+ effectnum = strcat("weapondamage_", e.netname);
+ // If the weapon is a bullet weapon, its damage effect is blood.
+ // Since blood is species dependent, we make this effect per-species.
+ if(type == WEP_SHOTGUN || type == WEP_UZI || type == WEP_RIFLE)
+ if(specstr != "")
+ {
+ effectnum = strcat(effectnum, "_", specstr);
+ effectnum = substring(effectnum, 0, strlen(effectnum) - 1); // remove the _ symbol at the end of the species name
+ }
+
+ entity head;
+
+ // Scan the owner of all gibs in the world. If a gib owner is the same as the player we're applying the
+ // effect to, it means our player is gibbed. Therefore, apply the particles to the gibs as well.
+ if(autocvar_cl_damageeffect_gibs && body > 1)
+ for(head = world; (head = find(head, classname, "gib")); )
+ {
+ if(head.team == entnumber)
+ if(random() < autocvar_cl_damageeffect_gibs)
+ pointparticles(particleeffectnum(effectnum), head.origin, '0 0 0', 1);
+ }
+
+ // if we aren't in third person mode, hide our own damage effect
+ if(entnumber == player_localentnum && !body)
+ if(!autocvar_chase_active)
+ return;
+ // if this is a gibbed dead body, don't apply the effects to it, only the gibs as done above
+ if(body > 1)
+ return;
+
+ // Now apply the effect to the actual player.
+ if(random() < autocvar_cl_damageeffect)
+ pointparticles(particleeffectnum(effectnum), org, '0 0 0', 1);
+}