3 //set g_mmm_sleuth_count 0.125 "number of players who will become sleuths, set between 0 and 0.9 to use a multiplier of the current players, or 1 and above to specify an exact number of players"
4 //float autocvar_g_mmm_sleuth_count = 0.125; //I don't think that it won't be used...
5 float autocvar_g_mmm_civilian_count = 0.625;
6 //float autocvar_g_mmm_murderer_count = 0.25;
7 float autocvar_g_mmm_round_timelimit = 180;
8 float autocvar_g_mmm_warmup = 10;
9 bool autocvar_g_mmm_punish_teamkill = false;
10 bool autocvar_g_mmm_reward_civilian = true;
11 bool autocvar_g_mmm_reward_sleuth = true; //sleuth reward if investigated corpses
12 float autocvar_g_mmm_max_karma_points = 1000; //LegendGuard sets Karma points 21-02-2021
13 float autocvar_g_mmm_min_karma_points = 400;
14 int autocvar_g_mmm_karma_bankick_tool = 0; //LegendGuard sets a ban tool for server admins 11-03-2021
15 float autocvar_g_mmm_karma_bantime = 1800; //karma ban seconds
16 bool autocvar_g_mmm_karma_damageactive = true; //LegendGuard sets Karma damage setting if active 20-03-2021
17 float autocvar_g_mmm_karma_severity = 0.25;
18 float autocvar_g_mmm_karma_damagepunishmentdeal = 20; //LegendGuard sets Karma punishment damage setting if player kills an ally 28-03-2021
19 int autocvar_g_mmm_playerammobrcstartquantity = 20;
20 // Sleuth is a created team, this team is added inside Civilians team
22 void mmm_FakeTimeLimit(entity e, float t)
24 if(!IS_REAL_CLIENT(e))
28 WriteByte(MSG_ONE, 3); // svc_updatestat
29 WriteByte(MSG_ONE, 236); // STAT_TIMELIMIT
31 WriteCoord(MSG_ONE, autocvar_timelimit);
33 WriteCoord(MSG_ONE, (t + 1) / 60);
35 STAT(MMM_ROUNDTIMER, e) = t;
39 void nades_Clear(entity player);
41 void karma_Control(entity it)
43 float masksize = autocvar_g_ban_default_masksize;
44 float bantime = autocvar_g_mmm_karma_bantime;
45 if(it.karmapoints >= autocvar_g_mmm_max_karma_points)
47 //Resets karmapoints to maintain the maximum
48 //PrintToChatAll("^3REWARD ^1MAXIMUM RESET");
49 GameRules_scoring_add(it, MMM_KARMA, autocvar_g_mmm_max_karma_points - it.karmapoints);
50 it.karmapoints = autocvar_g_mmm_max_karma_points;
52 else if(it.karmapoints <= autocvar_g_mmm_min_karma_points)
54 switch (autocvar_g_mmm_karma_bankick_tool)
57 case 0: PutObserverInServer(it); return;
59 case 1: dropclient(it); return;
61 case 2: Ban_KickBanClient(it, bantime, masksize, "Too low karma"); return;
63 default: PutObserverInServer(it); return;
68 void karmaLoseDifference(entity attacker, entity target)
70 if (autocvar_g_mmm_karma_severity <= 0.09)
71 autocvar_g_mmm_karma_severity = 0.1;
72 else if (autocvar_g_mmm_karma_severity > 1)
73 autocvar_g_mmm_karma_severity = 1;
75 //BASIC MATH THEORY: example: 1000 * 0.3 * (0.1 + 0.4) * 0.25 // karma points reduce when player attacked to other player
76 if (target.karmapoints < attacker.karmapoints)
78 float decreasekarma = - ( target.karmapoints * random() * ( 0.1 + random() ) * autocvar_g_mmm_karma_severity );
79 GameRules_scoring_add(attacker, MMM_KARMA, decreasekarma);
80 attacker.karmapoints = attacker.karmapoints + decreasekarma;
82 else if (target.karmapoints > attacker.karmapoints)
84 float decreasekarma = - ( target.karmapoints * random() * ( 0.1 + random() ) * autocvar_g_mmm_karma_severity );
85 GameRules_scoring_add(attacker, MMM_KARMA, decreasekarma);
86 attacker.karmapoints = attacker.karmapoints + decreasekarma;
90 float decreasekarma = - ( target.karmapoints * random() * ( 0.1 + random() ) * autocvar_g_mmm_karma_severity );
91 GameRules_scoring_add(attacker, MMM_KARMA, decreasekarma);
92 attacker.karmapoints = attacker.karmapoints + decreasekarma;
96 void karmaWinDifference(entity it)
98 GameRules_scoring_add(it, SCORE, 1); // reward civilians who make it to the end of the round time limit
99 float increasekarma = ( autocvar_g_mmm_min_karma_points * random() * ( 0.1 + random() ) * 0.12 );
100 GameRules_scoring_add(it, MMM_KARMA, increasekarma);
101 it.karmapoints = it.karmapoints + increasekarma;
105 void mmm_UpdateScores(bool timed_out)
107 // give players their hard-earned kills now that the round is over
110 it.totalfrags += it.mmm_validkills;
111 if(it.mmm_validkills)
113 GameRules_scoring_add(it, SCORE, it.mmm_validkills);
115 it.mmm_validkills = 0;
116 // player survived the round
117 if(IS_PLAYER(it) && !IS_DEAD(it)) // LegendGuard adds something for Karma 21-02-2021
119 if((autocvar_g_mmm_reward_civilian && timed_out && it.mmm_status == MMM_STATUS_CIVILIAN)
120 || (autocvar_g_mmm_reward_civilian && !timed_out && it.mmm_status == MMM_STATUS_CIVILIAN))
122 karmaWinDifference(it);
123 //PrintToChatAll(sprintf("^2REWARD ^7it.karmapoints: ^1%f", it.karmapoints));
126 //Sleuth reward after investigated a corpse
127 if((autocvar_g_mmm_reward_sleuth && timed_out && it.mmm_status == MMM_STATUS_SLEUTH)
128 || (autocvar_g_mmm_reward_sleuth && !timed_out && it.mmm_status == MMM_STATUS_SLEUTH))
130 if (it.investigated == true)
132 karmaWinDifference(it);
133 it.investigated = false;
137 if(it.mmm_status == MMM_STATUS_MURDERER)
139 karmaWinDifference(it);
140 //PrintToChatAll(sprintf("^1MURDERER ^7it.karmapoints: ^1%f", it.karmapoints));
146 float mmm_CheckWinner()
148 if(round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0)
150 // if the match times out, civilians win too!
151 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_MMM_CIVILIAN_WIN);
152 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_MMM_CIVILIAN_WIN);
157 mmm_FakeTimeLimit(it, -1);
161 mmm_UpdateScores(true);
163 allowed_to_spawn = false;
165 round_handler_Init(5, autocvar_g_mmm_warmup, autocvar_g_mmm_round_timelimit);
169 int civilian_count = 0, murderer_count = 0, sleuth_count = 0;
170 FOREACH_CLIENT(IS_PLAYER(it) && !IS_DEAD(it),
172 if(it.mmm_status == MMM_STATUS_CIVILIAN)
174 else if(it.mmm_status == MMM_STATUS_MURDERER)
176 else if(it.mmm_status == MMM_STATUS_SLEUTH) //LegendGuard adds sleuth_count 20-02-2021
179 if(civilian_count > 0 && murderer_count > 0)
184 if(murderer_count > 0) // murderers win
186 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_MMM_MURDERER_WIN);
187 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_MMM_MURDERER_WIN);
189 else if(civilian_count > 0) // civilians win
191 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_MMM_CIVILIAN_WIN);
192 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_MMM_CIVILIAN_WIN);
194 else if (sleuth_count > 0 && civilian_count > 0) // sleuths are same as civilians win
196 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_MMM_CIVILIAN_WIN);
197 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_MMM_CIVILIAN_WIN);
201 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_ROUND_TIED);
202 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ROUND_TIED);
205 mmm_UpdateScores(false);
207 allowed_to_spawn = false;
209 round_handler_Init(5, autocvar_g_mmm_warmup, autocvar_g_mmm_round_timelimit);
215 it.respawn_flags = RESPAWN_SILENT; //CSQC print output respawn lib.qh error fix
218 mmm_FakeTimeLimit(it, -1);
225 void mmm_RoundStart()
227 allowed_to_spawn = boolean(warmup_stage);
232 if(IS_PLAYER(it) && !IS_DEAD(it))
235 it.mmm_status = MMM_STATUS_CIVILIAN;
238 it.mmm_status = 0; // this is mostly a safety check; if a client manages to somehow maintain a mmm status, clear it before the round starts!
239 it.mmm_validkills = 0;
242 int civilian_count = bound(1, ((autocvar_g_mmm_civilian_count >= 1) ? autocvar_g_mmm_civilian_count : floor(playercount * autocvar_g_mmm_civilian_count)), playercount - 1); // 20%, but ensure at least 1 and less than total
243 int total_civilians = 0;
244 //int murderer_count = bound(1, ((autocvar_g_mmm_murderer_count >= 1) ? autocvar_g_mmm_murderer_count : floor(playercount * autocvar_g_mmm_murderer_count)), playercount - 1); // 20%, but ensure at least 1 and less than total
245 int total_murderers = 0;
246 //int sleuth_count = bound(1, ((autocvar_g_mmm_sleuth_count >= 1) ? autocvar_g_mmm_sleuth_count : floor(playercount * autocvar_g_mmm_sleuth_count)), playercount - 1); // 20%, but ensure at least 1 and less than total
247 int total_sleuths = 0;
250 FOREACH_CLIENT_RANDOM(IS_PLAYER(it) && !IS_DEAD(it),
252 if(total_civilians >= civilian_count)
254 //LegendGuard fixes the round start again 22-03-2021
256 if (total_civilians <= 1)
258 if (total_murderers <= 1)
261 it.mmm_status = MMM_STATUS_MURDERER;
264 else if (total_civilians == 2)
266 if (total_sleuths >= 1)
271 it.mmm_status = MMM_STATUS_SLEUTH;
274 else if (total_civilians == 5)
276 if (total_murderers <= 2)
281 it.mmm_status = MMM_STATUS_MURDERER;
284 else if (total_civilians == 6)
286 if (total_sleuths >= 2)
291 it.mmm_status = MMM_STATUS_SLEUTH;
294 else if (total_civilians == 7)
296 if (total_sleuths >= 3)
298 else if (total_murderers == 3)
301 it.mmm_status = MMM_STATUS_MURDERER;
306 it.mmm_status = MMM_STATUS_SLEUTH;
309 else if (total_civilians >= 8)
311 if (total_sleuths >= 4)
313 else if (total_murderers == 4)
316 it.mmm_status = MMM_STATUS_MURDERER;
321 it.mmm_status = MMM_STATUS_SLEUTH;
327 it.mmm_status = MMM_STATUS_MURDERER;
331 FOREACH_CLIENT(IS_PLAYER(it) && !IS_DEAD(it),
333 float totalmeankarma = ((autocvar_g_mmm_max_karma_points + autocvar_g_mmm_min_karma_points + it.karmapoints) / 3);
335 it.activekillerrole = false;
337 if(it.mmm_status == MMM_STATUS_CIVILIAN)
339 SetResource(it, RES_BULLETS, autocvar_g_mmm_playerammobrcstartquantity);
340 SetResource(it, RES_ROCKETS, autocvar_g_mmm_playerammobrcstartquantity);
341 SetResource(it, RES_CELLS, autocvar_g_mmm_playerammobrcstartquantity);
342 if (it.karmapoints <= totalmeankarma)
344 centerprint(it, strcat(BOLD_OPERATOR, "^1KARMA WARNING!\n^3Here, have the Rifle!"));
345 GiveWeapon(it, WEP_RIFLE.m_id, OP_PLUS, 1);
347 //Gives Mine Layer weapon to the player
348 GiveWeapon(it, WEP_MINE_LAYER.m_id, OP_PLUS, 1);
349 Send_Notification(NOTIF_ONE_ONLY, it, MSG_CENTER, CENTER_MMM_CIVILIAN);
350 Send_Notification(NOTIF_ONE_ONLY, it, MSG_INFO, INFO_MMM_CIVILIAN);
351 //PrintToChatAll(sprintf("^1DEBUG^7: %s is ^2Civilian^7!", it.netname));
353 else if(it.mmm_status == MMM_STATUS_MURDERER)
355 SetResource(it, RES_BULLETS, autocvar_g_mmm_playerammobrcstartquantity);
356 SetResource(it, RES_ROCKETS, autocvar_g_mmm_playerammobrcstartquantity);
357 SetResource(it, RES_CELLS, autocvar_g_mmm_playerammobrcstartquantity);
358 if (it.karmapoints <= totalmeankarma)
360 centerprint(it, strcat(BOLD_OPERATOR, "^1KARMA WARNING!\n^3Here, have the Rifle!"));
361 GiveWeapon(it, WEP_RIFLE.m_id, OP_PLUS, 1);
363 //Gives Mine Layer weapon to the player
364 GiveWeapon(it, WEP_MINE_LAYER.m_id, OP_PLUS, 1);
365 Send_Notification(NOTIF_ONE_ONLY, it, MSG_CENTER, CENTER_MMM_MURDERER);
366 Send_Notification(NOTIF_ONE_ONLY, it, MSG_INFO, INFO_MMM_MURDERER);
367 //PrintToChatAll(sprintf("^1DEBUG^7: %s is ^1Murderer^7!", it.netname));
369 else if(it.mmm_status == MMM_STATUS_SLEUTH)
371 SetResource(it, RES_ROCKETS, 10);
372 if (it.karmapoints <= totalmeankarma)
374 centerprint(it, strcat(BOLD_OPERATOR, "^1KARMA WARNING!\n^3Here, have the Rifle!"));
375 GiveWeapon(it, WEP_RIFLE.m_id, OP_PLUS, 1);
377 //Gives Shockwave and Mine Layer weapon to the player
378 GiveWeapon(it, WEP_SHOCKWAVE.m_id, OP_PLUS, 1);
379 GiveWeapon(it, WEP_MINE_LAYER.m_id, OP_PLUS, 1);
380 Send_Notification(NOTIF_ONE_ONLY, it, MSG_CENTER, CENTER_MMM_SLEUTH);
381 Send_Notification(NOTIF_ONE_ONLY, it, MSG_INFO, INFO_MMM_SLEUTH);
382 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_MMM_WHOISSLEUTH, it.netname);
384 mmm_FakeTimeLimit(it, round_handler_GetEndTime());
388 bool mmm_CheckPlayers()
390 static int prev_missing_players;
391 allowed_to_spawn = true;
394 FOREACH_CLIENT(IS_PLAYER(it) && !IS_DEAD(it),
396 //PrintToChatAll(sprintf("it.karmapoints ^5begin: ^3%f",it.karmapoints));
398 if (it.karmastarted != true)
400 GameRules_scoring_add(it, MMM_KARMA, autocvar_g_mmm_max_karma_points - it.karmapoints);
401 it.karmapoints = autocvar_g_mmm_max_karma_points;
402 it.karmastarted = true;
406 //PrintToChatAll(sprintf("it.karmapoints ^6end: ^3%f",it.karmapoints));
409 if (playercount >= 2)
411 if(prev_missing_players > 0)
412 Kill_Notification(NOTIF_ALL, NULL, MSG_CENTER, CPID_MISSING_PLAYERS);
413 prev_missing_players = -1;
419 if(prev_missing_players > 0)
420 Kill_Notification(NOTIF_ALL, NULL, MSG_CENTER, CPID_MISSING_PLAYERS);
421 prev_missing_players = -1;
425 // if we get here, only 1 player is missing
426 if(prev_missing_players != 1)
428 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_MISSING_PLAYERS, 1);
429 prev_missing_players = 1;
434 bool mmm_isEliminated(entity e)
436 if(e.caplayer == 1 && (IS_DEAD(e) || e.frags == FRAGS_PLAYER_OUT_OF_GAME))
438 if(e.caplayer == 0.5)
443 void mmm_Initialize() // run at the start of a match, initiates game mode
445 GameRules_scoring(0, SFL_SORT_PRIO_PRIMARY, 0, {
446 field(SP_MMM_KARMA, "karma", SFL_SORT_PRIO_SECONDARY); //LegendGuard adds Karma points in the scoreboard 22-02-2021
449 allowed_to_spawn = true;
450 round_handler_Spawn(mmm_CheckPlayers, mmm_CheckWinner, mmm_RoundStart);
451 round_handler_Init(5, autocvar_g_mmm_warmup, autocvar_g_mmm_round_timelimit);
452 EliminatedPlayers_Init(mmm_isEliminated);
455 void checkWeaponDeathtype(entity target, float deathtype)
459 case WEP_ARC.m_id: case 276: case 788: target.killedwithweapon = "Impacted by the Arc's electric shock"; return;
460 case WEP_BLASTER.m_id: case 513: target.killedwithweapon = "Blasted by the Blaster"; return;
461 case WEP_CRYLINK.m_id: case 263: case 519: target.killedwithweapon = "Shot by the Crylink"; return;
462 case WEP_DEVASTATOR.m_id: case 522: case 1546: target.killedwithweapon = "Bombarded by the Devastator"; return;
463 case WEP_ELECTRO.m_id: case 262: case 518: case 1542: target.killedwithweapon = "Electrocuted by the Electro"; return;
464 case WEP_FIREBALL.m_id: case 273: case 529: case 1297: target.killedwithweapon = "Burned by the Fireball"; return;
465 case WEP_HAGAR.m_id: case 265: target.killedwithweapon = "Gunned by the Hagar"; return;
466 case WEP_HLAC.m_id: case 270: case 526: target.killedwithweapon = "Cut down with the HLAC"; return;
467 case WEP_HOOK.m_id: case 1805: target.killedwithweapon = "Caught in Hook gravity bomb"; return;
468 case WEP_MACHINEGUN.m_id: target.activekillerrole = true; target.killedwithweapon = "Riddled full of holes by the Machine Gun"; return;
469 case WEP_MINE_LAYER.m_id: case 517: case 1541: target.killedwithweapon = "Exploited by the Mine Layer"; return;
470 case WEP_MORTAR.m_id: case 516: case 1284: target.killedwithweapon = "Blew up with the Mortar"; return;
471 case WEP_OVERKILL_NEX.m_id: target.killedwithweapon = "Sniped by the Overkill Nex"; return;
472 case WEP_RIFLE.m_id: case 272: target.activekillerrole = true; target.killedwithweapon = "Sniped by the Rifle"; return;
473 case WEP_SEEKER.m_id: case 274: case 786: target.killedwithweapon = "Blasted by the Seeker"; return;
474 case WEP_SHOCKWAVE.m_id: target.killedwithweapon = "Gunned down by the Shockwave"; return;
475 case 275: target.killedwithweapon = "Knocked by the Shockwave"; return;
476 case WEP_SHOTGUN.m_id: target.activekillerrole = true; target.killedwithweapon = "Shot by Shotgun"; return;
477 case 258: target.killedwithweapon = "Knocked by the Shotgun"; return;
478 case WEP_TUBA.m_id: target.killedwithweapon = "Ear pain by the @!#%'n Tuba"; return;
479 case WEP_VAPORIZER.m_id: case 257: case 769: target.killedwithweapon = "Sniped by the Vaporizer"; return;
480 case WEP_VORTEX.m_id: target.killedwithweapon = "Sniped by the Vortex"; return;
481 case DEATH_FALL.m_id: target.killedwithweapon = "Fall"; return;
482 case DEATH_FIRE.m_id: target.killedwithweapon = "Burned with the fire"; return;
483 case DEATH_LAVA.m_id: target.killedwithweapon = "Burned in lava"; return;
484 case DEATH_MIRRORDAMAGE.m_id: target.killedwithweapon = "Suicide"; return;
485 case DEATH_SLIME.m_id: target.killedwithweapon = "Melted in slime"; return;
486 case DEATH_TELEFRAG.m_id: target.killedwithweapon = "Telefragged"; return;
487 case DEATH_NADE.m_id: target.killedwithweapon = "Blown up by the nade"; return;
488 case DEATH_NADE_NAPALM.m_id: target.killedwithweapon = "Burned by the Napalm nade"; return;
489 case DEATH_NADE_ICE.m_id: target.killedwithweapon = "Frozen by the Ice nade"; return;
490 case DEATH_NADE_HEAL.m_id: target.killedwithweapon = "Sucked by the Heal nade"; return;
491 default: target.killedwithweapon = "Unknown"; return;
495 void ReduceKarmaPointsandFrags(entity frag_attacker, entity frag_target, float frag_deathtype, entity wep_ent)
497 karmaLoseDifference(frag_attacker, frag_target);
498 GiveFrags(frag_attacker, frag_target, ((autocvar_g_mmm_punish_teamkill) ? -1 : -2), frag_deathtype, wep_ent.weaponentity_fld);
499 frag_target.whokilled = frag_attacker.netname;
506 MUTATOR_HOOKFUNCTION(mmm, ClientObituary)
508 // LegendGuard's IDEA: To adjust the grade of severity of karma,
509 // we could add if sentence per weapons and adjust each weapon attack
510 // its own grade. Instead doing random decrease grade 22-02-2021
512 // in mmm, announcing a frag would tell everyone who the murderer is
513 entity frag_attacker = M_ARGV(1, entity);
514 entity frag_target = M_ARGV(2, entity);
516 if(IS_PLAYER(frag_attacker) && frag_attacker != frag_target)
518 float frag_deathtype = M_ARGV(3, float);
519 entity wep_ent = M_ARGV(4, entity);
521 //PrintToChatAll(strcat("deathtype var: ", ftos(frag_deathtype)));
522 checkWeaponDeathtype(frag_target, frag_deathtype);
523 // "team" kill, a point is awarded to the player by default so we must take it away plus an extra one
524 // unless the player is going to be punished for suicide, in which case just remove one
525 if(frag_attacker.mmm_status == frag_target.mmm_status)
527 //PrintToChatAll("^1DEBUG^7: A ^2PLAYER^7 has fragged a ^2PLAYER OF HIS OWN TEAM^7, TOO BAD!");
528 ReduceKarmaPointsandFrags(frag_attacker, frag_target, frag_deathtype, wep_ent);
529 switch (frag_attacker.mmm_status)
531 case MMM_STATUS_CIVILIAN: frag_target.killerrole = "\n^3Killer role: ^2Civilian"; return;
532 case MMM_STATUS_MURDERER: frag_target.killerrole = "\n^3Killer role: ^1Murderer"; return;
533 case MMM_STATUS_SLEUTH: frag_target.killerrole = "\n^3Killer role: ^4Sleuth"; return;
536 //PrintToChatAll(sprintf("frag_attacker.karmapoints: ^1%f", frag_attacker.karmapoints));
539 if(frag_attacker.mmm_status == MMM_STATUS_SLEUTH)
541 if (frag_target.mmm_status == MMM_STATUS_CIVILIAN || frag_target.mmm_status == MMM_STATUS_SLEUTH)
543 //PrintToChatAll("^1DEBUG^7: A ^4Sleuth^7 fragged an ^2Civilian^7/^4Sleuth^7, TOO BAD!");
544 ReduceKarmaPointsandFrags(frag_attacker, frag_target, frag_deathtype, wep_ent);
545 frag_target.killerrole = "\n^3Killer role: ^4Sleuth";
546 //PrintToChatAll(sprintf("frag_attacker.karmapoints: ^1%f", frag_attacker.karmapoints));
550 frag_target.whokilled = frag_attacker.netname;
551 frag_target.killerrole = "\n^3Killer role: ^4Sleuth";
555 if (frag_attacker.mmm_status == MMM_STATUS_CIVILIAN)
557 if (frag_target.mmm_status == MMM_STATUS_SLEUTH)
559 //PrintToChatAll("^1DEBUG^7: An ^2Civilian^7 fragged a ^4Sleuth^7, TOO BAD!");
560 ReduceKarmaPointsandFrags(frag_attacker, frag_target, frag_deathtype, wep_ent);
561 frag_target.killerrole = "\n^3Killer role: ^2Civilian";
565 frag_target.whokilled = frag_attacker.netname;
566 frag_target.killerrole = "\n^3Killer role: ^2Civilian";
570 if (frag_attacker.mmm_status == MMM_STATUS_MURDERER)
572 if (frag_target.mmm_status == MMM_STATUS_CIVILIAN)
574 frag_target.whokilled = frag_attacker.netname;
575 frag_target.killerrole = "\n^3Killer role: ^1Murderer";
579 frag_target.whokilled = frag_attacker.netname;
580 frag_target.killerrole = "\n^3Killer role: ^1Murderer";
583 //if mmm_status is 1, means civilian, 2 means murderer, 3 means sleuth
584 //PrintToChatAll(sprintf("^1DEBUG^7: frag_attacker.mmm_status is ^3%s^7",ftos(frag_attacker.mmm_status)));
585 //PrintToChatAll(sprintf("^1DEBUG^7: frag_target.mmm_status is ^3%s^7",ftos(frag_target.mmm_status)));
589 float frag_deathtype = M_ARGV(3, float);
590 checkWeaponDeathtype(frag_target, frag_deathtype);
593 M_ARGV(5, bool) = true; // anonymous attacker
596 //karma weapon damage, halve the damage attack when player has low karma 20-03-2021
597 MUTATOR_HOOKFUNCTION(mmm, Damage_Calculate)
599 entity attacker = M_ARGV(1, entity);
600 entity target = M_ARGV(2, entity);
601 float deathtype = M_ARGV(3, float);
602 float damage = M_ARGV(4, float);
603 vector force = M_ARGV(6, vector);
604 string corpsemessagestrcat = "";
606 if (autocvar_g_mmm_karma_damageactive != false)
608 if (IS_PLAYER(attacker))
610 if(target == attacker) // damage done to yourself
612 damage /= autocvar_g_weapondamagefactor / (attacker.karmapoints / autocvar_g_mmm_max_karma_points);
613 force /= autocvar_g_weaponforcefactor / (attacker.karmapoints / autocvar_g_mmm_max_karma_points);
615 else if (target != attacker)
617 damage /= autocvar_g_weapondamagefactor / (attacker.karmapoints / autocvar_g_mmm_max_karma_points);
618 force /= autocvar_g_weaponforcefactor / (attacker.karmapoints / autocvar_g_mmm_max_karma_points);
622 damage *= autocvar_g_weapondamagefactor;
623 force *= autocvar_g_weaponforcefactor;
628 //CORPSE DETECTION SKILL 21-03-2021
631 //Shockwave weapon as radar gun to check the corpses 22-03-2021
632 if(DEATH_ISWEAPON(deathtype, WEP_SHOCKWAVE))
634 if (target.killedwithweapon == "")
635 target.killedwithweapon = "UNKNOWN CAUSE";
637 if (target.activekillerrole != true)
639 target.killerrole = "";
640 target.activekillerrole = false;
643 string killedbyphrase = strcat("\n^3Killed by:^7 ", target.whokilled, target.killerrole);
644 string wepkilledphrase = strcat("\n^3Cause:^7 ", target.killedwithweapon);
645 if (target.whokilled == "")
648 if (target.killedwithweapon == "")
649 wepkilledphrase = "\n^3Cause:^7 UNKNOWN CAUSE";
654 if (target.mmm_status == MMM_STATUS_CIVILIAN)
656 //try to add centerprint message for chat privately if possible
657 corpsemessagestrcat = strcat("\n^3Name:^7 ", target.netname, "\n^3Role: ^2Civilian", killedbyphrase, wepkilledphrase);
658 centerprint(attacker, strcat(BOLD_OPERATOR, corpsemessagestrcat));//("\n^6Name^3:^7 ", target.netname, "\n^5Role^3: ^2Civilian\n", "^1Killed by^3:^7 ", target.whokilled)));
660 else if (target.mmm_status == MMM_STATUS_MURDERER)
662 corpsemessagestrcat = strcat("\n^3Name:^7 ", target.netname, "\n^3Role: ^1Murderer", killedbyphrase, wepkilledphrase);
663 centerprint(attacker, strcat(BOLD_OPERATOR, corpsemessagestrcat));//("\n^6Name^3:^7 ", target.netname, "\n^5Role^3: ^1Murderer\n", "^1Killed by^3:^7 ", target.whokilled)));
665 else if (target.mmm_status == MMM_STATUS_SLEUTH)
667 corpsemessagestrcat = strcat("\n^3Name:^7 ", target.netname, "\n^3Role: ^4Sleuth", killedbyphrase, wepkilledphrase);
668 centerprint(attacker, strcat(BOLD_OPERATOR, corpsemessagestrcat));//("\n^6Name^3:^7 ", target.netname, "\n^5Role^3: ^4Sleuth\n", "^1Killed by^3:^7 ", target.whokilled)));
670 attacker.investigated = true;
674 M_ARGV(4, float) = damage;
675 M_ARGV(6, vector) = force;
678 MUTATOR_HOOKFUNCTION(mmm, PlayerPreThink)
680 entity player = M_ARGV(0, entity);
682 if(IS_PLAYER(player) || player.caplayer)
684 // update the scoreboard colour display to out the real killer at the end of the round
685 // running this every frame to avoid cheats
686 int plcolor = MMM_COLOR_CIVILIAN;
687 if(player.mmm_status == MMM_STATUS_CIVILIAN && game_stopped) //Civilian status by default
688 plcolor = MMM_COLOR_CIVILIAN;
689 if(player.mmm_status == MMM_STATUS_MURDERER && game_stopped)
690 plcolor = MMM_COLOR_MURDERER;
691 //LegendGuard adds for Sleuth 21-02-2021
692 if(player.mmm_status == MMM_STATUS_SLEUTH)// && game_stopped)
693 plcolor = MMM_COLOR_SLEUTH;
694 setcolor(player, plcolor);
697 //CORPSE FEATURE 10-03-2021
700 player.event_damage = func_null;
702 player.solid = SOLID_CORPSE;
703 set_movetype(player, MOVETYPE_STEP); //test with MOVETYPE_TOSS or MOVETYPE_WALK (it's like sliding object) or MOVETYPE_BOUNCE (maybe not good)
707 MUTATOR_HOOKFUNCTION(mmm, PlayerSpawn)
709 entity player = M_ARGV(0, entity);
711 player.mmm_status = 0;
712 player.mmm_validkills = 0;
715 eliminatedPlayers.SendFlags |= 1;
718 MUTATOR_HOOKFUNCTION(mmm, ForbidSpawn)
720 entity player = M_ARGV(0, entity);
722 // spectators / observers that weren't playing can join; they are
723 // immediately forced to observe in the PutClientInServer hook
724 // this way they are put in a team and can play in the next round
725 if (!allowed_to_spawn && player.caplayer)
730 MUTATOR_HOOKFUNCTION(mmm, PutClientInServer)
732 entity player = M_ARGV(0, entity);
734 if (!allowed_to_spawn && IS_PLAYER(player)) // this is true even when player is trying to join
736 TRANSMUTE(Observer, player);
737 if (CS(player).jointime != time && !player.caplayer) // not when connecting
739 player.caplayer = 0.5;
740 Send_Notification(NOTIF_ONE_ONLY, player, MSG_INFO, INFO_CA_JOIN_LATE);
745 MUTATOR_HOOKFUNCTION(mmm, reset_map_players)
747 FOREACH_CLIENT(true, {
748 CS(it).killcount = 0;
750 mmm_FakeTimeLimit(it, -1); // restore original timelimit
751 if (!it.caplayer && IS_BOT_CLIENT(it))
755 TRANSMUTE(Player, it);
757 it.respawn_flags = RESPAWN_SILENT; //CSQC print output respawn lib.qh error fix
758 PutClientInServer(it);
761 bot_relinkplayerlist();
765 MUTATOR_HOOKFUNCTION(mmm, reset_map_global)
767 allowed_to_spawn = true;
771 entity mmm_LastPlayerForTeam(entity this)
773 entity last_pl = NULL;
774 FOREACH_CLIENT(IS_PLAYER(it) && it != this, {
775 if (!IS_DEAD(it) && this.mmm_status == it.mmm_status)
788 void mmm_LastPlayerForTeam_Notify(entity this)
790 if (!warmup_stage && round_handler_IsActive() && round_handler_IsRoundStarted())
792 entity pl = mmm_LastPlayerForTeam(this);
794 Send_Notification(NOTIF_ONE_ONLY, pl, MSG_CENTER, CENTER_ALONE);
798 MUTATOR_HOOKFUNCTION(mmm, PlayerDies)
800 entity frag_attacker = M_ARGV(1, entity);
801 entity frag_target = M_ARGV(2, entity);
802 //float frag_deathtype = M_ARGV(3, float);
804 mmm_LastPlayerForTeam_Notify(frag_target);
805 if (!allowed_to_spawn)
807 frag_target.respawn_flags = RESPAWN_DENY;
808 // prevent unwanted sudden rejoin as spectator and movement of spectator camera
809 frag_target.respawn_time = time + 2;
811 frag_target.respawn_flags |= RESPAWN_DENY;
812 frag_target.event_damage = func_null;
813 frag_target.health = 0;
817 eliminatedPlayers.SendFlags |= 1;
818 if (IS_BOT_CLIENT(frag_target))
819 bot_clear(frag_target);
822 //if(frag_attacker.mmm_status == frag_target.mmm_status)
823 // killed an ally! punishment is sentenced
824 if(frag_attacker.mmm_status == MMM_STATUS_SLEUTH)
826 if (frag_target.mmm_status == MMM_STATUS_CIVILIAN)
828 //PrintToChatAll("^1DEBUG^7: ^4SLEUTH ^1DAMAGE/DEAD^7 HAS TAKEN!");
829 Damage(frag_attacker, frag_attacker, frag_attacker, autocvar_g_mmm_karma_damagepunishmentdeal, DEATH_MIRRORDAMAGE.m_id, DMG_NOWEP, frag_attacker.origin, '0 0 0');
832 if (frag_attacker.mmm_status == MMM_STATUS_CIVILIAN)
834 if (frag_target.mmm_status == MMM_STATUS_SLEUTH)
836 //PrintToChatAll("^1DEBUG^7: ^2CIVILIAN ^1DAMAGE/DEAD^7 HAS TAKEN!");
837 Damage(frag_attacker, frag_attacker, frag_attacker, autocvar_g_mmm_karma_damagepunishmentdeal, DEATH_MIRRORDAMAGE.m_id, DMG_NOWEP, frag_attacker.origin, '0 0 0');
840 if (frag_attacker.mmm_status == MMM_STATUS_MURDERER)
842 if (frag_target.mmm_status == MMM_STATUS_MURDERER)
844 //PrintToChatAll("^1DEBUG^7: ^1MURDERER ^1DAMAGE/DEAD^7 HAS TAKEN!");
845 Damage(frag_attacker, frag_attacker, frag_attacker, autocvar_g_mmm_karma_damagepunishmentdeal, DEATH_MIRRORDAMAGE.m_id, DMG_NOWEP, frag_attacker.origin, '0 0 0');
851 MUTATOR_HOOKFUNCTION(mmm, ClientDisconnect)
853 entity player = M_ARGV(0, entity);
855 if (IS_PLAYER(player) && !IS_DEAD(player))
856 mmm_LastPlayerForTeam_Notify(player);
860 MUTATOR_HOOKFUNCTION(mmm, MakePlayerObserver)
862 entity player = M_ARGV(0, entity);
864 if (IS_PLAYER(player) && !IS_DEAD(player))
865 mmm_LastPlayerForTeam_Notify(player);
866 if (player.killindicator_teamchange == -2) // player wants to spectate
869 player.frags = FRAGS_PLAYER_OUT_OF_GAME;
871 eliminatedPlayers.SendFlags |= 1;
872 if (!player.caplayer)
874 player.mmm_validkills = 0;
875 player.mmm_status = 0;
876 mmm_FakeTimeLimit(player, -1); // restore original timelimit
877 return false; // allow team reset
879 return true; // prevent team reset
882 MUTATOR_HOOKFUNCTION(mmm, Scores_CountFragsRemaining)
884 // announce remaining frags?
888 MUTATOR_HOOKFUNCTION(mmm, GiveFragsForKill, CBC_ORDER_FIRST)
890 entity frag_attacker = M_ARGV(0, entity);
891 if(!warmup_stage && round_handler_IsActive() && round_handler_IsRoundStarted())
892 frag_attacker.mmm_validkills += M_ARGV(2, float);
893 M_ARGV(2, float) = 0; // score will be given to the winner when the round ends
897 MUTATOR_HOOKFUNCTION(mmm, AddPlayerScore)
899 // add scorefield for scoreboard here
900 entity scorefield = M_ARGV(0, entity);
901 if(scorefield == SP_KILLS || scorefield == SP_DEATHS || scorefield == SP_SUICIDES || scorefield == SP_DMG || scorefield == SP_DMGTAKEN)
902 M_ARGV(1, float) = 0; // don't report that the player has killed or been killed, that would out them as a murderer!
905 MUTATOR_HOOKFUNCTION(mmm, CalculateRespawnTime)
907 // no respawn calculations needed, player is forced to spectate anyway
911 MUTATOR_HOOKFUNCTION(mmm, Bot_FixCount, CBC_ORDER_EXCLUSIVE)
913 FOREACH_CLIENT(IS_REAL_CLIENT(it), {
914 if (IS_PLAYER(it) || it.caplayer == 1)
921 MUTATOR_HOOKFUNCTION(mmm, ClientCommand_Spectate)
923 entity player = M_ARGV(0, entity);
927 // they're going to spec, we can do other checks
928 if (autocvar_sv_spectate && (IS_SPEC(player) || IS_OBSERVER(player)))
929 Send_Notification(NOTIF_ONE_ONLY, player, MSG_INFO, INFO_CA_LEAVE);
930 return MUT_SPECCMD_FORCE;
933 return MUT_SPECCMD_CONTINUE;
936 MUTATOR_HOOKFUNCTION(mmm, GetPlayerStatus)
938 entity player = M_ARGV(0, entity);
940 return player.caplayer == 1;
943 MUTATOR_HOOKFUNCTION(mmm, BotShouldAttack)
945 entity bot = M_ARGV(0, entity);
946 entity targ = M_ARGV(1, entity);
948 if(targ.mmm_status == bot.mmm_status)
953 // LegendGuard fixed the problem of Sleuths and Civilians attacking each other 26-03-2021
954 if(bot.mmm_status == MMM_STATUS_SLEUTH)
956 if(targ.mmm_status == MMM_STATUS_CIVILIAN)