Added kill_stuck_bots

This commit is contained in:
Resxt 2022-03-16 19:48:00 +01:00
parent 62a2c67088
commit 627ce1adb6
2 changed files with 61 additions and 0 deletions

View File

@ -20,3 +20,10 @@ Display the player's killstreak, total kills and deaths on top of the screen
![image](images/display_player_stats.png)
</details>
## kill_stuck_bots.gsc
This is a temporary solution to inactive bots or bots stuck in corners on custom maps.
This checks for bots kills and deaths every 30 seconds. If they didn't do any kill or didn't die in 30 seconds they're considered inactive/stuck and they're killed.
Obviously a better way to do this would be checking for their positions or removing bad spawns on the map or creating waypoints for the map.
This is just a quick temporary solution that works for me.

View File

@ -0,0 +1,54 @@
Init()
{
level thread OnPlayerConnect();
}
OnPlayerConnect()
{
for(;;)
{
level waittill("connected", player);
player thread OnPlayerSpawned();
}
}
OnPlayerSpawned()
{
self endon("disconnect");
for(;;)
{
self waittill("spawned_player");
if (isDefined(self.pers["isBot"]))
{
if (self.pers["isBot"])
{
self thread KillStuckBots();
}
}
}
}
KillStuckBots()
{
self endon ("disconnect");
level endon("game_ended");
kills_before = self.pers["cur_kill_streak"];
deaths_before = self.pers["deaths"];
wait 30;
kills_now = self.pers["cur_kill_streak"];
deaths_now = self.pers["deaths"];
if (kills_now == kills_before && deaths_before == deaths_now)
{
self Suicide();
}
}
// Prints text in the bootstrapper
Debug(text)
{
Print(text);
}