.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   Ideas (http://forums.bots-united.com/forumdisplay.php?f=50)
-   -   Remove all bots when there is no human player on the server (http://forums.bots-united.com/showthread.php?t=6266)

e-t172 24-04-2007 12:13

Remove all bots when there is no human player on the server
 
I'm using PODBot MM on a dedicated server. My problem is that when there is no human player on the server, the bots continue to play, and thus continue to use a big deal of CPU.

It would be great to have an option to automatically remove bots when there is no human player on the server (and to make them automatically rejoin when a human player joins). The official bots for CS:S have such an option.

So I'm looking forward for a new CVAR :P

KWo 24-04-2007 16:37

Re: Remove all bots when there is no human player on the server
 
This is exactly as a contrary to this:
http://forums.bots-united.com/showthread.php?t=6253

Sorry - I'm not able to make everyone happy.

About that big CPU usage - try out V3B16c version - it should take less CPU.

e-t172 24-04-2007 20:50

Re: Remove all bots when there is no human player on the server
 
I hate wasting the CPU time of my machines so I coded it myself. Here is the patch :

Code:

diff -r -u podbot-orig/bot_globals.cpp podbot/bot_globals.cpp
--- podbot-orig/bot_globals.cpp    2007-03-24 14:58:48.000000000 +0100
+++ podbot/bot_globals.cpp    2007-04-24 20:00:07.000000000 +0200
@@ -151,6 +151,7 @@
 int g_i_botthink_index;  // KWo - 02.05.2006
 float g_fAutoKillTime = 0.0;  // KWo - 02.05.2006
 bool g_bAliveHumansPrevious = FALSE;  // KWo - 02.05.2006
+bool g_bHumansPrevious = true;
 int g_iUpdGlExpState = 0;  // KWo - 02.05.2006
 bool g_bRecalcKills = FALSE;  // KWo - 02.05.2006
 
@@ -180,6 +181,7 @@
 float g_f_cv_dangerfactor;        // KWo - 06.04.2006
 bool g_b_cv_chat;                  // KWo - 06.04.2006
 bool g_b_cv_autokill;              // KWo - 02.05.2006
+bool g_b_cv_autoremove;
 float g_f_cv_autokilldelay;        // KWo - 02.05.2006
 bool g_b_cv_ffa;                  // KWo - 04.10.2006
 bool g_b_cv_radio;                // KWo - 03.02.2007
@@ -236,6 +238,7 @@
    "pb_" "aim_target_anticipation_ratio",  // KWo - 04.03.2006
    "pb_" "aim_type",
    "pb_" "autokill",        // KWo - 02.05.2006
+  "pb_" "autoremove",
    "pb_" "autokilldelay",  // KWo - 02.05.2006
    "pb_" "bot_join_team",  // KWo - 16.09.2006
    "pb_" "bot_quota_match", // KWo - 16.09.2006
diff -r -u podbot-orig/bot_globals.h podbot/bot_globals.h
--- podbot-orig/bot_globals.h    2007-03-24 14:58:40.000000000 +0100
+++ podbot/bot_globals.h    2007-04-24 19:55:14.000000000 +0200
@@ -144,6 +144,7 @@
 extern float g_f_cv_dangerfactor; // KWo 06.04.2006
 extern bool g_b_cv_chat; // KWo 06.04.2006
 extern bool g_b_cv_autokill;  // KWo - 02.05.2006
+extern bool g_b_cv_autoremove;
 extern float g_f_cv_autokilldelay;  // KWo - 02.05.2006
 extern bool g_b_cv_ffa;  // KWo - 04.10.2006
 extern bool g_b_cv_radio;  // KWo - 03.02.2007
@@ -168,6 +169,7 @@
 extern int g_i_botthink_index;      // KWo - 02.05.2006
 extern float g_fAutoKillTime;      // KWo - 02.05.2006
 extern bool g_bAliveHumansPrevious; // KWo - 02.05.2006
+extern bool g_bHumansPrevious;
 extern int g_iUpdGlExpState;        // KWo - 02.05.2006
 extern bool g_bRecalcKills;        // KWo - 02.05.2006
 
diff -r -u podbot-orig/bot.h podbot/bot.h
--- podbot-orig/bot.h    2007-03-26 22:04:12.000000000 +0200
+++ podbot/bot.h    2007-04-24 19:49:52.000000000 +0200
@@ -118,6 +118,7 @@
    PBCVAR_AIM_TARGET_ANTICIPATION_RATIO,  // KWo - 04.03.2006
    PBCVAR_AIM_TYPE,
    PBCVAR_AUTOKILL,          // KWo - 02.05.2006
+  PBCVAR_AUTOREMOVE,
    PBCVAR_AUTOKILLDELAY,    // KWo - 02.05.2006
    PBCVAR_BOTJOINTEAM,      // KWo - 16.09.2006
    PBCVAR_BOTQUOTAMATCH,    // KWo - 16.09.2006
diff -r -u podbot-orig/dll.cpp podbot/dll.cpp
--- podbot-orig/dll.cpp    2007-03-24 21:38:44.000000000 +0100
+++ podbot/dll.cpp    2007-04-24 20:26:25.000000000 +0200
@@ -41,6 +41,7 @@
    {const_cast<char *>(g_rgpszPbCvars[PBCVAR_AIM_TARGET_ANTICIPATION_RATIO]), "2.2", FCVAR_SERVER | FCVAR_EXTDLL},  // KWo - 04.03.2006
    {const_cast<char *>(g_rgpszPbCvars[PBCVAR_AIM_TYPE]),                "4",    FCVAR_SERVER | FCVAR_EXTDLL},
    {const_cast<char *>(g_rgpszPbCvars[PBCVAR_AUTOKILL]),                "0.0",  FCVAR_SERVER | FCVAR_EXTDLL},      // KWo - 02.05.2006
+  {const_cast<char *>(g_rgpszPbCvars[PBCVAR_AUTOREMOVE]),              "0.0",  FCVAR_SERVER | FCVAR_EXTDLL},
    {const_cast<char *>(g_rgpszPbCvars[PBCVAR_AUTOKILLDELAY]),            "45.0",  FCVAR_SERVER | FCVAR_EXTDLL},    // KWo - 02.05.2006
    {const_cast<char *>(g_rgpszPbCvars[PBCVAR_BOTJOINTEAM]),              "ANY",  FCVAR_SERVER | FCVAR_EXTDLL},      // KWo - 16.09.2006
    {const_cast<char *>(g_rgpszPbCvars[PBCVAR_BOTQUOTAMATCH]),            "0.0",  FCVAR_SERVER | FCVAR_EXTDLL},      // KWo - 16.09.2006
@@ -1761,6 +1762,9 @@
    bool bAliveHumans; // KWo - 02.05.2006
 
    g_bPathWasCalculated = FALSE; // KWo 24.03.2007

+  char kickcmd[80];
+  int iSkill, iPersonality, iTeam, iClass;
 
    max_bots = g_i_cv_MaxBots;    // KWo - 06.04.2006
    min_bots = g_i_cv_MinBots;    // KWo - 06.04.2006
@@ -2095,6 +2099,95 @@
          UTIL_ServerPrint (g_szWaypointMessage);
      }
    }

