Fix sniper, reload cancel

This commit is contained in:
INeedBots 2021-03-19 15:28:59 -06:00
parent f405c523b3
commit a0c3666653
2 changed files with 311 additions and 223 deletions

View File

@ -155,6 +155,7 @@ resetBotVars()
self.bot.is_cur_full_auto = false; self.bot.is_cur_full_auto = false;
self.bot.cur_weap_dist_multi = 1; self.bot.cur_weap_dist_multi = 1;
self.bot.is_cur_sniper = false;
self.bot.rand = randomInt(100); self.bot.rand = randomInt(100);
@ -300,6 +301,20 @@ SetWeaponDistMulti(weap)
} }
} }
/*
Is the weap a sniper
*/
IsWeapSniper(weap)
{
if (weap == "none")
return false;
if (maps\mp\gametypes\_missions::getWeaponClass(weap) != "weapon_sniper")
return false;
return true;
}
/* /*
The hold breath thread. The hold breath thread.
*/ */
@ -363,6 +378,7 @@ onWeaponChange()
weap = self GetCurrentWeapon(); weap = self GetCurrentWeapon();
self.bot.is_cur_full_auto = WeaponIsFullAuto(weap); self.bot.is_cur_full_auto = WeaponIsFullAuto(weap);
self.bot.cur_weap_dist_multi = SetWeaponDistMulti(weap); self.bot.cur_weap_dist_multi = SetWeaponDistMulti(weap);
self.bot.is_cur_sniper = IsWeapSniper(weap);
if (weap != "none") if (weap != "none")
self changeToWeap(weap); self changeToWeap(weap);
@ -372,6 +388,7 @@ onWeaponChange()
self.bot.is_cur_full_auto = WeaponIsFullAuto(newWeapon); self.bot.is_cur_full_auto = WeaponIsFullAuto(newWeapon);
self.bot.cur_weap_dist_multi = SetWeaponDistMulti(weap); self.bot.cur_weap_dist_multi = SetWeaponDistMulti(weap);
self.bot.is_cur_sniper = IsWeapSniper(weap);
if (newWeapon == "none") if (newWeapon == "none")
{ {
@ -412,7 +429,18 @@ reload_watch()
{ {
self waittill("reload_start"); self waittill("reload_start");
self.bot.isreloading = true; self.bot.isreloading = true;
self waittill_notify_or_timeout("reload", 7.5);
while(true)
{
ret = self waittill_any_timeout(7.5, "reload");
if (ret == "timeout")
break;
weap = self GetCurrentWeapon();
if (self GetWeaponAmmoClip(weap) >= WeaponClipSize(weap))
break;
}
self.bot.isreloading = false; self.bot.isreloading = false;
} }
} }
@ -974,7 +1002,7 @@ watchToLook()
if(!self isInRange(self.bot.target.dist, curweap)) if(!self isInRange(self.bot.target.dist, curweap))
continue; continue;
if (weaponClass(curweap) == "sniper") if (self.bot.is_cur_sniper)
continue; continue;
if(randomInt(100) > self.pers["bots"]["behavior"]["jump"]) if(randomInt(100) > self.pers["bots"]["behavior"]["jump"])
@ -1132,7 +1160,7 @@ aim()
{ {
if (self canAds(dist, curweap)) if (self canAds(dist, curweap))
{ {
if (weaponClass(curweap) != "sniper" || !self.pers["bots"]["behavior"]["quickscope"]) if (!self.bot.is_cur_sniper || !self.pers["bots"]["behavior"]["quickscope"])
self thread pressAds(); self thread pressAds();
} }
} }
@ -1192,7 +1220,7 @@ aim()
if (canADS) if (canADS)
{ {
stopAdsOverride = false; stopAdsOverride = false;
if (weaponClass(curweap) == "sniper") if (self.bot.is_cur_sniper)
{ {
if (self.pers["bots"]["behavior"]["quickscope"] && self.bot.last_fire_time != -1 && getTime() - self.bot.last_fire_time < 1000) if (self.pers["bots"]["behavior"]["quickscope"] && self.bot.last_fire_time != -1 && getTime() - self.bot.last_fire_time < 1000)
stopAdsOverride = true; stopAdsOverride = true;
@ -1206,7 +1234,7 @@ aim()
if (trace_time > reaction_time) if (trace_time > reaction_time)
{ {
if((!canADS || adsAmount >= 1.0 || self InLastStand() || self GetStance() == "prone") && (conedot > 0.95 || dist < level.bots_maxKnifeDistance) && getDvarInt("bots_play_fire")) if((!canADS || adsAmount >= 1.0 || self InLastStand() || self GetStance() == "prone") && (conedot > 0.99 || dist < level.bots_maxKnifeDistance) && getDvarInt("bots_play_fire"))
self botFire(); self botFire();
if (isplay) if (isplay)
@ -1241,7 +1269,7 @@ aim()
if (canADS) if (canADS)
{ {
stopAdsOverride = false; stopAdsOverride = false;
if (weaponClass(curweap) == "sniper") if (self.bot.is_cur_sniper)
{ {
if (self.pers["bots"]["behavior"]["quickscope"] && self.bot.last_fire_time != -1 && getTime() - self.bot.last_fire_time < 1000) if (self.pers["bots"]["behavior"]["quickscope"] && self.bot.last_fire_time != -1 && getTime() - self.bot.last_fire_time < 1000)
stopAdsOverride = true; stopAdsOverride = true;
@ -1423,7 +1451,7 @@ walk()
if(self.bot.target.isplay && self.bot.target.trace_time && self canFire(curweap) && self isInRange(self.bot.target.dist, curweap)) if(self.bot.target.isplay && self.bot.target.trace_time && self canFire(curweap) && self isInRange(self.bot.target.dist, curweap))
{ {
if (self InLastStand() || self GetStance() == "prone" || (weaponClass(curweap) == "sniper" && self PlayerADS() > 0)) if (self InLastStand() || self GetStance() == "prone" || (self.bot.is_cur_sniper && self PlayerADS() > 0))
continue; continue;
if(self.bot.target.rand <= self.pers["bots"]["behavior"]["strafe"]) if(self.bot.target.rand <= self.pers["bots"]["behavior"]["strafe"])

View File

@ -263,13 +263,10 @@ difficulty()
for(;;) for(;;)
{ {
wait 5;
rankVar = GetDvarInt("bots_skill"); rankVar = GetDvarInt("bots_skill");
if(rankVar == 9) if(rankVar != 9)
continue; {
switch(self.pers["bots"]["skill"]["base"]) switch(self.pers["bots"]["skill"]["base"])
{ {
case 1: case 1:
@ -491,6 +488,9 @@ difficulty()
break; break;
} }
} }
wait 5;
}
} }
/* /*
@ -939,6 +939,7 @@ start_bot_threads()
self thread bot_killstreak_think(); self thread bot_killstreak_think();
self thread bot_weapon_think(); self thread bot_weapon_think();
self thread doReloadCancel();
// script targeting // script targeting
if (getDvarInt("bots_play_target_other")) if (getDvarInt("bots_play_target_other"))
@ -2143,6 +2144,65 @@ bot_revenge_think()
} }
} }
/*
Reload cancels
*/
doReloadCancel()
{
self endon("disconnect");
self endon("death");
for (;;)
{
self waittill("reload");
if(self BotIsFrozen())
continue;
if(self isDefusing() || self isPlanting())
continue;
if (self InLastStand())
continue;
curWeap = self GetCurrentWeapon();
// check single reloads
if (self GetWeaponAmmoClip(curWeap) < WeaponClipSize(curWeap))
continue;
// check difficulty
if (self.pers["bots"]["skill"]["base"] <= 3)
continue;
// check if got another weapon
weaponslist = self GetWeaponsListPrimaries();
weap = "";
while(weaponslist.size)
{
weapon = weaponslist[randomInt(weaponslist.size)];
weaponslist = array_remove(weaponslist, weapon);
if (!maps\mp\gametypes\_weapons::isSideArm( weapon ) && !maps\mp\gametypes\_weapons::isPrimaryWeapon( weapon ))
continue;
if(curWeap == weapon || weapon == "none" || weapon == "")
continue;
weap = weapon;
break;
}
if(weap == "")
continue;
// do the cancel
wait 0.1;
self BotChangeToWeapon(weap);
wait 0.25;
self BotChangeToWeapon(curWeap);
}
}
/* /*
Bot logic for switching weapons. Bot logic for switching weapons.
*/ */