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");
318 else if(deathtype == DEATH_TURRET)
319 bprint ("^1",s, "^1 was pushed into the line of fire by ^1", a, "\n");
321 bprint ("^1",s, "^1 was fragged by ", a, "\n");
323 if(g_ctf && targ.flagcarried)
324 GiveFrags(attacker, targ, cvar("g_ctf_flagscore_kill"));
326 GiveFrags(attacker, targ, 1);
327 if (targ.killcount > 2) {
329 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " scoring spree was ended by ", a, "\n");
331 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
333 attacker.killcount = attacker.killcount + 1;
334 if (attacker.killcount > 2) {
336 bprint ("^1",a,"^1 made ",ftos(attacker.killcount)," scores in a row\n");
338 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
341 LogDeath("frag", deathtype, attacker, targ);
343 if (attacker.killcount == 3)
346 bprint (a,"^7 made a ^1TRIPLE SCORE\n");
348 bprint (a,"^7 made a ^1TRIPLE FRAG\n");
349 announce(attacker, "announcer/male/03kills.ogg");
352 else if (attacker.killcount == 5)
355 bprint (a,"^7 unleashes ^1SCORING RAGE\n");
357 bprint (a,"^7 unleashes ^1RAGE\n");
358 announce(attacker, "announcer/male/05kills.ogg");
361 else if (attacker.killcount == 10)
364 bprint (a,"^7 made ^1TEN SCORES IN A ROW!\n");
366 bprint (a,"^7 starts the ^1MASSACRE!\n");
367 announce(attacker, "announcer/male/10kills.ogg");
370 else if (attacker.killcount == 15)
373 bprint (a,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
375 bprint (a,"^7 executes ^1MAYHEM!\n");
376 announce(attacker, "announcer/male/15kills.ogg");
379 else if (attacker.killcount == 20)
382 bprint (a,"^7 made ^1TWENTY SCORES IN A ROW!\n");
384 bprint (a,"^7 is a ^1BERSERKER!\n");
385 announce(attacker, "announcer/male/20kills.ogg");
388 else if (attacker.killcount == 25)
391 bprint (a,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
393 bprint (a,"^7 inflicts ^1CARNAGE!\n");
394 announce(attacker, "announcer/male/25kills.ogg");
397 else if (attacker.killcount == 30)
400 bprint (a,"^7 made ^1THIRTY SCORES IN A ROW!\n");
402 bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");
403 announce(attacker, "announcer/male/30kills.ogg");
410 centerprint(targ, "^1Watch your step!\n\n\n");
411 if (deathtype == DEATH_HURTTRIGGER && attacker.message != "")
412 bprint ("^1",s, "^1 ", attacker.message, "\n");
413 else if (deathtype == DEATH_DROWN)
415 bprint ("^1",s, "^1 was in the water for too long\n");
417 bprint ("^1",s, "^1 drowned\n");
418 else if (deathtype == DEATH_SLIME)
419 bprint ("^1",s, "^1 was slimed\n");
420 else if (deathtype == DEATH_LAVA)
422 bprint ("^1",s, "^1 found a hot place\n");
424 bprint ("^1",s, "^1 turned into hot slag\n");
425 else if (deathtype == DEATH_FALL)
427 bprint ("^1",s, "^1 tested gravity (and it worked)\n");
429 bprint ("^1",s, "^1 hit the ground with a crunch\n");
430 else if (deathtype == DEATH_SHOOTING_STAR)
431 bprint ("^1",s, "^1 became a shooting star\n");
432 else if (deathtype == DEATH_SWAMP)
434 bprint ("^1",s, "^1 discovered a swamp\n");
436 bprint ("^1",s, "^1 is now conserved for centuries to come\n");
437 else if(deathtype == DEATH_TURRET)
438 bprint ("^1",s, "^1 was mowed down by a turret \n");
441 bprint ("^1",s, "^1 needs a restart\n");
443 bprint ("^1",s, "^1 died\n");
444 GiveFrags(targ, targ, -1);
445 if(targ.frags == -5) {
446 announce(targ, "announcer/male/botlike.ogg");
449 if (targ.killcount > 2)
451 bprint ("^1",s,"^1 needs a restart after a ",ftos(targ.killcount)," scoring spree\n");
453 bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
455 LogDeath("accident", deathtype, targ, targ);
457 targ.death_origin = targ.origin;
459 targ.killer_origin = attacker.origin;
460 // FIXME: this should go in PutClientInServer
466 // these are updated by each Damage call for use in button triggering and such
468 entity damage_inflictor;
469 entity damage_attacker;
471 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
475 entity attacker_save;
479 if (gameover || targ.killcount == -666)
482 local entity oldself;
486 damage_inflictor = inflictor;
487 damage_attacker = attacker;
488 attacker_save = attacker;
490 if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
492 // These are ALWAYS lethal
493 // No damage modification here
494 // Instead, prepare the victim for his death...
496 targ.spawnshieldtime = 0;
497 targ.health = 0.9; // this is < 1
498 targ.flags -= targ.flags & FL_GODMODE;
503 if (targ.classname == "player")
504 if (attacker.classname == "player")
507 damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
509 // nullify damage if teamplay is on
510 if(deathtype != DEATH_TELEFRAG)
511 if(attacker.team == targ.team)
512 if(attacker.classname == "player")
516 else if(attacker != targ)
520 else if(teamplay == 4)
522 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
524 mirrordamage = cvar("g_mirrordamage") * damage;
525 mirrorforce = cvar("g_mirrordamage") * vlen(force);
528 if(cvar("g_friendlyfire") == 0)
532 damage = cvar("g_friendlyfire") * damage;
533 // mirrordamage will be used LATER
542 if(targ.classname == "player")
543 if(attacker.classname == "player")
546 targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
547 attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
553 if(targ.classname == "player")
555 attacker.hitsound += 1;
559 if ((deathtype == DEATH_FALL) ||
560 (deathtype == DEATH_DROWN) ||
561 (deathtype == DEATH_SLIME) ||
562 (deathtype == DEATH_LAVA))
564 if (targ.armorvalue && (deathtype == IT_NEX) && damage)
566 targ.armorvalue -= 1;
567 centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue),"\n"));
571 else if (deathtype == IT_NEX && targ.items & IT_STRENGTH)
573 if(clienttype(attacker) == CLIENTTYPE_REAL)
574 if(IsDifferentTeam(targ, attacker))
577 if (deathtype == IT_LASER)
580 if (targ != attacker)
582 if (targ.classname == "player")
583 centerprint(attacker, "Secondary fire inflicts no damage!\n");
593 if(targ.takedamage == DAMAGE_AIM)
595 if(IsDifferentTeam(targ, attacker))
599 // apply strength multiplier
600 if (attacker.items & IT_STRENGTH && !g_minstagib)
602 damage = damage * cvar("g_balance_powerup_strength_damage");
603 force = force * cvar("g_balance_powerup_strength_force");
605 // apply invincibility multiplier
606 if (targ.items & IT_INVINCIBLE && !g_minstagib)
607 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
612 // apply strength rune
613 if (attacker.runes & RUNE_STRENGTH)
615 if(attacker.runes & CURSE_WEAK) // have both curse & rune
617 damage = damage * cvar("g_balance_rune_strength_combo_damage");
618 force = force * cvar("g_balance_rune_strength_combo_force");
622 damage = damage * cvar("g_balance_rune_strength_damage");
623 force = force * cvar("g_balance_rune_strength_force");
626 else if (attacker.runes & CURSE_WEAK)
628 damage = damage * cvar("g_balance_curse_weak_damage");
629 force = force * cvar("g_balance_curse_weak_force");
632 // apply defense rune
633 if (targ.runes & RUNE_DEFENSE)
635 if (targ.runes & CURSE_VULNER) // have both curse & rune
636 damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
638 damage = damage * cvar("g_balance_rune_defense_takedamage");
640 else if (targ.runes & CURSE_VULNER)
641 damage = damage * cvar("g_balance_curse_vulner_takedamage");
646 if (self.damageforcescale)
649 self.velocity = self.velocity + self.damageforcescale * force;
650 self.flags = self.flags - (self.flags & FL_ONGROUND);
653 if (self.event_damage)
654 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
657 if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
659 // Savage: vampire mode
663 if (time > self.spawnshieldtime)
665 attacker.health += damage;
669 if (attacker.runes & RUNE_VAMPIRE)
671 // apply vampire rune
672 if (attacker.runes & CURSE_EMPATHY) // have the curse too
674 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
675 attacker.health = bound(
676 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
677 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
678 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
682 //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
683 attacker.health = bound(
684 attacker.health, // LA: was 3, but changed so that you can't lose health
685 // empathy won't let you gain health in the same way...
686 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
687 cvar("g_balance_rune_vampire_maxhealth")); // LA: was 1000, now 500
690 // apply empathy curse
691 else if (attacker.runes & CURSE_EMPATHY)
693 attacker.health = bound(
694 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
695 attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
701 // apply mirror damage if any
702 if(mirrordamage > 0 || mirrorforce > 0)
704 attacker = attacker_save;
708 // just lose extra LIVES, don't kill the player for mirror damage
709 if(attacker.armorvalue > 0)
711 attacker.armorvalue = attacker.armorvalue - 1;
712 centerprint(attacker, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue),"\n"));
713 attacker.hitsound += 1;
717 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
718 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
722 vector NearestPointOnBox(entity box, vector org)
724 vector m1, m2, nearest;
726 m1 = box.mins + box.origin;
727 m2 = box.maxs + box.origin;
729 nearest_x = bound(m1_x, org_x, m2_x);
730 nearest_y = bound(m1_y, org_y, m2_y);
731 nearest_z = bound(m1_z, org_z, m2_z);
736 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype)
737 // Returns total damage applies to creatures
747 float total_damage_to_creatures;
749 blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
750 total_damage_to_creatures = 0;
752 targ = findradius (blastorigin, rad);
755 if (targ != inflictor)
758 // LordHavoc: measure distance to nearest point on target (not origin)
759 // (this guarentees 100% damage on a touch impact)
760 nearest = NearestPointOnBox(targ, blastorigin);
761 diff = nearest - blastorigin;
762 // round up a little on the damage to ensure full damage on impacts
763 // and turn the distance into a fraction of the radius
764 power = 1 - ((vlen (diff) - 2) / rad);
766 //bprint(ftos(power));
771 finaldmg = coredamage * power + edgedamage * (1 - power);
774 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
775 // if it's a player, use the view origin as reference
776 if (targ.classname == "player")
777 center = targ.origin + targ.view_ofs;
778 force = normalize(center - blastorigin) * (finaldmg / coredamage) * forceintensity;
779 if (targ == attacker)
780 finaldmg = finaldmg * cvar("g_balance_selfdamagepercent"); // Partial damage if the attacker hits himself
781 // test line of sight to multiple positions on box,
782 // and do damage if any of them hit
784 c = ceil(finaldmg / 10);
790 traceline(blastorigin, nearest, TRUE, inflictor);
791 if (trace_fraction == 1 || trace_ent == targ
792 || cvar("g_throughfloor"))
795 total_damage_to_creatures += finaldmg;
796 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
799 nearest_x = targ.mins_x + random() * targ.size_x;
800 nearest_y = targ.mins_y + random() * targ.size_y;
801 nearest_z = targ.mins_z + random() * targ.size_z;
809 return total_damage_to_creatures;