1 void DamageEffect_Think()
3 // if particle distribution is enabled, slow ticrate by total number of damages
4 if(autocvar_cl_damageeffect_distribute)
5 self.nextthink = time + autocvar_cl_damageeffect_ticrate * self.owner.total_damages;
7 self.nextthink = time + autocvar_cl_damageeffect_ticrate;
9 if(time >= self.cnt || !self.owner || !self.owner.modelindex || !self.owner.drawmask)
11 // time is up or the player got gibbed / disconnected
12 self.owner.total_damages = max(0, self.owner.total_damages - 1);
16 if(self.state && !self.owner.csqcmodel_isdead)
18 // if the player was dead but is now alive, it means he respawned
19 // if so, clear his damage effects, or damages from his dead body will be copied back
20 self.owner.total_damages = max(0, self.owner.total_damages - 1);
24 self.state = self.owner.csqcmodel_isdead;
25 if(self.owner.isplayermodel && (self.owner.entnum == player_localentnum) && !autocvar_chase_active)
26 return; // if we aren't using a third person camera, hide our own effects
28 // now generate the particles
30 org = gettaginfo(self, 0); // origin at attached location
31 pointparticles(self.team, org, '0 0 0', 1);
34 void DamageEffect(vector hitorg, float dmg, float type, float specnum)
36 // particle effects for players and objects damaged by weapons (eg: flames coming out of victims shot with rockets)
38 float life, nearestbone = 0;
39 string specstr, effectname;
42 if(!autocvar_cl_damageeffect || autocvar_cl_gentle || autocvar_cl_gentle_damage)
44 if(!self || !self.modelindex || !self.drawmask)
47 // if this is a rigged mesh, the effect will show on the bone where damage was dealt
48 // we do this by choosing the skeletal bone closest to the impact, and attaching our entity to it
49 // if there's no skeleton, object origin will automatically be selected
53 continue; // skip empty bones
54 // blacklist bones positioned outside the mesh, or the effect will be floating
55 // TODO: Do we have to do it this way? Why do these bones exist at all?
56 if(gettaginfo_name == "master" || gettaginfo_name == "knee_L" || gettaginfo_name == "knee_R" || gettaginfo_name == "leg_L" || gettaginfo_name == "leg_R")
57 continue; // player model bone blacklist
59 // now choose the bone closest to impact origin
60 if(nearestbone == 0 || vlen(hitorg - gettaginfo(self, tagnum)) <= vlen(hitorg - gettaginfo(self, nearestbone)))
63 gettaginfo(self, nearestbone); // set gettaginfo_name
65 // return if we reached our damage effect limit or damages are disabled
66 // TODO: When the limit is reached, it would be better if the oldest damage was removed instead of not adding a new one
69 if(self.total_damages >= autocvar_cl_damageeffect_bones)
70 return; // allow multiple damages on skeletal models
74 if(autocvar_cl_damageeffect < 2 || self.total_damages)
75 return; // allow a single damage on non-skeletal models
78 life = bound(autocvar_cl_damageeffect_lifetime_min, dmg * autocvar_cl_damageeffect_lifetime, autocvar_cl_damageeffect_lifetime_max);
80 effectname = get_weaponinfo(DEATH_WEAPONOF(type)).netname;
82 if(substring(effectname, strlen(effectname) - 5, 5) == "BLOOD")
84 if(self.isplayermodel)
86 specstr = species_prefix(specnum);
87 specstr = substring(specstr, 0, strlen(specstr) - 1);
88 effectname = strreplace("BLOOD", specstr, effectname);
90 else { return; } // objects don't bleed
94 setmodel(e, "null"); // necessary to attach and read origin
95 setattachment(e, self, gettaginfo_name); // attach to the given bone
96 e.classname = "damage";
99 e.team = particleeffectnum(effectname);
100 e.think = DamageEffect_Think;
102 self.total_damages += 1;
105 void Ent_DamageInfo(float isNew)
107 float dmg, rad, edge, thisdmg, forcemul, species, hitplayer = FALSE;
108 vector force, thisforce;
113 w_deathtype = ReadShort();
114 w_issilent = (w_deathtype & 0x8000);
115 w_deathtype = (w_deathtype & 0x7FFF);
117 w_org_x = ReadCoord();
118 w_org_y = ReadCoord();
119 w_org_z = ReadCoord();
124 force = decompressShortVector(ReadShort());
125 species = ReadByte();
138 for(self = findradius(w_org, rad + MAX_DAMAGEEXTRARADIUS); self; self = self.chain)
140 // attached ents suck
144 vector nearest = NearestPointOnBox(self, w_org);
147 thisdmg = ((vlen (nearest - w_org) - bound(MIN_DAMAGEEXTRARADIUS, self.damageextraradius, MAX_DAMAGEEXTRARADIUS)) / rad);
154 thisdmg = dmg + (edge - dmg) * thisdmg;
155 thisforce = forcemul * vlen(force) * (thisdmg / dmg) * normalize(self.origin - w_org);
160 thisforce = forcemul * vlen(force) * normalize(self.origin - w_org);
165 if(vlen(nearest - w_org) > bound(MIN_DAMAGEEXTRARADIUS, self.damageextraradius, MAX_DAMAGEEXTRARADIUS))
169 thisforce = forcemul * force;
172 if(self.damageforcescale)
175 self.move_velocity = self.move_velocity + damage_explosion_calcpush(self.damageforcescale * thisforce, self.move_velocity, autocvar_g_balance_damagepush_speedfactor);
176 self.move_flags &= ~FL_ONGROUND;
182 if(self.event_damage)
183 self.event_damage(thisdmg, w_deathtype, w_org, thisforce);
185 DamageEffect(w_org, thisdmg, w_deathtype, species);
187 if(self.isplayermodel)
188 hitplayer = TRUE; // this impact damaged a player
193 if(DEATH_ISVEHICLE(w_deathtype))
195 traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
196 if(trace_plane_normal != '0 0 0')
197 w_backoff = trace_plane_normal;
199 w_backoff = -1 * normalize(w_org - (w_org + normalize(force) * 16));
201 setorigin(self, w_org + w_backoff * 2); // for sound() calls
209 case DEATH_VH_SPID_MINIGUN:
211 _snd = strcat("weapons/ric", ftos(1 + rint(random() * 2)), ".waw");
212 sound(self, CH_SHOTS, _snd, VOL_BASE, ATTEN_NORM);
213 pointparticles(particleeffectnum("spiderbot_minigun_impact"), self.origin, w_backoff * 1000, 1);
215 case DEATH_VH_SPID_ROCKET:
216 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
217 pointparticles(particleeffectnum("spiderbot_rocket_explode"), self.origin, w_backoff * 1000, 1);
219 case DEATH_VH_SPID_DEATH:
220 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_MIN);
221 pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
224 case DEATH_VH_WAKI_GUN:
225 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTEN_NORM);
226 pointparticles(particleeffectnum("wakizashi_gun_impact"), self.origin, w_backoff * 1000, 1);
228 case DEATH_VH_WAKI_ROCKET:
229 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
230 pointparticles(particleeffectnum("wakizashi_rocket_explode"), self.origin, w_backoff * 1000, 1);
232 case DEATH_VH_WAKI_DEATH:
233 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_MIN);
234 pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
237 case DEATH_VH_RAPT_CANNON:
238 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTEN_NORM);
239 pointparticles(particleeffectnum("raptor_cannon_impact"), self.origin, w_backoff * 1000, 1);
241 case DEATH_VH_RAPT_FRAGMENT:
244 for(i = 1; i < 4; ++i)
246 vel = normalize(w_org - (w_org + normalize(force) * 16)) + randomvec() * 128;
247 ang = vectoangles(vel);
248 RaptorCBShellfragToss(w_org, vel, ang + '0 0 1' * (120 * i));
250 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
251 pointparticles(particleeffectnum("raptor_bomb_spread"), self.origin, w_backoff * 1000, 1);
253 case DEATH_VH_RAPT_BOMB:
254 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
255 pointparticles(particleeffectnum("raptor_bomb_impact"), self.origin, w_backoff * 1000, 1);
257 case DEATH_VH_RAPT_DEATH:
258 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTEN_MIN);
259 pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
261 case DEATH_VH_BUMB_GUN:
262 sound(self, CH_SHOTS, "weapons/fireball_impact2.wav", VOL_BASE, ATTEN_NORM);
263 pointparticles(particleeffectnum("bigplasma_impact"), self.origin, w_backoff * 1000, 1);
269 if(DEATH_ISTURRET(w_deathtype))
272 traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
273 if(trace_plane_normal != '0 0 0')
274 w_backoff = trace_plane_normal;
276 w_backoff = -1 * normalize(w_org - (w_org + normalize(force) * 16));
278 setorigin(self, w_org + w_backoff * 2); // for sound() calls
282 case DEATH_TURRET_EWHEEL:
283 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTEN_MIN);
284 pointparticles(particleeffectnum("laser_impact"), self.origin, w_backoff * 1000, 1);
287 case DEATH_TURRET_FLAC:
288 pointparticles(particleeffectnum("hagar_explode"), w_org, '0 0 0', 1);
289 _snd = strcat("weapons/hagexp", ftos(1 + rint(random() * 2)), ".waw");
290 sound(self, CH_SHOTS, _snd, VOL_BASE, ATTEN_NORM);
293 case DEATH_TURRET_MLRS:
294 case DEATH_TURRET_HK:
295 case DEATH_TURRET_WALK_ROCKET:
296 case DEATH_TURRET_HELLION:
297 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_MIN);
298 pointparticles(particleeffectnum("rocket_explode"), self.origin, w_backoff * 1000, 1);
301 case DEATH_TURRET_MACHINEGUN:
302 case DEATH_TURRET_WALK_GUN:
303 _snd = strcat("weapons/ric", ftos(1 + rint(random() * 2)), ".waw");
304 sound(self, CH_SHOTS, _snd, VOL_BASE, ATTEN_NORM);
305 pointparticles(particleeffectnum("machinegun_impact"), self.origin, w_backoff * 1000, 1);
308 case DEATH_TURRET_PLASMA:
309 sound(self, CH_SHOTS, "weapons/electro_impact.wav", VOL_BASE, ATTEN_MIN);
310 pointparticles(particleeffectnum("electro_impact"), self.origin, w_backoff * 1000, 1);
313 case DEATH_TURRET_WALK_MEELE:
314 sound(self, CH_SHOTS, "weapons/ric1.wav", VOL_BASE, ATTEN_MIN);
315 pointparticles(particleeffectnum("TE_SPARK"), self.origin, w_backoff * 1000, 1);
318 case DEATH_TURRET_PHASER:
321 case DEATH_TURRET_TESLA:
322 te_smallflash(self.origin);
328 // TODO spawn particle effects and sounds based on w_deathtype
329 if(!DEATH_ISSPECIAL(w_deathtype))
330 if(!hitplayer || rad) // don't show ground impacts for hitscan weapons if a player was hit
334 hitwep = DEATH_WEAPONOFWEAPONDEATH(w_deathtype);
335 w_random = prandom();
337 traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
338 if(trace_fraction < 1 && hitwep != WEP_VORTEX && hitwep != WEP_VAPORIZER)
339 w_backoff = trace_plane_normal;
341 w_backoff = -1 * normalize(force);
342 setorigin(self, w_org + w_backoff * 2); // for sound() calls
344 if(!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY)) { WEP_ACTION(hitwep, WR_IMPACTEFFECT); }