@@ -60,78 +60,76 @@ function GameData()
60
60
return data
61
61
end
62
62
63
-
63
+ function GetClosestEnemy (pLocal , pLocalOrigin , players )
64
+ local closestDistance = 1000
65
+ local maxDistance = 1000
66
+ -- find clsoest enemy
67
+ for _ , vPlayer in ipairs (players ) do
68
+ if vPlayer ~= nil and vPlayer :IsAlive () and vPlayer :GetTeamNumber () ~= pLocal :GetTeamNumber () then
69
+ vPlayerOrigin = vPlayer :GetAbsOrigin ()
70
+ local distance = (vPlayerOrigin - pLocalOrigin ):Length ()
71
+ if distance < closestDistance and distance <= maxDistance then
72
+ closestPlayer = vPlayer
73
+ closestDistance = distance
74
+ end
75
+ end
76
+ end
77
+ return closestPlayer
78
+ end
64
79
--[[ Global table of velocity vectors
65
80
local velocitySamples = {}
66
81
local maxSamples = 3 -- maximum number of samples
67
82
local tickrate = 66 -- number of ticks per second
68
-
69
83
-- Returns the future position of a target based on its current position, last position, and a specified time ahead
70
84
function getFuturePosition(targetPosition, targetLastPos, timeAhead)
71
85
-- Calculate the current velocity
72
86
local currentVelocity = (targetPosition - targetLastPos) / tickrate
73
87
-- Add a new velocity sample to the table
74
88
table.insert(velocitySamples, currentVelocity)
75
-
76
89
-- Remove the oldest sample if the number of samples exceeds the limit
77
90
if #velocitySamples > maxSamples then
78
91
table.remove(velocitySamples, 1)
79
92
end
80
-
81
93
-- Calculate the average velocity from the latest samples
82
94
local avgVelocity = nil
83
95
for _, velocity in ipairs(velocitySamples) do
84
96
avgVelocity = avgVelocity + velocity
85
97
end
86
98
avgVelocity = avgVelocity / #velocitySamples
87
-
88
99
-- Calculate the trajectory
89
100
local trajectory = Vector3.new()
90
101
for i = 2, #velocitySamples do
91
102
local prevVelocity = velocitySamples[i - 1]
92
103
local currVelocity = velocitySamples[i]
93
-
94
104
-- Calculate the time difference between the two samples
95
105
local timeDiff = 1 / tickrate
96
-
97
106
-- Calculate the angle between the two velocity vectors
98
107
local angle = math.acos(currVelocity:Dot(prevVelocity) / (currVelocity.Magnitude * prevVelocity.Magnitude))
99
-
100
108
-- Calculate the cross product of the two velocity vectors
101
109
local cross = currVelocity:Cross(prevVelocity)
102
-
103
110
-- Flip the angle if the cross product is negative
104
111
if cross.Z < 0 then
105
112
angle = -angle
106
113
end
107
-
108
114
-- Calculate the curvature of the trajectory
109
115
local curvature = angle / timeDiff
110
-
111
116
-- Calculate the horizontal correction based on the curvature
112
117
local correction = Vector3.new(0, 0, -curvature * 0.25)
113
-
114
118
-- Calculate the lateral vector, which is perpendicular to the forward vector
115
119
local forwardVector = currVelocity.Unit
116
120
local lateralVector = forwardVector:Cross(Vector3.new(0,0,1)).Unit
117
-
118
121
-- Calculate the turn angle between the two velocity vectors
119
122
local turnAngle = math.atan2(forwardVector.Y, forwardVector.X) - math.atan2(prevVelocity.Y, prevVelocity.X)
120
-
121
123
-- Calculate the turn radius and center offset
122
124
local turnRadius = currVelocity.Magnitude / turnAngle
123
125
local turnCenterOffset = lateralVector * turnRadius
124
-
125
126
-- Calculate the horizontal correction based on the turn
126
127
local turnCorrection = Vector3.new(turnCenterOffset.X, turnCenterOffset.Y, 0)
127
-
128
128
-- Add the corrections to the trajectory
129
129
trajectory = trajectory + currVelocity + correction * timeDiff + turnCorrection
130
130
end
131
-
132
131
-- Calculate the future position based on the trajectory and time ahead
133
132
local futurePosition = targetPosition + trajectory * timeAhead
134
-
135
133
return futurePosition
136
134
end]]
137
135
@@ -270,24 +268,12 @@ local function OnCreateMove(pCmd, gameData)
270
268
271
269
-- Initialize closest distance and closest player
272
270
isMelee = pWeapon :IsMeleeWeapon () -- check if using melee weapon
273
- local closestDistance = 1200
274
- local maxDistance = 1000
275
271
local players = entities .FindByClass (" CTFPlayer" ) -- Create a table of all players in the game
276
272
277
273
if not isMelee then return end
278
274
279
- -- find clsoest enemy
280
- for _ , vPlayer in ipairs (players ) do
281
- if vPlayer ~= nil and vPlayer :IsAlive () and vPlayer :GetTeamNumber () ~= pLocal :GetTeamNumber () then
282
- vPlayerOrigin = vPlayer :GetAbsOrigin ()
283
- local distance = (vPlayerOrigin - pLocalOrigin ):Length ()
284
- if distance < closestDistance and distance <= maxDistance then
285
- closestPlayer = vPlayer
286
- closestDistance = distance
287
- end
288
- end
289
- end
290
-
275
+
276
+ closestPlayer = GetClosestEnemy (pLocal , pLocalOrigin , players )
291
277
if closestPlayer == nil then goto continue end
292
278
if closestDistance == 1200 then goto continue end
293
279
vPlayerOrigin = closestPlayer :GetAbsOrigin ()
@@ -303,11 +289,10 @@ if not isMelee then return end
303
289
local stop = false
304
290
if (pLocal :InCond (17 )) and pLocalClass == 4 or pLocalClass == 8 then -- If we are charging (17 is TF_COND_SHIELD_CHARGE)
305
291
stop = true
306
- dynamicstop = swingrange + 15
307
- if (pCmd .forwardmove == 0 ) then dynamicstop = swingrange + 10 end -- case if you dont hold w when charging
292
+ dynamicstop = swingrange + 10
293
+ if (pCmd .forwardmove == 0 ) then dynamicstop = swingrange end -- case if you dont hold w when charging
308
294
309
295
vdistance = (vPlayerFuture - pLocalOrigin ):Length ()
310
- print (vdistance )
311
296
if pLocalClass == 4 and vdistance <= dynamicstop then
312
297
pCmd :SetButtons (pCmd :GetButtons () | IN_ATTACK )
313
298
end
@@ -414,37 +399,29 @@ end
414
399
--[[ czapka
415
400
-- ustawienie rozdzielczości koła
416
401
local resolution = 36
417
-
418
402
-- promień koła
419
403
local radius = 50
420
-
421
404
-- wektor środka koła
422
405
local center = pLocalOrigin
423
-
424
406
-- wektor wysokości ostrosłupa
425
407
local height = Vector3(0, 0, 20)
426
-
427
408
-- inicjalizacja tablicy wierzchołków koła
428
409
local vertices = {}
429
-
430
410
-- wyznaczanie pozycji wierzchołków koła
431
411
for i = 1, resolution do
432
412
local angle = (2 * math.pi / resolution) * (i - 1)
433
413
local x = radius * math.cos(angle)
434
414
local y = radius * math.sin(angle)
435
415
vertices[i] = Vector3(center.x + x, center.y + y)
436
416
end
437
-
438
417
-- rysowanie linii z wierzchołków koła do punktu v2
439
418
for i = 1, resolution do
440
419
draw.line(vertices[i], height + vertices[i])
441
420
end
442
-
443
421
-- rysowanie linii łączących kolejne wierzchołki koła
444
422
for i = 1, resolution do
445
423
draw.line(vertices[i], vertices[(i % resolution) + 1])
446
424
end
447
-
448
425
-- rysowanie linii łączącej ostatni wierzchołek z pierwszym
449
426
draw.line(vertices[resolution], vertices[1])
450
427
]]
0 commit comments