Advertisement
magnetos

FF

Mar 11th, 2023
963
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.97 KB | None | 0 0
  1. local imagePercent = 25
  2. local imageOffset = 7
  3. local latencyCompensation = .1
  4.  
  5. local minHLead = 0
  6. local maxHLead = 10
  7.  
  8. local minVLead = 0
  9. local maxVLead = 10
  10.  
  11. local increment = 1
  12.  
  13. local lobKey = Enum.KeyCode.Z
  14. local stationaryKey = Enum.KeyCode.LeftControl
  15.  
  16. local vLeadUpKey = Enum.KeyCode.KeypadEight
  17. local vLeadDownKey = Enum.KeyCode.KeypadTwo
  18.  
  19. local hLeadUpKey = Enum.KeyCode.KeypadSix
  20. local hLeadDownKey = Enum.KeyCode.KeypadFour
  21.  
  22. local keys = {
  23.    "Y",
  24.    "G",
  25.    "H",
  26.    "J",
  27.    "B",
  28.    "N",
  29.    "M"
  30. }
  31. --END\\
  32.  
  33. --//CONSTANTS
  34. local plrs = game:GetService("Players")
  35. local runservice = game:GetService("RunService")
  36. local repstorage = game:GetService("ReplicatedStorage")
  37. local uis = game:GetService("UserInputService")
  38.  
  39. local values = repstorage:WaitForChild("Values")
  40. local status = values:WaitForChild("Status")
  41. local lp = plrs.LocalPlayer
  42.  
  43. local gravity = -28
  44. local walkspeed = 20
  45.  
  46. local text = Text.new()
  47.  
  48. text.Visible = true
  49. text.Size = 25
  50. text.Color = Color3.new(0, 0.0, 1.0)
  51.  
  52. local Utilities = {}; do
  53.    --//MODULE CONSTANTS
  54.    local zero = 1e-9
  55.  
  56.    local onethird = 1 / 3
  57.    local twotwsevs = 2 / 27
  58.    local thirdpi = math.pi / 3
  59.    --END\\
  60.  
  61.    local function isZero(num)
  62.        return num < zero and num > -zero
  63.    end
  64.  
  65.    local function cubicRoot(num)
  66.        return (num > 0 and math.pow(num, onethird)) or (num < 0 and -math.pow(-num, onethird)) or 0
  67.    end
  68.  
  69.    local function solveQuadric(c0, c1, c2, reftable)
  70.        local p, q, D
  71.  
  72.        p = c1 / (2 * c0)
  73.        q = c2 / c0
  74.  
  75.        D = p * p - q
  76.  
  77.        if isZero(D) then
  78.            reftable[1] = -p
  79.            return 1
  80.        elseif D < 0 then
  81.            return 0
  82.        else
  83.            local sqr = math.sqrt(D)
  84.  
  85.            reftable[1] = sqr - p
  86.            reftable[2] = -sqr - p
  87.  
  88.            return 2
  89.        end
  90.    end
  91.  
  92.    local function solveCubic(c0, c1, c2, c3, reftable)
  93.        local num, sub, A, B, C, sqA, p, q, cbp, D
  94.  
  95.        A = c1 / c0
  96.        B = c2 / c0
  97.        C = c3 / c0
  98.  
  99.        sqA = A * A
  100.        p = onethird * (-onethird * sqA + B)
  101.        q = .5 * (twotwsevs * A * sqA - onethird * A * B + C)
  102.  
  103.        cbp = p * p * p
  104.        D = q * q + cbp
  105.  
  106.        sub = onethird * A
  107.  
  108.        if isZero(D) then
  109.            if isZero(q) then
  110.                reftable[1] = 0 - sub
  111.                num = 1
  112.            else
  113.                local u = cubicRoot(-q)
  114.  
  115.                reftable[1] = 2 * u - sub
  116.                reftable[2] = -u - sub
  117.  
  118.                num = 2
  119.            end
  120.        elseif D < 0 then
  121.            local phi = onethird * math.acos(-q / math.sqrt(-cbp))
  122.            local t = 2 * math.sqrt(-p)
  123.  
  124.            reftable[1] = t * math.cos(phi) - sub
  125.            reftable[2] = -t * math.cos(phi + thirdpi) - sub
  126.            reftable[3] = -t * math.cos(phi - thirdpi) - sub
  127.  
  128.            num = 3
  129.        else
  130.            local sqrD = math.sqrt(D)
  131.  
  132.            reftable[1] = cubicRoot(sqrD - q) - cubicRoot(sqrD + q) - sub
  133.            num = 1
  134.        end
  135.  
  136.        return num
  137.    end
  138.  
  139.    local function solveQuartic(c0, c1, c2, c3, c4, reftable)
  140.        local num, z, u, v, sub, A, B, C, D, sqA, p, q, r
  141.  
  142.        A = c1 / c0
  143.        B = c2 / c0
  144.        C = c3 / c0
  145.        D = c4 / c0
  146.  
  147.        sqA = A * A
  148.        p = -.375 * sqA + B
  149.        q = .125 * sqA * A - .5 * A * B + C
  150.        r = -.01171875 * sqA * sqA + .0625 * sqA * B - .25 * A * C + D
  151.  
  152.        sub = .25 * A
  153.  
  154.        if isZero(r) then
  155.            num = solveCubic(1, 0, p, q, reftable)
  156.        else
  157.            local holder = {}
  158.            local h, j, k
  159.  
  160.            solveCubic(1, -.5 * p, -r, .5 * r * p - .125 * q * q, reftable)
  161.            z = reftable[1]
  162.  
  163.            u = z * z - r
  164.            v = 2 * z - p
  165.  
  166.            u = (isZero(u) and 0) or (u > 0 and math.sqrt(u)) or nil
  167.            v = (isZero(v) and 0) or (v > 0 and math.sqrt(v)) or nil
  168.  
  169.            if u == nil or v == nil then return 0 end
  170.  
  171.            h = 1
  172.            j = q < 0 and -v or v
  173.            k = z - u
  174.  
  175.            num = solveQuadric(h, j, k, reftable)
  176.  
  177.            j = -j
  178.            k = z + u
  179.  
  180.            if num == 0 then
  181.                num = num + solveQuadric(h, j, k, reftable)
  182.            elseif num == 1 then
  183.                num = num + solveQuadric(h, j, k, holder)
  184.  
  185.                reftable[2] = holder[1]
  186.                reftable[3] = holder[2]
  187.            elseif num == 2 then
  188.                num = num + solveQuadric(h, j, k, holder)
  189.  
  190.                reftable[3] = holder[1]
  191.                reftable[4] = holder[2]
  192.            end
  193.        end
  194.  
  195.        if num > 0 then reftable[1] = reftable[1] - sub end
  196.        if num > 1 then reftable[2] = reftable[2] - sub end
  197.        if num > 2 then reftable[3] = reftable[3] - sub end
  198.        if num > 3 then reftable[4] = reftable[4] - sub end
  199.  
  200.        return num
  201.    end
  202.  
  203.    local function solveTime(origin, g, speed, jump, target, tvel, islob)
  204.        local diff = target - origin
  205.        local roots = {}
  206.  
  207.        local c0 = g * g * .25
  208.        local c1 = -tvel.Y * g
  209.        local c2 = tvel:Dot(tvel) - g * diff.Y - speed * speed
  210.        local c3 = 2 * (tvel:Dot(diff) - speed * jump)
  211.        local c4 = diff:Dot(diff) - jump * jump
  212.  
  213.        local num = solveQuartic(c0, c1, c2, c3, c4, roots)
  214.  
  215.        if num > 0 then
  216.            local bullet, lob = math.huge, math.huge
  217.  
  218.            for i, t in ipairs(roots) do
  219.                if t > 0 then
  220.                    if t < bullet then
  221.                        lob = bullet
  222.                        bullet = t
  223.                    elseif t < lob then
  224.                        lob = t
  225.                    end
  226.                end
  227.            end
  228.  
  229.            return (islob and lob ~= math.huge and lob) or (bullet ~= math.huge and bullet)
  230.        end
  231.    end
  232.  
  233.    local function timeToTrajectory(origin, g, speed, jump, target, tvel, t)
  234.        return (target - origin + tvel * t - Vector3.new(0, .5 * g * t * t, 0)) / (speed * t + jump)
  235.    end
  236.  
  237.    local function solveTrajectory(origin, g, speed, jump, target, tvel, islob)
  238.        local t = solveTime(origin, g, speed, jump, target, tvel, islob)
  239.        return t and timeToTrajectory(origin, g, speed, jump, target, tvel, t)
  240.    end
  241.  
  242.    Utilities.solveTime =  solveTime
  243.    Utilities.timeToTrajectory =  timeToTrajectory
  244.    Utilities.solveTrajectory =   solveTrajectory
  245. end
  246.  
  247. --END\\
  248. imagePercent = math.clamp(imagePercent / 100, .01, 1)
  249. imageOffset = Vector3.new(0, imageOffset, 0)
  250.  
  251. if not isfolder("keyImages") then error("Missing key image folder") end
  252. if #keys < 7 then error("Too little keys") end
  253.  
  254. local hLead = minHLead
  255. local vLead = minVLead
  256.  
  257. local char = lp.Character
  258. local football
  259. local mouseDown
  260.  
  261. local images = {}
  262. local open = {}
  263. local reserved = {}
  264.  
  265. for i, k in ipairs(keys) do
  266.    local path = string.format("keyImages\\%s.png", k)
  267.    if not isfile(path) then error("Missing image: " .. path) end
  268.  
  269.    local img = Image.new()
  270.  
  271.    img.Visible = false
  272.    img.Size = img.ImageSize * imagePercent
  273.    img.Data = readfile(path)
  274.  
  275.    images[k] = img
  276. end
  277.  
  278. local function findFunction(scr)
  279.    local mainFunc
  280.  
  281.    while not mainFunc do
  282.        local suc, res = pcall(getscriptfunction, scr)
  283.  
  284.        if suc then
  285.            mainFunc = res
  286.        end
  287.  
  288.        task.wait()
  289.    end
  290.  
  291.    for i, v in ipairs(debug.getprotos(mainFunc)) do
  292.        if debug.getinfo(v).name == "onMouseDown" then
  293.            mouseDown = nil
  294.  
  295.            while not mouseDown do
  296.                local funcs = filtergc("function", {Proto = v})
  297.  
  298.                for i, v in pairs(funcs) do
  299.                    if getfenv(v).script == scr then
  300.                        mouseDown = v
  301.                    end
  302.                end
  303.  
  304.                task.wait()
  305.            end
  306.        end
  307.    end
  308. end
  309.  
  310. local function getPower()
  311.    return mouseDown and debug.getupvalue(mouseDown, 11) or 0
  312. end
  313.  
  314. local function getKeyPos(plr, k)
  315.    local hrp = plr.Character and plr.Character.PrimaryPart
  316.    local img = images[k]
  317.    
  318.    if hrp and img then
  319.        local cam = workspace.CurrentCamera
  320.  
  321.        if cam then
  322.            local pos, ison = cam:WorldToViewportPoint(hrp.Position + imageOffset)
  323.        
  324.            if ison then
  325.                return Vector2.new(pos.X, pos.Y) - img.Size / 2
  326.            end
  327.        end
  328.    end
  329. end
  330.  
  331. local function initiateKeys()
  332.    local team = lp.Team
  333.  
  334.    table.clear(open)
  335.    table.clear(reserved)
  336.  
  337.    if team and not lp.Neutral then
  338.        local at = 1
  339.  
  340.        for i, plr in ipairs(team:GetPlayers()) do
  341.            if lp ~= plr then
  342.                reserved[Enum.KeyCode[keys[at]]] = plr
  343.                open[plr] = true
  344.  
  345.                at = at + 1
  346.            end
  347.        end
  348.    end
  349. end
  350.  
  351. local function onToolAdded(tool)
  352.    if tool.ClassName == "Tool" and tool.Name == "Football" and status.Value == "PrePlay" then
  353.        tool:WaitForChild("Handle"):WaitForChild("RemoteEvent")
  354.        tool.Handle:WaitForChild("LocalScript")
  355.  
  356.        findFunction(tool.Handle.LocalScript)
  357.        initiateKeys()
  358.  
  359.        football = tool
  360.    end
  361. end
  362.  
  363. local function onCharacterAdded(c)
  364.    char = c
  365.    char.ChildAdded:Connect(onToolAdded)
  366. end
  367.  
  368. if char then
  369.    onCharacterAdded(char)
  370. end
  371.  
  372. lp.CharacterAdded:Connect(onCharacterAdded)
  373.  
  374. runservice.Heartbeat:Connect(function()
  375.    for plr, v in pairs(open) do
  376.        local hrp = plr.Character and plr.Character.PrimaryPart
  377.        local origin = char and char:FindFirstChild("Head") and char.Head.Position
  378.  
  379.        if football and football.Parent == char and hrp and origin then
  380.            local hvel = Vector3.new(hrp.Velocity.X, 0, hrp.Velocity.Z)
  381.  
  382.            local vel = (uis:IsKeyDown(stationaryKey) or hvel.Magnitude == 0) and Vector3.zero or hvel.Unit * walkspeed
  383.            local tpos = hrp.Position + (hvel * latencyCompensation) + (vel.Magnitude == 0 and vel or vel.Unit * hLead) + Vector3.new(0, vLead, 0)
  384.  
  385.            open[plr] = Utilities.solveTime(origin, gravity, getPower(), 5, tpos, vel, uis:IsKeyDown(lobKey)) and true or false
  386.        
  387.            continue
  388.        end
  389.  
  390.        open[plr] = false
  391.    end
  392. end)
  393.  
  394. runservice.RenderStepped:Connect(function()
  395.    local cam = workspace.CurrentCamera
  396.  
  397.    if cam then
  398.        text.Text = "HLead: " .. hLead .. "\nVLead: " .. vLead
  399.        text.Position = cam.ViewportSize - text.TextBounds
  400.    end
  401.  
  402.    for i, key in ipairs(keys) do
  403.        local plr = reserved[Enum.KeyCode[key]]
  404.        local img = images[key]
  405.  
  406.        if open[plr] then
  407.            local pos = getKeyPos(plr, key)
  408.  
  409.            if pos then
  410.                img.Position = pos
  411.                img.Size = img.ImageSize * imagePercent
  412.  
  413.                img.Visible = true
  414.                continue
  415.            end
  416.        end
  417.  
  418.        img.Visible = false
  419.    end
  420. end)
  421.  
  422. uis.InputBegan:Connect(function(what, proc)
  423.    if not proc then
  424.        local kc = what.KeyCode
  425.  
  426.        if kc == vLeadUpKey or kc == vLeadDownKey then
  427.            vLead = math.clamp(vLead + (kc == vLeadUpKey and increment or -increment), minVLead, maxVLead)
  428.            return
  429.        end
  430.  
  431.        if kc == hLeadUpKey or kc == hLeadDownKey then
  432.            hLead = math.clamp(hLead + (kc == hLeadUpKey and increment or -increment), minHLead, maxHLead)
  433.            return
  434.        end
  435.  
  436.        local plr = reserved[kc]
  437.        if not plr then return end
  438.  
  439.        local origin = char and char:FindFirstChild("Head") and char.Head.Position
  440.        local hrp = plr.Character and plr.Character.PrimaryPart
  441.  
  442.        if open[plr] and origin and hrp then
  443.            local pow = getPower()
  444.            local hvel = Vector3.new(hrp.Velocity.X, 0, hrp.Velocity.Z)
  445.  
  446.            local vel = (uis:IsKeyDown(stationaryKey) or hvel.Magnitude == 0) and Vector3.zero or hvel.Unit * walkspeed
  447.            local tpos = hrp.Position + (hvel * latencyCompensation) + (vel.Magnitude == 0 and vel or vel.Unit * hLead) + Vector3.new(0, vLead, 0)
  448.  
  449.            local traj = Utilities.solveTrajectory(origin, gravity, pow, 5, tpos, vel, uis:IsKeyDown(lobKey))
  450.  
  451.            if traj then
  452.                football.Handle.RemoteEvent:FireServer("Clicked", origin, origin + traj * 10000, pow, 60)
  453.            end
  454.        end
  455.    end
  456. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement