checked the 3 main bot scripts

Checked _bot again since there was an oversight when converting a foreach to a while loop. _bot_combat and _bot_loadout are checked but not tested.
This commit is contained in:
JezuzLizard 2020-04-30 11:15:36 -07:00
parent 09e3ff45ed
commit 419e026387
3 changed files with 521 additions and 652 deletions

View File

@ -250,12 +250,12 @@ bot_count_enemy_bots( friend_team ) //checked partially changed to match cerberu
i = 0; i = 0;
while ( i < level.teams.size ) while ( i < level.teams.size )
{ {
if ( team == friend_team ) if ( level.teams[ i ] == friend_team )
{ {
i++; i++;
continue; continue;
} }
enemies += bot_count_bots( team ); enemies += bot_count_bots( level.teams[ i ] );
i++; i++;
} }
return enemies; return enemies;
@ -595,7 +595,7 @@ bot_choose_class() //checked partially changed to match cerberus output did not
sidearm = self getloadoutweapon( i, "secondary" ); sidearm = self getloadoutweapon( i, "secondary" );
if ( sidearm == "fhj18_mp" ) if ( sidearm == "fhj18_mp" )
{ {
self notify( "menuresponse", "changeclass", bot_classes[i] ); self notify( "menuresponse", "changeclass", bot_classes[ i ] );
i++; i++;
continue; continue;
} }
@ -997,14 +997,14 @@ bot_update_failsafe() //checked partially changed to match cerberus output //did
{ {
while ( i < nodes.size ) while ( i < nodes.size )
{ {
if ( !bot_failsafe_node_valid( nearest, node ) ) if ( !bot_failsafe_node_valid( nearest, nodes[ i ] ) )
{ {
i++; i++;
continue; continue;
} }
else else
{ {
self botsetfailsafenode( node ); self botsetfailsafenode( nodes[ i ] );
wait 0.5; wait 0.5;
self.bot.update_idle_lookat = 0; self.bot.update_idle_lookat = 0;
self bot_update_lookat(); self bot_update_lookat();
@ -1767,7 +1767,7 @@ bot_update_weapon()
} }
if ( ( self getweaponammoclip( primaries[ i ] ) || self getweaponammostock( primaries[ i ] ) ) && primaries[ i ] != weapon ) if ( ( self getweaponammoclip( primaries[ i ] ) || self getweaponammostock( primaries[ i ] ) ) && primaries[ i ] != weapon )
{ {
self switchtoweapon( primary ); self switchtoweapon( primaries[ i ] );
return; return;
} }
} }
@ -1796,7 +1796,7 @@ bot_update_crate() //checked partially changed to match cerberus output continue
i++; i++;
continue; continue;
} }
if ( crate.hacker.team == self.team ) if ( crates[ i ].hacker.team == self.team )
{ {
i++; i++;
continue; continue;
@ -2580,3 +2580,4 @@ devgui_bot_spawn_think( origin, yaw ) //didn't check dev call
*/ */
} }

File diff suppressed because it is too large Load Diff

View File

@ -3,7 +3,7 @@
#include maps/mp/_utility; #include maps/mp/_utility;
#include common_scripts/utility; #include common_scripts/utility;
init() init() //checked changed to match cerberus output
{ {
level endon( "game_ended" ); level endon( "game_ended" );
level.bot_banned_killstreaks = array( "KILLSTREAK_RCBOMB", "KILLSTREAK_QRDRONE", "KILLSTREAK_REMOTE_MISSILE", "KILLSTREAK_REMOTE_MORTAR", "KILLSTREAK_HELICOPTER_GUNNER" ); level.bot_banned_killstreaks = array( "KILLSTREAK_RCBOMB", "KILLSTREAK_QRDRONE", "KILLSTREAK_REMOTE_MISSILE", "KILLSTREAK_REMOTE_MORTAR", "KILLSTREAK_HELICOPTER_GUNNER" );
@ -14,24 +14,21 @@ init()
{ {
continue; continue;
} }
else
{
player thread on_bot_connect(); player thread on_bot_connect();
} }
}
} }
on_bot_connect() on_bot_connect() //checked changed to match cerberus output
{ {
self endon( "disconnect" ); self endon( "disconnect" );
if ( isDefined( self.pers[ "bot_loadout" ] ) ) if ( isDefined( self.pers[ "bot_loadout" ] ) )
{ {
return; return;
} }
wait 0,1; wait 0.1;
if ( ( self getentitynumber() % 2 ) == 0 ) if ( ( self getentitynumber() % 2 ) == 0 )
{ {
wait 0,05; wait 0.05;
} }
self maps/mp/bots/_bot::bot_set_rank(); self maps/mp/bots/_bot::bot_set_rank();
if ( level.onlinegame && !sessionmodeisprivate() ) if ( level.onlinegame && !sessionmodeisprivate() )
@ -51,21 +48,18 @@ on_bot_connect()
self botsetdefaultclass( 9, "class_sniper" ); self botsetdefaultclass( 9, "class_sniper" );
} }
max_allocation = 10; max_allocation = 10;
i = 1; for ( i = 1; i <= 3; i++ )
while ( i <= 3 )
{ {
if ( self isitemlocked( maps/mp/gametypes/_rank::getitemindex( "feature_allocation_slot_" + i ) ) ) if ( self isitemlocked( maps/mp/gametypes/_rank::getitemindex( "feature_allocation_slot_" + i ) ) )
{ {
max_allocation--; max_allocation--;
} }
i++;
} }
self bot_construct_loadout( max_allocation ); self bot_construct_loadout( max_allocation );
self.pers[ "bot_loadout" ] = 1; self.pers[ "bot_loadout" ] = 1;
} }
bot_construct_loadout( allocation_max ) bot_construct_loadout( allocation_max ) //checked matches cerberus output
{ {
if ( self isitemlocked( maps/mp/gametypes/_rank::getitemindex( "feature_cac" ) ) ) if ( self isitemlocked( maps/mp/gametypes/_rank::getitemindex( "feature_cac" ) ) )
{ {
@ -97,7 +91,7 @@ bot_construct_loadout( allocation_max )
pixendevent(); pixendevent();
} }
bot_construct_class( class, items, allocation_max ) bot_construct_class( class, items, allocation_max ) //checked partially changed to match cerberus output did not change while loop to for loop see github for more info
{ {
allocation = 0; allocation = 0;
claimed_count = bot_build_claimed_list( items ); claimed_count = bot_build_claimed_list( items );
@ -115,13 +109,10 @@ bot_construct_class( class, items, allocation_max )
bot_choose_weapon_option( class, "reticle", 0 ); bot_choose_weapon_option( class, "reticle", 0 );
allocation += bot_choose_primary_attachments( class, weapon, allocation, allocation_max ); allocation += bot_choose_primary_attachments( class, weapon, allocation, allocation_max );
} }
else else if ( !claimed_count[ "primary" ] )
{
if ( !claimed_count[ "primary" ] )
{ {
secondary_chance = 100; secondary_chance = 100;
} }
}
remaining = allocation_max - allocation; remaining = allocation_max - allocation;
if ( remaining >= 1 && bot_make_choice( secondary_chance, claimed_count[ "secondary" ], 1 ) ) if ( remaining >= 1 && bot_make_choice( secondary_chance, claimed_count[ "secondary" ], 1 ) )
{ {
@ -130,7 +121,6 @@ bot_construct_class( class, items, allocation_max )
self botclassadditem( class, "BONUSCARD_OVERKILL" ); self botclassadditem( class, "BONUSCARD_OVERKILL" );
weapon = bot_choose_weapon( class, items[ "primary" ] ); weapon = bot_choose_weapon( class, items[ "primary" ] );
allocation++; allocation++;
allocation++;
continue; continue;
} }
else else
@ -220,11 +210,8 @@ bot_construct_class( class, items, allocation_max )
i++; i++;
continue; continue;
} }
else
{
} }
} i++;
else i++;
} }
} }
else if ( next_action == "lethal" ) else if ( next_action == "lethal" )
@ -241,17 +228,13 @@ bot_construct_class( class, items, allocation_max )
self botclassadditem( class, "BONUSCARD_DANGER_CLOSE" ); self botclassadditem( class, "BONUSCARD_DANGER_CLOSE" );
allocation++; allocation++;
} }
else else if ( remaining >= 1 && !claimed_count[ "primarygrenade" ] )
{
if ( remaining >= 1 && !claimed_count[ "primarygrenade" ] )
{ {
bot_choose_weapon( class, items[ "primarygrenade" ] ); bot_choose_weapon( class, items[ "primarygrenade" ] );
claimed_count[ "primarygrenade" ]++; claimed_count[ "primarygrenade" ]++;
allocation++; allocation++;
} }
} }
continue;
}
else if ( next_action == "tactical" ) else if ( next_action == "tactical" )
{ {
remaining = allocation_max - allocation; remaining = allocation_max - allocation;
@ -269,7 +252,6 @@ bot_construct_class( class, items, allocation_max )
claimed_count[ "specialgrenade" ] = 2; claimed_count[ "specialgrenade" ] = 2;
allocation += 2; allocation += 2;
} }
break;
} }
else else
{ {
@ -284,97 +266,80 @@ bot_construct_class( class, items, allocation_max )
} }
} }
bot_make_choice( chance, claimed, max_claim ) bot_make_choice( chance, claimed, max_claim ) //checked changed at own discretion
{ {
if ( claimed < max_claim ) if ( claimed < max_claim && randomint( 100 ) < chance )
{ {
return randomint( 100 ) < chance; return 1;
} }
return 0;
} }
bot_chose_action( action1, chance1, action2, chance2, action3, chance3, action4, chance4 ) bot_chose_action( action1, chance1, action2, chance2, action3, chance3, action4, chance4 ) //checked changed to match cerberus output
{ {
chance1 = int( chance1 / 10 ); chance1 = int( chance1 / 10 );
chance2 = int( chance2 / 10 ); chance2 = int( chance2 / 10 );
chance3 = int( chance3 / 10 ); chance3 = int( chance3 / 10 );
chance4 = int( chance4 / 10 ); chance4 = int( chance4 / 10 );
actions = []; actions = [];
i = 0; for ( i = 0; i < chance1; i++ )
while ( i < chance1 )
{ {
actions[ actions.size ] = action1; actions[ actions.size ] = action1;
i++;
} }
i = 0; for ( i = 0; i < chance2; i++ )
while ( i < chance2 )
{ {
actions[ actions.size ] = action2; actions[ actions.size ] = action2;
i++;
} }
i = 0; for ( i = 0; i < chance3; i++ )
while ( i < chance3 )
{ {
actions[ actions.size ] = action3; actions[ actions.size ] = action3;
i++;
} }
i = 0; for ( i = 0; i < chance4; i++ )
while ( i < chance4 )
{ {
actions[ actions.size ] = action4; actions[ actions.size ] = action4;
i++;
} }
return random( actions ); return random( actions );
} }
bot_item_is_claimed( item ) bot_item_is_claimed( item ) //checked changed to match cerberus output
{ {
_a370 = self.claimed_items; foreach ( claim in self.claimed_items )
_k370 = getFirstArrayKey( _a370 );
while ( isDefined( _k370 ) )
{ {
claim = _a370[ _k370 ];
if ( claim == item ) if ( claim == item )
{ {
return 1; return 1;
} }
_k370 = getNextArrayKey( _a370, _k370 );
} }
return 0; return 0;
} }
bot_choose_weapon( class, items ) bot_choose_weapon( class, items ) //checked changed to match cerberus output
{ {
if ( !isDefined( items ) || !items.size ) if ( !isDefined( items ) || !items.size )
{ {
return undefined; return undefined;
} }
start = randomint( items.size ); start = randomint( items.size );
i = 0; for ( i = 0; i < items.size; i++ )
while ( i < items.size )
{ {
weapon = items[ start ]; weapon = items[ start ];
if ( !bot_item_is_claimed( weapon ) ) if ( !bot_item_is_claimed( weapon ) )
{ {
break; break;
} }
else
{
start = ( start + 1 ) % items.size; start = ( start + 1 ) % items.size;
i++;
}
} }
self.claimed_items[ self.claimed_items.size ] = weapon; self.claimed_items[ self.claimed_items.size ] = weapon;
self botclassadditem( class, weapon ); self botclassadditem( class, weapon );
return weapon; return weapon;
} }
bot_build_weapon_options_list( optiontype ) bot_build_weapon_options_list( optiontype ) //checked changed to match cerberus output
{ {
level.botweaponoptionsid[ optiontype ] = []; level.botweaponoptionsid[ optiontype ] = [];
level.botweaponoptionsprob[ optiontype ] = []; level.botweaponoptionsprob[ optiontype ] = [];
prob = 0; prob = 0;
row = 0; for ( row = 0; row < 255; row++ )
while ( row < 255 )
{ {
if ( tablelookupcolumnforrow( "mp/attachmentTable.csv", row, 1 ) == optiontype ) if ( tablelookupcolumnforrow( "mp/attachmentTable.csv", row, 1 ) == optiontype )
{ {
@ -383,11 +348,10 @@ bot_build_weapon_options_list( optiontype )
prob += int( tablelookupcolumnforrow( "mp/attachmentTable.csv", row, 15 ) ); prob += int( tablelookupcolumnforrow( "mp/attachmentTable.csv", row, 15 ) );
level.botweaponoptionsprob[ optiontype ][ index ] = prob; level.botweaponoptionsprob[ optiontype ][ index ] = prob;
} }
row++;
} }
} }
bot_choose_weapon_option( class, optiontype, primary ) bot_choose_weapon_option( class, optiontype, primary ) //checked changed to match cerberus output may need to review order of operations
{ {
if ( !isDefined( level.botweaponoptionsid ) ) if ( !isDefined( level.botweaponoptionsid ) )
{ {
@ -407,22 +371,17 @@ bot_choose_weapon_option( class, optiontype, primary )
maxprob += ( 4 * maxprob ) * ( ( 20 - self.pers[ "rank" ] ) / 20 ); maxprob += ( 4 * maxprob ) * ( ( 20 - self.pers[ "rank" ] ) / 20 );
} }
rnd = randomint( int( maxprob ) ); rnd = randomint( int( maxprob ) );
i = 0; for ( i = 0; i < numoptions; i++ )
while ( i < numoptions )
{ {
if ( level.botweaponoptionsprob[ optiontype ][ i ] > rnd ) if ( level.botweaponoptionsprob[ optiontype ][ i ] > rnd )
{ {
self botclasssetweaponoption( class, primary, optiontype, level.botweaponoptionsid[ optiontype ][ i ] ); self botclasssetweaponoption( class, primary, optiontype, level.botweaponoptionsid[ optiontype ][ i ] );
return; return;
} }
else
{
i++;
}
} }
} }
bot_choose_primary_attachments( class, weapon, allocation, allocation_max ) bot_choose_primary_attachments( class, weapon, allocation, allocation_max ) //checked changed to match cerberus output
{ {
attachments = getweaponattachments( weapon ); attachments = getweaponattachments( weapon );
remaining = allocation_max - allocation; remaining = allocation_max - allocation;
@ -453,9 +412,7 @@ bot_choose_primary_attachments( class, weapon, allocation, allocation_max )
} }
return count; return count;
} }
else else if ( remaining >= 2 && attachment_action == "2_attachments" )
{
if ( remaining >= 2 && attachment_action == "2_attachments" )
{ {
a1 = random( attachments ); a1 = random( attachments );
self botclassaddattachment( class, weapon, a1, "primaryattachment1" ); self botclassaddattachment( class, weapon, a1, "primaryattachment1" );
@ -468,20 +425,16 @@ bot_choose_primary_attachments( class, weapon, allocation, allocation_max )
} }
return 1; return 1;
} }
else else if ( remaining >= 1 && attachment_action == "1_attachments" )
{
if ( remaining >= 1 && attachment_action == "1_attachments" )
{ {
a = random( attachments ); a = random( attachments );
self botclassaddattachment( class, weapon, a, "primaryattachment1" ); self botclassaddattachment( class, weapon, a, "primaryattachment1" );
return 1; return 1;
} }
}
}
return 0; return 0;
} }
bot_choose_secondary_attachments( class, weapon, allocation, allocation_max ) bot_choose_secondary_attachments( class, weapon, allocation, allocation_max ) //checked changed to match cerberus output
{ {
attachments = getweaponattachments( weapon ); attachments = getweaponattachments( weapon );
remaining = allocation_max - allocation; remaining = allocation_max - allocation;
@ -504,19 +457,16 @@ bot_choose_secondary_attachments( class, weapon, allocation, allocation_max )
} }
return 1; return 1;
} }
else else if ( remaining >= 1 && attachment_action == "1_attachments" )
{
if ( remaining >= 1 && attachment_action == "1_attachments" )
{ {
a = random( attachments ); a = random( attachments );
self botclassaddattachment( class, weapon, a, "secondaryattachment1" ); self botclassaddattachment( class, weapon, a, "secondaryattachment1" );
return 1; return 1;
} }
}
return 0; return 0;
} }
bot_build_item_list() bot_build_item_list() //checked partially changed to match cerberus output did not change while loop to for loop see github for more info
{ {
pixbeginevent( "bot_build_item_list" ); pixbeginevent( "bot_build_item_list" );
items = []; items = [];
@ -532,46 +482,43 @@ bot_build_item_list()
i++; i++;
continue; continue;
} }
else number = int( tablelookupcolumnforrow( level.statstableid, row, 0 ) ); number = int( tablelookupcolumnforrow( level.statstableid, row, 0 ) );
if ( self isitemlocked( number ) ) if ( self isitemlocked( number ) )
{ {
i++; i++;
continue; continue;
} }
else allocation = int( tablelookupcolumnforrow( level.statstableid, row, 12 ) ); allocation = int( tablelookupcolumnforrow( level.statstableid, row, 12 ) );
if ( allocation < 0 ) if ( allocation < 0 )
{ {
i++; i++;
continue; continue;
} }
else name = tablelookupcolumnforrow( level.statstableid, row, 3 ); name = tablelookupcolumnforrow( level.statstableid, row, 3 );
if ( bot_item_is_banned( slot, name ) ) if ( bot_item_is_banned( slot, name ) )
{ {
i++; i++;
continue; continue;
} }
else
{
if ( !isDefined( items[ slot ] ) ) if ( !isDefined( items[ slot ] ) )
{ {
items[ slot ] = []; items[ slot ] = [];
} }
items[ slot ][ items[ slot ].size ] = name; items[ slot ][ items[ slot ].size ] = name;
} }
}
i++; i++;
} }
pixendevent(); pixendevent();
return items; return items;
} }
bot_item_is_banned( slot, item ) bot_item_is_banned( slot, item ) //checked changed to match cerberus output
{ {
if ( item == "WEAPON_KNIFE_BALLISTIC" ) if ( item == "WEAPON_KNIFE_BALLISTIC" )
{ {
return 1; return 1;
} }
if ( getDvarInt( #"97A055DA" ) == 0 && item == "WEAPON_PEACEKEEPER" ) if ( /* getDvarInt( #"97A055DA" ) == 0 && */ item == "WEAPON_PEACEKEEPER" )
{ {
return 1; return 1;
} }
@ -579,31 +526,24 @@ bot_item_is_banned( slot, item )
{ {
return 0; return 0;
} }
_a633 = level.bot_banned_killstreaks; foreach ( banned in level.bot_banned_killstreaks )
_k633 = getFirstArrayKey( _a633 );
while ( isDefined( _k633 ) )
{ {
banned = _a633[ _k633 ];
if ( item == banned ) if ( item == banned )
{ {
return 1; return 1;
} }
_k633 = getNextArrayKey( _a633, _k633 );
} }
return 0; return 0;
} }
bot_build_claimed_list( items ) bot_build_claimed_list( items ) //checked changed to match cerberus output
{ {
claimed = []; claimed = [];
keys = getarraykeys( items ); keys = getarraykeys( items );
_a649 = keys; foreach ( key in keys )
_k649 = getFirstArrayKey( _a649 );
while ( isDefined( _k649 ) )
{ {
key = _a649[ _k649 ];
claimed[ key ] = 0; claimed[ key ] = 0;
_k649 = getNextArrayKey( _a649, _k649 );
} }
return claimed; return claimed;
} }