Skip to content

Commit b68a475

Browse files
v2.6.3
1 parent 00fb901 commit b68a475

File tree

1 file changed

+86
-2
lines changed

1 file changed

+86
-2
lines changed

Hvh_Tools.lua

Lines changed: 86 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ local function GetBestTarget(me, pLocalOrigin, pLocal)
110110
if ValidTarget and (entity:GetPropInt("m_iClass") == 2 or entity:GetPropInt("m_iClass") == 8) then
111111
-- Calculate the distance between the player and the local player
112112
local distance = (entity:GetAbsOrigin() - me:GetAbsOrigin()):Length()
113-
113+
114114
-- If the player is closer than the closest distance so far, set them as the closest player
115115
if distance < closestDistance and distance < 2000 then
116116
closestPlayer = entity
@@ -184,6 +184,7 @@ end
184184

185185
callbacks.Register("FireGameEvent", "exampledamageLogger", damageLogger)
186186

187+
187188
local angleTable = {}
188189

189190
-- initialize angleTable and evaluationTable
@@ -208,6 +209,89 @@ function createAngleTable(Jitter_Min_Real, Jitter_Max_Real, dist)
208209
end
209210
end
210211

212+
function randomizeValue(Jitter_Min_Real, Jitter_Max_Real, dist)
213+
if #angleTable == 0 then
214+
-- if all angles have been used, regenerate the table
215+
createAngleTable(Jitter_Min_Real, Jitter_Max_Real, dist)
216+
end
217+
218+
-- update evaluationTable by 0.1 for each angle every iteration
219+
for i = 1, #evaluationTable do
220+
if evaluationTable[i] > 1 then
221+
evaluationTable[i] = evaluationTable[i] - 0.1
222+
elseif evaluationTable[i] < 1 then
223+
evaluationTable[i] = evaluationTable[i] + 0.1
224+
end
225+
end
226+
227+
228+
229+
230+
-- sort angleTable by evaluationTable in descending order
231+
local sortedTable = {}
232+
for i = 1, #angleTable do
233+
sortedTable[i] = {angle = angleTable[i], evaluation = evaluationTable[i]}
234+
end
235+
table.sort(sortedTable, function(a, b) return a.evaluation > b.evaluation end)
236+
237+
-- find the highest rated angles and randomize between them
238+
local highestRated = {}
239+
local highestRating = sortedTable[1].evaluation
240+
for i = 1, #sortedTable do
241+
if sortedTable[i].evaluation == highestRating then
242+
table.insert(highestRated, sortedTable[i].angle)
243+
else
244+
break
245+
end
246+
end
247+
248+
local randomIndex = math.random(1, #highestRated)
249+
local randomValue = highestRated[randomIndex]
250+
251+
-- update the evaluation of the randomly selected angle to 2.0
252+
for i = 1, #angleTable do
253+
if angleTable[i] == randomValue then
254+
evaluationTable[i] = 1.1
255+
break
256+
end
257+
end
258+
259+
-- remove the randomly selected angle from angleTable and evaluationTable
260+
for i = 1, #angleTable do
261+
if angleTable[i] == randomValue then
262+
table.remove(angleTable, i)
263+
table.remove(evaluationTable, i)
264+
break
265+
end
266+
end
267+
268+
return randomValue
269+
end
270+
271+
--[[local angleTable = {}
272+
273+
-- initialize angleTable and evaluationTable
274+
local evaluationTable = {}
275+
276+
function createAngleTable(Jitter_Min_Real, Jitter_Max_Real, dist)
277+
local numPoints = math.floor((Jitter_Max_Real - Jitter_Min_Real) / dist) + 1
278+
local stepSize = (Jitter_Max_Real - Jitter_Min_Real) / (numPoints - 1)
279+
for i = 1, numPoints do
280+
local angle = Jitter_Min_Real + (i - 1) * stepSize
281+
local evaluation = 1 -- initialize evaluation to 1
282+
if msafe_angles:GetValue() then
283+
if angle ~= 90 and angle ~= -90 and angle ~= 0 and angle ~= 180 then
284+
table.insert(angleTable, angle)
285+
table.insert(evaluationTable, evaluation)
286+
end
287+
else
288+
evaluation = 0
289+
table.insert(angleTable, angle)
290+
table.insert(evaluationTable, evaluation)
291+
end
292+
end
293+
end
294+
211295
function randomizeValue(jitterMin, jitterMax, dist, gotHit)
212296
if #angleTable == 0 then
213297
-- if all angles have been used, regenerate the table
@@ -277,7 +361,7 @@ function randomizeValue(jitterMin, jitterMax, dist, gotHit)
277361
end
278362
279363
return randomValue
280-
end
364+
end]]
281365

282366

283367

0 commit comments

Comments
 (0)