]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mutators/mutator/kick_teamkiller/sv_kick_teamkiller.qc
Kick teamkiller mutator: use a teamkill rate
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / kick_teamkiller / sv_kick_teamkiller.qc
1
2 float autocvar_g_kick_teamkiller_rate;
3 float autocvar_g_kick_teamkiller_mintime;
4
5 REGISTER_MUTATOR(kick_teamkiller, (autocvar_g_kick_teamkiller_rate > 0));
6
7 MUTATOR_HOOKFUNCTION(kick_teamkiller, PlayerDies)
8 {
9         if (!teamplay)
10         {
11                 return;
12         }
13         if (warmup_stage)
14         {
15                 return;
16         }
17         entity attacker = M_ARGV(1, entity);
18         if (!IS_REAL_CLIENT(attacker))
19         {
20                 return;
21         }
22
23         int teamkills = PlayerScore_Get(attacker, SP_TEAMKILLS);
24         // don't use the players actual playtime if they just started playing
25         // to avoid kicking players who only teamkilled by mistake just after joining
26         float playtime_minutes = max((time - attacker.alivetime)/60.0, autocvar_g_kick_teamkiller_mintime);
27         if (teamkills >= autocvar_g_kick_teamkiller_rate*playtime_minutes)
28         {
29                 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_QUIT_KICK_TEAMKILL, attacker.netname);
30                 dropclient(attacker);
31         }
32 }