Advertisement
SpacecowboyHX

Untitled

Nov 22nd, 2020
859
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 16.65 KB | None | 0 0
  1. --[[
  2. Roblox AutoFight, made by Indencito.
  3. Good for fencing and such.
  4. ====================================================
  5. Simply say "/e auto ", then the radius you want
  6. the attack to be triggered at.
  7. ========================================================
  8. set "parent" to the directory you want the bot to check for
  9. available targets.
  10. ============================================================
  11. ]]
  12. local parent = workspace
  13. local char= game.Players.LocalPlayer.Character
  14. repeat wait() char= game.Players.LocalPlayer.Character until char
  15. wait(1)
  16. char.Archivable = true
  17. local rootC = char.HumanoidRootPart
  18. local distance = 20
  19. local reach = 4
  20. local amnttl = math.pow(math.huge,math.huge)*math.huge
  21. local gyro= Instance.new("BodyGyro",rootC)
  22. gyro.MaxTorque = Vector3.new(0,amnttl,0)
  23. gyro.MaxTorque = Vector3.new(0,0,0)
  24. gyro.P = 10000
  25. gyro.D = 0
  26. local difficulty = 10
  27. local died = false
  28. local jumped = false
  29. local auto = false
  30. function run(charr)
  31.     local find = charr:FindFirstChild("HumanoidRootPart")
  32.     if find then
  33.         local char = game.Players.LocalPlayer.Character
  34.         local frame = CFrame.new(find.Position,char.HumanoidRootPart.Position)*CFrame.new(0,0,-distance+10)
  35.         local pos = frame.Position
  36.         char.Humanoid:MoveTo(pos)
  37.     end
  38. end
  39. function onHealthChanged(health)
  40.     if health == 0 and died == false then died = true
  41.         warn("DIED")
  42.         wait(game.Players.RespawnTime+.3)
  43.         char= game.Players.LocalPlayer.Character
  44.         repeat wait() char= game.Players.LocalPlayer.Character until char
  45.         wait(.3)
  46.         char.Archivable = true
  47.         rootC = char.HumanoidRootPart
  48.         reach = 6
  49.         gyro= Instance.new("BodyGyro",rootC)
  50.         gyro.MaxTorque = Vector3.new(0,0,0)
  51.         gyro.P = 999999999999
  52.         gyro.D = 0
  53.         jumped = false
  54.     end
  55. end
  56. local OverSpin = false
  57. local spinning = false
  58. local start
  59. function attack(char2,sword)
  60.     char = game.Players.LocalPlayer.Character
  61.     if sword and sword.Parent == char and char:FindFirstChild("Humanoid")~=nil then
  62.         --attacker is char2
  63.         local root = char2:FindFirstChild("HumanoidRootPart")
  64.         if root then
  65.             if char2.Humanoid.Health>0 and char.Humanoid.Health>0 then
  66.                 local mag = (rootC.Position-root.Position).Magnitude
  67.                 local rag = root.CFrame:ToObjectSpace(rootC.CFrame)
  68.                 local rag2 = rootC.CFrame:ToObjectSpace(root.CFrame)
  69.                 local side = rag.Position.X
  70.                 local face = rag.Position.Z
  71.                 local top = rag.Position.Y
  72.                 --front face is in negative
  73.                 --side negative is left
  74.                 local convS = tostring(side)
  75.                 local convF = tostring(face)
  76.                 local findS = string.sub(convS,1,1)
  77.                 local findF = string.sub(convF,1,1)
  78.                 local velocityY = root.RotVelocity.Y
  79.                 if spinning== false then
  80.                     start = tick()
  81.                 end
  82.                 if tick()-start>=0.5 then
  83.                     OverSpin = true
  84.                 else
  85.                     OverSpin = false
  86.                 end
  87.                 if velocityY<=-1 or velocityY>=1 then
  88.                     warn(velocityY)
  89.                     if spinning == false then
  90.                         spinning = true
  91.                     end
  92.                 else
  93.                     print(velocityY)
  94.                     spinning = false
  95.                 end
  96.  
  97.                 if rootC.Velocity.Magnitude >100 then
  98.                     print("velocity is too high")
  99.                     rootC.Velocity = Vector3.new(0,0,0)
  100.                 end
  101.                 if OverSpin == false then
  102.                     if side<0 then
  103.                         if mag<=reach/2 then
  104.                             local rando = math.random(1,100)
  105.                             if rando == 100 then
  106.                                 if jumped == false then jumped = true
  107.                                     char.Humanoid.Jump = true
  108.                                     jumped = false
  109.                                 end
  110.                             end
  111.                             jumped = false
  112.                             local frame = CFrame.new(sword.Handle.Position,root.Parent["Left Arm"].Position)
  113.                             local mag2 = (rootC.Position-root.Parent["Left Arm"].Position).Magnitude
  114.                             local mag3 = (rootC.Parent["Left Arm"].Position-root.Parent["Right Arm"].Position).Magnitude
  115.                             if mag2<=reach/2 then
  116.                                 jumped = false
  117.                                 local framer = root.CFrame*CFrame.new(-2,0,-reach)
  118.                                 if mag3<=reach/2 then
  119.                                     print("may die")
  120.                                     if jumped == false then jumped = true
  121.                                         char.Humanoid.Jump = true
  122.                                         jumped = false
  123.                                     end
  124.                                     local hum = char.Humanoid
  125.                                     hum:MoveTo((root.CFrame*CFrame.new(-2,0,-(reach*2))).Position)
  126.                                 else
  127.                                     local hum = char.Humanoid
  128.                                     hum:MoveTo((root.CFrame*CFrame.new(-2,0,-(reach))).Position)
  129.                                 end
  130.                                 gyro.CFrame = frame
  131.                                 for i = 1,2 do
  132.                                     wait()
  133.                                     sword:Activate()
  134.                                 end
  135.                             else
  136.                                 print("very close")
  137.                                 jumped = false
  138.                                 gyro.CFrame = frame
  139.                                 frame = CFrame.new(sword.Handle.Position,root.Parent["Left Arm"].Position)
  140.                                 for i = 1,2 do
  141.                                     wait()
  142.                                     sword:Activate()
  143.                                 end
  144.                             end
  145.                         else
  146.                             if mag<=reach then
  147.                                 local mag2 = (rootC.Parent["Left Arm"].Position-root.Parent["Right Arm"].Position).Magnitude
  148.                                 --temporary
  149.                                 --[[if char2.Humanoid.Jump == true then
  150.                                     char.Humanoid.Jump = true
  151.                                     local framer = root.CFrame*CFrame.new(0,0,-2)
  152.                                     local frame = CFrame.new(sword.Handle.Position,root.Position)
  153.                                     gyro.CFrame = frame
  154.                                     char.Humanoid:MoveTo((root.CFrame*CFrame.new(0,0,-reach)).Position)
  155.                                 end]]
  156.                                 if mag2<=reach then
  157.                                     print("left arm vunerable")
  158.                                     local frame = CFrame.new(sword.Handle.Position,char2["Right Arm"].Position)
  159.                                     gyro.CFrame = frame
  160.                                     local framer = root.CFrame*CFrame.new(-reach,0,-(reach/2))
  161.                                     local started = tick()
  162.                                     repeat wait() local frame = CFrame.new(sword.Handle.Position,(char2.HumanoidRootPart.CFrame*CFrame.new(3,0,2)).Position) gyro.CFrame = frame char.Humanoid:MoveTo(framer.Position) until char.Humanoid.Jump == false or tick()-started>0.1
  163.                                     char.Humanoid.Jump = true
  164.                                     wait()
  165.                                     framer = root.CFrame*CFrame.new(-4,0,reach)
  166.                                     char.Humanoid:MoveTo(framer.Position)
  167.                                     local frame = CFrame.new(sword.Handle.Position,char2["Right Arm"].Position)
  168.                                     gyro.CFrame = frame
  169.                                     local hum = char.Humanoid
  170.                                     if hum.Jump == false then
  171.                                         for i = 1,2 do
  172.                                             wait()
  173.                                             sword:Activate()
  174.                                         end
  175.                                     end
  176.                                 else
  177.                                     print("within reach")
  178.                                     local mag2 = (rootC.Position-root.Parent["Right Arm"].Position).Magnitude
  179.                                     local framer = root.CFrame*CFrame.new(reach,0,-(reach*2))
  180.                                     local frame = CFrame.new(sword.Handle.Position,char2["Right Arm"].Position)
  181.                                     gyro.CFrame = frame
  182.                                     framer = root.CFrame*CFrame.new(-4,0,-reach)
  183.                                     char.Humanoid:MoveTo(framer.Position)
  184.                                     for i = 1,2 do
  185.                                         wait()
  186.                                         sword:Activate()
  187.                                     end
  188.                                     framer = root.CFrame*CFrame.new(-4,0,-reach)
  189.                                     char.Humanoid:MoveTo(framer.Position)
  190.                                 end
  191.                             else
  192.                                 if mag<=reach*2 then
  193.                                     jumped = false
  194.                                     local mag2 = (rootC.Parent["Left Arm"].Position-root.Parent["Right Arm"].Position).Magnitude
  195.                                     if mag2<=reach+((reach*2)/3) and rag2.Position.Y<=0 then
  196.                                         print("left arm Semi-close")
  197.                                         jumped = false
  198.                                         local framer = root.CFrame*CFrame.new(4,0,-reach)
  199.                                         char.Humanoid:MoveTo(framer.Position)
  200.                                         char.Humanoid.Jump = true
  201.                                         local frame = CFrame.new(sword.Handle.Position,(root.Parent["Right Arm"].CFrame*CFrame.new(0,0,0)).Position)
  202.                                         gyro.CFrame = frame
  203.                                         for i = 1,2 do
  204.                                             wait()
  205.                                             sword:Activate()
  206.                                         end
  207.                                         local frame = CFrame.new(sword.Handle.Position,(root.Parent["Torso"].CFrame*CFrame.new(2,0,0)).Position)
  208.                                         gyro.CFrame = frame
  209.                                     else
  210.                                         print("approching")
  211.                                         jumped = false
  212.                                         local frame = CFrame.new(rootC.Position,root.Parent["Right Arm"].Position)
  213.                                         --local framer2 = CFrame.new(rootC.Position)*CFrame.Angles(0,math.rad(root.Orientation.Y)+math.pi,0)
  214.                                         gyro.CFrame = frame
  215.                                         local hum = char.Humanoid
  216.                                         for i = 1,2 do
  217.                                             wait()
  218.                                             sword:Activate()
  219.                                         end
  220.                                         hum:MoveTo((root.CFrame*CFrame.new(4,0,-(reach))).Position)
  221.                                     end
  222.                                 else
  223.                                     print("far away")
  224.                                     jumped = false
  225.                                     local framer = root.CFrame*CFrame.new(-4,0,-reach)
  226.                                     local framer2 = CFrame.new(sword.Handle.Position,(root.Parent["Left Arm"].CFrame*CFrame.new(0,0,0)).Position)
  227.                                     gyro.CFrame = framer2
  228.                                     char.Humanoid:MoveTo(framer.Position)
  229.                                 end
  230.                             end
  231.                         end
  232.                     else
  233.                         if face<=0 then
  234.                             if top>-5 then
  235.                                 if side<4 then
  236.                                     jumped = false
  237.                                     local framer2 = CFrame.new(rootC.Position)*CFrame.Angles(0,math.rad(root.Orientation.Y)+math.pi,0)
  238.                                     if mag<=reach+3 then
  239.                                         local arm = "Right Arm"
  240.                                         if side<4 and side>0 then else if side<=0 then arm = "Left Arm" end end
  241.                                         print("attempting "..arm)
  242.                                         local function shake()
  243.                                             local frame = CFrame.new(sword.Handle.Position,(root.Parent[arm].CFrame*CFrame.new(0,0,-1)).Position)
  244.                                             gyro.CFrame = frame
  245.                                             wait()
  246.                                             local frame = CFrame.new(sword.Handle.Position,(root.Parent[arm].CFrame*CFrame.new(0,0,0)).Position)
  247.                                             gyro.CFrame = frame
  248.                                         end
  249.                                         shake()
  250.                                         local hum = char.Humanoid
  251.                                         local timer = tick()
  252.                                         repeat wait() hum:MoveTo((root.CFrame*CFrame.new(-(reach/2),0,-(reach))).Position) until hum.Jump == false or tick()-timer>0.1
  253.                                         hum.Jump = true
  254.                                         hum:MoveTo((root.CFrame*CFrame.new(reach,0,-(reach))).Position)
  255.                                         if hum.Jump == false then
  256.                                             for i = 1,2 do
  257.                                                 wait()
  258.                                                 sword:Activate()
  259.                                             end
  260.                                         end
  261.                                         return shake()
  262.                                     else
  263.                                         local frame = CFrame.new(sword.Handle.Position,(root.Parent["Right Arm"].CFrame*CFrame.new(1,0,-1)).Position)
  264.                                         print("on wrong side")
  265.                                         gyro.CFrame = frame
  266.                                         local hum = char.Humanoid
  267.                                         hum:MoveTo((root.CFrame*CFrame.new(reach,0,-(reach))).Position)
  268.                                         for i = 1,2 do
  269.                                             wait()
  270.                                             sword:Activate()
  271.                                         end    
  272.                                     end
  273.                                 else
  274.                                     if side>= 4 then
  275.                                         print("coming from arm")
  276.                                         local frame = CFrame.new(sword.Handle.Position,(root.Parent["Right Arm"].CFrame*CFrame.new(0,0,-4)).Position)
  277.                                         gyro.CFrame = frame
  278.                                         local hum = char.Humanoid
  279.                                         hum:MoveTo((root.Parent["Right Arm"].CFrame*CFrame.new(-(reach),0,-(reach))).Position)
  280.                                         if mag<=reach*2 then
  281.                                             for i = 1,2 do
  282.                                                 wait()
  283.                                                 sword:Activate()
  284.                                             end
  285.                                             if mag<=reach then
  286.                                                 hum.Jump = true
  287.                                             end
  288.                                         end
  289.                                         local frame = CFrame.new(sword.Handle.Position,(root.Parent["Right Arm"].CFrame*CFrame.new(-(reach/2),0,2)).Position)
  290.                                         gyro.CFrame = frame
  291.                                     end
  292.                                 end
  293.                             else
  294.                                 print("player has high ground")
  295.                                 if mag<=reach*2 then
  296.                                     print("player coming from top at "..top)
  297.                                     local frame = CFrame.new(sword.Handle.Position,(root.Parent["Left Arm"].CFrame*CFrame.new(0,0,0)).Position)
  298.                                     gyro.CFrame = frame
  299.                                     char.Humanoid:MoveTo((root.CFrame*CFrame.new(-3,0,(reach))).Position)
  300.                                     local l = tick()
  301.                                     --[[repeat
  302.                                         wait()
  303.                                         local ragg = root.CFrame:ToObjectSpace(rootC.CFrame)
  304.                                         if sword:FindFirstChild("Handle") then
  305.                                             local frame = CFrame.new(sword.Handle.Position,root.Parent["Left Arm"].Position)
  306.                                         end
  307.                                         gyro.CFrame = frame
  308.                                         char.Humanoid:MoveTo((root.CFrame*CFrame.new(-reach,0,-4)).Position)
  309.                                     until rag.Position.Y>=-6 or tick()-l>0.05]]
  310.                                     --print("under")
  311.                                     frame = CFrame.new(sword.Handle.Position,(root.Parent["Left Leg"].CFrame*CFrame.new(0,0,0)).Position)
  312.                                     gyro.CFrame = frame
  313.                                     for i = 1,2 do
  314.                                         wait()
  315.                                         sword:Activate()
  316.                                     end
  317.                                     local function twitch()
  318.                                         frame = CFrame.new(sword.Handle.Position,(root.Parent["Left Leg"].CFrame*CFrame.new(0,0,0)).Position)
  319.                                         gyro.CFrame = frame
  320.                                         wait()
  321.                                         frame = CFrame.new(sword.Handle.Position,(root.Parent["Right Leg"].CFrame*CFrame.new(0,0,0)).Position)
  322.                                         gyro.CFrame = frame
  323.                                     end
  324.                                     --char.Humanoid:MoveTo((root.CFrame*CFrame.new(-3,0,(reach/2))).Position)
  325.                                     char.Humanoid.Jump = true
  326.                                     return twitch()
  327.                                 else
  328.                                     print(mag)
  329.                                 end
  330.                             end
  331.                         else
  332.                             if face>0 then
  333.                                 print("coming from behind")
  334.                                 local framer2 = CFrame.new(rootC.Position,root.Position)
  335.                                 gyro.CFrame = framer2
  336.                                 local hum = char.Humanoid
  337.                                 hum:MoveTo((root.CFrame*CFrame.new(reach,0,(reach))).Position)
  338.                                 if mag<=reach*2 then
  339.                                     for i = 1,2 do
  340.                                         wait()
  341.                                         sword:Activate()
  342.                                     end
  343.                                 end
  344.                                 local framer3 = CFrame.new(rootC.Position,char2["Left Arm"].Position)
  345.                                 gyro.CFrame = framer3
  346.                                 --hum:MoveTo((root.CFrame*CFrame.new(2,0,(reach/2))).Position)
  347.                             end
  348.                         end
  349.                     end
  350.                 else
  351.                     local all = char2:GetChildren()
  352.                     local positions = {}
  353.                     local part
  354.                     for i = 1,#all do
  355.                         if all[i].ClassName == "Part" then
  356.                             local mag = (sword.Handle.Position-all[i].Position).Magnitude
  357.                             table.insert(positions,#positions+1,mag)
  358.                         end
  359.                     end
  360.                     if #all> 0 then
  361.                         table.sort(positions)
  362.                         local closest = positions[1]
  363.                         for i = 1,#all do
  364.                             if all[i].ClassName == "Part" then
  365.                                 local mag = (sword.Handle.Position-all[i].Position).Magnitude
  366.                                 if mag == closest then
  367.                                     part = all[i]
  368.                                 end
  369.                             end
  370.                         end
  371.                     end
  372.                     print("opponent is spinning out")
  373.                     local hum = char.Humanoid
  374.                     local frame1 = CFrame.new(sword.Handle.Position,part.Position)
  375.                     local frame2 = CFrame.new(part.Position,sword.Handle.Position)
  376.                     if mag<= reach*2 then
  377.                         if char.Humanoid.Jump ~= true then
  378.                             char.Humanoid.Jump = true
  379.                             hum:MoveTo((frame2*CFrame.new(-4,0,-(reach/2))).Position)
  380.                         else
  381.                             hum:MoveTo((frame2*CFrame.new(-reach,0,-(reach))).Position)
  382.                         end
  383.                     end
  384.                     gyro.CFrame = frame1
  385.                     for i = 1,2 do
  386.                         wait()
  387.                         sword:Activate()
  388.                     end
  389.                 end
  390.             end
  391.         end
  392.     end
  393. end
  394. function findNearest()
  395.     local dist = distance
  396.     local root
  397.     local all = parent:GetChildren()
  398.     local chars = {}
  399.     local mag
  400.     local rooter
  401.     if #all>0 then
  402.         for i= 1,#all do
  403.             local hum = all[i]:FindFirstChildOfClass("Humanoid")
  404.             if hum~=nil and hum.Health>0 then
  405.                 if all[i].Parent~=script.Parent then
  406.                     root = all[i]:FindFirstChild("HumanoidRootPart")
  407.                     if root then
  408.                         mag = (root.Position-rootC.Position).Magnitude
  409.                         if mag<= dist then
  410.                             if root~=rootC then
  411.                                 table.insert(chars,#chars+1,mag)
  412.                             end
  413.                         end
  414.                     end
  415.                 end
  416.             end
  417.         end
  418.         table.sort(chars)
  419.         if #chars>0 then
  420.             for i= 1,#all do
  421.                 local hum = all[i]:FindFirstChildOfClass("Humanoid")
  422.                 if hum~=nil then
  423.                     if all[i].Parent~=char then
  424.                         root = all[i]:FindFirstChild("HumanoidRootPart")
  425.                         if root then
  426.                             mag = (root.Position-rootC.Position).Magnitude
  427.                             if mag == chars[1] then
  428.                                 rooter = root
  429.                             end
  430.                         end
  431.                     end
  432.                 end
  433.             end
  434.         end
  435.     end
  436.     return rooter
  437. end
  438. local lastHealth = char.Humanoid.Health
  439. function autoFight(dista)
  440.     char = game.Players.LocalPlayer.Character
  441.     distance = dista
  442.     local swo
  443.     local all = char:GetChildren()
  444.     local sword
  445.     for _,v in pairs(all) do
  446.         if v.ClassName == "Tool" then
  447.             sword = v
  448.         end
  449.     end
  450.     if not sword then
  451.         local all = game.Players.LocalPlayer.Backpack:GetChildren()
  452.         repeat wait() all = game.Players.LocalPlayer.Backpack:GetChildren() until #all>0
  453.         if all[1].ClassName == "Tool" then
  454.             all[1].Parent = char
  455.             sword = all[1]
  456.         end
  457.     end
  458.     auto = true
  459.     local run
  460.     gyro.MaxTorque = Vector3.new(0,math.huge,0)
  461.     while wait(((10-difficulty)/10)) do
  462.         local new = char.Humanoid.Health
  463.         if new~=lastHealth then
  464.             onHealthChanged(new)
  465.             if died == true then
  466.                 wait(0.5)
  467.                 died = false
  468.                 return autoFight(dista)
  469.             end
  470.         end
  471.         lastHealth = char.Humanoid.Health
  472.         game.Players.LocalPlayer.Chatted:Connect(function(mes)
  473.             if string.lower(mes) == "/e stop" then
  474.                 auto = false
  475.             end
  476.         end)
  477.         if auto == true then
  478.             local root = findNearest()
  479.             if root then
  480.                 if char:FindFirstChild("Humanoid")~=nil then
  481.                     attack(root.Parent,sword)
  482.                 end
  483.             else
  484.             end
  485.         else
  486.             gyro.MaxTorque = Vector3.new(0,0,0)
  487.             break
  488.         end
  489.     end
  490. end
  491. game.Players.LocalPlayer.Chatted:Connect(function(mes)
  492.     if string.sub(mes,1,8) == "/e auto " then
  493.         if auto == false then
  494.             autoFight(tonumber(string.sub(mes,9,#mes)))
  495.         end
  496.     else
  497.         if string.sub(mes,1,7) == "/e dif " then
  498.             print("set difficulty to "..string.sub(mes,8,#mes))
  499.             difficulty = tonumber(string.sub(mes,8,#mes))
  500.         end
  501.     end
  502. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement