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 UpdateFrags(entity player, float f)
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.BUTTON_CHAT)
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) {
152 centerprint(targ, strcat("You are now on: ", ColoredTeamName(targ.team)));
153 } else if (deathtype == DEATH_AUTOTEAMCHANGE) {
154 centerprint(targ, strcat("You have been moved into a different team to improve team balance\nYou are now on: ", ColoredTeamName(targ.team)));
156 } else if (deathtype == DEATH_CAMP) {
158 centerprint(targ, "^1Reconsider your tactics, camper!\n\n\n");
160 centerprint(targ, "^1Die camper!\n\n\n");
161 } else if (deathtype == DEATH_NOAMMO) {
163 centerprint(targ, "^1You are reinserted into the game for running out of ammo...\n\n\n");
165 centerprint(targ, "^1You were killed for running out of ammo...\n\n\n");
166 } else if (deathtype == DEATH_ROT) {
168 centerprint(targ, "^1You need to preserve your health\n\n\n");
170 centerprint(targ, "^1You grew too old without taking your medicine\n\n\n");
171 } else if (deathtype == DEATH_MIRRORDAMAGE) {
173 centerprint(targ, "^1Don't go against team mates!\n\n\n");
175 centerprint(targ, "^1Don't shoot your team mates!\n\n\n");
178 centerprint(targ, "^1You need to be more careful!\n\n\n");
180 centerprint(targ, "^1You killed your own dumb self!\n\n\n");
184 if (deathtype == DEATH_CAMP)
185 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
186 else if (deathtype == DEATH_MIRRORDAMAGE)
187 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
189 bprint ("^1",s, "^1 will be reinserted into the game due to his own actions\n");
191 if(deathtype != DEATH_TEAMCHANGE)
193 LogDeath("suicide", deathtype, targ, targ);
194 GiveFrags(attacker, targ, -1);
196 if (targ.killcount > 2)
197 bprint ("^1",s,"^1 ended it all with a ",ftos(targ.killcount)," scoring spree\n");
200 if (deathtype == IT_GRENADE_LAUNCHER)
201 bprint ("^1",s, "^1 detonated\n");
202 else if (deathtype == IT_ELECTRO)
203 bprint ("^1",s, "^1 played with plasma\n");
204 else if (deathtype == IT_ROCKET_LAUNCHER)
205 bprint ("^1",s, "^1 exploded\n");
206 else if (deathtype == DEATH_KILL)
207 bprint ("^1",s, "^1 couldn't take it anymore\n");
208 else if (deathtype == DEATH_ROT)
209 bprint ("^1",s, "^1 died\n");
210 else if (deathtype == DEATH_NOAMMO)
212 bprint ("^7",s, " ^7committed suicide. What's the point of living without ammo?\n");
213 //sound (self, CHAN_BODY, "minstagib/mockery.wav", 1, ATTN_NONE);
215 else if (deathtype == DEATH_CAMP)
216 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
217 else if (deathtype == DEATH_MIRRORDAMAGE)
218 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
219 else if (deathtype != DEATH_TEAMCHANGE)
220 bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");
222 if(deathtype != DEATH_TEAMCHANGE)
224 LogDeath("suicide", deathtype, targ, targ);
225 GiveFrags(attacker, targ, -1);
227 if (targ.killcount > 2)
228 bprint ("^1",s,"^1 ended it all with a ",ftos(targ.killcount)," kill spree\n");
231 else if (attacker.classname == "player" || attacker.classname == "gib")
233 if(teamplay && attacker.team == targ.team)
236 centerprint(attacker, "^1Moron! You went against a teammate!\n\n\n");
237 bprint ("^1", a, "^1 took action against a teammate\n");
239 centerprint(attacker, "^1Moron! You fragged a teammate!\n\n\n");
240 bprint ("^1", a, "^1 mows down a teammate\n");
242 GiveFrags(attacker, targ, -1);
243 if (targ.killcount > 2) {
245 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," scoring spree was ended by a teammate!\n");
247 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," kill spree was ended by a teammate!\n");
249 if (attacker.killcount > 2) {
251 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," scoring spree by going against a teammate\n");
253 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," kill spree by killing a teammate\n");
255 attacker.killcount = 0;
257 LogDeath("tk", deathtype, attacker, targ);
261 if (!checkrules_firstblood)
263 checkrules_firstblood = TRUE;
264 //sound(world, CHAN_AUTO, "announcer/firstblood.wav", 1, ATTN_NONE);
266 //sound(world, CHAN_AUTO, "announce/male/mapkill1.wav", 1, ATTN_NONE);
268 bprint("^1",a, "^1 was the first to score", "\n");
270 bprint("^1",a, "^1 drew first blood", "\n");
274 centerprint(attacker, strcat("^4You scored against ^7", s, "\n\n\n"));
275 centerprint(targ, strcat(a,"^1 scored against you ^7\n\n\n"));
277 centerprint(attacker, strcat("^4You fragged ^7", s, "\n\n\n"));
278 centerprint(targ, strcat("^1You were fragged by ^7", a, "\n\n\n"));
282 bprint ("^1",s, "^1 needs a restart thanks to ", a, "\n");
284 if (deathtype == IT_LASER)
285 bprint ("^1",s, "^1 was blasted by ", a, "\n");
286 else if (deathtype == IT_UZI)
287 bprint ("^1",s, "^1 was riddled full of holes by ", a, "\n");
288 else if (deathtype == IT_SHOTGUN)
289 bprint ("^1",s, "^1 was gunned by ", a, "\n");
290 else if (deathtype == IT_GRENADE_LAUNCHER)
291 bprint ("^1", s, "^1 was blasted by ", a, "\n");
292 else if (deathtype == IT_ELECTRO)
293 bprint ("^1",s, "^1 was blasted by ", a, "\n");
294 else if (deathtype == IT_CRYLINK)
295 bprint ("^1",s, "^1 was blasted by ", a, "\n");
296 else if (deathtype == IT_NEX)
297 bprint ("^1",s, "^1 has been vaporized by ", a, "\n");
298 else if (deathtype == IT_HAGAR)
299 bprint ("^1",s, "^1 was pummeled by ", a, "\n");
300 else if (deathtype == IT_ROCKET_LAUNCHER)
301 bprint ("^1",s, "^1 was blasted by ", a, "\n");
302 else if (deathtype == DEATH_TELEFRAG)
303 bprint ("^1",s, "^1 was telefragged by ", a, "\n");
304 else if (deathtype == DEATH_DROWN)
305 bprint ("^1",s, "^1 was drowned by ", a, "\n");
306 else if (deathtype == DEATH_SLIME)
307 bprint ("^1",s, "^1 was slimed by ", a, "\n");
308 else if (deathtype == DEATH_LAVA)
309 bprint ("^1",s, "^1 was cooked by ", a, "\n");
310 else if (deathtype == DEATH_FALL)
311 bprint ("^1",s, "^1 was grounded by ", a, "\n");
312 else if (deathtype == DEATH_SHOOTING_STAR)
313 bprint ("^1",s, "^1 was shot into space by ", a, "\n");
314 else if (deathtype == DEATH_SWAMP)
315 bprint ("^1",s, "^1 was conserved by ", a, "\n");
316 else if (deathtype == DEATH_HURTTRIGGER)
317 bprint ("^1",s, "^1 was thrown into a world of hurt by ", a, "\n");
319 bprint ("^1",s, "^1 was fragged by ", a, "\n");
322 GiveFrags(attacker, targ, 1);
323 if (targ.killcount > 2) {
325 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " scoring spree was ended by ", a, "\n");
327 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
329 attacker.killcount = attacker.killcount + 1;
330 if (attacker.killcount > 2) {
332 bprint ("^1",a,"^1 made ",ftos(attacker.killcount)," scores in a row\n");
334 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
337 LogDeath("frag", deathtype, attacker, targ);
339 if (attacker.killcount == 3)
342 bprint (a,"^7 made a ^1TRIPLE SCORE\n");
344 bprint (a,"^7 made a ^1TRIPLE FRAG\n");
345 announce(attacker, "announcer/male/03kills.ogg");
348 else if (attacker.killcount == 5)
351 bprint (a,"^7 unleashes ^1SCORING RAGE\n");
353 bprint (a,"^7 unleashes ^1RAGE\n");
354 announce(attacker, "announcer/male/05kills.ogg");
357 else if (attacker.killcount == 10)
360 bprint (a,"^7 made ^1TEN SCORES IN A ROW!\n");
362 bprint (a,"^7 starts the ^1MASSACRE!\n");
363 announce(attacker, "announcer/male/10kills.ogg");
366 else if (attacker.killcount == 15)
369 bprint (a,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
371 bprint (a,"^7 executes ^1MAYHEM!\n");
372 announce(attacker, "announcer/male/15kills.ogg");
375 else if (attacker.killcount == 20)
378 bprint (a,"^7 made ^1TWENTY SCORES IN A ROW!\n");
380 bprint (a,"^7 is a ^1BERSERKER!\n");
381 announce(attacker, "announcer/male/20kills.ogg");
384 else if (attacker.killcount == 25)
387 bprint (a,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
389 bprint (a,"^7 inflicts ^1CARNAGE!\n");
390 announce(attacker, "announcer/male/25kills.ogg");
393 else if (attacker.killcount == 30)
396 bprint (a,"^7 made ^1THIRTY SCORES IN A ROW!\n");
398 bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");
399 announce(attacker, "announcer/male/30kills.ogg");
406 centerprint(targ, "^1Watch your step!\n\n\n");
407 if (deathtype == DEATH_HURTTRIGGER && attacker.message != "")
408 bprint ("^1",s, "^1 ", attacker.message, "\n");
409 else if (deathtype == DEATH_DROWN)
411 bprint ("^1",s, "^1 was in the water for too long\n");
413 bprint ("^1",s, "^1 drowned\n");
414 else if (deathtype == DEATH_SLIME)
415 bprint ("^1",s, "^1 was slimed\n");
416 else if (deathtype == DEATH_LAVA)
418 bprint ("^1",s, "^1 found a hot place\n");
420 bprint ("^1",s, "^1 turned into hot slag\n");
421 else if (deathtype == DEATH_FALL)
423 bprint ("^1",s, "^1 tested gravity (and it worked)\n");
425 bprint ("^1",s, "^1 hit the ground with a crunch\n");
426 else if (deathtype == DEATH_SHOOTING_STAR)
427 bprint ("^1",s, "^1 became a shooting star\n");
428 else if (deathtype == DEATH_SWAMP)
430 bprint ("^1",s, "^1 discovered a swamp\n");
432 bprint ("^1",s, "^1 is now conserved for centuries to come\n");
435 bprint ("^1",s, "^1 needs a restart\n");
437 bprint ("^1",s, "^1 died\n");
438 GiveFrags(targ, targ, -1);
439 if(targ.frags == -5) {
440 announce(targ, "announcer/male/botlike.ogg");
443 if (targ.killcount > 2)
445 bprint ("^1",s,"^1 needs a restart after a ",ftos(targ.killcount)," scoring spree\n");
447 bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
449 LogDeath("accident", deathtype, targ, targ);
451 targ.death_origin = targ.origin;
453 targ.killer_origin = attacker.origin;
454 // FIXME: this should go in PutClientInServer
460 // these are updated by each Damage call for use in button triggering and such
462 entity damage_inflictor;
463 entity damage_attacker;
465 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
469 entity attacker_save;
473 if (gameover || targ.killcount == -666)
476 local entity oldself;
480 damage_inflictor = inflictor;
481 damage_attacker = attacker;
482 attacker_save = attacker;
484 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
486 // These are ALWAYS lethal
487 // No damage modification here
488 // Instead, prepare the victim for his death...
490 targ.spawnshieldtime = 0;
492 targ.flags -= targ.flags & FL_GODMODE;
497 if (targ.classname == "player")
498 if (attacker.classname == "player")
501 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
503 // nullify damage if teamplay is on
504 if(deathtype != DEATH_TELEFRAG)
505 if(attacker.team == targ.team)
506 if(attacker.classname == "player")
510 else if(attacker != targ)
514 else if(teamplay == 4)
516 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
518 mirrordamage = cvar("g_mirrordamage") * damage;
519 mirrorforce = cvar("g_mirrordamage") * vlen(force);
522 if(cvar("g_friendlyfire") == 0)
526 damage = cvar("g_friendlyfire") * damage;
527 // mirrordamage will be used LATER
536 if(targ.classname == "player")
537 if(attacker.classname == "player")
540 targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
541 attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
547 if(targ.classname == "player")
549 attacker.hitsound += 1;
553 if ((deathtype == DEATH_FALL) ||
554 (deathtype == DEATH_DROWN) ||
555 (deathtype == DEATH_SLIME) ||
556 (deathtype == DEATH_LAVA))
558 if (targ.armorvalue && (deathtype == IT_NEX) && damage)
560 targ.armorvalue -= 1;
561 centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue),"\n"));
565 else if (deathtype == IT_NEX && targ.items & IT_STRENGTH)
567 if(clienttype(attacker) == CLIENTTYPE_REAL)
568 if(IsDifferentTeam(targ, attacker))
571 if (deathtype == IT_LASER)
574 if (targ != attacker)
576 if (targ.classname == "player")
577 centerprint(attacker, "Secondary fire inflicts no damage!\n");
587 if(targ.takedamage == DAMAGE_AIM)
589 if(IsDifferentTeam(targ, attacker))
593 // apply strength multiplier
594 if (attacker.items & IT_STRENGTH && !g_minstagib)
596 damage = damage * cvar("g_balance_powerup_strength_damage");
597 force = force * cvar("g_balance_powerup_strength_force");
599 // apply invincibility multiplier
600 if (targ.items & IT_INVINCIBLE && !g_minstagib)
601 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
606 // apply strength rune
607 if (attacker.runes & RUNE_STRENGTH)
609 if(attacker.runes & CURSE_WEAK) // have both curse & rune
611 damage = damage * cvar("g_balance_rune_strength_combo_damage");
612 force = force * cvar("g_balance_rune_strength_combo_force");
616 damage = damage * cvar("g_balance_rune_strength_damage");
617 force = force * cvar("g_balance_rune_strength_force");
620 else if (attacker.runes & CURSE_WEAK)
622 damage = damage * cvar("g_balance_curse_weak_damage");
623 force = force * cvar("g_balance_curse_weak_force");
626 // apply defense rune
627 if (targ.runes & RUNE_DEFENSE)
629 if (targ.runes & CURSE_VULNER) // have both curse & rune
630 damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
632 damage = damage * cvar("g_balance_rune_defense_takedamage");
634 else if (targ.runes & CURSE_VULNER)
635 damage = damage * cvar("g_balance_curse_vulner_takedamage");
640 if (self.damageforcescale)
643 self.velocity = self.velocity + self.damageforcescale * force;
644 self.flags = self.flags - (self.flags & FL_ONGROUND);
647 if (self.event_damage)
648 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
651 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
653 // Savage: vampire mode
657 if (time > self.spawnshieldtime)
659 attacker.health += damage;
663 if (attacker.runes & RUNE_VAMPIRE)
665 // apply vampire rune
666 if (attacker.runes & CURSE_EMPATHY) // have the curse too
668 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
669 attacker.health = bound(
670 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
671 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
672 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
676 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
677 attacker.health = bound(
678 attacker.health, // LA: was 3, but changed so that you can't lose health
679 // empathy won't let you gain health in the same way...
680 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
681 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
684 // apply empathy curse
685 else if (attacker.runes & CURSE_EMPATHY)
687 attacker.health = bound(
688 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
689 attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
695 // apply mirror damage if any
696 if(mirrordamage > 0 || mirrorforce > 0)
698 attacker = attacker_save;
702 // just lose extra LIVES, don't kill the player for mirror damage
703 if(attacker.armorvalue > 0)
705 attacker.armorvalue = attacker.armorvalue - 1;
706 centerprint(attacker, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue),"\n"));
707 attacker.hitsound += 1;
711 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
712 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
716 vector NearestPointOnBox(entity box, vector org)
718 vector m1, m2, nearest;
720 m1 = box.mins + box.origin;
721 m2 = box.maxs + box.origin;
723 nearest_x = bound(m1_x, org_x, m2_x);
724 nearest_y = bound(m1_y, org_y, m2_y);
725 nearest_z = bound(m1_z, org_z, m2_z);
730 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype)
731 // Returns total damage applies to creatures
741 float total_damage_to_creatures;
743 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
744 total_damage_to_creatures = 0;
746 targ = findradius (blastorigin, rad);
749 if (targ != inflictor)
752 // LordHavoc: measure distance to nearest point on target (not origin)
753 // (this guarentees 100% damage on a touch impact)
754 nearest = NearestPointOnBox(targ, blastorigin);
755 diff = nearest - blastorigin;
756 // round up a little on the damage to ensure full damage on impacts
757 // and turn the distance into a fraction of the radius
758 power = 1 - ((vlen (diff) - 2) / rad);
760 //bprint(ftos(power));
765 finaldmg = coredamage * power + edgedamage * (1 - power);
768 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
769 // if it's a player, use the view origin as reference
770 if (targ.classname == "player")
771 center = targ.origin + targ.view_ofs;
772 force = normalize(center - blastorigin) * (finaldmg / coredamage) * forceintensity;
773 if (targ == attacker)
774 finaldmg = finaldmg * cvar("g_balance_selfdamagepercent"); // Partial damage if the attacker hits himself
775 // test line of sight to multiple positions on box,
776 // and do damage if any of them hit
778 c = ceil(finaldmg / 10);
784 traceline(blastorigin, nearest, TRUE, inflictor);
785 if (trace_fraction == 1 || trace_ent == targ
786 || cvar("g_throughfloor"))
789 total_damage_to_creatures += finaldmg;
790 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
793 nearest_x = targ.mins_x + random() * targ.size_x;
794 nearest_y = targ.mins_y + random() * targ.size_y;
795 nearest_z = targ.mins_z + random() * targ.size_z;
803 return total_damage_to_creatures;