/
Triggerbot.cpp
57 lines (51 loc) · 1.68 KB
/
Triggerbot.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "Triggerbot.h"
#include "AutoShoot.h"
void Triggerbot::Shoot(SourceEngine::CUserCmd* pCmd)
{
auto pLocal = C_CSPlayer::GetLocalPlayer();
auto ActiveWeapon = pLocal->GetActiveWeapon();
if (!ActiveWeapon) return;
if (!ActiveWeapon->CanFire()) return;
if (ActiveWeapon->IsSniper())
if (!pLocal->IsScoped()) return;
if (ActiveWeapon->IsKnife())
{
Knife(pCmd);
return;
}
pCmd->buttons |= IN_ATTACK;
}
void Triggerbot::Knife(SourceEngine::CUserCmd* pCmd, int ID)
{
auto pLocal = C_CSPlayer::GetLocalPlayer();
int CrosshairID;
if (!ID)
CrosshairID = pLocal->InCross();
else
CrosshairID = ID;
if (!CrosshairID) return;
auto pEntity = static_cast<C_CSPlayer*>(SourceEngine::Interfaces::EntityList()->GetClientEntity(CrosshairID));
if (!Utils::IsViableTarget(pEntity)) return;
float Distance = (pEntity->GetEyePos() - pLocal->GetEyePos()).Length();
if (Distance < 85.6f)
{
SourceEngine::QAngle ClientAngles;
SourceEngine::Interfaces::Engine()->GetViewAngles(ClientAngles);
SourceEngine::Vector LocalYaw = SourceEngine::QAngle(0, ClientAngles.y, 0).Direction();
SourceEngine::Vector EnemyYaw = SourceEngine::QAngle(0, pEntity->GetEyeAngles().y, 0).Direction();
if ((pEntity->GetHealth() <= 55 && Distance < 72.4f) || (LocalYaw.Dot(EnemyYaw) > 0.8 && Distance < 72.4f))
pCmd->buttons |= IN_ATTACK2;
else
pCmd->buttons |= IN_ATTACK;
}
}
void Triggerbot::Think(SourceEngine::CUserCmd* pCmd)
{
auto pLocal = C_CSPlayer::GetLocalPlayer();
if (pLocal->InCross())
{
SourceEngine::IClientEntity* Target = SourceEngine::Interfaces::EntityList()->GetClientEntity(pLocal->InCross());
if (Utils::IsViableTarget(static_cast<C_CSPlayer*>(Target)))
Triggerbot::Shoot(pCmd);
}
}