just use timers tf
This commit is contained in:
parent
11505574cd
commit
f734e45344
@ -52,9 +52,9 @@ static CatVar autojump(CV_SWITCH, "fb_autojump", "1", "Autojump",
|
|||||||
"Automatically jump if stuck");
|
"Automatically jump if stuck");
|
||||||
static CatVar afk(CV_SWITCH, "fb_afk", "1", "Switch target if AFK",
|
static CatVar afk(CV_SWITCH, "fb_afk", "1", "Switch target if AFK",
|
||||||
"Automatically switch target if the target is afk");
|
"Automatically switch target if the target is afk");
|
||||||
static CatVar afktime(CV_INT, "fb_afk_time", "990", "Max AFK Time",
|
static CatVar afktime(
|
||||||
"Max ticks (66 * time in seconds) spent standing still "
|
CV_INT, "fb_afk_time", "15000", "Max AFK Time",
|
||||||
"until a player is declared afk.");
|
"Max time in ms spent standing still before player gets declared afk");
|
||||||
|
|
||||||
// Something to store breadcrumbs created by followed players
|
// Something to store breadcrumbs created by followed players
|
||||||
static std::vector<Vector> breadcrumbs;
|
static std::vector<Vector> breadcrumbs;
|
||||||
@ -62,9 +62,10 @@ static const int crumb_limit = 64; // limit
|
|||||||
|
|
||||||
// Followed entity, externed for highlight color
|
// Followed entity, externed for highlight color
|
||||||
int follow_target = 0;
|
int follow_target = 0;
|
||||||
|
bool inited;
|
||||||
|
|
||||||
static long int lasttaunt; //time since epoch when "taunt" was last executed
|
Timer lastTaunt{}; //time since taunt was last executed, used to avoid kicks
|
||||||
std::array<int, 32> afkticks; //for how many createmove ticks the player hasn't been moving
|
std::array<Timer, 32> afkTicks; //for how many ms the player hasn't been moving
|
||||||
|
|
||||||
void checkAFK()
|
void checkAFK()
|
||||||
{
|
{
|
||||||
@ -73,17 +74,22 @@ void checkAFK()
|
|||||||
auto entity = ENTITY(i);
|
auto entity = ENTITY(i);
|
||||||
if (CE_BAD(entity))
|
if (CE_BAD(entity))
|
||||||
continue;
|
continue;
|
||||||
if (CE_VECTOR(entity, netvar.vVelocity).IsZero(5.0f))
|
if (!CE_VECTOR(entity, netvar.vVelocity).IsZero(5.0f))
|
||||||
{
|
{
|
||||||
afkTicks[i] = afkTicks[i] + 1;
|
afkTicks[i].update();
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
afkTicks[i] = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void init()
|
||||||
|
{
|
||||||
|
for (int i; i < afkTicks.size(); i++)
|
||||||
|
{
|
||||||
|
afkTicks[i].update();
|
||||||
|
}
|
||||||
|
inited = true;
|
||||||
|
}
|
||||||
|
|
||||||
void WorldTick()
|
void WorldTick()
|
||||||
{
|
{
|
||||||
if (!followbot)
|
if (!followbot)
|
||||||
@ -91,6 +97,8 @@ void WorldTick()
|
|||||||
follow_target = 0;
|
follow_target = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!inited)
|
||||||
|
init();
|
||||||
|
|
||||||
// We need a local player to control
|
// We need a local player to control
|
||||||
if (CE_BAD(LOCAL_E) || !LOCAL_E->m_bAlivePlayer())
|
if (CE_BAD(LOCAL_E) || !LOCAL_E->m_bAlivePlayer())
|
||||||
@ -157,7 +165,7 @@ void WorldTick()
|
|||||||
continue;
|
continue;
|
||||||
if (entity->m_bEnemy())
|
if (entity->m_bEnemy())
|
||||||
continue;
|
continue;
|
||||||
if (afk && afkTicks[i] >= int(afktime)) //don't follow target that was determined afk
|
if (afk && afkTicks[i].check(int(afktime))) //don't follow target that was determined afk
|
||||||
continue;
|
continue;
|
||||||
if (IsPlayerDisguised(entity) || IsPlayerInvisible(entity))
|
if (IsPlayerDisguised(entity) || IsPlayerInvisible(entity))
|
||||||
continue;
|
continue;
|
||||||
@ -188,7 +196,7 @@ void WorldTick()
|
|||||||
continue;
|
continue;
|
||||||
// ooooo, a target
|
// ooooo, a target
|
||||||
follow_target = i;
|
follow_target = i;
|
||||||
afkTicks[i] = 0; //set afk ticks to 0
|
afkTicks[i].update(); //set afk time to 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// last check for entity before we continue
|
// last check for entity before we continue
|
||||||
@ -208,7 +216,7 @@ void WorldTick()
|
|||||||
//check if target is afk
|
//check if target is afk
|
||||||
if (afk)
|
if (afk)
|
||||||
{
|
{
|
||||||
if (afkTicks[follow_target] >= int(afktime))
|
if (afkTicks[follow_target].check(int(afktime)))
|
||||||
{
|
{
|
||||||
follow_target = 0;
|
follow_target = 0;
|
||||||
return;
|
return;
|
||||||
@ -267,11 +275,8 @@ void WorldTick()
|
|||||||
|
|
||||||
//moved because its worthless otherwise
|
//moved because its worthless otherwise
|
||||||
if (sync_taunt && HasCondition<TFCond_Taunting>(followtar)) {
|
if (sync_taunt && HasCondition<TFCond_Taunting>(followtar)) {
|
||||||
//std::time_t time = std::time(nullptr);
|
if (lastTaunt.test_and_set(1000))
|
||||||
long int t = static_cast<long int> (std::time(nullptr));
|
|
||||||
if (!(t == lasttaunt))
|
|
||||||
{
|
{
|
||||||
lasttaunt = t;
|
|
||||||
g_IEngine->ClientCmd("taunt");
|
g_IEngine->ClientCmd("taunt");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user