Add a few bots if the playercount is under 2

This commit is contained in:
Wizzard 2023-07-30 03:19:40 -04:00
parent bbd047a493
commit 692d83494b
1 changed files with 79 additions and 0 deletions

79
auto_bots.sp Normal file
View File

@ -0,0 +1,79 @@
#include <sourcemod>
#include <tf2>
#define BOT_COUNT 6
bool g_bBotsAdded = false;
public Plugin myinfo =
{
name = "Auto Bots Manager",
author = "Retard",
description = "Automatically manages bots based on player count.",
version = "1.0",
url = "https://deadzone.lol"
};
public void OnPluginStart()
{
CreateTimer(10.0, CheckPlayerCount);
}
public Action CheckPlayerCount(Handle timer, any data)
{
int totalClients = 0;
int realClients = 0;
for(int i = 1; i <= MaxClients; i++)
{
if(IsClientConnected(i) && !IsFakeClient(i))
{
realClients++;
}
if(IsClientConnected(i))
{
totalClients++;
}
}
if(realClients < 2 && !g_bBotsAdded)
{
int botsToBeAdded = BOT_COUNT - (totalClients - realClients);
for(int i = 0; i < botsToBeAdded; i++)
{
ServerCommand("tf_bot_add");
}
g_bBotsAdded = true;
}
else if(realClients >= 2 && g_bBotsAdded)
{
for(int i = 1; i <= MaxClients; i++)
{
if(IsClientConnected(i) && IsFakeClient(i))
{
KickClient(i);
}
}
g_bBotsAdded = false;
}
return Plugin_Continue; // Continue the timer
}
public void OnPluginEnd()
{
if(g_bBotsAdded)
{
for(int i = 1; i <= MaxClients; i++)
{
if(IsClientConnected(i) && IsFakeClient(i))
{
KickClient(i);
}
}
}
}