From 979d1135bebbf64c38802eba1d068c182666d7de Mon Sep 17 00:00:00 2001 From: ineedbots Date: Tue, 4 May 2021 16:54:05 -0600 Subject: [PATCH] Fix weap swap vars, partial c4 support --- main_shared/maps/mp/bots/_bot_internal.gsc | 82 ++++++++++++++++++---- main_shared/maps/mp/bots/_bot_script.gsc | 9 ++- 2 files changed, 76 insertions(+), 15 deletions(-) diff --git a/main_shared/maps/mp/bots/_bot_internal.gsc b/main_shared/maps/mp/bots/_bot_internal.gsc index 95a45ff..14ec51e 100644 --- a/main_shared/maps/mp/bots/_bot_internal.gsc +++ b/main_shared/maps/mp/bots/_bot_internal.gsc @@ -303,10 +303,69 @@ spawned() self thread aim(); self thread watchHoldBreath(); self thread onNewEnemy(); + self thread watchGrenadeFire(); self notify("bot_spawned"); } +/* + Watches when the bot fires a grenade +*/ +watchGrenadeFire() +{ + self endon("disconnect"); + self endon("death"); + + for (;;) + { + self waittill( "grenade_fire", nade, weapname ); + + if ( weapname == "satchel_charge_mp" ) + self thread watchC4Thrown(nade); + } +} + +/* + Watches the c4 +*/ +watchC4Thrown(c4) +{ + self endon("disconnect"); + c4 endon("death"); + + wait 0.5; + + for (;;) + { + wait 1 + randomInt(50) * 0.05; + + shouldBreak = false; + for (i = 0; i < level.players.size; i++) + { + player = level.players[i]; + + if(player == self) + continue; + + if((level.teamBased && self.team == player.team) || player.sessionstate != "playing" || !isAlive(player)) + continue; + + if (distanceSquared(c4.origin, player.origin) > 200*200) + continue; + + if (!bulletTracePassed(c4.origin, player.origin + (0, 0, 25), false, c4)) + continue; + + shouldBreak = true; + } + + if (shouldBreak) + break; + } + + self notify( "alt_detonate" ); +} + /* Sets the factor of distance for a weapon */ @@ -405,26 +464,25 @@ onWeaponChange() { self endon("disconnect"); self endon("death"); - - weap = self GetCurrentWeapon(); - self.bot.is_cur_full_auto = WeaponIsFullAuto(weap); - self.bot.cur_weap_dist_multi = SetWeaponDistMulti(weap); - self.bot.is_cur_sniper = IsWeapSniper(weap); - if (weap != "none") - self changeToWeap(weap); + first = true; for(;;) { - self waittill( "weapon_change", newWeapon ); + newWeapon = undefined; + if (first) + { + first = false; + newWeapon = self getCurrentWeapon(); + } + else + self waittill( "weapon_change", newWeapon ); self.bot.is_cur_full_auto = WeaponIsFullAuto(newWeapon); - self.bot.cur_weap_dist_multi = SetWeaponDistMulti(weap); - self.bot.is_cur_sniper = IsWeapSniper(weap); + self.bot.cur_weap_dist_multi = SetWeaponDistMulti(newWeapon); + self.bot.is_cur_sniper = IsWeapSniper(newWeapon); if (newWeapon == "none") - { continue; - } self changeToWeap(newWeapon); } diff --git a/main_shared/maps/mp/bots/_bot_script.gsc b/main_shared/maps/mp/bots/_bot_script.gsc index fc3c118..07adb8a 100644 --- a/main_shared/maps/mp/bots/_bot_script.gsc +++ b/main_shared/maps/mp/bots/_bot_script.gsc @@ -2061,6 +2061,8 @@ bot_use_equipment_think() nade = undefined; if (self GetAmmoCount("mine_bouncing_betty_mp")) nade = "mine_bouncing_betty_mp"; + if (self GetAmmoCount("satchel_charge_mp")) + nade = "satchel_charge_mp"; if (!isDefined(nade)) continue; @@ -2138,7 +2140,8 @@ bot_use_equipment_think() if (self changeToWeapon(nade)) { - self thread fire_current_weapon(); + if (nade != "satchel_charge_mp") + self thread fire_current_weapon(); self waittill_any_timeout(5, "grenade_fire", "weapon_change"); self notify("stop_firing_weapon"); } @@ -2523,7 +2526,7 @@ bot_weapon_think() } else { - if(curWeap != "none" && self getAmmoCount(curWeap) && curWeap != "satchel_charge_mp" && curWeap != "squadcommand_mp") + if(curWeap != "none" && self getAmmoCount(curWeap) && curWeap != "squadcommand_mp") { if(randomInt(100) > self.pers["bots"]["behavior"]["switch"]) continue; @@ -2549,7 +2552,7 @@ bot_weapon_think() if (maps\mp\gametypes\_weapons::isGrenade( weapon )) continue; - if(curWeap == weapon || weapon == "satchel_charge_mp" || weapon == "none" || weapon == "mine_bouncing_betty_mp" || weapon == "" || weapon == "squadcommand_mp")//c4 no work + if(curWeap == weapon || weapon == "satchel_charge_mp" || weapon == "none" || weapon == "mine_bouncing_betty_mp" || weapon == "" || weapon == "squadcommand_mp") continue; weap = weapon;