6 entity Nade_TrailEffect(int proj, int nade_team)
10 case PROJECTILE_NADE: return EFFECT_NADE_TRAIL(nade_team);
11 case PROJECTILE_NADE_BURN: return EFFECT_NADE_TRAIL_BURN(nade_team);
14 FOREACH(Nades, true, LAMBDA(
15 for (int j = 0; j < 2; j++)
17 if (it.m_projectile[j] == proj)
19 string trail = it.m_trail[j].eent_eff_name;
20 if (trail) return it.m_trail[j];
31 REGISTER_MUTATOR(cl_nades, true);
32 MUTATOR_HOOKFUNCTION(cl_nades, HUD_Draw_overlay)
34 if (STAT(HEALING_ORB) <= time) return false;
35 MUTATOR_ARGV(0, vector) = NADE_TYPE_HEAL.m_color;
36 MUTATOR_ARGV(0, float) = STAT(HEALING_ORB_ALPHA);
39 MUTATOR_HOOKFUNCTION(cl_nades, Ent_Projectile)
41 if (self.cnt == PROJECTILE_NAPALM_FOUNTAIN)
44 self.traileffect = EFFECT_FIREBALL.m_id;
47 if (Nade_FromProjectile(self.cnt) != NADE_TYPE_Null)
49 setmodel(self, MDL_PROJECTILE_NADE);
50 entity trail = Nade_TrailEffect(self.cnt, self.team);
51 if (trail.eent_eff_name) self.traileffect = trail.m_id;
55 MUTATOR_HOOKFUNCTION(cl_nades, EditProjectile)
57 if (self.cnt == PROJECTILE_NAPALM_FOUNTAIN)
59 loopsound(self, CH_SHOTS_SINGLE, SND(FIREBALL_FLY2), VOL_BASE, ATTEN_NORM);
60 self.mins = '-16 -16 -16';
61 self.maxs = '16 16 16';
64 entity nade_type = Nade_FromProjectile(self.cnt);
65 if (nade_type == NADE_TYPE_Null) return;
66 self.mins = '-16 -16 -16';
67 self.maxs = '16 16 16';
68 self.colormod = nade_type.m_color;
69 self.move_movetype = MOVETYPE_BOUNCE;
70 self.move_touch = func_null;
72 self.avelocity = randomvec() * 720;
74 if (nade_type == NADE_TYPE_TRANSLOCATE || nade_type == NADE_TYPE_SPAWN)
75 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
77 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
79 bool Projectile_isnade(int p)
81 return Nade_FromProjectile(p) != NADE_TYPE_Null;
83 void DrawAmmoNades(vector myPos, vector mySize, bool draw_expanding, float expand_time)
85 float bonusNades = STAT(NADE_BONUS);
86 float bonusProgress = STAT(NADE_BONUS_SCORE);
87 float bonusType = STAT(NADE_BONUS_TYPE);
88 Nade def = Nades_from(bonusType);
89 vector nadeColor = def.m_color;
90 string nadeIcon = def.m_icon;
92 vector iconPos, textPos;
94 if(autocvar_hud_panel_ammo_iconalign)
96 iconPos = myPos + eX * 2 * mySize.y;
102 textPos = myPos + eX * mySize.y;
105 if(bonusNades > 0 || bonusProgress > 0)
107 DrawNadeProgressBar(myPos, mySize, bonusProgress, nadeColor);
109 if(autocvar_hud_panel_ammo_text)
110 drawstring_aspect(textPos, ftos(bonusNades), eX * (2/3) * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
113 drawpic_aspect_skin_expanding(iconPos, nadeIcon, '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, expand_time);
115 drawpic_aspect_skin(iconPos, nadeIcon, '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
122 #include <common/gamemodes/all.qh>
123 #include <common/monsters/spawn.qh>
124 #include <common/monsters/sv_monsters.qh>
125 #include <server/g_subs.qh>
127 REGISTER_MUTATOR(nades, cvar("g_nades"));
129 .float nade_time_primed;
131 .entity nade_spawnloc;
133 void nade_timer_think()
135 self.skin = 8 - (self.owner.wait - time) / (autocvar_g_nades_nade_lifetime / 10);
136 self.nextthink = time;
137 if(!self.owner || wasfreed(self.owner))
141 void nade_burn_spawn(entity _nade)
143 CSQCProjectile(_nade, true, Nades_from(_nade.nade_type).m_projectile[true], true);
146 void nade_spawn(entity _nade)
148 entity timer = new(nade_timer);
149 setmodel(timer, MDL_NADE_TIMER);
150 setattachment(timer, _nade, "");
151 timer.colormap = _nade.colormap;
152 timer.glowmod = _nade.glowmod;
153 timer.think = nade_timer_think;
154 timer.nextthink = time;
155 timer.wait = _nade.wait;
159 _nade.effects |= EF_LOWPRECISION;
161 CSQCProjectile(_nade, true, Nades_from(_nade.nade_type).m_projectile[false], true);
164 void napalm_damage(float dist, float damage, float edgedamage, float burntime)
173 RandomSelection_Init();
174 for(e = WarpZone_FindRadius(self.origin, dist, true); e; e = e.chain)
175 if(e.takedamage == DAMAGE_AIM)
176 if(self.realowner != e || autocvar_g_nades_napalm_selfdamage)
177 if(!IS_PLAYER(e) || !self.realowner || DIFF_TEAM(e, self))
181 p.x += e.mins.x + random() * (e.maxs.x - e.mins.x);
182 p.y += e.mins.y + random() * (e.maxs.y - e.mins.y);
183 p.z += e.mins.z + random() * (e.maxs.z - e.mins.z);
184 d = vlen(WarpZone_UnTransformOrigin(e, self.origin) - p);
187 e.fireball_impactvec = p;
188 RandomSelection_Add(e, 0, string_null, 1 / (1 + d), !Fire_IsBurning(e));
191 if(RandomSelection_chosen_ent)
193 d = vlen(WarpZone_UnTransformOrigin(RandomSelection_chosen_ent, self.origin) - RandomSelection_chosen_ent.fireball_impactvec);
194 d = damage + (edgedamage - damage) * (d / dist);
195 Fire_AddDamage(RandomSelection_chosen_ent, self.realowner, d * burntime, burntime, self.projectiledeathtype | HITTYPE_BOUNCE);
196 //trailparticles(self, particleeffectnum(EFFECT_FIREBALL_LASER), self.origin, RandomSelection_chosen_ent.fireball_impactvec);
197 Send_Effect(EFFECT_FIREBALL_LASER, self.origin, RandomSelection_chosen_ent.fireball_impactvec - self.origin, 1);
202 void napalm_ball_think()
204 if(round_handler_IsActive())
205 if(!round_handler_IsRoundStarted())
211 if(time > self.pushltime)
217 vector midpoint = ((self.absmin + self.absmax) * 0.5);
218 if(pointcontents(midpoint) == CONTENT_WATER)
220 self.velocity = self.velocity * 0.5;
222 if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
223 { self.velocity_z = 200; }
226 self.angles = vectoangles(self.velocity);
228 napalm_damage(autocvar_g_nades_napalm_ball_radius,autocvar_g_nades_napalm_ball_damage,
229 autocvar_g_nades_napalm_ball_damage,autocvar_g_nades_napalm_burntime);
231 self.nextthink = time + 0.1;
235 void nade_napalm_ball()
240 spamsound(self, CH_SHOTS, SND(FIREBALL_FIRE), VOL_BASE, ATTEN_NORM);
243 proj.owner = self.owner;
244 proj.realowner = self.realowner;
245 proj.team = self.owner.team;
246 proj.bot_dodge = true;
247 proj.bot_dodgerating = autocvar_g_nades_napalm_ball_damage;
248 proj.movetype = MOVETYPE_BOUNCE;
249 proj.projectiledeathtype = DEATH_NADE_NAPALM.m_id;
250 PROJECTILE_MAKETRIGGER(proj);
251 setmodel(proj, MDL_Null);
252 proj.scale = 1;//0.5;
253 setsize(proj, '-4 -4 -4', '4 4 4');
254 setorigin(proj, self.origin);
255 proj.think = napalm_ball_think;
256 proj.nextthink = time;
257 proj.damageforcescale = autocvar_g_nades_napalm_ball_damageforcescale;
258 proj.effects = EF_LOWPRECISION | EF_FLAME;
260 kick.x =(random() - 0.5) * 2 * autocvar_g_nades_napalm_ball_spread;
261 kick.y = (random() - 0.5) * 2 * autocvar_g_nades_napalm_ball_spread;
262 kick.z = (random()/2+0.5) * autocvar_g_nades_napalm_ball_spread;
263 proj.velocity = kick;
265 proj.pushltime = time + autocvar_g_nades_napalm_ball_lifetime;
267 proj.angles = vectoangles(proj.velocity);
268 proj.flags = FL_PROJECTILE;
269 proj.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_ARC;
271 //CSQCProjectile(proj, true, PROJECTILE_NAPALM_FIRE, true);
275 void napalm_fountain_think()
278 if(round_handler_IsActive())
279 if(!round_handler_IsRoundStarted())
285 if(time >= self.ltime)
291 vector midpoint = ((self.absmin + self.absmax) * 0.5);
292 if(pointcontents(midpoint) == CONTENT_WATER)
294 self.velocity = self.velocity * 0.5;
296 if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
297 { self.velocity_z = 200; }
299 UpdateCSQCProjectile(self);
302 napalm_damage(autocvar_g_nades_napalm_fountain_radius, autocvar_g_nades_napalm_fountain_damage,
303 autocvar_g_nades_napalm_fountain_edgedamage, autocvar_g_nades_napalm_burntime);
305 self.nextthink = time + 0.1;
306 if(time >= self.nade_special_time)
308 self.nade_special_time = time + autocvar_g_nades_napalm_fountain_delay;
313 void nade_napalm_boom()
317 for (c = 0; c < autocvar_g_nades_napalm_ball_count; c++)
322 fountain.owner = self.owner;
323 fountain.realowner = self.realowner;
324 fountain.origin = self.origin;
325 setorigin(fountain, fountain.origin);
326 fountain.think = napalm_fountain_think;
327 fountain.nextthink = time;
328 fountain.ltime = time + autocvar_g_nades_napalm_fountain_lifetime;
329 fountain.pushltime = fountain.ltime;
330 fountain.team = self.team;
331 fountain.movetype = MOVETYPE_TOSS;
332 fountain.projectiledeathtype = DEATH_NADE_NAPALM.m_id;
333 fountain.bot_dodge = true;
334 fountain.bot_dodgerating = autocvar_g_nades_napalm_fountain_damage;
335 fountain.nade_special_time = time;
336 setsize(fountain, '-16 -16 -16', '16 16 16');
337 CSQCProjectile(fountain, true, PROJECTILE_NAPALM_FOUNTAIN, true);
340 void nade_ice_freeze(entity freezefield, entity frost_target, float freeze_time)
342 frost_target.frozen_by = freezefield.realowner;
343 Send_Effect(EFFECT_ELECTRO_IMPACT, frost_target.origin, '0 0 0', 1);
344 Freeze(frost_target, 1/freeze_time, 3, false);
346 Drop_Special_Items(frost_target);
349 void nade_ice_think()
352 if(round_handler_IsActive())
353 if(!round_handler_IsRoundStarted())
359 if(time >= self.ltime)
361 if ( autocvar_g_nades_ice_explode )
363 entity expef = EFFECT_NADE_EXPLODE(self.realowner.team);
364 Send_Effect(expef, self.origin + '0 0 1', '0 0 0', 1);
365 sound(self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
367 RadiusDamage(self, self.realowner, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
368 autocvar_g_nades_nade_radius, self, world, autocvar_g_nades_nade_force, self.projectiledeathtype, self.enemy);
369 Damage_DamageInfo(self.origin, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
370 autocvar_g_nades_nade_radius, '1 1 1' * autocvar_g_nades_nade_force, self.projectiledeathtype, 0, self);
377 self.nextthink = time+0.1;
382 randomr = exp(-5*randomr*randomr)*autocvar_g_nades_nade_radius;
384 randomw = random()*M_PI*2;
386 randomp.x = randomr*cos(randomw);
387 randomp.y = randomr*sin(randomw);
389 Send_Effect(EFFECT_ELECTRO_MUZZLEFLASH, self.origin + randomp, '0 0 0', 1);
391 if(time >= self.nade_special_time)
393 self.nade_special_time = time+0.7;
395 Send_Effect(EFFECT_ELECTRO_IMPACT, self.origin, '0 0 0', 1);
396 Send_Effect(EFFECT_ICEFIELD, self.origin, '0 0 0', 1);
400 float current_freeze_time = self.ltime - time - 0.1;
403 for(e = findradius(self.origin, autocvar_g_nades_nade_radius); e; e = e.chain)
405 if(!autocvar_g_nades_ice_teamcheck || (DIFF_TEAM(e, self.realowner) || e == self.realowner))
406 if(e.takedamage && !IS_DEAD(e))
408 if(!e.revival_time || ((time - e.revival_time) >= 1.5))
410 if(current_freeze_time > 0)
411 nade_ice_freeze(self, e, current_freeze_time);
418 fountain.owner = self.owner;
419 fountain.realowner = self.realowner;
420 fountain.origin = self.origin;
421 setorigin(fountain, fountain.origin);
422 fountain.think = nade_ice_think;
423 fountain.nextthink = time;
424 fountain.ltime = time + autocvar_g_nades_ice_freeze_time;
425 fountain.pushltime = fountain.wait = fountain.ltime;
426 fountain.team = self.team;
427 fountain.movetype = MOVETYPE_TOSS;
428 fountain.projectiledeathtype = DEATH_NADE_ICE.m_id;
429 fountain.bot_dodge = false;
430 setsize(fountain, '-16 -16 -16', '16 16 16');
431 fountain.nade_special_time = time+0.3;
432 fountain.angles = self.angles;
434 if ( autocvar_g_nades_ice_explode )
436 setmodel(fountain, MDL_PROJECTILE_GRENADE);
437 entity timer = new(nade_timer);
438 setmodel(timer, MDL_NADE_TIMER);
439 setattachment(timer, fountain, "");
440 timer.colormap = self.colormap;
441 timer.glowmod = self.glowmod;
442 timer.think = nade_timer_think;
443 timer.nextthink = time;
444 timer.wait = fountain.ltime;
445 timer.owner = fountain;
449 setmodel(fountain, MDL_Null);
452 void nade_translocate_boom()
454 if(self.realowner.vehicle)
457 vector locout = self.origin + '0 0 1' * (1 - self.realowner.mins.z - 24);
458 tracebox(locout, self.realowner.mins, self.realowner.maxs, locout, MOVE_NOMONSTERS, self.realowner);
459 locout = trace_endpos;
461 makevectors(self.realowner.angles);
463 MUTATOR_CALLHOOK(PortalTeleport, self.realowner);
465 TeleportPlayer(self, self.realowner, locout, self.realowner.angles, v_forward * vlen(self.realowner.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
468 void nade_spawn_boom()
470 entity spawnloc = spawn();
471 setorigin(spawnloc, self.origin);
472 setsize(spawnloc, self.realowner.mins, self.realowner.maxs);
473 spawnloc.movetype = MOVETYPE_NONE;
474 spawnloc.solid = SOLID_NOT;
475 spawnloc.drawonlytoclient = self.realowner;
476 spawnloc.effects = EF_STARDUST;
477 spawnloc.cnt = autocvar_g_nades_spawn_count;
479 if(self.realowner.nade_spawnloc)
481 remove(self.realowner.nade_spawnloc);
482 self.realowner.nade_spawnloc = world;
485 self.realowner.nade_spawnloc = spawnloc;
488 void nade_heal_think()
490 if(time >= self.ltime)
496 self.nextthink = time;
498 if(time >= self.nade_special_time)
500 self.nade_special_time = time+0.25;
501 self.nade_show_particles = 1;
504 self.nade_show_particles = 0;
507 void nade_heal_touch()
511 if(IS_PLAYER(other) || IS_MONSTER(other))
513 if(!STAT(FROZEN, other))
515 health_factor = autocvar_g_nades_heal_rate*frametime/2;
516 if ( other != self.realowner )
518 if ( SAME_TEAM(other,self) )
519 health_factor *= autocvar_g_nades_heal_friend;
521 health_factor *= autocvar_g_nades_heal_foe;
523 if ( health_factor > 0 )
525 maxhealth = (IS_MONSTER(other)) ? other.max_health : g_pickup_healthmega_max;
526 if ( other.health < maxhealth )
528 if ( self.nade_show_particles )
529 Send_Effect(EFFECT_HEALING, other.origin, '0 0 0', 1);
530 other.health = min(other.health+health_factor, maxhealth);
532 other.pauserothealth_finished = max(other.pauserothealth_finished, time + autocvar_g_balance_pause_health_rot);
534 else if ( health_factor < 0 )
536 Damage(other,self,self.realowner,-health_factor,DEATH_NADE_HEAL.m_id,other.origin,'0 0 0');
541 if ( IS_REAL_CLIENT(other) || IS_VEHICLE(other) )
543 entity show_red = (IS_VEHICLE(other)) ? other.owner : other;
544 show_red.stat_healing_orb = time+0.1;
545 show_red.stat_healing_orb_alpha = 0.75 * (self.ltime - time) / self.healer_lifetime;
549 void nade_heal_boom()
553 healer.owner = self.owner;
554 healer.realowner = self.realowner;
555 setorigin(healer, self.origin);
556 healer.healer_lifetime = autocvar_g_nades_heal_time; // save the cvar
557 healer.ltime = time + healer.healer_lifetime;
558 healer.team = self.realowner.team;
559 healer.bot_dodge = false;
560 healer.solid = SOLID_TRIGGER;
561 healer.touch = nade_heal_touch;
563 setmodel(healer, MDL_NADE_HEAL);
564 healer.healer_radius = autocvar_g_nades_nade_radius;
565 vector size = '1 1 1' * healer.healer_radius / 2;
566 setsize(healer,-size,size);
568 Net_LinkEntity(healer, true, 0, healer_send);
570 healer.think = nade_heal_think;
571 healer.nextthink = time;
572 healer.SendFlags |= 1;
575 void nade_monster_boom()
577 entity e = spawnmonster(self.pokenade_type, 0, self.realowner, self.realowner, self.origin, false, false, 1);
579 if(autocvar_g_nades_pokenade_monster_lifetime > 0)
580 e.monster_lifetime = time + autocvar_g_nades_pokenade_monster_lifetime;
581 e.monster_skill = MONSTER_SKILL_INSANE;
587 bool nade_blast = true;
589 switch ( Nades_from(self.nade_type) )
591 case NADE_TYPE_NAPALM:
592 nade_blast = autocvar_g_nades_napalm_blast;
593 expef = EFFECT_EXPLOSION_MEDIUM;
597 expef = EFFECT_ELECTRO_COMBO; // hookbomb_explode electro_combo bigplasma_impact
599 case NADE_TYPE_TRANSLOCATE:
602 case NADE_TYPE_MONSTER:
603 case NADE_TYPE_SPAWN:
605 switch(self.realowner.team)
607 case NUM_TEAM_1: expef = EFFECT_SPAWN_RED; break;
608 case NUM_TEAM_2: expef = EFFECT_SPAWN_BLUE; break;
609 case NUM_TEAM_3: expef = EFFECT_SPAWN_YELLOW; break;
610 case NUM_TEAM_4: expef = EFFECT_SPAWN_PINK; break;
611 default: expef = EFFECT_SPAWN_NEUTRAL; break;
616 expef = EFFECT_SPAWN_RED;
620 case NADE_TYPE_NORMAL:
621 expef = EFFECT_NADE_EXPLODE(self.realowner.team);
626 Send_Effect(expef, findbetterlocation(self.origin, 8), '0 0 0', 1);
628 sound(self, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM);
629 sound(self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
631 self.event_damage = func_null; // prevent somehow calling damage in the next call
635 RadiusDamage(self, self.realowner, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage,
636 autocvar_g_nades_nade_radius, self, world, autocvar_g_nades_nade_force, self.projectiledeathtype, self.enemy);
637 Damage_DamageInfo(self.origin, autocvar_g_nades_nade_damage, autocvar_g_nades_nade_edgedamage, autocvar_g_nades_nade_radius, '1 1 1' * autocvar_g_nades_nade_force, self.projectiledeathtype, 0, self);
641 switch ( Nades_from(self.nade_type) )
643 case NADE_TYPE_NAPALM: nade_napalm_boom(); break;
644 case NADE_TYPE_ICE: nade_ice_boom(); break;
645 case NADE_TYPE_TRANSLOCATE: nade_translocate_boom(); break;
646 case NADE_TYPE_SPAWN: nade_spawn_boom(); break;
647 case NADE_TYPE_HEAL: nade_heal_boom(); break;
648 case NADE_TYPE_MONSTER: nade_monster_boom(); break;
651 FOREACH_ENTITY_ENT(aiment, self,
653 if(it.classname == "grapplinghook")
654 RemoveGrapplingHook(it.realowner);
663 UpdateCSQCProjectile(self);
665 if(other == self.realowner)
666 return; // no self impacts
667 /*float is_weapclip = 0;
668 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NODRAW)
669 if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NONSOLID))
670 if (!(trace_dphitcontents & DPCONTENTS_OPAQUE))
672 if(ITEM_TOUCH_NEEDKILL()) // || is_weapclip)
674 FOREACH_ENTITY_ENT(aiment, self,
676 if(it.classname == "grapplinghook")
677 RemoveGrapplingHook(it.realowner);
685 //setsize(self, '-2 -2 -2', '2 2 2');
686 //UpdateCSQCProjectile(self);
687 if(self.health == self.max_health)
689 spamsound(self, CH_SHOTS, SND(GRENADE_BOUNCE_RANDOM()), VOL_BASE, ATTEN_NORM);
699 sound(self, CH_SHOTS_SINGLE, SND_NADE_BEEP, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
700 self.think = nade_boom;
701 self.nextthink = max(self.wait, time);
704 void nade_damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
706 if(ITEM_DAMAGE_NEEDKILL(deathtype))
708 self.takedamage = DAMAGE_NO;
713 if(self.nade_type == NADE_TYPE_TRANSLOCATE.m_id || self.nade_type == NADE_TYPE_SPAWN.m_id)
716 if (MUTATOR_CALLHOOK(Nade_Damage, DEATH_WEAPONOF(deathtype), force, damage)) {}
717 else if(DEATH_ISWEAPON(deathtype, WEP_BLASTER))
722 else if(DEATH_ISWEAPON(deathtype, WEP_VAPORIZER) && (deathtype & HITTYPE_SECONDARY))
724 force *= 0.5; // too much
727 else if(DEATH_ISWEAPON(deathtype, WEP_VORTEX) || DEATH_ISWEAPON(deathtype, WEP_VAPORIZER))
730 damage = self.max_health * 0.55;
732 else if(DEATH_ISWEAPON(deathtype, WEP_MACHINEGUN))
733 damage = self.max_health * 0.1;
734 else if(DEATH_ISWEAPON(deathtype, WEP_SHOCKWAVE) || DEATH_ISWEAPON(deathtype, WEP_SHOTGUN)) // WEAPONTODO
736 if(deathtype & HITTYPE_SECONDARY)
738 damage = self.max_health * 0.1;
742 damage = self.max_health * 1.15;
745 self.velocity += force;
746 UpdateCSQCProjectile(self);
748 if(damage <= 0 || ((IS_ONGROUND(self)) && IS_PLAYER(attacker)))
751 if(self.health == self.max_health)
753 sound(self, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, 0.5 *(ATTEN_LARGE + ATTEN_MAX));
754 self.nextthink = max(time + autocvar_g_nades_nade_lifetime, time);
755 self.think = nade_beep;
758 self.health -= damage;
760 if ( self.nade_type != NADE_TYPE_HEAL.m_id || IS_PLAYER(attacker) )
761 self.realowner = attacker;
764 W_PrepareExplosionByDamage(attacker, nade_boom);
766 nade_burn_spawn(self);
769 void toss_nade(entity e, vector _velocity, float _time)
774 entity _nade = e.nade;
780 makevectors(e.v_angle);
782 W_SetupShot(e, false, false, "", CH_WEAPON_A, 0);
784 Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER_CPID, CPID_NADES);
786 vector offset = (v_forward * autocvar_g_nades_throw_offset.x)
787 + (v_right * autocvar_g_nades_throw_offset.y)
788 + (v_up * autocvar_g_nades_throw_offset.z);
789 if(autocvar_g_nades_throw_offset == '0 0 0')
792 setorigin(_nade, w_shotorg + offset + (v_right * 25) * -1);
793 //setmodel(_nade, MDL_PROJECTILE_NADE);
794 //setattachment(_nade, world, "");
795 PROJECTILE_MAKETRIGGER(_nade);
796 setsize(_nade, '-16 -16 -16', '16 16 16');
797 _nade.movetype = MOVETYPE_BOUNCE;
799 tracebox(_nade.origin, _nade.mins, _nade.maxs, _nade.origin, false, _nade);
800 if (trace_startsolid)
801 setorigin(_nade, e.origin);
803 if(self.v_angle.x >= 70 && self.v_angle.x <= 110 && self.BUTTON_CROUCH)
804 _nade.velocity = '0 0 100';
805 else if(autocvar_g_nades_nade_newton_style == 1)
806 _nade.velocity = e.velocity + _velocity;
807 else if(autocvar_g_nades_nade_newton_style == 2)
808 _nade.velocity = _velocity;
810 _nade.velocity = W_CalculateProjectileVelocity(e.velocity, _velocity, true);
812 _nade.touch = nade_touch;
813 _nade.health = autocvar_g_nades_nade_health;
814 _nade.max_health = _nade.health;
815 _nade.takedamage = DAMAGE_AIM;
816 _nade.event_damage = nade_damage;
817 _nade.customizeentityforclient = func_null;
818 _nade.exteriormodeltoclient = world;
819 _nade.traileffectnum = 0;
820 _nade.teleportable = true;
821 _nade.pushable = true;
823 _nade.missile_flags = MIF_SPLASH | MIF_ARC;
824 _nade.damagedbycontents = true;
825 _nade.angles = vectoangles(_nade.velocity);
826 _nade.flags = FL_PROJECTILE;
827 _nade.projectiledeathtype = DEATH_NADE.m_id;
828 _nade.toss_time = time;
829 _nade.solid = SOLID_CORPSE; //((_nade.nade_type == NADE_TYPE_TRANSLOCATE) ? SOLID_CORPSE : SOLID_BBOX);
831 if(_nade.nade_type == NADE_TYPE_TRANSLOCATE.m_id || _nade.nade_type == NADE_TYPE_SPAWN.m_id)
832 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
834 _nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
840 _nade.think = nade_boom;
841 _nade.nextthink = _time;
844 e.nade_refire = time + autocvar_g_nades_nade_refire;
848 void nades_GiveBonus(entity player, float score)
850 if (autocvar_g_nades)
851 if (autocvar_g_nades_bonus)
852 if (IS_REAL_CLIENT(player))
853 if (IS_PLAYER(player) && player.bonus_nades < autocvar_g_nades_bonus_max)
854 if (STAT(FROZEN, player) == 0)
855 if (!IS_DEAD(player))
857 if ( player.bonus_nade_score < 1 )
858 player.bonus_nade_score += score/autocvar_g_nades_bonus_score_max;
860 if ( player.bonus_nade_score >= 1 )
862 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_NADE_BONUS);
863 play2(player, SND(KH_ALARM));
864 player.bonus_nades++;
865 player.bonus_nade_score -= 1;
870 /** Remove all bonus nades from a player */
871 void nades_RemoveBonus(entity player)
873 player.bonus_nades = player.bonus_nade_score = 0;
876 MUTATOR_HOOKFUNCTION(nades, PutClientInServer)
878 nades_RemoveBonus(self);
881 float nade_customize()
883 //if(IS_SPEC(other)) { return false; }
884 if(other == self.realowner || (IS_SPEC(other) && other.enemy == self.realowner))
886 // somewhat hide the model, but keep the glow
888 if(self.traileffectnum)
889 self.traileffectnum = 0;
894 //self.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
895 if(!self.traileffectnum)
896 self.traileffectnum = _particleeffectnum(Nade_TrailEffect(Nades_from(self.nade_type).m_projectile[false], self.team).eent_eff_name);
905 if(autocvar_g_nades_bonus_only)
906 if(!self.bonus_nades)
907 return; // only allow bonus nades
913 remove(self.fake_nade);
915 entity n = new(nade), fn = new(fake_nade);
917 if(self.items & ITEM_Strength.m_itemid && autocvar_g_nades_bonus_onstrength)
918 n.nade_type = self.nade_type;
919 else if (self.bonus_nades >= 1)
921 n.nade_type = self.nade_type;
922 n.pokenade_type = self.pokenade_type;
923 self.bonus_nades -= 1;
927 n.nade_type = ((autocvar_g_nades_client_select) ? self.cvar_cl_nade_type : autocvar_g_nades_nade_type);
928 n.pokenade_type = ((autocvar_g_nades_client_select) ? self.cvar_cl_pokenade_type : autocvar_g_nades_pokenade_monster_type);
931 n.nade_type = bound(1, n.nade_type, Nades_COUNT);
933 setmodel(n, MDL_PROJECTILE_NADE);
934 //setattachment(n, self, "bip01 l hand");
935 n.exteriormodeltoclient = self;
936 n.customizeentityforclient = nade_customize;
937 n.traileffectnum = _particleeffectnum(Nade_TrailEffect(Nades_from(n.nade_type).m_projectile[false], self.team).eent_eff_name);
938 n.colormod = Nades_from(n.nade_type).m_color;
940 n.colormap = self.colormap;
941 n.glowmod = self.glowmod;
942 n.wait = time + autocvar_g_nades_nade_lifetime;
943 n.nade_time_primed = time;
945 n.nextthink = max(n.wait - 3, time);
946 n.projectiledeathtype = DEATH_NADE.m_id;
948 setmodel(fn, MDL_NADE_VIEW);
949 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
950 setattachment(fn, self.(weaponentity), "");
951 fn.realowner = fn.owner = self;
952 fn.colormod = Nades_from(n.nade_type).m_color;
953 fn.colormap = self.colormap;
954 fn.glowmod = self.glowmod;
955 fn.think = SUB_Remove_self;
956 fn.nextthink = n.wait;
973 if (!autocvar_g_nades)
974 return false; // allow turning them off mid match
976 if(forbidWeaponUse(self))
979 if (!IS_PLAYER(self))
985 .bool nade_altbutton;
987 void nades_CheckThrow()
992 entity held_nade = self.nade;
995 self.nade_altbutton = true;
996 if(time > self.nade_refire)
998 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_NADE_THROW);
1000 self.nade_refire = time + autocvar_g_nades_nade_refire;
1005 self.nade_altbutton = false;
1006 if (time >= held_nade.nade_time_primed + 1) {
1007 makevectors(self.v_angle);
1008 float _force = time - held_nade.nade_time_primed;
1009 _force /= autocvar_g_nades_nade_lifetime;
1010 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
1011 toss_nade(self, (v_forward * 0.75 + v_up * 0.2 + v_right * 0.05) * _force, 0);
1016 void nades_Clear(entity player)
1019 remove(player.nade);
1020 if(player.fake_nade)
1021 remove(player.fake_nade);
1023 player.nade = player.fake_nade = world;
1024 player.nade_timer = 0;
1027 MUTATOR_HOOKFUNCTION(nades, VehicleEnter)
1030 toss_nade(vh_player, '0 0 100', max(vh_player.nade.wait, time + 0.05));
1035 CLASS(NadeOffhand, OffhandWeapon)
1036 METHOD(NadeOffhand, offhand_think, void(NadeOffhand this, entity player, bool key_pressed))
1038 entity held_nade = player.nade;
1041 player.nade_timer = bound(0, (time - held_nade.nade_time_primed) / autocvar_g_nades_nade_lifetime, 1);
1042 // LOG_TRACEF("%d %d\n", player.nade_timer, time - held_nade.nade_time_primed);
1043 makevectors(player.angles);
1044 held_nade.velocity = player.velocity;
1045 setorigin(held_nade, player.origin + player.view_ofs + v_forward * 8 + v_right * -8 + v_up * 0);
1046 held_nade.angles_y = player.angles.y;
1048 if (time + 0.1 >= held_nade.wait)
1049 toss_nade(player, '0 0 0', time + 0.05);
1052 if (!CanThrowNade()) return;
1053 if (!(time > player.nade_refire)) return;
1057 held_nade = player.nade;
1059 } else if (time >= held_nade.nade_time_primed + 1) {
1061 makevectors(player.v_angle);
1062 float _force = time - held_nade.nade_time_primed;
1063 _force /= autocvar_g_nades_nade_lifetime;
1064 _force = autocvar_g_nades_nade_minforce + (_force * (autocvar_g_nades_nade_maxforce - autocvar_g_nades_nade_minforce));
1065 toss_nade(player, (v_forward * 0.7 + v_up * 0.2 + v_right * 0.1) * _force, 0);
1069 ENDCLASS(NadeOffhand)
1070 NadeOffhand OFFHAND_NADE; STATIC_INIT(OFFHAND_NADE) { OFFHAND_NADE = NEW(NadeOffhand); }
1072 MUTATOR_HOOKFUNCTION(nades, ForbidThrowCurrentWeapon, CBC_ORDER_LAST)
1074 if (self.offhand != OFFHAND_NADE || (self.weapons & WEPSET(HOOK)) || autocvar_g_nades_override_dropweapon) {
1081 MUTATOR_HOOKFUNCTION(nades, PlayerPreThink)
1083 if (!IS_PLAYER(self)) { return false; }
1085 if (self.nade && (self.offhand != OFFHAND_NADE || (self.weapons & WEPSET(HOOK)))) OFFHAND_NADE.offhand_think(OFFHAND_NADE, self, self.nade_altbutton);
1089 if ( autocvar_g_nades_bonus && autocvar_g_nades )
1092 float key_count = 0;
1093 FOR_EACH_KH_KEY(key) if(key.owner == self) { ++key_count; }
1096 if(self.flagcarried || self.ballcarried) // this player is important
1097 time_score = autocvar_g_nades_bonus_score_time_flagcarrier;
1099 time_score = autocvar_g_nades_bonus_score_time;
1102 time_score = autocvar_g_nades_bonus_score_time_flagcarrier * key_count; // multiply by the number of keys the player is holding
1104 if(autocvar_g_nades_bonus_client_select)
1106 self.nade_type = self.cvar_cl_nade_type;
1107 self.pokenade_type = self.cvar_cl_pokenade_type;
1111 self.nade_type = autocvar_g_nades_bonus_type;
1112 self.pokenade_type = autocvar_g_nades_pokenade_monster_type;
1115 self.nade_type = bound(1, self.nade_type, Nades_COUNT);
1117 if(self.bonus_nade_score >= 0 && autocvar_g_nades_bonus_score_max)
1118 nades_GiveBonus(self, time_score / autocvar_g_nades_bonus_score_max);
1122 self.bonus_nades = self.bonus_nade_score = 0;
1128 if(self.freezetag_frozen_timeout > 0 && time >= self.freezetag_frozen_timeout)
1132 vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
1134 FOREACH_CLIENT(IS_PLAYER(it) && it != self, LAMBDA(
1136 if(STAT(FROZEN, it) == 0)
1137 if(SAME_TEAM(it, self))
1138 if(boxesoverlap(self.absmin - revive_extra_size, self.absmax + revive_extra_size, it.absmin, it.absmax))
1142 if(STAT(FROZEN, self) == 1)
1149 if(n && STAT(FROZEN, self) == 3) // OK, there is at least one teammate reviving us
1151 self.revive_progress = bound(0, self.revive_progress + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
1152 self.health = max(1, self.revive_progress * start_health);
1154 if(self.revive_progress >= 1)
1158 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_REVIVED, o.netname);
1159 Send_Notification(NOTIF_ONE, o, MSG_CENTER, CENTER_FREEZETAG_REVIVE, self.netname);
1162 FOREACH_CLIENT(IS_PLAYER(it) && it.reviving, LAMBDA(
1163 other.revive_progress = self.revive_progress;
1164 other.reviving = false;
1171 MUTATOR_HOOKFUNCTION(nades, PlayerSpawn)
1173 if(autocvar_g_nades_spawn)
1174 self.nade_refire = time + autocvar_g_spawnshieldtime;
1176 self.nade_refire = time + autocvar_g_nades_nade_refire;
1178 if(autocvar_g_nades_bonus_client_select)
1179 self.nade_type = self.cvar_cl_nade_type;
1181 self.nade_timer = 0;
1183 if (!self.offhand) self.offhand = OFFHAND_NADE;
1185 if(self.nade_spawnloc)
1187 setorigin(self, self.nade_spawnloc.origin);
1188 self.nade_spawnloc.cnt -= 1;
1190 if(self.nade_spawnloc.cnt <= 0)
1192 remove(self.nade_spawnloc);
1193 self.nade_spawnloc = world;
1200 MUTATOR_HOOKFUNCTION(nades, PlayerDies, CBC_ORDER_LAST)
1202 if(frag_target.nade)
1203 if(!STAT(FROZEN, frag_target) || !autocvar_g_freezetag_revive_nade)
1204 toss_nade(frag_target, '0 0 100', max(frag_target.nade.wait, time + 0.05));
1206 float killcount_bonus = ((frag_attacker.killcount >= 1) ? bound(0, autocvar_g_nades_bonus_score_minor * frag_attacker.killcount, autocvar_g_nades_bonus_score_medium) : autocvar_g_nades_bonus_score_minor);
1208 if(IS_PLAYER(frag_attacker))
1210 if (SAME_TEAM(frag_attacker, frag_target) || frag_attacker == frag_target)
1211 nades_RemoveBonus(frag_attacker);
1212 else if(frag_target.flagcarried)
1213 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_medium);
1214 else if(autocvar_g_nades_bonus_score_spree && frag_attacker.killcount > 1)
1216 #define SPREE_ITEM(counta,countb,center,normal,gentle) \
1217 case counta: { nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_spree); break; }
1218 switch(frag_attacker.killcount)
1221 default: nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor); break;
1226 nades_GiveBonus(frag_attacker, killcount_bonus);
1229 nades_RemoveBonus(frag_target);
1234 MUTATOR_HOOKFUNCTION(nades, PlayerDamage_Calculate)
1236 if(STAT(FROZEN, frag_target))
1237 if(autocvar_g_freezetag_revive_nade)
1238 if(frag_attacker == frag_target)
1239 if(frag_deathtype == DEATH_NADE.m_id)
1240 if(time - frag_inflictor.toss_time <= 0.1)
1242 Unfreeze(frag_target);
1243 frag_target.health = autocvar_g_freezetag_revive_nade_health;
1244 Send_Effect(EFFECT_ICEORGLASS, frag_target.origin, '0 0 0', 3);
1246 frag_force = '0 0 0';
1247 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_REVIVED_NADE, frag_target.netname);
1248 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_REVIVE_SELF);
1254 MUTATOR_HOOKFUNCTION(nades, MonsterDies)
1256 if(IS_PLAYER(frag_attacker))
1257 if(DIFF_TEAM(frag_attacker, self))
1258 if(!(self.spawnflags & MONSTERFLAG_SPAWNED))
1259 nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_minor);
1264 MUTATOR_HOOKFUNCTION(nades, DropSpecialItems)
1266 if(frag_target.nade)
1267 toss_nade(frag_target, '0 0 0', time + 0.05);
1272 bool nades_RemovePlayer()
1275 nades_RemoveBonus(self);
1279 MUTATOR_HOOKFUNCTION(nades, MakePlayerObserver) { nades_RemovePlayer(); }
1280 MUTATOR_HOOKFUNCTION(nades, ClientDisconnect) { nades_RemovePlayer(); }
1281 MUTATOR_HOOKFUNCTION(nades, reset_map_global) { nades_RemovePlayer(); }
1283 MUTATOR_HOOKFUNCTION(nades, SpectateCopy)
1285 self.nade_timer = other.nade_timer;
1286 self.nade_type = other.nade_type;
1287 self.pokenade_type = other.pokenade_type;
1288 self.bonus_nades = other.bonus_nades;
1289 self.bonus_nade_score = other.bonus_nade_score;
1290 self.stat_healing_orb = other.stat_healing_orb;
1291 self.stat_healing_orb_alpha = other.stat_healing_orb_alpha;
1295 MUTATOR_HOOKFUNCTION(nades, GetCvars)
1297 GetCvars_handleFloat(get_cvars_s, get_cvars_f, cvar_cl_nade_type, "cl_nade_type");
1298 GetCvars_handleString(get_cvars_s, get_cvars_f, cvar_cl_pokenade_type, "cl_pokenade_type");
1303 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsString)
1305 ret_string = strcat(ret_string, ":Nades");
1309 MUTATOR_HOOKFUNCTION(nades, BuildMutatorsPrettyString)
1311 ret_string = strcat(ret_string, ", Nades");
1315 MUTATOR_HOOKFUNCTION(nades, BuildGameplayTipsString)
1317 ret_string = strcat(ret_string, "\n\n^3nades^8 are enabled, press 'g' to use them\n");