+  if (g_b_cv_autoremove && (g_bHumansPrevious) && num_humans <= 0)
+  {
+      g_bHumansPrevious = false;
+     
+      UTIL_HostPrint ("No more human players, removing bots\n");
+     
+      // taken from lines 2644-2667 (removebots) :
+     
+      // removebots is against BotsQuotaMatch - needs make it zero;
+      if (g_i_cv_BotsQuotaMatch > 0) // 16.09.2006
+      {
+        CVAR_SET_STRING (g_rgpszPbCvars[PBCVAR_BOTQUOTAMATCH], "0");
+        g_i_cv_BotsQuotaMatch = 0;
+      }
+
+      g_iPeoBotsKept = ((g_i_cv_MinBots == 0) && !g_bIsDedicatedServer)? 1 : g_i_cv_MinBots;
+
+      for (bot_index = 0; bot_index < gpGlobals->maxClients; bot_index++)
+      {
+        // Reset our Creation Tab if there are still Bots waiting to be spawned
+        memset (&BotCreateTab[bot_index], 0, sizeof (createbot_t));
+        botcreation_time = 0.0;
+
+        // is this slot used?
+        if (bots[bot_index].is_used && !FNullEnt (bots[bot_index].pEdict))
+        {
+            snprintf (kickcmd, sizeof (kickcmd), "kick \"%s\"\n", STRING (bots[bot_index].pEdict->v.netname));
+            SERVER_COMMAND (kickcmd); // kick the bot using (kick "name")
+            bots[bot_index].is_used = FALSE; // KWo - 11.02.2006
+        }
+      }
+  }

