Advertisement
SpacecowboyHX

Untitled

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