tf2-scripts/auto_bots.sp

80 lines
1.5 KiB
SourcePawn

#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);
}
}
}
}