2 float checkrules_firstblood;
6 void announce(entity player, string msg)
8 if(time > player.announcetime)
9 if(clienttype(player) == CLIENTTYPE_REAL)
11 player.announcetime = time + 0.3;
16 float IsDifferentTeam(entity a, entity b)
31 float IsFlying(entity a)
33 if(a.flags & FL_ONGROUND)
37 traceline(a.origin, a.origin - '0 0 48', MOVE_NORMAL, a);
38 if(trace_fraction < 1)
43 void(entity player, float f) UpdateFrags =
46 player.totalfrags += f;
49 void GiveFrags (entity attacker, entity targ, float f)
54 if(cvar("g_arena_roundbased"))
59 if(cvar("g_domination_disable_frags"))
66 f = RunematchHandleFrags(attacker, targ, f);
70 f = kh_HandleFrags(attacker, targ, f);
74 // count remaining lives, not frags in lms
76 // keep track of the worst players lives
77 if(targ.frags < lms_lowest_lives)
78 lms_lowest_lives = targ.frags;
79 // player has no more lives left
83 lms_next_place = player_count;
84 targ.frags = -lms_next_place;
91 UpdateFrags(attacker, f);
94 string AppendItemcodes(string s, entity player)
99 // w = player.switchweapon;
101 w = player.cnt; // previous weapon!
102 s = strcat(s, ftos(W_ItemCode(w)));
103 if(time < player.strength_finished)
105 if(time < player.invincible_finished)
107 if(player.flagcarried != world)
109 if(player.buttonchat)
114 s = strcat(s, "|", ftos(player.runes));
118 void LogDeath(string mode, float deathtype, entity killer, entity killed)
121 if(!cvar("sv_eventlog"))
123 s = strcat(":kill:", mode);
124 s = strcat(s, ":", ftos(killer.playerid));
125 s = strcat(s, ":", ftos(killed.playerid));
126 s = strcat(s, ":type=", ftos(deathtype));
127 s = strcat(s, ":items=");
128 s = AppendItemcodes(s, killer);
131 s = strcat(s, ":victimitems=");
132 s = AppendItemcodes(s, killed);
134 GameLogEcho(s, FALSE);
137 void Obituary (entity attacker, entity targ, float deathtype)
141 if (targ.classname == "player" || targ.classname == "corpse")
143 if (targ.classname == "corpse")
147 a = attacker.netname;
149 if (targ == attacker)
151 if (deathtype == DEATH_TEAMCHANGE)
153 centerprint(targ, strcat("You are now on: ", ColoredTeamName(targ.team)));
155 else if (deathtype == DEATH_AUTOTEAMCHANGE)
157 centerprint(targ, strcat("You have been moved into a different team to improve team balance\nYou are now on: ", ColoredTeamName(targ.team)));
160 else if (deathtype == DEATH_CAMP)
161 centerprint(targ, "^1Die camper!\n\n\n");
162 else if (deathtype == DEATH_NOAMMO)
163 centerprint(targ, "^1You were killed for running out of ammo...\n\n\n");
164 else if (deathtype == DEATH_ROT)
165 centerprint(targ, "^1You grew too old without taking your medicine\n\n\n");
166 else if (deathtype == DEATH_MIRRORDAMAGE)
167 centerprint(targ, "^1Don't shoot your team mates!\n\n\n");
169 centerprint(targ, "^1You killed your own dumb self!\n\n\n");
171 if (deathtype == IT_GRENADE_LAUNCHER)
172 bprint ("^1",s, "^1 detonated\n");
173 else if (deathtype == IT_ELECTRO)
174 bprint ("^1",s, "^1 played with plasma\n");
175 else if (deathtype == IT_ROCKET_LAUNCHER)
176 bprint ("^1",s, "^1 exploded\n");
177 else if (deathtype == DEATH_KILL)
178 bprint ("^1",s, "^1 couldn't take it anymore\n");
179 else if (deathtype == DEATH_ROT)
180 bprint ("^1",s, "^1 died\n");
181 else if (deathtype == DEATH_NOAMMO)
183 bprint ("^7",s, " ^7committed suicide. What's the point of living without ammo?\n");
184 //sound (self, CHAN_BODY, "minstagib/mockery.wav", 1, ATTN_NONE);
186 else if (deathtype == DEATH_CAMP)
187 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
188 else if (deathtype == DEATH_MIRRORDAMAGE)
189 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
190 else if (deathtype != DEATH_TEAMCHANGE)
191 bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");
193 if(deathtype != DEATH_TEAMCHANGE)
195 LogDeath("suicide", deathtype, targ, targ);
196 GiveFrags(attacker, targ, -1);
198 if (targ.killcount > 2)
199 bprint ("^1",s,"^1 ended it all with a ",ftos(targ.killcount)," kill spree\n");
201 else if (attacker.classname == "player" || attacker.classname == "gib")
203 if(teamplay && attacker.team == targ.team)
205 centerprint(attacker, "^1Moron! You fragged a teammate!\n\n\n");
206 bprint ("^1", a, "^1 mows down a teammate\n");
207 GiveFrags(attacker, targ, -1);
208 if (targ.killcount > 2)
209 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," kill spree was ended by a teammate!\n");
210 if (attacker.killcount > 2)
211 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," kill spree by killing a teammate\n");
212 attacker.killcount = 0;
214 LogDeath("tk", deathtype, attacker, targ);
218 if (!checkrules_firstblood)
220 checkrules_firstblood = TRUE;
221 //sound(world, CHAN_AUTO, "announcer/firstblood.wav", 1, ATTN_NONE);
223 //sound(world, CHAN_AUTO, "announce/male/mapkill1.wav", 1, ATTN_NONE);
224 bprint("^1",a, "^1 drew first blood", "\n");
228 centerprint(attacker, strcat("^4You scored against ^7", s, "\n\n\n"));
229 centerprint(targ, strcat(a,"^1 scored against you ^7\n\n\n"));
231 centerprint(attacker, strcat("^4You fragged ^7", s, "\n\n\n"));
232 centerprint(targ, strcat("^1You were fragged by ^7", a, "\n\n\n"));
235 if (deathtype == IT_LASER)
236 bprint ("^1",s, "^1 was blasted by ", a, "\n");
237 else if (deathtype == IT_UZI)
238 bprint ("^1",s, "^1 was riddled full of holes by ", a, "\n");
239 else if (deathtype == IT_SHOTGUN)
240 bprint ("^1",s, "^1 was gunned by ", a, "\n");
241 else if (deathtype == IT_GRENADE_LAUNCHER)
242 bprint ("^1", s, "^1 was blasted by ", a, "\n");
243 else if (deathtype == IT_ELECTRO)
244 bprint ("^1",s, "^1 was blasted by ", a, "\n");
245 else if (deathtype == IT_CRYLINK)
246 bprint ("^1",s, "^1 was blasted by ", a, "\n");
247 else if (deathtype == IT_NEX)
248 bprint ("^1",s, "^1 has been vaporized by ", a, "\n");
249 else if (deathtype == IT_HAGAR)
250 bprint ("^1",s, "^1 was pummeled by ", a, "\n");
251 else if (deathtype == IT_ROCKET_LAUNCHER)
252 bprint ("^1",s, "^1 was blasted by ", a, "\n");
253 else if (deathtype == DEATH_TELEFRAG)
254 bprint ("^1",s, "^1 was telefragged by ", a, "\n");
255 else if (deathtype == DEATH_DROWN)
256 bprint ("^1",s, "^1 was drowned by ", a, "\n");
257 else if (deathtype == DEATH_SLIME)
258 bprint ("^1",s, "^1 was slimed by ", a, "\n");
259 else if (deathtype == DEATH_LAVA)
260 bprint ("^1",s, "^1 was cooked by ", a, "\n");
261 else if (deathtype == DEATH_FALL)
262 bprint ("^1",s, "^1 was grounded by ", a, "\n");
263 else if (deathtype == DEATH_SHOOTING_STAR)
264 bprint ("^1",s, "^1 was shot into space by ", a, "\n");
265 else if (deathtype == DEATH_SWAMP)
266 bprint ("^1",s, "^1 was conserved by ", a, "\n");
267 else if (deathtype == DEATH_HURTTRIGGER)
268 bprint ("^1",s, "^1 was thrown into a world of hurt by ", a, "\n");
270 bprint ("^1",s, "^1 was fragged by ", a, "\n");
272 GiveFrags(attacker, targ, 1);
273 if (targ.killcount > 2)
274 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
275 attacker.killcount = attacker.killcount + 1;
276 if (attacker.killcount > 2)
277 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
279 LogDeath("frag", deathtype, attacker, targ);
281 if (attacker.killcount == 3)
283 bprint (a,"^7 made a ^1TRIPLE FRAG\n");
284 announce(attacker, "announcer/male/03kills.ogg");
286 else if (attacker.killcount == 5)
288 bprint (a,"^7 unleashes ^1RAGE\n");
289 announce(attacker, "announcer/male/05kills.ogg");
291 else if (attacker.killcount == 10)
293 bprint (a,"^7 starts the ^1MASSACRE!\n");
294 announce(attacker, "announcer/male/10kills.ogg");
296 else if (attacker.killcount == 15)
298 bprint (a,"^7 executes ^1MAYHEM!\n");
299 announce(attacker, "announcer/male/15kills.ogg");
301 else if (attacker.killcount == 20)
303 bprint (a,"^7 is a ^1BERSERKER!\n");
304 announce(attacker, "announcer/male/20kills.ogg");
306 else if (attacker.killcount == 25)
308 bprint (a,"^7 inflicts ^1CARNAGE!\n");
309 announce(attacker, "announcer/male/25kills.ogg");
311 else if (attacker.killcount == 30)
313 bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");
314 announce(attacker, "announcer/male/30kills.ogg");
320 centerprint(targ, "^1Watch your step!\n\n\n");
321 if (deathtype == DEATH_HURTTRIGGER && attacker.message != "")
322 bprint ("^1",s, "^1 ", attacker.message, "\n");
323 else if (deathtype == DEATH_DROWN)
324 bprint ("^1",s, "^1 drowned\n");
325 else if (deathtype == DEATH_SLIME)
326 bprint ("^1",s, "^1 was slimed\n");
327 else if (deathtype == DEATH_LAVA)
328 bprint ("^1",s, "^1 turned into hot slag\n");
329 else if (deathtype == DEATH_FALL)
330 bprint ("^1",s, "^1 hit the ground with a crunch\n");
331 else if (deathtype == DEATH_SHOOTING_STAR)
332 bprint ("^1",s, "^1 became a shooting star\n");
333 else if (deathtype == DEATH_SWAMP)
334 bprint ("^1",s, "^1 is now conserved for centuries to come\n");
336 bprint ("^1",s, "^1 died\n");
337 GiveFrags(targ, targ, -1);
338 if(targ.frags == -5) {
339 announce(targ, "announcer/male/botlike.ogg");
342 if (targ.killcount > 2)
343 bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
345 LogDeath("accident", deathtype, targ, targ);
347 targ.death_origin = targ.origin;
349 targ.killer_origin = attacker.origin;
350 // FIXME: this should go in PutClientInServer
356 // these are updated by each Damage call for use in button triggering and such
358 entity damage_inflictor;
359 entity damage_attacker;
361 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
365 entity attacker_save;
369 if (gameover || targ.killcount == -666)
372 local entity oldself;
376 damage_inflictor = inflictor;
377 damage_attacker = attacker;
378 attacker_save = attacker;
380 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
382 // These are ALWAYS lethal
383 // No damage modification here
384 // Instead, prepare the victim for his death...
386 targ.spawnshieldtime = 0;
388 targ.flags -= targ.flags & FL_GODMODE;
393 if (targ.classname == "player")
394 if (attacker.classname == "player")
397 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
399 // nullify damage if teamplay is on
400 if(deathtype != DEATH_TELEFRAG)
401 if(attacker.team == targ.team)
402 if(attacker.classname == "player")
406 else if(attacker != targ)
410 else if(teamplay == 4)
412 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
414 mirrordamage = cvar("g_mirrordamage") * damage;
415 mirrorforce = cvar("g_mirrordamage") * vlen(force);
418 if(cvar("g_friendlyfire") == 0)
422 damage = cvar("g_friendlyfire") * damage;
423 // mirrordamage will be used LATER
432 if(targ.classname == "player")
433 if(attacker.classname == "player")
436 targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
437 attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
443 if(targ.classname == "player")
445 attacker.hitsound += 1;
449 if ((deathtype == DEATH_FALL) ||
450 (deathtype == DEATH_DROWN) ||
451 (deathtype == DEATH_SLIME) ||
452 (deathtype == DEATH_LAVA))
454 if (targ.armorvalue && (deathtype == IT_NEX) && damage)
456 targ.armorvalue -= 1;
457 centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue),"\n"));
461 else if (deathtype == IT_NEX && targ.items & IT_STRENGTH)
463 if(clienttype(attacker) == CLIENTTYPE_REAL)
464 if(IsDifferentTeam(targ, attacker))
467 if (deathtype == IT_LASER)
470 if (targ != attacker)
472 if (targ.classname == "player")
473 centerprint(attacker, "Secondary fire inflicts no damage!\n");
483 if(targ.takedamage == DAMAGE_AIM)
485 if(IsDifferentTeam(targ, attacker))
489 // apply strength multiplier
490 if (attacker.items & IT_STRENGTH && !g_minstagib)
492 damage = damage * cvar("g_balance_powerup_strength_damage");
493 force = force * cvar("g_balance_powerup_strength_force");
495 // apply invincibility multiplier
496 if (targ.items & IT_INVINCIBLE && !g_minstagib)
497 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
502 // apply strength rune
503 if (attacker.runes & RUNE_STRENGTH)
505 if(attacker.runes & CURSE_WEAK) // have both curse & rune
507 damage = damage * cvar("g_balance_rune_strength_combo_damage");
508 force = force * cvar("g_balance_rune_strength_combo_force");
512 damage = damage * cvar("g_balance_rune_strength_damage");
513 force = force * cvar("g_balance_rune_strength_force");
516 else if (attacker.runes & CURSE_WEAK)
518 damage = damage * cvar("g_balance_curse_weak_damage");
519 force = force * cvar("g_balance_curse_weak_force");
522 // apply defense rune
523 if (targ.runes & RUNE_DEFENSE)
525 if (targ.runes & CURSE_VULNER) // have both curse & rune
526 damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
528 damage = damage * cvar("g_balance_rune_defense_takedamage");
530 else if (targ.runes & CURSE_VULNER)
531 damage = damage * cvar("g_balance_curse_vulner_takedamage");
536 if (self.damageforcescale)
539 self.velocity = self.velocity + self.damageforcescale * force;
540 self.flags = self.flags - (self.flags & FL_ONGROUND);
543 if (self.event_damage)
544 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
547 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
549 // Savage: vampire mode
553 if (time > self.spawnshieldtime)
555 attacker.health += damage;
559 if (attacker.runes & RUNE_VAMPIRE)
561 // apply vampire rune
562 if (attacker.runes & CURSE_EMPATHY) // have the curse too
564 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
565 attacker.health = bound(
566 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
567 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
568 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
572 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
573 attacker.health = bound(
574 attacker.health, // LA: was 3, but changed so that you can't lose health
575 // empathy won't let you gain health in the same way...
576 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
577 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
580 // apply empathy curse
581 else if (attacker.runes & CURSE_EMPATHY)
583 attacker.health = bound(
584 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
585 attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
591 // apply mirror damage if any
592 if(mirrordamage > 0 || mirrorforce > 0)
594 attacker = attacker_save;
598 // just lose extra LIVES, don't kill the player for mirror damage
599 if(attacker.armorvalue > 0)
601 attacker.armorvalue = attacker.armorvalue - 1;
602 centerprint(attacker, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue),"\n"));
603 attacker.hitsound += 1;
607 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
608 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
612 vector NearestPointOnBox(entity box, vector org)
614 vector m1, m2, nearest;
616 m1 = box.mins + box.origin;
617 m2 = box.maxs + box.origin;
619 nearest_x = bound(m1_x, org_x, m2_x);
620 nearest_y = bound(m1_y, org_y, m2_y);
621 nearest_z = bound(m1_z, org_z, m2_z);
626 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype)
627 // Returns total damage applies to creatures
637 float total_damage_to_creatures;
639 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
640 total_damage_to_creatures = 0;
642 targ = findradius (blastorigin, rad);
645 if (targ != inflictor)
648 // LordHavoc: measure distance to nearest point on target (not origin)
649 // (this guarentees 100% damage on a touch impact)
650 nearest = NearestPointOnBox(targ, blastorigin);
651 diff = nearest - blastorigin;
652 // round up a little on the damage to ensure full damage on impacts
653 // and turn the distance into a fraction of the radius
654 power = 1 - ((vlen (diff) - 2) / rad);
656 //bprint(ftos(power));
661 finaldmg = coredamage * power + edgedamage * (1 - power);
664 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
665 // if it's a player, use the view origin as reference
666 if (targ.classname == "player")
667 center = targ.origin + targ.view_ofs;
668 force = normalize(center - blastorigin) * (finaldmg / coredamage) * forceintensity;
669 if (targ == attacker)
670 finaldmg = finaldmg * cvar("g_balance_selfdamagepercent"); // Partial damage if the attacker hits himself
671 // test line of sight to multiple positions on box,
672 // and do damage if any of them hit
674 c = ceil(finaldmg / 10);
680 traceline(blastorigin, nearest, TRUE, inflictor);
681 if (trace_fraction == 1 || trace_ent == targ
682 || cvar("g_throughfloor"))
685 total_damage_to_creatures += finaldmg;
686 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
689 nearest_x = targ.mins_x + random() * targ.size_x;
690 nearest_y = targ.mins_y + random() * targ.size_y;
691 nearest_z = targ.mins_z + random() * targ.size_z;
699 return total_damage_to_creatures;