forked from ztxs/Aimware-v5-luas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Blockbot.lua
134 lines (118 loc) · 5.85 KB
/
Blockbot.lua
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
-- * Useful functions
local function round(n, d)
local p = 10^d
return math.floor(n*p)/p
end
local function cap(x, min, max)
if x < min then
return min
elseif x > max then
return max
end
return x
end
-- * Register Menu
local GriefReference = gui.Reference("MISC")
local GriefMenuTab = gui.Tab(GriefReference, "griefmenu.tab", "Griefing")
-- Blockbot groupbox
local GriefBlockbotGroupbox = gui.Groupbox(GriefMenuTab, "Blockbot", 15, 15, 200, 100)
BlockbotEnable = gui.Checkbox(GriefBlockbotGroupbox, BlockbotEnable, "Enable", true)
BlockbotKey = gui.Keybox(GriefBlockbotGroupbox, "blockbot.key", "Key", 0)
BlockbotRetreatBhop = gui.Checkbox(GriefBlockbotGroupbox, BlockbotRetreatBhop, "Retreat on Bhop", 0)
BlockbotRetreatSpeed = gui.Slider(GriefBlockbotGroupbox, BlockbotRetreatSpeed, "Retreat Speed", 285.0, 50.0, 300.0)
-- * Blockbot
local BlockbotIconFont = draw.CreateFont("Veranda", 64, 64)
local BlockbotTextFont = draw.CreateFont("Veranda", 24, 24)
local BlockbotTarget = nil
local BlockbotCrouchBlock = false
local BlockbotLocalPlayer = nil
local function BlockbotOnFrameMain()
if BlockbotEnable:GetValue() == false then
return
end
BlockbotLocalPlayer = entities.GetLocalPlayer()
if BlockbotLocalPlayer == nil or engine.GetServerIP() == nil then
return
end
if (BlockbotKey:GetValue() == nil or BlockbotKey:GetValue() == 0) or not BlockbotLocalPlayer:IsAlive() then
return
end
if input.IsButtonDown(BlockbotKey:GetValue()) and BlockbotTarget == nil then
for Index, Entity in pairs(entities.FindByClass("CCSPlayer")) do
if Entity:GetIndex() ~= BlockbotLocalPlayer:GetIndex() and Entity:IsAlive() then
if BlockbotTarget == nil then
BlockbotTarget = Entity;
elseif (BlockbotLocalPlayer:GetAbsOrigin() - BlockbotTarget:GetAbsOrigin()):Length() > (BlockbotLocalPlayer:GetAbsOrigin() - Entity:GetAbsOrigin()):Length() then
BlockbotTarget = Entity;
end
end
end
elseif not input.IsButtonDown(BlockbotKey:GetValue()) or not BlockbotTarget:IsAlive() then
BlockbotTarget = nil
end
if BlockbotTarget ~= nil then
local TargetPos = BlockbotTarget:GetBonePosition(5)
local PosX, PosY = client.WorldToScreen(TargetPos)
if PosX ~= nil and PosY ~= nil then
-- Indicator
if BlockbotTarget:GetHitboxPosition(0).z < BlockbotLocalPlayer:GetAbsOrigin().z and vector.Distance({BlockbotLocalPlayer:GetAbsOrigin()}, {BlockbotTarget:GetAbsOrigin()}) < 100 then
BlockbotCrouchBlock = true
draw.Color(255, 255, 0, 255)
else
BlockbotCrouchBlock = false
draw.Color(255, 0, 0, 255)
end
draw.SetFont(BlockbotIconFont)
local IconSizeW, IconSizeH = draw.GetTextSize("X")
draw.TextShadow(PosX - IconSizeW / 2, PosY, "X")
-- Distance
local Diff = BlockbotLocalPlayer:GetAbsOrigin() - BlockbotTarget:GetAbsOrigin()
local Distance = tostring( round(Diff:Length(), 1) )
draw.Color(64, 255, 64, 255)
draw.SetFont(BlockbotTextFont)
local DistanceSizeW, DistanceSizeH = draw.GetTextSize(Distance)
draw.TextShadow(PosX - DistanceSizeW / 2, PosY + IconSizeH*5/4, Distance)
-- Velocity
local TargetSpeed = vector.Length(BlockbotTarget:GetPropFloat("localdata", "m_vecVelocity[0]"), BlockbotTarget:GetPropFloat("localdata", "m_vecVelocity[1]"), BlockbotTarget:GetPropFloat("localdata", "m_vecVelocity[2]"))
draw.Color(64, 64, 255, 255)
if TargetSpeed > BlockbotRetreatSpeed:GetValue() and BlockbotRetreatBhop:GetValue() then
draw.Color(255, 255, 64, 255)
end
local SpeedStr = tostring(round(TargetSpeed, 1))
local SpeedSizeW, SpeedSizeH = draw.GetTextSize(SpeedStr)
draw.TextShadow(PosX - SpeedSizeW / 2, PosY - IconSizeH*2/4, SpeedStr)
end
end
end
local function BlockbotOnCreateMoveMain(UserCmd)
if BlockbotEnable:GetValue() == false then
return
end
if BlockbotTarget ~= nil then
local LocalAngles = UserCmd:GetViewAngles()
local VecForward = BlockbotTarget:GetAbsOrigin() - BlockbotLocalPlayer:GetAbsOrigin()
local AimAngles = VecForward:Angles()
local TargetSpeed = vector.Length(BlockbotTarget:GetPropFloat("localdata", "m_vecVelocity[0]"), BlockbotTarget:GetPropFloat("localdata", "m_vecVelocity[1]"), BlockbotTarget:GetPropFloat("localdata", "m_vecVelocity[2]"))
if BlockbotCrouchBlock == true then
UserCmd.forwardmove = cap( ((math.sin(math.rad(LocalAngles.y) ) * VecForward.y) + (math.cos(math.rad(LocalAngles.y) ) * VecForward.x)) * 450, -450, 450)
UserCmd.sidemove = cap( ((math.cos(math.rad(LocalAngles.y) ) * -VecForward.y) + (math.sin(math.rad(LocalAngles.y) ) * VecForward.x)) * 450, -450, 450)
else
local DiffYaw = AimAngles.y - LocalAngles.y
if DiffYaw > 180 then
DiffYaw = DiffYaw - 360
elseif DiffYaw < -180 then
DiffYaw = DiffYaw + 360
end
if TargetSpeed > BlockbotRetreatSpeed:GetValue() and BlockbotRetreatBhop:GetValue() then
UserCmd.forwardmove = -math.abs(TargetSpeed)
end
if DiffYaw > 0.25 then
UserCmd.sidemove = -450
elseif DiffYaw < -0.25 then
UserCmd.sidemove = 450
end
end
end
end
callbacks.Register("Draw", BlockbotOnFrameMain)
callbacks.Register("CreateMove", BlockbotOnCreateMoveMain)