.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   General Bot Coding (http://forums.bots-united.com/forumdisplay.php?f=24)
-   -   Bot respawn delay problem (http://forums.bots-united.com/showthread.php?t=1646)

Tea 11-05-2004 23:39

Bot respawn delay problem
 
Hi all, my bot is base on HPB_Bot, when the first map start, everything have no problem, bot will wait for 60 seconds before first spawn and the rest will wait for 2 seconds between each spawn.

But after the map change, they won't wait for 60 seconds before the first spawn anymore and they also won't wait 2 seconds between each spawn but they will spawn immediately. I didn't done something wrong at the dll.cpp since even the HPB_Bot 4.03 have the same problem and almost all the other bots have the same problem, it seem only check the bot_check_time = gpGlobals->time + 60.0; which under BOOL ClientConnect one time but not check it again after map change, but I think this is not the only problem since bot_cfg_pause_time = gpGlobals->time + 2.0; which not under BOOL ClientConnect.

Could someone give me some suggestion please ? thank you very much.

Pierre-Marie Baty 12-05-2004 03:32

Re: Bot respawn delay problem
 
If you want your bots to wait 60 seconds before joining each time a new map start, then this
bot_check_time = gpGlobals->time + 60.0
should rather be put in ServerActivate(), because ServerActivate() is the first function called when a new map is about to start.

There are several ways in the code that lead to a bot being added. Do a search for each BotCreate() call, and check which one is called on the first map and which ones are called for the following ones. The difference among the checks that lead to BotCreate() will tell you all that you want to know.

Tea 12-05-2004 14:41

Re: Bot respawn delay problem
 
Thank for the quick reply Pierre, but I did not found any ServerActivate(), do you mean the StartFrame () ? If yes here is the code :
Quote:


void StartFrame( void )
{
if (gpGlobals->deathmatch)
{
edict_t *pPlayer;
static int i, index, player_index, bot_index;
static float previous_time = -1.0;
char msg[256];
int count;

// if a new map has started then (MUST BE FIRST IN StartFrame)...
if ((gpGlobals->time + 0.1) < previous_time)
{
char filename[256];
char mapname[64];

// check if mapname_bot.cfg file exists...

strcpy(mapname, STRING(gpGlobals->mapname));
strcat(mapname, "_HPB_bot.cfg");

UTIL_BuildFileName(filename, "maps", mapname);

if ((bot_cfg_fp = fopen(filename, "r")) != NULL)
{
sprintf(msg, "Executing %s\n", filename);
ALERT( at_console, msg );

for (index = 0; index < 32; index++)
{
bots[index].is_used = FALSE;
bots[index].respawn_state = 0;
bots[index].f_kick_time = 0.0;
}

if (IsDedicatedServer)
bot_cfg_pause_time = gpGlobals->time + 5.0;
else
bot_cfg_pause_time = gpGlobals->time + 20.0;

}
else
{
count = 0;

// mark the bots as needing to be respawned...
for (index = 0; index < 32; index++)
{
if (count >= prev_num_bots)
{
bots[index].is_used = FALSE;
bots[index].respawn_state = 0;
bots[index].f_kick_time = 0.0;
}

if (bots[index].is_used) // is this slot used?
{
bots[index].respawn_state = RESPAWN_NEED_TO_RESPAWN;
count++;
}

// check for any bots that were very recently kicked...
if ((bots[index].f_kick_time + 5.0) > previous_time)
{
bots[index].respawn_state = RESPAWN_NEED_TO_RESPAWN;
count++;
}
else
bots[index].f_kick_time = 0.0; // reset to prevent false spawns later
}

// set the respawn time
if (IsDedicatedServer)
respawn_time = gpGlobals->time + 5.0;
else
respawn_time = gpGlobals->time + 20.0;
}

bot_check_time = gpGlobals->time + 60.0;
}


It did run this StartFrame when start a new map but not anymore for the next map, Pierre could you have a quick look to see what problem of this code ?

PS: this code is from HPB_Bot 4.0 and I didn't change it at all, thank.

Cheeseh 14-05-2004 19:30

Re: Bot respawn delay problem
 
the ServerActivate function is in the dll.cpp file in HPB bot template, check it out :p

Pierre-Marie Baty 14-05-2004 19:46

Re: Bot respawn delay problem
 
If ServerActivate() isn't featured in the dll.cpp file of the HPB_bot 4.0 (which is a metamod plugin), that's because ServerActivate() isn't hooked yet by the HPB_bot in the list of the game DLL functions. Just add a hook for it like it is done for StartFrame, ClientConnect, etc.

Tea 14-05-2004 22:37

Re: Bot respawn delay problem
 
I have added the following lines in dll.cpp and mark out the welcome message in StartFrame()

Code:


void ServerActivate( edict_t *pEdictList, int edictCount, int clientMax )
{
 
        if (!IsDedicatedServer)
        {
                if ((listenserver_edict != NULL) && (welcome_sent == FALSE) &&
                        (welcome_time < 1.0))
                {
                        // are they out of observer mode yet?
                        if (IsAlive(listenserver_edict))
                        welcome_time = gpGlobals->time + 5.0; // welcome in 5 seconds
                }
                if ((welcome_time > 0.0) && (welcome_time < gpGlobals->time))
                {
                        char version[80];
                        sprintf(version,"%s Version %d.%d\n", welcome_msg, VER_MAJOR, VER_MINOR);
                        // let's send a welcome message to this client...
                        UTIL_SayText(version, listenserver_edict);
                }
        }
 
        RETURN_META (MRES_IGNORED);
}

And this inside C_DLLEXPORT int GetEntityAPI2

Code:

gFunctionTable.pfnServerActivate = ServerActivate;
I am sure it never call the ServerActive() since I never saw the welcome message, am I miss something to add in dll.cpp ?

BTW if the ServerActive() really can't work than doesn't matter, because I knew the StartFrame() did call on every map change when I use welcome message to test it.

I have found out the reason why bots not delay when respawn because the bots never disconnect when map changed, I have tried not to use max_bot function but only type addbot in console to add 2 bots, but when the map changed, that 2 bots join the game again automatic, I think when the map changed, that 2 bots only respawn but not rejoin, that's why the bot_check_time not work for them again.

Hmm, any idea ?

Pierre-Marie Baty 15-05-2004 19:19

Re: Bot respawn delay problem
 
hmm no, some explanation is needed here. Unless StartFrame() which is continuously called for each video frame, ServerActivate() is only called ONCE, when the server is about to start - and when no client has joined yet. That's why you can't see the welcome message (since you aren't connected to the server yet when ServerActivate() executes).

The bots are automatically disconnected by the server on map change (since a map change is in fact a server shutdown and a server restart). There's nothing the bot code can do against it. What botman did, however, is that he added some code to make the bots that WERE on the server during the last map be automatically re-added in the new one. Hence it's not a bug but a feature. If you want to change this, comment out this code and make the bot re-read the configuration file (with the "addbot" commands in it) that makes the bots be added the first time, at each map change and not at the first start of the game ; i.e, to do this, put this code in ServerActivate().

Tea 16-05-2004 17:40

Re: Bot respawn delay problem
 
Thank for the information, I'll take a look of it. :)


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

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