From d6a91320031224b41c76f22d61437c51935c5929 Mon Sep 17 00:00:00 2001 From: TotallyNotElite <1yourexperiment@protonmail.com> Date: Sun, 24 Jun 2018 16:16:41 +0200 Subject: [PATCH] AFK check --- src/hacks/FollowBot.cpp | 37 ++++++++++++++++++++++++++++++++----- src/visual/EffectChams.cpp | 13 +++++-------- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/hacks/FollowBot.cpp b/src/hacks/FollowBot.cpp index 6edd27a7..bd4505f8 100644 --- a/src/hacks/FollowBot.cpp +++ b/src/hacks/FollowBot.cpp @@ -50,10 +50,12 @@ static CatVar always_medigun(CV_SWITCH, "fb_always_medigun", "0", "Always Medigun", "Always use medigun"); static CatVar sync_taunt(CV_SWITCH, "fb_sync_taunt", "0", "Synced taunt", "Taunt when follow target does"); -static CatVar change(CV_SWITCH, "fb_switch", "1", "Change followbot target", +static CatVar change(CV_SWITCH, "fb_switch", "0", "Change followbot target", "Always change roaming target when possible"); static CatVar autojump(CV_SWITCH, "fb_autojump", "1", "Autojump", "Automatically jump if stuck"); +static CatVar afk(CV_SWITCH, "fb_afk", "1", "Switch target if AFK", + "Automatically switch target if the target is afk"); // Something to store breadcrumbs created by followed players static std::vector breadcrumbs; @@ -61,7 +63,10 @@ static const int crumb_limit = 64; // limit // Followed entity, externed for highlight color int follow_target = 0; -long int lasttaunt; + +long int lasttaunt; //time since epoch when "taunt" was last executed +int lasttarget; //target we should not follow again +int tickswasted; //how many createmove ticks we have wasted because a target is afk void WorldTick() { @@ -133,6 +138,8 @@ void WorldTick() continue; if (entity->m_bEnemy()) continue; + if (i == lasttarget) //don't follow target that was determined afk + continue; if (IsPlayerDisguised(entity) || IsPlayerInvisible(entity)) continue; if (!entity->m_bAlivePlayer()) // Dont follow dead players @@ -162,6 +169,7 @@ void WorldTick() continue; // ooooo, a target follow_target = entity->m_IDX; + tickswasted = 0; //set afk ticks to 0 } } // last check for entity before we continue @@ -173,11 +181,31 @@ void WorldTick() if (CE_BAD(followtar)) return; // Check if we are following a disguised/spy - if (IsPlayerDisguised(entity) || IsPlayerInvisible(entity)) + if (IsPlayerDisguised(followtar) || IsPlayerInvisible(followtar)) { follow_target = 0; return; } + //check if player is afk + if (afk) + { + if (CE_VECTOR(followtar, netvar.vVelocity).IsZero(1.0f)) + { + tickswasted = tickswasted + 1; + if (tickswasted >= 990) + { + lasttarget = follow_target; + follow_target = 0; + return; + } + } + else + { + tickswasted = 0; + } + + } + // Update timer on new target static Timer idle_time{}; if (breadcrumbs.empty()) @@ -233,8 +261,7 @@ void WorldTick() if (dist_to_target > (float) follow_distance) { // Check for idle - if (autojump && (idle_time.check(3000) || - (breadcrumbs.size() > 1 && LOCAL_E->m_vecVelocity.IsZero(5.0f)))) + if (autojump && idle_time.check(3000)) g_pUserCmd->buttons |= IN_JUMP; if (idle_time.test_and_set(5000)) { diff --git a/src/visual/EffectChams.cpp b/src/visual/EffectChams.cpp index 02a7da55..eb13fcea 100644 --- a/src/visual/EffectChams.cpp +++ b/src/visual/EffectChams.cpp @@ -222,11 +222,11 @@ rgba_t EffectChams::ChamsColor(IClientEntity *entity) bool EffectChams::ShouldRenderChams(IClientEntity *entity) { + if (!enable) + return false; if (entity->entindex() < 0) return false; CachedEntity *ent = ENTITY(entity->entindex()); - if (CE_BAD(ent)) - return false; if (ent->m_IDX == LOCAL_E->m_IDX && !chamsself) return false; switch (ent->m_Type()) @@ -317,13 +317,9 @@ void EffectChams::RenderChamsRecursive(IClientEntity *entity) } } -void EffectChams::RenderChams(int idx) void EffectChams::RenderChams(IClientEntity *entity) { CMatRenderContextPtr ptr(GET_RENDER_CONTEXT); - IClientEntity *entity = g_IEntityList->GetClientEntity(idx); - if (entity && !entity->IsDormant()) - { if (ShouldRenderChams(entity)) { rgba_t color = ChamsColor(entity); @@ -347,7 +343,6 @@ void EffectChams::RenderChams(IClientEntity *entity) g_IVModelRender->ForcedMaterialOverride(flat ? mat_unlit : mat_lit); RenderChamsRecursive(entity); - } } } } @@ -365,7 +360,9 @@ void EffectChams::Render(int x, int y, int w, int h) BeginRenderChams(); for (int i = 1; i < HIGHEST_ENTITY; i++) { - RenderChams(i); + IClientEntity *entity = g_IEntityList->GetClientEntity(i); + if (!entity || entity->IsDormant() || CE_BAD(ENTITY(i))) + return; RenderChams(entity); } EndRenderChams();