I'm getting some weird errors when kicking meatbots.
Basically, I created a monitor (code below) to add a bot if team size < 6, and remove a bot if team size > 6 && there is at least one bot in the team.
The problem is:
I join the server and a team, the bot is kicked;
The bot is still in the server, although the slot was freed (first image);
The bot still counts as being in the team I joined, so the server keeps trying to kick it constantly;
When I leave the server, this "ghost" bot rejoins the team (the server shows 11 players only, since its slot was freed);
When I reconnect, I use the slot of the kicked bot. The team score hud is duplicated (second image), and, as a spectator, I keep aiming at the other bots (which is what meatbot's check enemy function does, in an infinite loop);
At this moment, when I join the same team I joined earler, I get disconnected - it seems that I have self.isbot defined (the kicked bot had this it defined), so I count as a bot and the bot monitor tries to kick me to make room for myself, lol;
After I disconnect, the server keeps trying to kick whoever is in the slot I was using, so, in the console, it prints "Client 1 is not active" every time it goes through the monitor function.
PHP Code:
botMonitor()
{
self endon("intermission");
currentteam = "allies";
for(;;)
{
// start the monitor a while after map loading
timepassed = (getTime() - level.starttime) / 1000;
delayonstart = 20;
if
(
(timepassed > delayonstart) &&
(getCvar("mod_allow_bots") == "1")
)
{
// get bot count and player count for the current team
botsonteam = 0;
playersonteam = 0;
players = getentarray("player", "classname");
for(i = 0; i < players.size; i++)
{
if(players[i].pers["team"] == currentteam)
{
if
(
(isDefined(players[i].isbot)) ||
(players[i] getIP() == "0")
)
{
botsonteam++;
}
else
{
playersonteam++;
iprintln(players[i].name);
}
}
}
// add a bot to the current team if it is not complete
botmaxnumber = getCvarInt("mod_bots_" + currentteam);
if((playersonteam + botsonteam) < botmaxnumber)
{
reAddBot(currentteam);
}
else
{
// remove a bot from the current team if it has too many
if
(
(botsonteam > 0) &&
((playersonteam + botsonteam) > botmaxnumber)
)
{
iprintln("trying to kick a bot from " + currentteam);
level kickBotFromTeam(currentteam);
}
}
if(currentteam == "allies")
{
currentteam = "axis";
}
else
{
currentteam = "allies";
}
}
wait(0.5);
}
}
PHP Code:
kickBotFromTeam(team)
{
players = getentarray("player", "classname");
for(i = 0; i < players.size; i++)
{
if
(
(players[i].pers["team"] == team) &&
(
(isDefined(players[i].isbot)) ||
(players[i] getIP() == "0")
)
)
{
entnum = players[i] getentitynumber();
kick(entnum);
free_slot(entnum);
break;
}
}
}
Any ideas?