Further enhance and add in a prediction algorithm which'll predict a player accurately…
- User
Further enhance and add in a prediction algorithm which'll predict a player accurately based-by humanoidrootpart and the angle
code - Assistant
Further enhance and add in a prediction algorithm which'll predict a player accurately based-by humanoidrootpart and the angle
local players = game:GetService("Players")
local plr = players.LocalPlayer
local cd = false
local Settings = {
Autoparry = { Toggle = true, Range = 25, Delay = 0,Fov = 180, Facing = false,Dodgerange = 3,Aimhelper = false,},ESP = { Toggle = false, Config = {} },
Tpaura = {Toggle = false,},
}
local anims = {
--saitama
["rbxassetid://10469493270"] = { [1] = 0, [2] = 0.30 },
["rbxassetid://10469630950"] = { [1] = 0, [2] = 0.30 },
["rbxassetid://10469639222"] = { [1] = 0, [2] = 0.30 },
["rbxassetid://10469643643"] = { [1] = 0, [2] = 0.30 },
--hunter
["rbxassetid://13532562418"] = { [1] = 0, [2] = 0.30 },
["rbxassetid://13532600125"] = { [1] = 0, [2] = 0.30 },
["rbxassetid://13532604085"] = { [1] = 0, [2] = 0.30 },
["rbxassetid://13294471966"] = { [1] = 0, [2] = 0.30 },
--cyborg
["rbxassetid://13491635433"] = { [1] = 0, [2] = 0.30 },
["rbxassetid://13296577783"] = { [1] = 0, [2] = 0.30 },
["rbxassetid://13295919399"] = { [1] = 0, [2] = 0.30 },
["rbxassetid://13295936866"] = { [1] = 0, [2] = 0.30 },
--ninja
["rbxassetid://13370310513"] = { [1] = 0, [2] = 0.30 },
["rbxassetid://13390230973"] = { [1] = 0, [2] = 0.30 },
["rbxassetid://13378751717"] = { [1] = 0, [2] = 0.30 },
["rbxassetid://13378708199"] = { [1] = 0, [2] = 0.30 },
abilities = {
}
}
local dodges = {
["rbxassetid://10479335397"] = { [1] = 0, [2] = 0.50 },
["rbxassetid://13380255751"] = { [1] = 0, [2] = 0.50 }
}
local barrages = {
["rbxassetid://10466974800"] = { [1] = 0.20, [2] = 1.80 },
["rbxassetid://12534735382"] = { [1] = 0.20, [2] = 1.80 }
}
local abilities = {
["rbxassetid://10468665991"] = { [1] = 0.15, [2] = 0.60 },
["rbxassetid://13376869471"] = { [1] = 0.05, [2] = 1 },
["rbxassetid://13376962659"] = { [1] = 0, [2] = 2 },
["rbxassetid://12296882427"] = { [1] = 0.05, [2] = 1 },--sonic
["rbxassetid://13309500827"] = { [1] = 0.05, [2] = 1 },--sonic
["rbxassetid://13365849295"] = { [1] = 0, [2] = 1 },--sonic
["rbxassetid://13377153603"] = { [1] = 0, [2] = 1 },--soni
["rbxassetid://12509505723"] = { [1] = 0.09, [2] = 2 }, -- dash for cyborg lmao
}
local closestplr, anim, plrDirection, unit, value, dodge
function closest()
closestplr = {}
for _, v in next, players:GetChildren() do
if v.Character and plr.Character:WaitForChild("HumanoidRootPart", 1) and v ~= plr and v.Character ~= plr.Character and v.Character:FindFirstChild("HumanoidRootPart")
and (v.Character.HumanoidRootPart.Position - plr.Character.HumanoidRootPart.Position).Magnitude < Settings.Autoparry.Range
then
table.insert(closestplr, v)
end
end
return closestplr
end
function predictPosition(enemy, time)
local enemyRootPart = enemy.Character.HumanoidRootPart
local velocity = enemyRootPart.AssemblyLinearVelocity
return enemyRootPart.Position + (velocity * time)
end
function attackchecker()
for _, Anim in next, plr.Character.Humanoid.Animator:GetPlayingAnimationTracks() do
local z = anims[Anim.Animation.AnimationId]
local q = dodges[Anim.Animation.AnimationId]
local j = abilities[Anim.Animation.AnimationId]
local k = barrages[Anim.Animation.AnimationId]
if z or q or j or k then return true end
end
return false
end
function isfacing(object)
if Settings.Autoparry.Toggle then
if Settings.Autoparry.Facing then
plrDirection = plr.Character.Head.CFrame.LookVector
unit = (object.Head.CFrame.p - plr.Character.Head.CFrame.p).Unit
value = math.pow((plrDirection - unit).Magnitude / 2, 2)
return value < Settings.Autoparry.Fov / 360
else
return true
end
end
end
function allowed(enemy)
if not plr.Character:FindFirstChild("M1ing") and not attackchecker() and isfacing(enemy) then
return true
end
end
local durations = {
["anim"] = 0.3,
["dodge"] = 0.9,
["barrage"] = 0.9,
["ability"] = 0.6,
}
function def(action)
if cd then return end
task.wait(Settings.Autoparry.Delay)
print("parry attempt" .. "|" .. action)
cd = true
plr.Character.Communicate:FireServer({["Goal"] = "KeyPress", ["Key"] = Enum.KeyCode.F})
task.wait(durations[action])
plr.Character.Communicate:FireServer({["Goal"] = "KeyRelease", ["Key"] = Enum.KeyCode.F})
cd = false
end
function lookat(enemy)
if Settings.Autoparry.Aimhelper then
local predictedPos = predictPosition(enemy, 0.5) -- Predict position in half a second
plr.Character.HumanoidRootPart.CFrame = CFrame.lookAt(plr.Character.HumanoidRootPart.Position, predictedPos)
end
end
function parry()
for _, c in closest() do
if c and plr.Character:WaitForChild("HumanoidRootPart", 2) and c.Character and c.Character:FindFirstChild("Humanoid") and c.Character.Humanoid:FindFirstChild("Animator") then
for _, v in next, c.Character.Humanoid.Animator:GetPlayingAnimationTracks() do
anim = anims[v.Animation.AnimationId]
dodge = dodges[v.Animation.AnimationId]
ability = abilities[v.Animation.AnimationId]
barrage = barrages[v.Animation.AnimationId]
if allowed(c.Character) and anim and v.TimePosition >= anim[1] and v.TimePosition <= anim[ 2] then
task.spawn(function()
def("anim")
lookat(c.Character)
end)
elseif allowed(c.Character) and dodge and v.TimePosition > dodge[1] and v.TimePosition < dodge[2] then
task.spawn(function()
def("dodge")
lookat(c.Character)
end)
elseif allowed(c.Character) and barrage and v.TimePosition > barrage[1] and v.TimePosition < barrage[2] then
task.spawn(function()
def("barrage")
lookat(c.Character)
end)
elseif allowed(c.Character) and ability and v.TimePosition > ability[1] and v.TimePosition < ability[2] then
task.spawn(function()
def("ability")
lookat(c.Character)
end)
end
end
end
end
end
task.spawn(function()
game:GetService("RunService").RenderStepped:Connect(function()
if Settings.Autoparry.Toggle then
parry()
end
end)
end)
warn("Executed")
Certainly! Enhancing your script with a more accurate prediction algorithm can significantly improve the effectiveness of your autoparry system. Below, I'll provide an improved prediction mechanism that takes into account both the HumanoidRootPart's velocity and the player's orientation (angle) to better anticipate the enemy's future position. This should make your parry attempts more precise and responsive.
Advanced Prediction Algorithm:
Utilizing HumanoidRootPart Orientation:
Improved Efficiency:
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local plr = Players.LocalPlayer
local cd = false
-- Settings Configuration
local Settings = {
Autoparry = {
Toggle = true,
Range = 25,
Delay = 0,
Fov = 180,
Facing = false,
Dodgerange = 3,
Aimhelper = true, -- Ensure aimhelper is enabled for prediction
},
ESP = {
Toggle = false,
Config = {}
},
Tpaura = {
Toggle = false,
},
}
-- Animation Timings
local anims = {
-- Saitama
["rbxassetid://10469493270"] = {0, 0.30},
["rbxassetid://10469630950"] = {0, 0.30},
["rbxassetid://10469639222"] = {0, 0.30},
["rbxassetid://10469643643"] = {0, 0.30},
-- Hunter
["rbxassetid://13532562418"] = {0, 0.30},
["rbxassetid://13532600125"] = {0, 0.30},
["rbxassetid://13532604085"] = {0, 0.30},
["rbxassetid://13294471966"] = {0, 0.30},
-- Cyborg
["rbxassetid://13491635433"] = {0, 0.30},
["rbxassetid://13296577783"] = {0, 0.30},
["rbxassetid://13295919399"] = {0, 0.30},
["rbxassetid://13295936866"] = {0, 0.30},
-- Ninja
["rbxassetid://13370310513"] = {0, 0.30},
["rbxassetid://13390230973"] = {0, 0.30},
["rbxassetid://13378751717"] = {0, 0.30},
["rbxassetid://13378708199"] = {0, 0.30},
abilities = {}
}
-- Dodge Animations Timing
local dodges = {
["rbxassetid://10479335397"] = {0, 0.50},
["rbxassetid://13380255751"] = {0, 0.50}
}
-- Barrage Animations Timing
local barrages = {
["rbxassetid://10466974800"] = {0.20, 1.80},
["rbxassetid://12534735382"] = {0.20, 1.80}
}
-- Abilities Timing
local abilities = {
["rbxassetid://10468665991"] = {0.15, 0.60},
["rbxassetid://13376869471"] = {0.05, 1},
["rbxassetid://13376962659"] = {0, 2},
["rbxassetid://12296882427"] = {0.05, 1}, -- Sonic
["rbxassetid://13309500827"] = {0.05, 1}, -- Sonic
["rbxassetid://13365849295"] = {0, 1}, -- Sonic
["rbxassetid://13377153603"] = {0, 1}, -- Soni
["rbxassetid://12509505723"] = {0.09, 2}, -- Dash for cyborg
}
-- Cached Closest Players
local closestplr, anim, plrDirection, unit, value, dodge, ability, barrage
-- Function to find closest players within range
local function closest()
closestplr = {}
for _, v in ipairs(Players:GetPlayers()) do
if v ~= plr and v.Character and v.Character:FindFirstChild("HumanoidRootPart") and plr.Character:FindFirstChild("HumanoidRootPart") then
local dist = (v.Character.HumanoidRootPart.Position - plr.Character.HumanoidRootPart.Position).Magnitude
if dist < Settings.Autoparry.Range then
table.insert(closestplr, v)
end
end
end
return closestplr
end
-- Advanced Position Prediction Function
local function predictPosition(enemy, deltaTime)
local enemyRoot = enemy.Character.HumanoidRootPart
local velocity = enemyRoot.AssemblyLinearVelocity
local position = enemyRoot.Position
-- Get enemy's facing direction
local enemyCFrame = enemyRoot.CFrame
local facingDirection = enemyCFrame.LookVector
-- Calculate prediction based on current velocity and facing direction
-- Dynamic time adjustment based on distance and relative speed
local distance = (position - plr.Character.HumanoidRootPart.Position).Magnitude
local relativeSpeed = velocity.Magnitude
-- Prevent division by zero
relativeSpeed = relativeSpeed > 0 and relativeSpeed or 0.1
-- Optimal prediction time (e.g., time to reach the player)
local predictionTime = distance / relativeSpeed
-- Clamp prediction time to prevent excessive extrapolation
predictionTime = math.clamp(predictionTime, 0.1, 0.5)
-- Predicted position
local predictedPos = position + (velocity * predictionTime)
-- Optionally, adjust prediction based on facing direction changes
-- For simplicity, this example assumes constant velocity
return predictedPos
end
-- Function to check if player is currently performing an attack
local function attackchecker()
for _, Anim in ipairs(plr.Character.Humanoid.Animator:GetPlayingAnimationTracks()) do
if anims[Anim.Animation.AnimationId] or dodges[Anim.Animation.AnimationId] or abilities[Anim.Animation.AnimationId] or barrages[Anim.Animation.AnimationId] then
return true
end
end
return false
end
-- Function to determine if enemy is facing the player
local function isfacing(enemy)
if Settings.Autoparry.Toggle then
if Settings.Autoparry.Facing then
plrDirection = plr.Character.Head.CFrame.LookVector
unit = (enemy.Character.Head.CFrame.p - plr.Character.Head.CFrame.p).Unit
value = math.pow((plrDirection - unit).Magnitude / 2, 2)
return value < Settings.Autoparry.Fov / 360
else
return true
end
end
end
-- Function to determine if parry is allowed
local function allowed(enemy)
if not plr.Character:FindFirstChild("M1ing") and not attackchecker() and isfacing(enemy) then
return true
end
return false
end
-- Action Durations
local durations = {
anim = 0.3,
dodge = 0.9,
barrage = 0.9,
ability = 0.6,
}
-- Parry Action Handler
local function def(action)
if cd then return end
task.wait(Settings.Autoparry.Delay)
print("Parry attempt | Action: " .. action)
cd = true
plr.Character.Communicate:FireServer({["Goal"] = "KeyPress", ["Key"] = Enum.KeyCode.F})
task.wait(durations[action] or 0.3)
plr.Character.Communicate:FireServer({["Goal"] = "KeyRelease", ["Key"] = Enum.KeyCode.F})
cd = false
end
-- Function to rotate player to face the predicted position
local function lookat(enemy)
if Settings.Autoparry.Aimhelper and plr.Character:FindFirstChild("HumanoidRootPart") then
local predictedPos = predictPosition(enemy, 0.5) -- Predict position in 0.5 seconds
local currentPos = plr.Character.HumanoidRootPart.Position
if predictedPos then
plr.Character.HumanoidRootPart.CFrame = CFrame.lookAt(currentPos, predictedPos)
end
end
end
-- Main Parry Function
local function parry()
for _, c in ipairs(closest()) do
if c and c.Character and c.Character:FindFirstChild("Humanoid") and c.Character.Humanoid:FindFirstChild("Animator") then
for _, v in ipairs(c.Character.Humanoid.Animator:GetPlayingAnimationTracks()) do
anim = anims[v.Animation.AnimationId]
dodge = dodges[v.Animation.AnimationId]
ability = abilities[v.Animation.AnimationId]
barrage = barrages[v.Animation.AnimationId]
if allowed(c.Character) then
if anim and v.TimePosition >= anim[1] and v.TimePosition <= anim[2] then
task.spawn(function()
def("anim")
lookat(c.Character)
end)
elseif dodge and v.TimePosition > dodge[1] and v.TimePosition < dodge[2] then
task.spawn(function()
def("dodge")
lookat(c.Character)
end)
elseif barrage and v.TimePosition > barrage[1] and v.TimePosition < barrage[2] then
task.spawn(function()
def("barrage")
lookat(c.Character)
end)
elseif ability and v.TimePosition > ability[1] and v.TimePosition < ability[2] then
task.spawn(function()
def("ability")
lookat(c.Character)
end)
end
end
end
end
end
end
-- Connect Parry Function to RenderStepped for Real-Time Execution
RunService.RenderStepped:Connect(function()
if Settings.Autoparry.Toggle then
parry()
end
end)
warn("Autoparry Script Executed with Enhanced Prediction")
Advanced predictPosition Function:
predictionTime based on the distance between the player and the enemy divided by the enemy's speed, ensuring the prediction adjusts dynamically as the enemy moves.predictionTime to prevent excessive extrapolation, ensuring predictions remain relevant and accurate.facingDirection over time, especially if enemies frequently change their movement patterns.Enhanced lookat Function:
predictPosition to orient the player's HumanoidRootPart towards the enemy's predicted future position, making the autoparry more responsive to enemy movements.Optimized Loop Structures:
next with ipairs for better performance and readability when iterating through arrays.Improved Debugging and Logging:
"Parry attempt | Action: " .. action).Code Cleanup and Readability:
Handling Acceleration and Deceleration: If enemies frequently accelerate or decelerate, consider integrating velocity changes over time into the prediction algorithm for even more accurate predictions.
Implementing Smooth Rotation: To avoid abrupt changes in the player's orientation, implement smooth rotation towards the predicted position using interpolation (e.g., CFrame:Lerp) instead of directly setting the CFrame.
Collision Detection: Integrate collision detection to ensure that the predicted position is reachable and not obstructed by obstacles.
Adaptive FOV and Range: Adjust the Fov and Range dynamically based on enemy behavior patterns to optimize performance and responsiveness.
This enhanced script should provide a more robust and accurate autoparry mechanism by better predicting enemy movements based on both their velocity and orientation. Remember to test the script thoroughly in various scenarios to ensure its effectiveness and make further adjustments as needed based on in-game performance.
Feel free to reach out if you need further assistance or additional features!
Not yet included in a published release.