此代码可以踢出双方阵营中,多出来的 1 个 BOT。
如果 5V5 时候发现永远有一个阵营比对面多出1个bot,然后kick掉这个bot,另外一个阵营又出现了bot,这可能是 bot_quota 10造成的,请改成 bot_quota 9
参考:bot_quota - Valve Developer Community
public void KickPlayer(CCSPlayerController player)
{
if (player.UserId.HasValue)
{
Server.ExecuteCommand($"kickid {(ushort)player.UserId}");
}
}
public void KickTheOneUnWelcomedBot(CsTeam botSide, int ctNum, int tNum)
{
if (Math.Abs(ctNum - tNum) == 1)
{
foreach (var player in Utilities.GetPlayers())
{
if (player == null || !player.IsValid) continue;
if (player.IsBot)
{
KickPlayer(player);
return;
}
}
}
}
public static int GetTeamPlayerNum(CsTeam teamSide)
{
int num = 0;
foreach (var player in Utilities.GetPlayers())
{
if (player == null || !player.IsValid) continue;
if ( player.Team == teamSide)
{
num++;
}
}
return num;
}
[GameEventHandler(HookMode.Pre)]
public HookResult OnEventRoundStartPre(EventRoundStart @event, GameEventInfo info)
{
Logger.LogInformation("Round has started with Timelimit: {Timelimit}", @event.Timelimit);
int CtPlayerNum = GetTeamPlayerNum(CsTeam.CounterTerrorist);
int TPlayerNum = GetTeamPlayerNum(CsTeam.Terrorist);
CsTeam needKickTeam = (CtPlayerNum > TPlayerNum) ? CsTeam.CounterTerrorist : CsTeam.Terrorist;
KickTheOneUnWelcomedBot(needKickTeam, CtPlayerNum, TPlayerNum);
return HookResult.Continue;
}
// https://discord.com/channels/1160907911501991946/1366217956618534975/1366217956618534975
// [GameEventHandler(HookMode.Pre)]
[GameEventHandler]
public HookResult OnEventBotTakeover(EventBotTakeover @event, GameEventInfo info)
{
if (@event == null)return HookResult.Continue;
var player = @event.Userid;
if (player == null || !player.IsValid) return HookResult.Continue;
CCSPlayerController? takenOverBot = null;
foreach (var allplayers in Utilities.GetPlayers())
{
if (allplayers == null || !allplayers.IsValid) continue;
if (player == allplayers.OriginalControllerOfCurrentPawn.Value)
{
takenOverBot = allplayers;
break;
}
}
if (takenOverBot != null && takenOverBot.IsValid)
{
Server.PrintToChatAll($"{player.PlayerName} has taken over the bot: {takenOverBot.PlayerName}");
}
return HookResult.Continue;
}