Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local imagePercent = 25
- local imageOffset = 7
- local latencyCompensation = .1
- local minHLead = 0
- local maxHLead = 10
- local minVLead = 0
- local maxVLead = 10
- local increment = 1
- local lobKey = Enum.KeyCode.Z
- local stationaryKey = Enum.KeyCode.LeftControl
- local vLeadUpKey = Enum.KeyCode.KeypadEight
- local vLeadDownKey = Enum.KeyCode.KeypadTwo
- local hLeadUpKey = Enum.KeyCode.KeypadSix
- local hLeadDownKey = Enum.KeyCode.KeypadFour
- local keys = {
- "Y",
- "G",
- "H",
- "J",
- "B",
- "N",
- "M"
- }
- --END\\
- --//CONSTANTS
- local plrs = game:GetService("Players")
- local runservice = game:GetService("RunService")
- local repstorage = game:GetService("ReplicatedStorage")
- local uis = game:GetService("UserInputService")
- local values = repstorage:WaitForChild("Values")
- local status = values:WaitForChild("Status")
- local lp = plrs.LocalPlayer
- local gravity = -28
- local walkspeed = 20
- local text = Text.new()
- text.Visible = true
- text.Size = 25
- text.Color = Color3.new(0, 0.0, 1.0)
- local Utilities = {}; do
- --//MODULE CONSTANTS
- local zero = 1e-9
- local onethird = 1 / 3
- local twotwsevs = 2 / 27
- local thirdpi = math.pi / 3
- --END\\
- local function isZero(num)
- return num < zero and num > -zero
- end
- local function cubicRoot(num)
- return (num > 0 and math.pow(num, onethird)) or (num < 0 and -math.pow(-num, onethird)) or 0
- end
- local function solveQuadric(c0, c1, c2, reftable)
- local p, q, D
- p = c1 / (2 * c0)
- q = c2 / c0
- D = p * p - q
- if isZero(D) then
- reftable[1] = -p
- return 1
- elseif D < 0 then
- return 0
- else
- local sqr = math.sqrt(D)
- reftable[1] = sqr - p
- reftable[2] = -sqr - p
- return 2
- end
- end
- local function solveCubic(c0, c1, c2, c3, reftable)
- local num, sub, A, B, C, sqA, p, q, cbp, D
- A = c1 / c0
- B = c2 / c0
- C = c3 / c0
- sqA = A * A
- p = onethird * (-onethird * sqA + B)
- q = .5 * (twotwsevs * A * sqA - onethird * A * B + C)
- cbp = p * p * p
- D = q * q + cbp
- sub = onethird * A
- if isZero(D) then
- if isZero(q) then
- reftable[1] = 0 - sub
- num = 1
- else
- local u = cubicRoot(-q)
- reftable[1] = 2 * u - sub
- reftable[2] = -u - sub
- num = 2
- end
- elseif D < 0 then
- local phi = onethird * math.acos(-q / math.sqrt(-cbp))
- local t = 2 * math.sqrt(-p)
- reftable[1] = t * math.cos(phi) - sub
- reftable[2] = -t * math.cos(phi + thirdpi) - sub
- reftable[3] = -t * math.cos(phi - thirdpi) - sub
- num = 3
- else
- local sqrD = math.sqrt(D)
- reftable[1] = cubicRoot(sqrD - q) - cubicRoot(sqrD + q) - sub
- num = 1
- end
- return num
- end
- local function solveQuartic(c0, c1, c2, c3, c4, reftable)
- local num, z, u, v, sub, A, B, C, D, sqA, p, q, r
- A = c1 / c0
- B = c2 / c0
- C = c3 / c0
- D = c4 / c0
- sqA = A * A
- p = -.375 * sqA + B
- q = .125 * sqA * A - .5 * A * B + C
- r = -.01171875 * sqA * sqA + .0625 * sqA * B - .25 * A * C + D
- sub = .25 * A
- if isZero(r) then
- num = solveCubic(1, 0, p, q, reftable)
- else
- local holder = {}
- local h, j, k
- solveCubic(1, -.5 * p, -r, .5 * r * p - .125 * q * q, reftable)
- z = reftable[1]
- u = z * z - r
- v = 2 * z - p
- u = (isZero(u) and 0) or (u > 0 and math.sqrt(u)) or nil
- v = (isZero(v) and 0) or (v > 0 and math.sqrt(v)) or nil
- if u == nil or v == nil then return 0 end
- h = 1
- j = q < 0 and -v or v
- k = z - u
- num = solveQuadric(h, j, k, reftable)
- j = -j
- k = z + u
- if num == 0 then
- num = num + solveQuadric(h, j, k, reftable)
- elseif num == 1 then
- num = num + solveQuadric(h, j, k, holder)
- reftable[2] = holder[1]
- reftable[3] = holder[2]
- elseif num == 2 then
- num = num + solveQuadric(h, j, k, holder)
- reftable[3] = holder[1]
- reftable[4] = holder[2]
- end
- end
- if num > 0 then reftable[1] = reftable[1] - sub end
- if num > 1 then reftable[2] = reftable[2] - sub end
- if num > 2 then reftable[3] = reftable[3] - sub end
- if num > 3 then reftable[4] = reftable[4] - sub end
- return num
- end
- local function solveTime(origin, g, speed, jump, target, tvel, islob)
- local diff = target - origin
- local roots = {}
- local c0 = g * g * .25
- local c1 = -tvel.Y * g
- local c2 = tvel:Dot(tvel) - g * diff.Y - speed * speed
- local c3 = 2 * (tvel:Dot(diff) - speed * jump)
- local c4 = diff:Dot(diff) - jump * jump
- local num = solveQuartic(c0, c1, c2, c3, c4, roots)
- if num > 0 then
- local bullet, lob = math.huge, math.huge
- for i, t in ipairs(roots) do
- if t > 0 then
- if t < bullet then
- lob = bullet
- bullet = t
- elseif t < lob then
- lob = t
- end
- end
- end
- return (islob and lob ~= math.huge and lob) or (bullet ~= math.huge and bullet)
- end
- end
- local function timeToTrajectory(origin, g, speed, jump, target, tvel, t)
- return (target - origin + tvel * t - Vector3.new(0, .5 * g * t * t, 0)) / (speed * t + jump)
- end
- local function solveTrajectory(origin, g, speed, jump, target, tvel, islob)
- local t = solveTime(origin, g, speed, jump, target, tvel, islob)
- return t and timeToTrajectory(origin, g, speed, jump, target, tvel, t)
- end
- Utilities.solveTime = solveTime
- Utilities.timeToTrajectory = timeToTrajectory
- Utilities.solveTrajectory = solveTrajectory
- end
- --END\\
- imagePercent = math.clamp(imagePercent / 100, .01, 1)
- imageOffset = Vector3.new(0, imageOffset, 0)
- if not isfolder("keyImages") then error("Missing key image folder") end
- if #keys < 7 then error("Too little keys") end
- local hLead = minHLead
- local vLead = minVLead
- local char = lp.Character
- local football
- local mouseDown
- local images = {}
- local open = {}
- local reserved = {}
- for i, k in ipairs(keys) do
- local path = string.format("keyImages\\%s.png", k)
- if not isfile(path) then error("Missing image: " .. path) end
- local img = Image.new()
- img.Visible = false
- img.Size = img.ImageSize * imagePercent
- img.Data = readfile(path)
- images[k] = img
- end
- local function findFunction(scr)
- local mainFunc
- while not mainFunc do
- local suc, res = pcall(getscriptfunction, scr)
- if suc then
- mainFunc = res
- end
- task.wait()
- end
- for i, v in ipairs(debug.getprotos(mainFunc)) do
- if debug.getinfo(v).name == "onMouseDown" then
- mouseDown = nil
- while not mouseDown do
- local funcs = filtergc("function", {Proto = v})
- for i, v in pairs(funcs) do
- if getfenv(v).script == scr then
- mouseDown = v
- end
- end
- task.wait()
- end
- end
- end
- end
- local function getPower()
- return mouseDown and debug.getupvalue(mouseDown, 11) or 0
- end
- local function getKeyPos(plr, k)
- local hrp = plr.Character and plr.Character.PrimaryPart
- local img = images[k]
- if hrp and img then
- local cam = workspace.CurrentCamera
- if cam then
- local pos, ison = cam:WorldToViewportPoint(hrp.Position + imageOffset)
- if ison then
- return Vector2.new(pos.X, pos.Y) - img.Size / 2
- end
- end
- end
- end
- local function initiateKeys()
- local team = lp.Team
- table.clear(open)
- table.clear(reserved)
- if team and not lp.Neutral then
- local at = 1
- for i, plr in ipairs(team:GetPlayers()) do
- if lp ~= plr then
- reserved[Enum.KeyCode[keys[at]]] = plr
- open[plr] = true
- at = at + 1
- end
- end
- end
- end
- local function onToolAdded(tool)
- if tool.ClassName == "Tool" and tool.Name == "Football" and status.Value == "PrePlay" then
- tool:WaitForChild("Handle"):WaitForChild("RemoteEvent")
- tool.Handle:WaitForChild("LocalScript")
- findFunction(tool.Handle.LocalScript)
- initiateKeys()
- football = tool
- end
- end
- local function onCharacterAdded(c)
- char = c
- char.ChildAdded:Connect(onToolAdded)
- end
- if char then
- onCharacterAdded(char)
- end
- lp.CharacterAdded:Connect(onCharacterAdded)
- runservice.Heartbeat:Connect(function()
- for plr, v in pairs(open) do
- local hrp = plr.Character and plr.Character.PrimaryPart
- local origin = char and char:FindFirstChild("Head") and char.Head.Position
- if football and football.Parent == char and hrp and origin then
- local hvel = Vector3.new(hrp.Velocity.X, 0, hrp.Velocity.Z)
- local vel = (uis:IsKeyDown(stationaryKey) or hvel.Magnitude == 0) and Vector3.zero or hvel.Unit * walkspeed
- local tpos = hrp.Position + (hvel * latencyCompensation) + (vel.Magnitude == 0 and vel or vel.Unit * hLead) + Vector3.new(0, vLead, 0)
- open[plr] = Utilities.solveTime(origin, gravity, getPower(), 5, tpos, vel, uis:IsKeyDown(lobKey)) and true or false
- continue
- end
- open[plr] = false
- end
- end)
- runservice.RenderStepped:Connect(function()
- local cam = workspace.CurrentCamera
- if cam then
- text.Text = "HLead: " .. hLead .. "\nVLead: " .. vLead
- text.Position = cam.ViewportSize - text.TextBounds
- end
- for i, key in ipairs(keys) do
- local plr = reserved[Enum.KeyCode[key]]
- local img = images[key]
- if open[plr] then
- local pos = getKeyPos(plr, key)
- if pos then
- img.Position = pos
- img.Size = img.ImageSize * imagePercent
- img.Visible = true
- continue
- end
- end
- img.Visible = false
- end
- end)
- uis.InputBegan:Connect(function(what, proc)
- if not proc then
- local kc = what.KeyCode
- if kc == vLeadUpKey or kc == vLeadDownKey then
- vLead = math.clamp(vLead + (kc == vLeadUpKey and increment or -increment), minVLead, maxVLead)
- return
- end
- if kc == hLeadUpKey or kc == hLeadDownKey then
- hLead = math.clamp(hLead + (kc == hLeadUpKey and increment or -increment), minHLead, maxHLead)
- return
- end
- local plr = reserved[kc]
- if not plr then return end
- local origin = char and char:FindFirstChild("Head") and char.Head.Position
- local hrp = plr.Character and plr.Character.PrimaryPart
- if open[plr] and origin and hrp then
- local pow = getPower()
- local hvel = Vector3.new(hrp.Velocity.X, 0, hrp.Velocity.Z)
- local vel = (uis:IsKeyDown(stationaryKey) or hvel.Magnitude == 0) and Vector3.zero or hvel.Unit * walkspeed
- local tpos = hrp.Position + (hvel * latencyCompensation) + (vel.Magnitude == 0 and vel or vel.Unit * hLead) + Vector3.new(0, vLead, 0)
- local traj = Utilities.solveTrajectory(origin, gravity, pow, 5, tpos, vel, uis:IsKeyDown(lobKey))
- if traj then
- football.Handle.RemoteEvent:FireServer("Clicked", origin, origin + traj * 10000, pow, 60)
- end
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement