More NavBot
This commit is contained in:
parent
1e7ea12796
commit
e559114506
@ -8,6 +8,8 @@
|
|||||||
namespace hacks::tf2::NavBot
|
namespace hacks::tf2::NavBot
|
||||||
{
|
{
|
||||||
static settings::Bool enable("navbot.enable", "false");
|
static settings::Bool enable("navbot.enable", "false");
|
||||||
|
static settings::Bool spy_mode("navbot.spy-mode", "false");
|
||||||
|
static settings::Bool heavy_mode("navbot.heavy-mode", "false");
|
||||||
static settings::Bool primary_only("navbot.primary-only", "true");
|
static settings::Bool primary_only("navbot.primary-only", "true");
|
||||||
|
|
||||||
bool HasLowAmmo()
|
bool HasLowAmmo()
|
||||||
@ -78,15 +80,40 @@ CachedEntity *nearestAmmo()
|
|||||||
}
|
}
|
||||||
return bestent;
|
return bestent;
|
||||||
}
|
}
|
||||||
|
CachedEntity *NearestEnemy()
|
||||||
|
{
|
||||||
|
float bestscr = FLT_MAX;
|
||||||
|
CachedEntity *bestent = nullptr;
|
||||||
|
for (int i = 0; i < g_IEngine->GetMaxClients(); i++)
|
||||||
|
{
|
||||||
|
CachedEntity *ent = ENTITY(i);
|
||||||
|
if (CE_BAD(ent) || ent->m_Type() != ENTITY_PLAYER)
|
||||||
|
continue;
|
||||||
|
if (ent == LOCAL_E || !ent->m_bAlivePlayer() ||
|
||||||
|
ent->m_iTeam() == LOCAL_E->m_iTeam())
|
||||||
|
continue;
|
||||||
|
float scr = ent->m_flDistance();
|
||||||
|
if (g_pPlayerResource->GetClass(ent) == tf_engineer)
|
||||||
|
scr *= 5.0f;
|
||||||
|
if (g_pPlayerResource->GetClass(ent) == tf_pyro)
|
||||||
|
scr *= 7.0f;
|
||||||
|
if (scr < bestscr)
|
||||||
|
{
|
||||||
|
bestscr = scr;
|
||||||
|
bestent = ent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bestent;
|
||||||
|
}
|
||||||
std::vector<Vector> sniper_spots;
|
std::vector<Vector> sniper_spots;
|
||||||
void Init()
|
void Init()
|
||||||
{
|
{
|
||||||
sniper_spots.clear();
|
sniper_spots.clear();
|
||||||
for (auto area : nav::areas)
|
for (auto area : nav::areas)
|
||||||
for (auto hide : area.m_hidingSpots)
|
for (auto hide : area.m_hidingSpots)
|
||||||
if (hide.IsGoodSniperSpot() || hide.IsIdealSniperSpot() || hide.IsExposed())
|
if (hide.IsGoodSniperSpot() || hide.IsIdealSniperSpot() ||
|
||||||
|
hide.IsExposed())
|
||||||
sniper_spots.push_back(hide.m_pos);
|
sniper_spots.push_back(hide.m_pos);
|
||||||
|
|
||||||
}
|
}
|
||||||
Timer slot_timer{};
|
Timer slot_timer{};
|
||||||
void UpdateSlot()
|
void UpdateSlot()
|
||||||
@ -99,10 +126,13 @@ void UpdateSlot()
|
|||||||
// IsBaseCombatWeapon()
|
// IsBaseCombatWeapon()
|
||||||
if (re::C_BaseCombatWeapon::IsBaseCombatWeapon(weapon))
|
if (re::C_BaseCombatWeapon::IsBaseCombatWeapon(weapon))
|
||||||
{
|
{
|
||||||
int slot = re::C_BaseCombatWeapon::GetSlot(weapon);
|
int slot = re::C_BaseCombatWeapon::GetSlot(weapon);
|
||||||
if (slot != 0)
|
int newslot = 1;
|
||||||
g_IEngine->ClientCmd(format("slot", 1).c_str());
|
if (spy_mode)
|
||||||
|
newslot = 3;
|
||||||
|
if (slot != newslot - 1)
|
||||||
|
g_IEngine->ClientCmd_Unrestricted(
|
||||||
|
format("slot", newslot).c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -115,7 +145,8 @@ void CreateMove()
|
|||||||
return;
|
return;
|
||||||
if (CE_BAD(LOCAL_E) || !LOCAL_E->m_bAlivePlayer())
|
if (CE_BAD(LOCAL_E) || !LOCAL_E->m_bAlivePlayer())
|
||||||
return;
|
return;
|
||||||
UpdateSlot();
|
if (primary_only)
|
||||||
|
UpdateSlot();
|
||||||
if (HasLowHealth() && cdr.test_and_set(5000))
|
if (HasLowHealth() && cdr.test_and_set(5000))
|
||||||
{
|
{
|
||||||
CachedEntity *med = nearestHealth();
|
CachedEntity *med = nearestHealth();
|
||||||
@ -134,21 +165,47 @@ void CreateMove()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!nav::ReadyForCommands)
|
if (!nav::ReadyForCommands && !spy_mode)
|
||||||
cd3.update();
|
cd3.update();
|
||||||
if (nav::ReadyForCommands && cd3.test_and_set(5000))
|
bool isready = (spy_mode || heavy_mode) ? 1 : nav::ReadyForCommands;
|
||||||
|
int waittime = (spy_mode || heavy_mode) ? 100 : 5000;
|
||||||
|
if (isready && cd3.test_and_set(waittime))
|
||||||
{
|
{
|
||||||
Vector random_spot;
|
if (!spy_mode && !heavy_mode)
|
||||||
if (sniper_spots.empty())
|
|
||||||
{
|
{
|
||||||
if (cd2.test_and_set(5000))
|
cd3.update();
|
||||||
Init();
|
Vector random_spot;
|
||||||
return;
|
if (sniper_spots.empty())
|
||||||
|
{
|
||||||
|
if (cd2.test_and_set(5000))
|
||||||
|
Init();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int rng = rand() % sniper_spots.size();
|
||||||
|
random_spot = sniper_spots.at(rng);
|
||||||
|
if (random_spot.z)
|
||||||
|
nav::NavTo(random_spot);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CachedEntity *tar = NearestEnemy();
|
||||||
|
if (CE_BAD(tar))
|
||||||
|
{
|
||||||
|
Vector random_spot;
|
||||||
|
if (sniper_spots.empty())
|
||||||
|
{
|
||||||
|
if (cd2.test_and_set(5000))
|
||||||
|
Init();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int rng = rand() % sniper_spots.size();
|
||||||
|
random_spot = sniper_spots.at(rng);
|
||||||
|
if (random_spot.z)
|
||||||
|
nav::NavTo(random_spot);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
nav::NavTo(tar->m_vecOrigin());
|
||||||
}
|
}
|
||||||
int rng = rand() % sniper_spots.size();
|
|
||||||
random_spot = sniper_spots.at(rng);
|
|
||||||
if (random_spot.z)
|
|
||||||
nav::NavTo(random_spot);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace hacks::tf2::NavBot
|
} // namespace hacks::tf2::NavBot
|
||||||
|
Reference in New Issue
Block a user