diff --git a/auto_bots.sp b/auto_bots.sp new file mode 100644 index 0000000..62cd32e --- /dev/null +++ b/auto_bots.sp @@ -0,0 +1,79 @@ +#include +#include + +#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); + } + } + } +}