From 584277d760d1b89fb49442df50e5e468129a0e82 Mon Sep 17 00:00:00 2001 From: ineed bots Date: Wed, 13 Dec 2023 12:51:12 -0600 Subject: [PATCH] better bot kicking logic --- maps/mp/bots/_bot_utility.gsc | 80 +++++++++++++++++++ maps/mp/gametypes/_bot.gsc | 2 +- ...{bots_adapter.gsc => bots_adapter_pt5.gsc} | 0 3 files changed, 81 insertions(+), 1 deletion(-) rename scripts/{bots_adapter.gsc => bots_adapter_pt5.gsc} (100%) diff --git a/maps/mp/bots/_bot_utility.gsc b/maps/mp/bots/_bot_utility.gsc index a83a275..d333c5a 100644 --- a/maps/mp/bots/_bot_utility.gsc +++ b/maps/mp/bots/_bot_utility.gsc @@ -398,6 +398,86 @@ _timeout( delay ) self notify( "returned", "timeout" ); } +/* + Returns a bot to be kicked +*/ +getBotToKick() +{ + bots = getBotArray(); + + if ( !isDefined( bots ) || !isDefined( bots.size ) || bots.size <= 0 || !isDefined( bots[0] ) ) + return undefined; + + tokick = undefined; + axis = 0; + allies = 0; + team = getDvar( "bots_team" ); + + // count teams + for ( i = 0; i < bots.size; i++ ) + { + bot = bots[i]; + + if ( !isDefined( bot ) || !isDefined( bot.team ) ) + continue; + + if ( bot.team == "allies" ) + allies++; + else if ( bot.team == "axis" ) + axis++; + else // choose bots that are not on a team first + return bot; + } + + // search for a bot on the other team + if ( team == "custom" || team == "axis" ) + { + team = "allies"; + } + else if ( team == "autoassign" ) + { + // get the team with the most bots + team = "allies"; + + if ( axis > allies ) + team = "axis"; + } + else + { + team = "axis"; + } + + // get the bot on this team with lowest skill + for ( i = 0; i < bots.size; i++ ) + { + bot = bots[i]; + + if ( !isDefined( bot ) || !isDefined( bot.team ) ) + continue; + + if ( bot.team != team ) + continue; + + tokick = bot; + } + + if ( isDefined( tokick ) ) + return tokick; + + // just kick lowest skill + for ( i = 0; i < bots.size; i++ ) + { + bot = bots[i]; + + if ( !isDefined( bot ) || !isDefined( bot.team ) ) + continue; + + tokick = bot; + } + + return tokick; +} + /* Waits for a host player */ diff --git a/maps/mp/gametypes/_bot.gsc b/maps/mp/gametypes/_bot.gsc index eba6e31..13d89d3 100644 --- a/maps/mp/gametypes/_bot.gsc +++ b/maps/mp/gametypes/_bot.gsc @@ -709,7 +709,7 @@ addBots_loop() setDvar( "bots_manage_add", 1 ); else if ( amount > fillAmount && getDvarInt( "bots_manage_fill_kick" ) ) { - tempBot = PickRandom( getBotArray() ); + tempBot = getBotToKick(); if ( isDefined( tempBot ) ) kick( tempBot getEntityNumber(), "EXE_PLAYERKICKED" ); diff --git a/scripts/bots_adapter.gsc b/scripts/bots_adapter_pt5.gsc similarity index 100% rename from scripts/bots_adapter.gsc rename to scripts/bots_adapter_pt5.gsc