Compare commits

...
3 Commits
Author SHA1 Message Date
ineed bots 225950c693 complete iw2 bot warfare 2026-08-31 15:35:15 -06:00
ineed bots b0e3e1d384 sd finished, script finished!! 2026-08-31 12:31:15 -06:00
ineed bots b63b9544d1 ctf 2026-08-28 13:29:12 -06:00
7 changed files with 1004 additions and 516 deletions
+2 -3
View File
@@ -1,7 +1,6 @@
# IW2 Bot Warfare
Bot Warfare for CoD2, in progress...
Bot Warfare for CoD2.
TODO:
- _bot_script
- _bot_chat
- docs
+54 -501
View File
@@ -5,9 +5,7 @@
Does bot chatter.
*/
#include common_scripts\utility;
#include maps\mp\_utility;
#include maps\mp\gametypes\_hud_util;
#include maps\mp\bots\_bot_utility;
/*
@@ -15,9 +13,9 @@
*/
init()
{
if ( getdvar( "bots_main_chat" ) == "" )
if ( getcvar( "bots_main_chat" ) == "" )
{
setdvar( "bots_main_chat", 1.0 );
setcvar( "bots_main_chat", 1.0 );
}
level thread onBotConnected();
@@ -41,7 +39,7 @@ onBotConnected()
*/
BotDoChat( chance, string, isTeam )
{
mod = getdvarfloat( "bots_main_chat" );
mod = getcvarfloat( "bots_main_chat" );
if ( mod <= 0.0 )
{
@@ -88,7 +86,7 @@ start_death_watch()
{
self waittill( "death" );
self thread bot_chat_death_watch( self.lastattacker, self.bots_lastks );
self thread bot_chat_death_watch( self.lastkiller, self.bots_lastks );
self.bots_lastks = 0;
}
@@ -169,10 +167,6 @@ start_chat_watch()
switch ( msg )
{
case "revive":
self thread bot_chat_revive_watch( a, b, c, d, e, f, g );
break;
case "killcam":
self thread bot_chat_killcam_watch( a, b, c, d, e, f, g );
break;
@@ -181,18 +175,6 @@ start_chat_watch()
self thread bot_chat_stuck_watch( a, b, c, d, e, f, g );
break;
case "tube":
self thread bot_chat_tube_watch( a, b, c, d, e, f, g );
break;
case "killstreak":
self thread bot_chat_killstreak_watch( a, b, c, d, e, f, g );
break;
case "attack_vehicle":
self thread bot_chat_attack_vehicle_watch( a, b, c, d, e, f, g );
break;
case "follow_threat":
self thread bot_chat_follow_threat_watch( a, b, c, d, e, f, g );
break;
@@ -205,18 +187,10 @@ start_chat_watch()
self thread bot_chat_follow_watch( a, b, c, d, e, f, g );
break;
case "equ":
self thread bot_chat_equ_watch( a, b, c, d, e, f, g );
break;
case "nade":
self thread bot_chat_nade_watch( a, b, c, d, e, f, g );
break;
case "throwback":
self thread bot_chat_throwback_watch( a, b, c, d, e, f, g );
break;
case "rage":
self thread bot_chat_rage_watch( a, b, c, d, e, f, g );
break;
@@ -237,22 +211,10 @@ start_chat_watch()
self thread bot_chat_uav_target_watch( a, b, c, d, e, f, g );
break;
case "attack_equ":
self thread bot_chat_attack_equ_watch( a, b, c, d, e, f, g );
break;
case "dom":
self thread bot_chat_dom_watch( a, b, c, d, e, f, g );
break;
case "hq":
self thread bot_chat_hq_watch( a, b, c, d, e, f, g );
break;
case "sab":
self thread bot_chat_sab_watch( a, b, c, d, e, f, g );
break;
case "sd":
self thread bot_chat_sd_watch( a, b, c, d, e, f, g );
break;
@@ -261,18 +223,10 @@ start_chat_watch()
self thread bot_chat_cap_watch( a, b, c, d, e, f, g );
break;
case "twar":
self thread bot_chat_twar_watch( a, b, c, d, e, f, g );
break;
case "attack_dog":
self thread bot_chat_attack_dog_watch( a, b, c, d, e, f, g );
break;
case "connection":
self thread bot_chat_connection_player_watch( a, b, c, d, e, f, g );
break;
case "chat":
self thread bot_chat_chat_player_watch( a, b, c, d, e, f, g );
break;
@@ -316,7 +270,7 @@ start_startgame_watch()
switch ( level.gametype )
{
case "war":
case "tdm":
switch ( randomint( 3 ) )
{
case 0:
@@ -334,24 +288,6 @@ start_startgame_watch()
break;
case "dom":
switch ( randomint( 3 ) )
{
case 0:
self BotDoChat( 7, "Yaaayy!! I LOVE DOMINATION!!!!" );
break;
case 1:
self BotDoChat( 7, "Lets cap the flags and them." );
break;
case 2:
self BotDoChat( 7, "Yeeeesss master..." );
break;
}
break;
case "sd":
switch ( randomint( 3 ) )
{
@@ -370,24 +306,6 @@ start_startgame_watch()
break;
case "sab":
switch ( randomint( 3 ) )
{
case 0:
self BotDoChat( 7, "Soccer/Football! Lets play it!" );
break;
case 1:
self BotDoChat( 7, "Who plays sab these days." );
break;
case 2:
self BotDoChat( 7, "I do not know what to say." );
break;
}
break;
case "dm":
switch ( randomint( 3 ) )
{
@@ -406,7 +324,7 @@ start_startgame_watch()
break;
case "koth":
case "hq":
self BotDoChat( 7, "HQ TIME!" );
break;
}
@@ -426,42 +344,41 @@ doQuickMessage()
soundalias = "";
saytext = "";
wait 2;
self.spamdelay = true;
switch ( randomint( 11 ) )
switch ( randomint( 4 ) )
{
case 4 :
soundalias = "mp_cmd_suppressfire";
saytext = "Suppressing fire!";
case 0:
soundalias = "quickcommands";
saytext = ( randomint( 8 ) + 1 ) + "";
break;
case 5 :
soundalias = "mp_cmd_followme";
saytext = "Follow Me!";
case 1:
soundalias = "quickstatements";
saytext = ( randomint( 8 ) + 1 ) + "";
break;
case 6 :
soundalias = "mp_stm_enemyspotted";
saytext = "Enemy spotted!";
break;
case 7 :
soundalias = "mp_cmd_fallback";
saytext = "Fall back!";
break;
case 8 :
soundalias = "mp_stm_needreinforcements";
saytext = "Need reinforcements!";
case 2:
soundalias = "quickresponses";
saytext = ( randomint( 7 ) + 1 ) + "";
break;
}
if ( soundalias != "" && saytext != "" )
{
self maps\mp\gametypes\_quickmessages::saveheadicon();
self maps\mp\gametypes\_quickmessages::doquickmessage( soundalias, saytext );
wait 2;
self maps\mp\gametypes\_quickmessages::restoreheadicon();
switch ( soundalias )
{
case "quickcommands":
self maps\mp\gametypes\_quickmessages::quickcommands( saytext );
break;
case "quickstatements":
self maps\mp\gametypes\_quickmessages::quickstatements( saytext );
break;
case "quickresponses":
self maps\mp\gametypes\_quickmessages::quickresponses( saytext );
break;
}
}
else
{
@@ -471,7 +388,6 @@ doQuickMessage()
}
}
self.spamdelay = undefined;
wait randomint( 5 );
self.talking = false;
}
@@ -494,22 +410,33 @@ endgame_chat()
{
player = level.players[ i ];
if ( player.pers[ "score" ] > b )
if ( player.score > b )
{
winner = player;
b = player.pers[ "score" ];
b = player.score;
}
if ( player.pers[ "score" ] < w )
if ( player.score < w )
{
loser = player;
w = player.pers[ "score" ];
w = player.score;
}
}
if ( level.teambased )
{
winningteam = maps\mp\gametypes\_globallogic::getwinningteam();
winningteam = "none";
alliedscore = getTeamScore( "allies" );
axisscore = getTeamScore( "axis" );
if ( alliedscore > axisscore )
{
winningteam = "allies";
}
else if ( axisscore > alliedscore )
{
winningteam = "axis";
}
if ( self.pers[ "team" ] == winningteam )
{
@@ -935,23 +862,6 @@ endgame_chat()
bot_chat_streak( streakCount )
{
self endon( "disconnect" );
if ( streakCount == 7 )
{
if ( isdefined( self.pers[ "hardPointItem" ] ) && self.pers[ "hardPointItem" ] == "dogs_mp" )
{
switch ( randomint( 1 ) )
{
case 0:
self BotDoChat( 33, "Nice! I acheived the dogs!" );
break;
}
}
else
{
self BotDoChat( 33, "Huh?? I dont got my dogs :((" );
}
}
}
/*
@@ -1107,11 +1017,11 @@ bot_chat_killed_watch( victim )
break;
case 34:
message = ( "i love " + getMapName( getdvar( "mapname" ) ) + "!" );
message = ( "i love " + getMapName( getcvar( "mapname" ) ) + "!" );
break;
case 35:
message = ( getMapName( getdvar( "mapname" ) ) + " is my favorite map!" );
message = ( getMapName( getcvar( "mapname" ) ) + " is my favorite map!" );
break;
case 36:
@@ -1329,7 +1239,7 @@ bot_chat_death_watch( killer, last_ks )
break;
case 40:
message = ( "wow " + getMapName( getdvar( "mapname" ) ) + " is messed up" );
message = ( "wow " + getMapName( getcvar( "mapname" ) ) + " is messed up" );
break;
case 41:
@@ -1373,19 +1283,19 @@ bot_chat_death_watch( killer, last_ks )
break;
case 51:
message = ( "lol " + getMapName( getdvar( "mapname" ) ) + " sux" );
message = ( "lol " + getMapName( getcvar( "mapname" ) ) + " sux" );
break;
case 52:
message = ( "why are we even playing on " + getMapName( getdvar( "mapname" ) ) + "?" );
message = ( "why are we even playing on " + getMapName( getcvar( "mapname" ) ) + "?" );
break;
case 53:
message = ( getMapName( getdvar( "mapname" ) ) + " is such an unfair map!!" );
message = ( getMapName( getcvar( "mapname" ) ) + " is such an unfair map!!" );
break;
case 54:
message = ( "what were they thinking when making " + getMapName( getdvar( "mapname" ) ) + "?!" );
message = ( "what were they thinking when making " + getMapName( getcvar( "mapname" ) ) + "?!" );
break;
case 55:
@@ -1446,47 +1356,6 @@ bot_chat_death_watch( killer, last_ks )
self BotDoChat( 8, message );
}
/*
Revive
*/
bot_chat_revive_watch( state, revive, c, d, e, f, g )
{
self endon( "disconnect" );
switch ( state )
{
case "go":
switch ( randomint( 1 ) )
{
case 0:
self BotDoChat( 10, "i am going to revive " + revive.name );
break;
}
break;
case "start":
switch ( randomint( 1 ) )
{
case 0:
self BotDoChat( 10, "i am reviving " + revive.name );
break;
}
break;
case "stop":
switch ( randomint( 1 ) )
{
case 0:
self BotDoChat( 10, "i revived " + revive.name );
break;
}
break;
}
}
/*
Killcam
*/
@@ -1581,73 +1450,6 @@ bot_chat_stuck_watch( a, b, c, d, e, f, g )
self BotDoChat( 20, msg );
}
/*
Tube
*/
bot_chat_tube_watch( state, tubeWp, tubeWeap, d, e, f, g )
{
self endon( "disconnect" );
switch ( state )
{
case "go":
switch ( randomint( 1 ) )
{
case 0:
self BotDoChat( 10, "i am going to go tube" );
break;
}
break;
case "start":
switch ( randomint( 1 ) )
{
case 0:
self BotDoChat( 10, "i tubed" );
break;
}
break;
}
}
/*
bot_chat_killstreak_watch( streakName, b, c, d, e, f, g )
*/
bot_chat_killstreak_watch( state, location, directionYaw, d, e, f, g )
{
self endon( "disconnect" );
switch ( state )
{
case "call":
if ( self.pers[ "hardPointItem" ] == "dogs_mp" )
{
self BotDoChat( 20, "wewt! i got the dogs!!" );
}
break;
}
}
/*
bot_chat_attack_vehicle_watch( a, b, c, d, e, f, g )
*/
bot_chat_attack_vehicle_watch( state, vehicle, c, d, e, f, g )
{
self endon( "disconnect" );
switch ( state )
{
case "start":
break;
case "stop":
break;
}
}
/*
bot_chat_follow_threat_watch( a, b, c, d, e, f, g )
*/
@@ -1778,37 +1580,6 @@ bot_chat_follow_watch( state, player, time, d, e, f, g )
}
}
/*
bot_chat_equ_watch
*/
bot_chat_equ_watch( state, wp, weap, d, e, f, g )
{
self endon( "disconnect" );
switch ( state )
{
case "go":
switch ( randomint( 1 ) )
{
case 0:
self BotDoChat( 10, "going to place a " + getBaseWeaponName( weap ) );
break;
}
break;
case "start":
switch ( randomint( 1 ) )
{
case 0:
self BotDoChat( 10, "placed a " + getBaseWeaponName( weap ) );
break;
}
break;
}
}
/*
bot_chat_nade_watch
*/
@@ -1840,37 +1611,6 @@ bot_chat_nade_watch( state, wp, weap, d, e, f, g )
}
}
/*
bot_chat_throwback_watch
*/
bot_chat_throwback_watch( state, nade, c, d, e, f, g )
{
self endon( "disconnect" );
switch ( state )
{
case "start":
switch ( randomint( 1 ) )
{
case 0:
self BotDoChat( 10, "i am going to throw back the grenade!" );
break;
}
break;
case "stop":
switch ( randomint( 1 ) )
{
case 0:
self BotDoChat( 10, "i threw back the grenade!" );
break;
}
break;
}
}
/*
bot_chat_tbag_watch
*/
@@ -2028,73 +1768,6 @@ bot_chat_uav_target_watch( state, heard, c, d, e, f, g )
}
}
/*
bot_chat_attack_equ_watch
*/
bot_chat_attack_equ_watch( state, equ, c, d, e, f, g )
{
self endon( "disconnect" );
switch ( state )
{
case "start":
break;
case "stop":
break;
}
}
/*
bot_chat_dom_watch
*/
bot_chat_dom_watch( state, sub_state, flag, d, e, f, g )
{
self endon( "disconnect" );
switch ( sub_state )
{
case "spawnkill":
switch ( state )
{
case "start":
break;
case "stop":
break;
}
break;
case "defend":
switch ( state )
{
case "start":
break;
case "stop":
break;
}
break;
case "cap":
switch ( state )
{
case "go":
break;
case "start":
break;
case "stop":
break;
}
break;
}
}
/*
bot_chat_hq_watch
*/
@@ -2133,83 +1806,6 @@ bot_chat_hq_watch( state, sub_state, c, d, e, f, g )
}
}
/*
bot_chat_sab_watch
*/
bot_chat_sab_watch( state, sub_state, c, d, e, f, g )
{
self endon( "disconnect" );
switch ( sub_state )
{
case "bomb":
switch ( state )
{
case "start":
break;
case "stop":
break;
}
break;
case "defuser":
switch ( state )
{
case "start":
break;
case "stop":
break;
}
break;
case "planter":
switch ( state )
{
case "start":
break;
case "stop":
break;
}
break;
case "plant":
switch ( state )
{
case "go":
break;
case "start":
break;
case "stop":
break;
}
break;
case "defuse":
switch ( state )
{
case "go":
break;
case "start":
break;
case "stop":
break;
}
break;
}
}
/*
bot_chat_sd_watch
*/
@@ -2341,46 +1937,3 @@ bot_chat_cap_watch( state, sub_state, obj, d, e, f, g )
break;
}
}
/*
bot_chat_twar_watch
*/
bot_chat_twar_watch( state, sub_state, c, d, e, f, g )
{
self endon( "disconnect" );
switch ( sub_state )
{
case "cap":
switch ( state )
{
case "go":
break;
case "start":
break;
case "stop":
break;
}
break;
}
}
/*
bot_chat_attack_dog_watch
*/
bot_chat_attack_dog_watch( state, dog, c, d, e, f, g )
{
self endon( "disconnect" );
switch ( state )
{
case "start":
break;
case "stop":
break;
}
}
+11 -3
View File
@@ -164,7 +164,15 @@ bot_skip_killcam()
if ( isdefined( self.killcam ) )
{
self BotNotifyBotEvent( "killcam", "start" );
wait 0.5 + randomint( 3 );
wait 0.1;
self notify( "end_killcam" );
self BotNotifyBotEvent( "killcam", "stop" );
}
}
}
@@ -1359,7 +1367,7 @@ aim_loop()
if ( trace_time > reaction_time )
{
if ( ( !canADS || adsAmount >= 1.0 || self GetStance() == "prone" ) && ( conedot > 0.99 || dist < level.bots_maxknifedistance ) && getcvarint( "bots_play_fire" ) )
if ( ( !canADS || adsAmount >= 1.0 || self getStance() == "prone" ) && ( conedot > 0.99 || dist < level.bots_maxknifedistance ) && getcvarint( "bots_play_fire" ) )
{
self botFire();
}
@@ -1420,7 +1428,7 @@ aim_loop()
}
}
if ( ( !canADS || adsAmount >= 1.0 || self GetStance() == "prone" ) && ( conedot > 0.95 || dist < level.bots_maxknifedistance ) && getcvarint( "bots_play_fire" ) )
if ( ( !canADS || adsAmount >= 1.0 || self getStance() == "prone" ) && ( conedot > 0.95 || dist < level.bots_maxknifedistance ) && getcvarint( "bots_play_fire" ) )
{
self botFire();
}
@@ -1630,7 +1638,7 @@ walk_loop()
if ( isplayer( self.bot.target.entity ) && self.bot.target.trace_time && self canFire( curweap ) && self isInRange( self.bot.target.dist, curweap ) )
{
if ( self GetStance() == "prone" || ( self.bot.is_cur_sniper && self playerads() > 0 ) )
if ( self getStance() == "prone" || ( self.bot.is_cur_sniper && self playerads() > 0 ) )
{
return;
}
+875 -5
View File
@@ -26,6 +26,9 @@ connected()
self.killerlocation = undefined;
self.lastkiller = undefined;
self.bot_change_class = true;
self.lastkilledplayer = undefined;
self.cur_kill_streak = 0;
self.cur_death_streak = 0;
self thread difficulty();
self thread teamWatch();
@@ -84,6 +87,15 @@ onKilled( eInflictor, eAttacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc,
self.killerlocation = eAttacker.origin;
self.lastkiller = eAttacker;
self.cur_death_streak++;
if ( eAttacker is_bot() )
{
eAttacker.cur_death_streak = 0;
eAttacker.lastkilledplayer = self;
eAttacker.cur_kill_streak++;
eAttacker notify( "killed_enemy" );
}
}
/*
@@ -640,6 +652,7 @@ onSpawned()
self.bot_lock_goal = false;
self.help_time = undefined;
self.bot_was_follow_script_update = undefined;
self.cur_kill_streak = 0;
}
}
@@ -692,10 +705,10 @@ start_bot_threads()
{
self thread bot_hq();
// self thread bot_sd_defenders();
// self thread bot_sd_attackers();
self thread bot_sd_defenders();
self thread bot_sd_attackers();
// self thread bot_cap();
self thread bot_cap();
}
}
@@ -1487,12 +1500,12 @@ killCampAfterTime( time )
self endon( "disconnect" );
self endon( "kill_camp_bot" );
timeleft = 90; // cod2
timeleft = getTimeRemaining() / 1000;
while ( time > 0 && timeleft >= 60 )
{
wait 1;
timeleft = 90;
timeleft = getTimeRemaining() / 1000;
time--;
}
@@ -2095,3 +2108,860 @@ bot_do_random_action_for_objective( obj_target )
wait 2;
self.bot_random_obj_action = undefined;
}
/*
CoD2
*/
getFlagCarrier( flag )
{
for ( i = 0; i < level.players.size; i++ )
{
if ( !isdefined( level.players[ i ].flag ) )
{
continue;
}
if ( level.players[ i ].flag != flag )
{
continue;
}
return level.players[ i ];
}
return undefined;
}
/*
Bots play capture the flag
*/
bot_cap_loop()
{
allied_flag = getent( "allied_flag", "targetname" );
if ( !isdefined( allied_flag ) )
{
return;
}
axis_flag = getent( "axis_flag", "targetname" );
if ( !isdefined( axis_flag ) )
{
return;
}
myTeam = self.pers[ "team" ];
otherTeam = getotherteam( myTeam );
myflag = allied_flag;
theirflag = axis_flag;
if ( myTeam == "axis" )
{
myflag = axis_flag;
theirflag = allied_flag;
}
if ( !myflag.atbase )
{
carrier = getFlagCarrier( myflag );
if ( !isdefined( carrier ) ) // someone doesnt has our flag
{
if ( !isdefined( getFlagCarrier( theirflag ) ) && distancesquared( self.origin, theirflag.origin ) < distancesquared( self.origin, myflag.origin ) ) // no one has their flag and its closer
{
self BotNotifyBotEvent( "cap", "start", "their_flag", theirflag );
self bot_cap_get_flag( theirflag );
self BotNotifyBotEvent( "cap", "stop", "their_flag", theirflag );
}
else // go get it
{
self BotNotifyBotEvent( "cap", "start", "my_flag", myflag );
self bot_cap_get_flag( myflag );
self BotNotifyBotEvent( "cap", "stop", "my_flag", myflag );
}
return;
}
else
{
if ( theirflag.atbase && randomint( 100 ) < 50 )
{
// take their flag
self BotNotifyBotEvent( "cap", "start", "their_flag", theirflag );
self bot_cap_get_flag( theirflag );
self BotNotifyBotEvent( "cap", "stop", "their_flag", theirflag );
}
else
{
if ( self HasScriptGoal() )
{
return;
}
if ( !isdefined( theirflag.bots ) )
{
theirflag.bots = 0;
}
origin = theirflag.home_origin;
if ( theirflag.bots > 2 || randomint( 100 ) < 45 )
{
// kill carrier
origin = carrier.origin;
self SetScriptGoal( origin, 64 );
self thread bot_escort_flag( myflag, carrier );
if ( self waittill_any_return( "goal", "bad_path", "new_goal" ) != "new_goal" )
{
self ClearScriptGoal();
}
return;
}
self thread bot_inc_bots( theirflag );
// camp their zone
if ( distancesquared( origin, self.origin ) <= 1024 * 1024 )
{
wait 4;
self notify( "bot_inc_bots" );
theirflag.bots--;
return;
}
self SetScriptGoal( origin, 256 );
self thread bot_inc_bots( theirflag );
self thread bot_escort_flag( myflag, carrier );
if ( self waittill_any_return( "goal", "bad_path", "new_goal" ) != "new_goal" )
{
self ClearScriptGoal();
}
}
}
}
else // our flag is ok
{
if ( isdefined( self.flag ) ) // if have flag
{
// go cap
origin = myflag.home_origin;
self BotNotifyBotEvent( "cap", "start", "cap" );
self.bot_lock_goal = true;
self SetScriptGoal( origin, 32 );
self thread bot_get_flag( myflag );
evt = self waittill_any_return( "goal", "bad_path", "new_goal" );
wait 1;
if ( evt != "new_goal" )
{
self ClearScriptGoal();
}
self.bot_lock_goal = false;
self BotNotifyBotEvent( "cap", "stop", "cap" );
return;
}
carrier = getFlagCarrier( theirflag );
if ( !isdefined( carrier ) ) // if no one has enemy flag
{
self BotNotifyBotEvent( "cap", "start", "their_flag", theirflag );
self bot_cap_get_flag( theirflag );
self BotNotifyBotEvent( "cap", "stop", "their_flag", theirflag );
return;
}
// escort them
if ( self HasScriptGoal() )
{
return;
}
origin = carrier.origin;
if ( distancesquared( origin, self.origin ) <= 1024 * 1024 )
{
return;
}
self SetScriptGoal( origin, 256 );
self thread bot_escort_flag( theirflag, carrier );
if ( self waittill_any_return( "goal", "bad_path", "new_goal" ) != "new_goal" )
{
self ClearScriptGoal();
}
}
}
/*
Bots play capture the flag
*/
bot_cap()
{
self endon( "death" );
self endon( "disconnect" );
level endon( "game_ended" );
if ( level.gametype != "ctf" )
{
return;
}
for ( ;; )
{
wait( randomintrange( 3, 5 ) );
if ( self.bot_lock_goal )
{
continue;
}
self bot_cap_loop();
}
}
/*
Increments the number of bots approching the obj, decrements when needed
Used for preventing too many bots going to one obj, or unreachable objs
*/
bot_inc_bots( obj, unreach )
{
level endon( "game_ended" );
self endon( "bot_inc_bots" );
if ( !isdefined( obj ) )
{
return;
}
if ( !isdefined( obj.bots ) )
{
obj.bots = 0;
}
obj.bots++;
ret = self waittill_any_return( "death", "disconnect", "bad_path", "goal", "new_goal" );
if ( isdefined( obj ) && ( ret != "bad_path" || !isdefined( unreach ) ) )
{
obj.bots--;
}
}
/*
Watches while the obj is being carried, calls 'goal' when complete
*/
bot_escort_flag( flag, carrier )
{
self endon( "death" );
self endon( "disconnect" );
self endon( "goal" );
self endon( "bad_path" );
self endon( "new_goal" );
for ( ;; )
{
wait 0.5;
if ( !isdefined( flag ) )
{
break;
}
flagCarrier = getFlagCarrier( flag );
if ( !isdefined( flagCarrier ) || carrier == flagCarrier )
{
break;
}
}
self notify( "goal" );
}
/*
Watches while the obj is not being carried, calls 'goal' when complete
*/
bot_get_flag( flag )
{
self endon( "death" );
self endon( "disconnect" );
self endon( "goal" );
self endon( "bad_path" );
self endon( "new_goal" );
for ( ;; )
{
wait 0.5;
if ( !isdefined( flag ) )
{
break;
}
if ( isdefined( getFlagCarrier( flag ) ) )
{
break;
}
}
self notify( "goal" );
}
/*
Bots go and get the flag
*/
bot_cap_get_flag( flag )
{
origin = flag.origin;
// go get it
self.bot_lock_goal = true;
self SetScriptGoal( origin, 32 );
self thread bot_get_flag( flag );
evt = self waittill_any_return( "goal", "bad_path", "new_goal" );
if ( evt != "new_goal" )
{
self ClearScriptGoal();
}
if ( evt != "goal" )
{
self.bot_lock_goal = false;
return;
}
self ClearScriptGoal();
self.bot_lock_goal = false;
}
/*
Gets the object thats the closest in the array
*/
bot_array_nearest_origin( array )
{
result = undefined;
for ( i = 0; i < array.size; i++ )
{
if ( !isdefined( result ) || distancesquared( self.origin, array[ i ].origin ) < distancesquared( self.origin, result.origin ) )
{
result = array[ i ];
}
}
return result;
}
/*
bots will defend their site from a planter/defuser
*/
bot_defend_site( site )
{
self endon( "death" );
self endon( "disconnect" );
level endon( "game_ended" );
self endon( "goal" );
self endon( "bad_path" );
self endon( "new_goal" );
for ( ;; )
{
wait 0.5;
if ( !isdefined( site.planting ) && !isdefined( site.defusing ) )
{
break;
}
}
self notify( "bad_path" );
}
/*
Bots will go defuse the bomb
*/
bot_go_defuse( plant )
{
self endon( "death" );
self endon( "disconnect" );
level endon( "game_ended" );
self endon( "goal" );
self endon( "bad_path" );
self endon( "new_goal" );
for ( ;; )
{
wait 1;
if ( !level.bombplanted )
{
break;
}
if ( self istouching( plant ) )
{
break;
}
}
if ( !level.bombplanted )
{
self notify( "bad_path" );
}
else
{
self notify( "goal" );
}
}
/*
Bots will go plant the bomb
*/
bot_go_plant( plant )
{
self endon( "death" );
self endon( "disconnect" );
level endon( "game_ended" );
self endon( "goal" );
self endon( "bad_path" );
self endon( "new_goal" );
for ( ;; )
{
wait 1;
if ( level.bombplanted )
{
break;
}
if ( self istouching( plant ) )
{
break;
}
}
if ( level.bombplanted )
{
self notify( "bad_path" );
}
else
{
self notify( "goal" );
}
}
/*
Waits for the bot to stop moving
*/
bot_wait_stop_move()
{
while ( !self isonground() || lengthsquared( self getVelocity() ) > 1 )
{
wait 0.25;
}
}
/*
Bots play sd defenders
*/
bot_sd_defenders_loop( data )
{
myTeam = self.pers[ "team" ];
otherTeam = getotherteam( myTeam );
// bomb not planted, lets protect our sites
if ( !level.bombplanted )
{
timeleft = getTimeRemaining() / 1000;
if ( timeleft >= 90 )
{
return;
}
// pick a site to protect
sites = getentarray( "bombzone", "targetname" );
if ( !sites.size )
{
return;
}
if ( data.rand > 50 )
{
site = self bot_array_nearest_origin( sites );
}
else
{
site = random( sites );
}
if ( !isdefined( site ) )
{
return;
}
origin = ( site.origin[ 0 ] + 50, site.origin[ 1 ] + 50, site.origin[ 2 ] + 5 );
if ( isdefined( site.planting ) ) // somebody is planting
{
self BotNotifyBotEvent( "sd", "start", "planter", site );
self.bot_lock_goal = true;
self SetScriptGoal( origin, 64 );
self thread bot_defend_site( site );
if ( self waittill_any_return( "goal", "bad_path", "new_goal" ) != "new_goal" )
{
self ClearScriptGoal();
}
self.bot_lock_goal = false;
self BotNotifyBotEvent( "sd", "stop", "planter", site );
return;
}
// else hang around the site
if ( distancesquared( origin, self.origin ) <= 1024 * 1024 )
{
return;
}
self.bot_lock_goal = true;
self SetScriptGoal( origin, 256 );
if ( self waittill_any_return( "goal", "bad_path", "new_goal" ) != "new_goal" )
{
self ClearScriptGoal();
}
self.bot_lock_goal = false;
return;
}
// bomb is planted, we need to defuse
defuse = getent( "bombtrigger", "targetname" );
if ( !isdefined( defuse ) )
{
return;
}
if ( !isdefined( defuse.bots ) )
{
defuse.bots = 0;
}
origin = ( defuse.origin[ 0 ], defuse.origin[ 1 ], defuse.origin[ 2 ] + 5 );
// someone is going to go defuse ,lets just hang around
if ( defuse.bots > 1 )
{
if ( self HasScriptGoal() )
{
return;
}
if ( distancesquared( origin, self.origin ) <= 1024 * 1024 )
{
return;
}
self SetScriptGoal( origin, 256 );
self thread bot_go_defuse( defuse );
if ( self waittill_any_return( "goal", "bad_path", "new_goal" ) != "new_goal" )
{
self ClearScriptGoal();
}
return;
}
// lets defuse
self BotNotifyBotEvent( "sd", "go", "defuse" );
self.bot_lock_goal = true;
self SetScriptGoal( origin, 1 );
self thread bot_inc_bots( defuse );
self thread bot_go_defuse( defuse );
event = self waittill_any_return( "goal", "bad_path", "new_goal" );
if ( event != "new_goal" )
{
self ClearScriptGoal();
}
if ( event != "goal" || !level.bombplanted || isdefined( defuse.defusing ) || !self istouching( defuse ) || self hasThreat() )
{
self.bot_lock_goal = false;
return;
}
self BotNotifyBotEvent( "sd", "start", "defuse" );
self BotRandomStance();
self SetScriptGoal( self.origin, 64 );
self bot_wait_stop_move();
waitTime = level.defusetime + 2.5;
self thread BotPressUse( waitTime );
wait waitTime;
self ClearScriptGoal();
self.bot_lock_goal = false;
self BotNotifyBotEvent( "sd", "stop", "defuse" );
}
/*
Bots play sd defenders
*/
bot_sd_defenders()
{
self endon( "death" );
self endon( "disconnect" );
level endon( "game_ended" );
if ( level.gametype != "sd" )
{
return;
}
if ( self.team == game[ "attackers" ] )
{
return;
}
data = spawnstruct();
data.rand = self BotGetRandom();
for ( ;; )
{
wait( randomintrange( 3, 5 ) );
if ( self.bot_lock_goal )
{
continue;
}
if ( self isPlantingOrDefusing() )
{
continue;
}
self bot_sd_defenders_loop( data );
}
}
/*
Bots play sd attackers
*/
bot_sd_attackers_loop( data )
{
if ( data.first )
{
data.first = false;
}
else
{
wait( randomintrange( 3, 5 ) );
}
if ( self.bot_lock_goal )
{
return;
}
myTeam = self.pers[ "team" ];
otherTeam = getotherteam( myTeam );
// bomb planted
if ( level.bombplanted )
{
site = getent( "bombtrigger", "targetname" );
if ( !isdefined( site ) )
{
return;
}
origin = ( site.origin[ 0 ], site.origin[ 1 ], site.origin[ 2 ] + 5 );
if ( isdefined( site.defusing ) ) // somebody is defusing
{
self BotNotifyBotEvent( "sd", "start", "defuser" );
self.bot_lock_goal = true;
self SetScriptGoal( origin, 64 );
self thread bot_defend_site( site );
if ( self waittill_any_return( "goal", "bad_path", "new_goal" ) != "new_goal" )
{
self ClearScriptGoal();
}
self.bot_lock_goal = false;
self BotNotifyBotEvent( "sd", "stop", "defuser" );
return;
}
// else hang around the site
if ( distancesquared( origin, self.origin ) <= 1024 * 1024 )
{
return;
}
self.bot_lock_goal = true;
self SetScriptGoal( origin, 256 );
if ( self waittill_any_return( "goal", "bad_path", "new_goal" ) != "new_goal" )
{
self ClearScriptGoal();
}
self.bot_lock_goal = false;
return;
}
timeleft = getTimeRemaining() / 1000;
timepassed = getTimePassed() / 1000;
// check if to plant
if ( timepassed < 120 && timeleft >= 90 && randomint( 100 ) < 98 )
{
return;
}
sites = getentarray( "bombzone", "targetname" );
if ( !sites.size )
{
return;
}
if ( data.rand > 50 )
{
plant = self bot_array_nearest_origin( sites );
}
else
{
plant = random( sites );
}
if ( !isdefined( plant ) )
{
return;
}
other = undefined;
for ( i = 0; i < sites.size; i++ )
{
if ( sites[ i ] != plant )
{
other = sites[ i ];
break;
}
}
origin = ( plant.origin[ 0 ] + 50, plant.origin[ 1 ] + 50, plant.origin[ 2 ] + 5 );
self BotNotifyBotEvent( "sd", "go", "plant", plant );
self.bot_lock_goal = true;
self SetScriptGoal( origin, 1 );
self thread bot_go_plant( plant );
event = self waittill_any_return( "goal", "bad_path", "new_goal" );
if ( event != "new_goal" )
{
self ClearScriptGoal();
}
if ( event != "goal" || level.bombplanted || ( isdefined( other ) && isdefined( other.planting ) ) || !self istouching( plant ) || self hasThreat() || isdefined( plant.planting ) )
{
self.bot_lock_goal = false;
return;
}
self BotNotifyBotEvent( "sd", "start", "plant", plant );
self BotRandomStance();
self SetScriptGoal( self.origin, 64 );
self bot_wait_stop_move();
waitTime = level.planttime + 2.5;
self thread BotPressUse( waitTime );
wait waitTime;
self ClearScriptGoal();
self.bot_lock_goal = false;
self BotNotifyBotEvent( "sd", "stop", "plant", plant );
}
/*
Bots play sd attackers
*/
bot_sd_attackers()
{
self endon( "death" );
self endon( "disconnect" );
level endon( "game_ended" );
if ( level.gametype != "sd" )
{
return;
}
if ( self.team != game[ "attackers" ] )
{
return;
}
data = spawnstruct();
data.rand = self BotGetRandom();
data.first = true;
for ( ;; )
{
self bot_sd_attackers_loop( data );
}
}
+40 -1
View File
@@ -691,6 +691,37 @@ getStance()
return "crouch";
}
/*
CoD2
*/
getTimePassed()
{
if ( !isdefined( level.starttime ) )
{
return 0;
}
return ( gettime() - level.starttime );
}
/*
CoD2
*/
getTimeRemaining()
{
if ( isdefined( level.roundlength ) )
{
return level.roundlength * 60 * 1000 - getTimePassed();
}
if ( !isdefined( level.timelimit ) )
{
return 0;
}
return level.timelimit * 60 * 1000 - getTimePassed();
}
/*
CoD2
*/
@@ -727,7 +758,7 @@ WeaponIsFullAuto( weap )
*/
getEyeHeight()
{
stance = self GetStance();
stance = self getStance();
if ( stance == "prone" )
{
@@ -1867,6 +1898,14 @@ getMapName( map )
return map;
}
/*
CoD4
*/
getBaseWeaponName( weap )
{
return strtok( weap, "_" )[ 0 ];
}
/*
cod2
*/
+1 -1
View File
@@ -8,7 +8,7 @@ init()
level thread scripts\mp\bots_adapter_libcod::init();
level thread scripts\mp\bots_wp_editor::init();
level thread scripts\mp\bots::init();
//level thread scripts\mp\bots_chat::init();
level thread scripts\mp\bots_chat::init();
level thread scripts\mp\bots_menu::init();
}
+21 -2
View File
@@ -171,10 +171,29 @@ do_botaction( action )
case "+gostand":
self setbotstance( "jump" );
break;
case "-smoke": // no equal in libcod
case "-activate":
// self activate( false ); // no equal in libcod
break;
case "+activate":
// self activate( true );
break;
case "+smoke":
// self throwsmoke( true );
break;
case "-smoke":
// self throwsmoke( false );
break;
case "+holdbreath":
// self holdbreath( true );
break;
case "-holdbreath":
// self holdbreath( false );
break;
}