Skip to content

Commit 371d0e1

Browse files
Add files via upload
1 parent 1f8b3f3 commit 371d0e1

File tree

1 file changed

+160
-101
lines changed

1 file changed

+160
-101
lines changed

A_Swing_Prediction.lua

Lines changed: 160 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,26 @@ local Menu = {
6363
},
6464
Visuals = {
6565
EnableVisuals = false,
66-
RangeCircle = true,
67-
Visualization = true,
6866
Sphere = false,
67+
Section = 1,
68+
Sections = {"Local", "Target", "Experimental"},
69+
Local = {
70+
RangeCircle = true,
71+
path = {
72+
enable = true,
73+
Color = { 255, 255, 255, 255 },
74+
Styles = {"Pavement", "ArrowPath", "Arrows", "L Line" , "dashed", "line"},
75+
Style = 1,
76+
},
77+
},
78+
Target = {
79+
path = {
80+
enable = true,
81+
Color = { 255, 255, 255, 255 },
82+
Styles = {"Pavement", "ArrowPath", "Arrows", "L Line" , "dashed", "line"},
83+
Style = 1,
84+
},
85+
},
6986
},
7087
Misc = {
7188
ChargeControl = true,
@@ -485,8 +502,6 @@ end
485502
local inaccuracyValue = inaccuracy[vPlayer:GetIndex()]
486503
if not inaccuracyValue then return nil end
487504

488-
print(inaccuracyValue)
489-
490505
local hitbox_min_trigger = Vector3(drawVhitbox[1].x + inaccuracyValue, drawVhitbox[1].y + inaccuracyValue, drawVhitbox[1].z)
491506
local hitbox_max_trigger = Vector3(drawVhitbox[2].x - inaccuracyValue, drawVhitbox[2].y - inaccuracyValue, drawVhitbox[2].z)
492507

@@ -1029,26 +1044,11 @@ if not (engine.Con_IsVisible() or engine.IsGameUIVisible()) then
10291044
--local pLocal = entities.GetLocalPlayer()
10301045
pWeapon = pLocal:GetPropEntity("m_hActiveWeapon") -- Set "pWeapon" to the local player's active weapon
10311046
if Menu.Visuals.EnableVisuals or pWeapon:IsMeleeWeapon() and pLocal and pLocal:IsAlive() then
1032-
draw.Color( 255, 255, 255, 255 )
1033-
local w, h = draw.GetScreenSize()
1034-
-- Strafe prediction visualization
1035-
if Menu.Visuals.Visualization then
1036-
if Menu.Visuals.RangeCircle and pLocalFuture then
1047+
draw.Color( 255, 255, 255, 255 )
1048+
local w, h = draw.GetScreenSize()
1049+
if Menu.Visuals.Local.RangeCircle and pLocalFuture then
10371050
draw.Color(255, 255, 255, 255)
10381051

1039-
-- Draw lines between the predicted positions
1040-
for i = 1, #pLocalPath - 1 do
1041-
local pos1 = pLocalPath[i]
1042-
local pos2 = pLocalPath[i + 1]
1043-
1044-
local screenPos1 = client.WorldToScreen(pos1)
1045-
local screenPos2 = client.WorldToScreen(pos2)
1046-
1047-
if screenPos1 ~= nil and screenPos2 ~= nil then
1048-
draw.Line(screenPos1[1], screenPos1[2], screenPos2[1], screenPos2[2])
1049-
end
1050-
end
1051-
10521052
local center = pLocalFuture - Vheight -- Center of the circle at the player's feet
10531053
local viewPos = pLocalOrigin -- View position to shoot traces from
10541054
local radius = Menu.Misc.ChargeReach and Charge_Range or swingrange -- Radius of the circle
@@ -1081,86 +1081,126 @@ if not (engine.Con_IsVisible() or engine.IsGameUIVisible()) then
10811081
draw.Line(vertices[i][1], vertices[i][2], vertices[j][1], vertices[j][2])
10821082
end
10831083
end
1084-
end
1085-
---------------------------------------------------------sphere
1086-
if Menu.Visuals.Sphere then
1087-
-- Function to draw the sphere
1088-
local function draw_sphere()
1089-
local playerYaw = engine.GetViewAngles().yaw
1090-
local cos_yaw = math.cos(math.rad(playerYaw))
1091-
local sin_yaw = math.sin(math.rad(playerYaw))
1092-
1093-
local playerForward = Vector3(-cos_yaw, -sin_yaw, 0) -- Forward vector based on player's yaw
1094-
1095-
for _, vertex in ipairs(sphere_cache.vertices) do
1096-
local rotated_vertex1 = Vector3(-vertex[1].x * cos_yaw + vertex[1].y * sin_yaw, -vertex[1].x * sin_yaw - vertex[1].y * cos_yaw, vertex[1].z)
1097-
local rotated_vertex2 = Vector3(-vertex[2].x * cos_yaw + vertex[2].y * sin_yaw, -vertex[2].x * sin_yaw - vertex[2].y * cos_yaw, vertex[2].z)
1098-
local rotated_vertex3 = Vector3(-vertex[3].x * cos_yaw + vertex[3].y * sin_yaw, -vertex[3].x * sin_yaw - vertex[3].y * cos_yaw, vertex[3].z)
1099-
local rotated_vertex4 = Vector3(-vertex[4].x * cos_yaw + vertex[4].y * sin_yaw, -vertex[4].x * sin_yaw - vertex[4].y * cos_yaw, vertex[4].z)
1100-
1101-
local worldPos1 = sphere_cache.center + rotated_vertex1 * sphere_cache.radius
1102-
local worldPos2 = sphere_cache.center + rotated_vertex2 * sphere_cache.radius
1103-
local worldPos3 = sphere_cache.center + rotated_vertex3 * sphere_cache.radius
1104-
local worldPos4 = sphere_cache.center + rotated_vertex4 * sphere_cache.radius
1105-
1106-
-- Trace from the center to the vertices with a hull size of 18x18
1107-
local hullSize = Vector3(18, 18, 18)
1108-
local trace1 = engine.TraceHull(sphere_cache.center, worldPos1, -hullSize, hullSize, MASK_SHOT_HULL)
1109-
local trace2 = engine.TraceHull(sphere_cache.center, worldPos2, -hullSize, hullSize, MASK_SHOT_HULL)
1110-
local trace3 = engine.TraceHull(sphere_cache.center, worldPos3, -hullSize, hullSize, MASK_SHOT_HULL)
1111-
local trace4 = engine.TraceHull(sphere_cache.center, worldPos4, -hullSize, hullSize, MASK_SHOT_HULL)
1112-
1113-
local endPos1 = trace1.fraction < 1.0 and trace1.endpos or worldPos1
1114-
local endPos2 = trace2.fraction < 1.0 and trace2.endpos or worldPos2
1115-
local endPos3 = trace3.fraction < 1.0 and trace3.endpos or worldPos3
1116-
local endPos4 = trace4.fraction < 1.0 and trace4.endpos or worldPos4
1117-
1118-
local screenPos1 = client.WorldToScreen(endPos1)
1119-
local screenPos2 = client.WorldToScreen(endPos2)
1120-
local screenPos3 = client.WorldToScreen(endPos3)
1121-
local screenPos4 = client.WorldToScreen(endPos4)
1122-
1123-
-- Calculate normal vector of the square
1124-
local normal = Normalize(rotated_vertex2 - rotated_vertex1):Cross(rotated_vertex3 - rotated_vertex1)
1125-
1126-
-- Draw square only if its normal faces towards the player
1127-
if normal:Dot(playerForward) > 0.1 then
1128-
if screenPos1 and screenPos2 and screenPos3 and screenPos4 then
1129-
-- Draw the square
1130-
drawPolygon({screenPos1, screenPos2, screenPos3, screenPos4})
1131-
1132-
-- Optionally, draw lines between the vertices of the square for wireframe visualization
1133-
draw.Color(255, 255, 255, 25) -- Set color and alpha for lines
1134-
draw.Line(screenPos1[1], screenPos1[2], screenPos2[1], screenPos2[2])
1135-
draw.Line(screenPos2[1], screenPos2[2], screenPos3[1], screenPos3[2])
1136-
draw.Line(screenPos3[1], screenPos3[2], screenPos4[1], screenPos4[2])
1137-
draw.Line(screenPos4[1], screenPos4[2], screenPos1[1], screenPos1[2])
1138-
end
1139-
end
11401084
end
1141-
end
1142-
1143-
-- Example draw call
1144-
sphere_cache.center = pLocalOrigin -- Replace with actual player origin
1145-
sphere_cache.radius = swingrange -- Replace with actual swing range value
1146-
draw_sphere()
1147-
end
1148-
1085+
if Menu.Visuals.Local.path.enable and pLocalFuture then
1086+
-- Draw lines between the predicted positions
1087+
for i = 1, #pLocalPath - 1 do
1088+
local pos1 = pLocalPath[i]
1089+
local pos2 = pLocalPath[i + 1]
1090+
1091+
local screenPos1 = client.WorldToScreen(pos1)
1092+
local screenPos2 = client.WorldToScreen(pos2)
1093+
1094+
if screenPos1 ~= nil and screenPos2 ~= nil then
1095+
draw.Line(screenPos1[1], screenPos1[2], screenPos2[1], screenPos2[2])
1096+
end
1097+
end
1098+
end
1099+
---------------------------------------------------------sphere
1100+
if Menu.Visuals.Sphere then
1101+
-- Function to draw the sphere
1102+
local function draw_sphere()
1103+
local playerYaw = engine.GetViewAngles().yaw
1104+
local cos_yaw = math.cos(math.rad(playerYaw))
1105+
local sin_yaw = math.sin(math.rad(playerYaw))
1106+
1107+
local playerForward = Vector3(-cos_yaw, -sin_yaw, 0) -- Forward vector based on player's yaw
1108+
1109+
for _, vertex in ipairs(sphere_cache.vertices) do
1110+
local rotated_vertex1 = Vector3(-vertex[1].x * cos_yaw + vertex[1].y * sin_yaw, -vertex[1].x * sin_yaw - vertex[1].y * cos_yaw, vertex[1].z)
1111+
local rotated_vertex2 = Vector3(-vertex[2].x * cos_yaw + vertex[2].y * sin_yaw, -vertex[2].x * sin_yaw - vertex[2].y * cos_yaw, vertex[2].z)
1112+
local rotated_vertex3 = Vector3(-vertex[3].x * cos_yaw + vertex[3].y * sin_yaw, -vertex[3].x * sin_yaw - vertex[3].y * cos_yaw, vertex[3].z)
1113+
local rotated_vertex4 = Vector3(-vertex[4].x * cos_yaw + vertex[4].y * sin_yaw, -vertex[4].x * sin_yaw - vertex[4].y * cos_yaw, vertex[4].z)
1114+
1115+
local worldPos1 = sphere_cache.center + rotated_vertex1 * sphere_cache.radius
1116+
local worldPos2 = sphere_cache.center + rotated_vertex2 * sphere_cache.radius
1117+
local worldPos3 = sphere_cache.center + rotated_vertex3 * sphere_cache.radius
1118+
local worldPos4 = sphere_cache.center + rotated_vertex4 * sphere_cache.radius
1119+
1120+
-- Trace from the center to the vertices with a hull size of 18x18
1121+
local hullSize = Vector3(18, 18, 18)
1122+
local trace1 = engine.TraceHull(sphere_cache.center, worldPos1, -hullSize, hullSize, MASK_SHOT_HULL)
1123+
local trace2 = engine.TraceHull(sphere_cache.center, worldPos2, -hullSize, hullSize, MASK_SHOT_HULL)
1124+
local trace3 = engine.TraceHull(sphere_cache.center, worldPos3, -hullSize, hullSize, MASK_SHOT_HULL)
1125+
local trace4 = engine.TraceHull(sphere_cache.center, worldPos4, -hullSize, hullSize, MASK_SHOT_HULL)
1126+
1127+
local endPos1 = trace1.fraction < 1.0 and trace1.endpos or worldPos1
1128+
local endPos2 = trace2.fraction < 1.0 and trace2.endpos or worldPos2
1129+
local endPos3 = trace3.fraction < 1.0 and trace3.endpos or worldPos3
1130+
local endPos4 = trace4.fraction < 1.0 and trace4.endpos or worldPos4
1131+
1132+
local screenPos1 = client.WorldToScreen(endPos1)
1133+
local screenPos2 = client.WorldToScreen(endPos2)
1134+
local screenPos3 = client.WorldToScreen(endPos3)
1135+
local screenPos4 = client.WorldToScreen(endPos4)
1136+
1137+
-- Calculate normal vector of the square
1138+
local normal = Normalize(rotated_vertex2 - rotated_vertex1):Cross(rotated_vertex3 - rotated_vertex1)
1139+
1140+
-- Draw square only if its normal faces towards the player
1141+
if normal:Dot(playerForward) > 0.1 then
1142+
if screenPos1 and screenPos2 and screenPos3 and screenPos4 then
1143+
-- Draw the square
1144+
drawPolygon({screenPos1, screenPos2, screenPos3, screenPos4})
1145+
1146+
-- Optionally, draw lines between the vertices of the square for wireframe visualization
1147+
draw.Color(255, 255, 255, 25) -- Set color and alpha for lines
1148+
draw.Line(screenPos1[1], screenPos1[2], screenPos2[1], screenPos2[2])
1149+
draw.Line(screenPos2[1], screenPos2[2], screenPos3[1], screenPos3[2])
1150+
draw.Line(screenPos3[1], screenPos3[2], screenPos4[1], screenPos4[2])
1151+
draw.Line(screenPos4[1], screenPos4[2], screenPos1[1], screenPos1[2])
1152+
end
1153+
end
1154+
end
1155+
end
11491156

1157+
-- Example draw call
1158+
sphere_cache.center = pLocalOrigin -- Replace with actual player origin
1159+
sphere_cache.radius = swingrange -- Replace with actual swing range value
1160+
draw_sphere()
1161+
end
11501162

11511163
-- enemy
11521164
if vPlayerFuture then
11531165

11541166
-- Draw lines between the predicted positions
1155-
for i = 1, #vPlayerPath - 1 do
1156-
local pos1 = vPlayerPath[i]
1157-
local pos2 = vPlayerPath[i + 1]
1158-
1159-
local screenPos3 = client.WorldToScreen(pos1)
1160-
local screenPos4 = client.WorldToScreen(pos2)
1161-
1162-
if screenPos3 ~= nil and screenPos4 ~= nil then
1163-
draw.Line(screenPos3[1], screenPos3[2], screenPos4[1], screenPos4[2])
1167+
if Menu.Visuals.Target.path.enable then
1168+
if style == 1 then
1169+
-- Draw a double L line in both directions
1170+
for i = 1, #vPlayerPath - 1 do
1171+
local pos1 = vPlayerPath[i]
1172+
local pos2 = vPlayerPath[i + 1]
1173+
1174+
-- Draw the left side of the L line
1175+
draw.Line(pos1[1], pos1[2], pos2[1], pos2[2])
1176+
-- Draw the right side of the L line
1177+
draw.Line(pos1[1] + 1, pos1[2] + 1, pos2[1] + 1, pos2[2] + 1)
1178+
end
1179+
elseif style == 2 then
1180+
-- Draw the path with arrows
1181+
-- ...
1182+
elseif style == 3 then
1183+
-- Draw arrows
1184+
-- ...
1185+
elseif style == 4 then
1186+
-- Draw an L line
1187+
-- ...
1188+
elseif style == 5 then
1189+
-- Draw a dashed line
1190+
-- ...
1191+
elseif style == 6 then
1192+
-- Draw a line
1193+
for i = 1, #vPlayerPath - 1 do
1194+
local pos1 = vPlayerPath[i]
1195+
local pos2 = vPlayerPath[i + 1]
1196+
1197+
local screenPos3 = client.WorldToScreen(pos1)
1198+
local screenPos4 = client.WorldToScreen(pos2)
1199+
1200+
if screenPos3 ~= nil and screenPos4 ~= nil then
1201+
draw.Line(screenPos3[1], screenPos3[2], screenPos4[1], screenPos4[2])
1202+
end
1203+
end
11641204
end
11651205
end
11661206

@@ -1216,9 +1256,9 @@ end
12161256
draw.Line(vertices[4][1], vertices[4][2], vertices[8][1], vertices[8][2])
12171257
end
12181258
end
1219-
end
12201259
end
12211260
end
1261+
12221262
-- Inside your OnCreateMove or similar function where you check for input
12231263
if input.IsButtonDown(KEY_INSERT) then -- Replace 72 with the actual key code for the button you want to use
12241264
toggleMenu()
@@ -1289,14 +1329,33 @@ end
12891329
ImMenu.EndFrame()
12901330

12911331
ImMenu.BeginFrame(1)
1332+
Menu.Visuals.Section = ImMenu.Option(Menu.Visuals.Section, Menu.Visuals.Sections)
1333+
ImMenu.EndFrame()
1334+
1335+
if Menu.Visuals.Section == 1 then
1336+
Menu.Visuals.Local.RangeCircle = ImMenu.Checkbox("Range Circle", Menu.Visuals.Local.RangeCircle)
1337+
Menu.Visuals.Local.path.enable = ImMenu.Checkbox("Local Path", Menu.Visuals.Local.path.enable)
1338+
--Menu.Visuals.Local.path.style = ImMenu.Option(Menu.Visuals.Local.path.style, Menu.Visuals.Local.path.Styles)
1339+
end
1340+
1341+
if Menu.Visuals.Section == 2 then
1342+
Menu.Visuals.Target.path.enable = ImMenu.Checkbox("Target Path", Menu.Visuals.Target.path.enable)
1343+
--Menu.Visuals.Target.path.style = ImMenu.Option(Menu.Visuals.Target.path.style, Menu.Visuals.Target.path.Styles)
1344+
end
1345+
1346+
if Menu.Visuals.Section == 3 then
1347+
ImMenu.BeginFrame(1)
1348+
ImMenu.Text("Experimental")
1349+
Menu.Visuals.Sphere = ImMenu.Checkbox("Range Shield", Menu.Visuals.Sphere)
1350+
ImMenu.EndFrame()
1351+
end
1352+
1353+
--[[ImMenu.BeginFrame(1)
12921354
Menu.Visuals.Visualization = ImMenu.Checkbox("Visualization", Menu.Visuals.Visualization)
12931355
Menu.Visuals.RangeCircle = ImMenu.Checkbox("Range Circle", Menu.Visuals.RangeCircle)
1294-
ImMenu.EndFrame()
1356+
ImMenu.EndFrame()]]
1357+
12951358

1296-
ImMenu.BeginFrame(1)
1297-
ImMenu.Text("Experimental")
1298-
Menu.Visuals.Sphere = ImMenu.Checkbox("Range Sphere", Menu.Visuals.Sphere)
1299-
ImMenu.EndFrame()
13001359
end
13011360
ImMenu.End()
13021361
end

0 commit comments

Comments
 (0)