+  if (g_b_cv_autoremove && (!g_bHumansPrevious) && num_humans > 0)
+  {
+      g_bHumansPrevious = true;
+     
+      UTIL_HostPrint ("A human is playing, filling server with bots\n");
+     
+      // taken from lines 2540-2585 (fillserver) :
+     
+      // fillserver is against BotsQuotaMatch - needs make it zero;
+      if (g_i_cv_BotsQuotaMatch > 0) // 16.09.2006
+      {
+        CVAR_SET_STRING (g_rgpszPbCvars[PBCVAR_BOTQUOTAMATCH], "0");
+        g_i_cv_BotsQuotaMatch = 0;
+      }
+      if ((arg1 != NULL) && (*arg1 != 0))
+        iSkill = atoi (arg1);
+      else
+        iSkill = 101;
+
+      if ((arg2 != NULL) && (*arg2 != 0))
+        iPersonality = atoi (arg2) - 1;
+      else
+        iPersonality = 5;
+
+      if ((arg3 != NULL) && (*arg3 != 0))
+      {
+        iTeam = atoi (arg3);
+        CVAR_SET_STRING ("mp_limitteams", "0");
+        CVAR_SET_STRING ("mp_autoteambalance", "0");
+      }
+      else
+        iTeam = 5;
+
+      if ((arg4 != NULL) && (*arg4 != 0))
+        iClass = atoi (arg4);
+      else
+        iClass = 5;
+
+      for (bot_index = 0; bot_index < gpGlobals->maxClients; bot_index++)
+      {
+        if (!BotCreateTab[bot_index].bNeedsCreation)
+        {
+            memset (&BotCreateTab[bot_index], 0, sizeof (createbot_t));
+            BotCreateTab[bot_index].bot_skill = iSkill;
+            BotCreateTab[bot_index].bot_personality = iPersonality;
+            BotCreateTab[bot_index].bot_team = iTeam;
+            BotCreateTab[bot_index].bot_class = iClass;
+            BotCreateTab[bot_index].bNeedsCreation = TRUE;
+        }
+      }
+      g_iPeoBotsKept = (max_bots == 0) ? gpGlobals->maxClients : max_bots;
+
+      if (botcreation_time == 0.0)
+        botcreation_time = gpGlobals->time;
+  }
 
 // autokill function here - KWo 02.05.2006
 
diff -r -u podbot-orig/util.cpp podbot/util.cpp
--- podbot-orig/util.cpp    2007-03-25 21:07:36.000000000 +0200
+++ podbot/util.cpp    2007-04-24 19:48:10.000000000 +0200
@@ -886,6 +886,18 @@
      if (CVAR_GET_FLOAT(g_rgpszPbCvars[PBCVAR_AUTOKILL]) > 0.f)
          g_b_cv_autokill = true;
    }

+  g_b_cv_autoremove = false;
+  if (g_rgcvarPointer[PBCVAR_AUTOREMOVE])  // KWo - 13.10.2006
+  {
+      if (g_rgcvarPointer[PBCVAR_AUTOREMOVE]->value > 0.f)
+        g_b_cv_autoremove = true;
+  }
+  else
+  {
+      if (CVAR_GET_FLOAT(g_rgpszPbCvars[PBCVAR_AUTOREMOVE]) > 0.f)
+        g_b_cv_autoremove = true;
+  }
 
    if (g_rgcvarPointer[PBCVAR_AUTOKILLDELAY])  // KWo - 13.10.2006
      g_f_cv_autokilldelay = g_rgcvarPointer[PBCVAR_AUTOKILLDELAY]->value;

To use the new feature : pb_autoremove 1. It has been designed not to interfere too much with manually adding/removing the bots. Basically, it works by doing "removebots" when there is no more human players on the server, and by doing "fillserver" when there is human players on the server.
Hope it'll be useful to someone :P

Ancient 25-04-2007 03:20

Re: Remove all bots when there is no human player on the server
 
I don't understand how this feature will help?

The bots are to attract players in the first place....
Unless you have a private server then I could understand.

e-t172 25-04-2007 15:23

Re: Remove all bots when there is no human player on the server
 
Quote:

Originally Posted by Ancient (Post 54879)
I don't understand how this feature will help?

The bots are to attract players in the first place....
Unless you have a private server then I could understand.

It's for a very small LAN (4 PCs). 4 players is not very exciting, so we play with bots. But when there is no human playing, the bots are completly useless. Therefore I did this patch.

KWo 25-04-2007 17:07

Re: Remove all bots when there is no human player on the server
 
Maybe it was just sufficient to setup podbots so:
pb_minbots 0
pb_maxbots 10
pb_bot_quota_match 1

No humans on the server - no bots is there. One human enters - one bot joins. Next human enters - one bot more joins and it works so until reaching Your pb_maxbots value. If one human disconnects - one bot gets kicked (unless there is more than pb_maxbots humans).

Maybe Your patch wasn't needed at all (but this above might not work with Your code now - try it with original V3B18c).


All times are GMT +2. The time now is 23:16.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.