Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- /////////AutoFight///////
- ////Made by Indencito////
- ]]
- local lp = game.Players.LocalPlayer
- local players = game.Players:GetChildren()
- local availPlayers = {}
- local currentOuts = {}
- local outlined = false
- local cam = workspace.CurrentCamera
- local db = false
- local gotoRefresh = 0.5
- local pf = false
- local params = {
- ["AgentHeight"] = 5;
- ["AgentRaduis"] = 7;
- ["AgentCanJump"] = true
- }
- function Goto(player,pos)
- local char
- if player~=nil then
- char = player.Character
- end
- local hum
- if char then
- hum = char:FindFirstChild("Humanoid")
- end
- if char and hum then
- local parts = {}
- local health = hum.Health
- local paths = game:GetService("PathfindingService")
- local path = paths:CreatePath(params)
- local health2 = lp.Character.Humanoid.Health
- if health>0 and health2>0 then
- path:ComputeAsync(char.PrimaryPart.Position,(lp.Character.PrimaryPart.CFrame*CFrame.new(0,0,-7.5)).Position)
- local points = path:GetWaypoints()
- for i=1,#points do
- local new = Instance.new("Part")
- new.Material = Enum.Material.Neon
- new.Transparency = 0.5
- new.Color = Color3.new(255,0,0)
- table.insert(parts,i,new)
- new.Anchored = true
- new.CanCollide = false
- new.Parent = workspace
- if i>1 then
- local mag = (points[i-1].Position-points[i].Position).Magnitude
- new.CFrame = CFrame.new(points[i-1].Position,points[i].Position)*CFrame.new(0,0,-mag/2)
- new.Size = Vector3.new(1,1,mag)
- end
- end
- if #points>0 then
- for i = 1,#points do
- local i = #points-(i-1)
- if health>0 and health2>0 then
- if path.Status == Enum.PathStatus.Success then
- lp.Character.Humanoid:MoveTo(points[i].Position)
- if points[i].Action == Enum.PathWaypointAction.Jump then
- lp.Character.Humanoid.Jump = true
- end
- lp.Character.Humanoid.MoveToFinished:Wait()
- if i == 1 then
- for i = 1,#parts do
- parts[i]:Destroy()
- end
- parts = {}
- db = true
- end
- else
- break
- end
- else
- break
- end
- end
- end
- end
- else
- if pos and not hum then
- local parts = {}
- local timer = tick()
- local paths = game:GetService("PathfindingService")
- local path = paths:CreatePath(params)
- local health2 = lp.Character.Humanoid.Health
- if health2>0 then
- path:ComputeAsync(pos,(lp.Character.PrimaryPart.CFrame*CFrame.new(0,0,-7.5)).Position)
- local points = path:GetWaypoints()
- for i=1,#points do
- local new = Instance.new("Part")
- new.Material = Enum.Material.Neon
- new.Transparency = 0.5
- new.BrickColor = BrickColor.new("Really red")
- table.insert(parts,i,new)
- new.Anchored = true
- new.CanCollide = false
- new.Parent = workspace
- if i>1 then
- local mag = (points[i-1].Position-points[i].Position).Magnitude
- new.CFrame = CFrame.new(points[i-1].Position,points[i].Position)*CFrame.new(0,0,-mag/2)
- new.Size = Vector3.new(0.5,0.5,mag)
- end
- end
- if #points>0 then
- for i = 1,#points do
- local i = #points-(i-1)
- if health2>0 then
- if path.Status == Enum.PathStatus.Success then
- if tick()-timer<gotoRefresh then
- local ray = Ray.new(lp.Character.PrimaryPart.Position,(lp.Character.PrimaryPart.Position-pos))
- local hit,pos = workspace:FindPartOnRayWithIgnoreList(ray,{lp.Character})
- if hit then
- lp.Character.Humanoid:MoveTo(points[i].Position)
- if points[i].Action == Enum.PathWaypointAction.Jump then
- lp.Character.Humanoid.Jump = true
- end
- lp.Character.Humanoid.MoveToFinished:Wait()
- if i == 1 then
- for i = 1,#parts do
- parts[i]:Destroy()
- end
- parts = {}
- end
- else
- pf = false
- break
- end
- else
- print("timed out pathfinding")
- for i = 1,#parts do
- parts[i]:Destroy()
- end
- parts = {}
- break
- end
- else
- break
- end
- else
- break
- end
- end
- end
- end
- end
- end
- end
- function chat(string)
- local Event = game:GetService("ReplicatedStorage").DefaultChatSystemChatEvents.SayMessageRequest
- Event:FireServer(string)
- end
- function auto(dist)
- while wait() do
- local function FindTorso(dist)
- local pos = lp.Character:FindFirstChild("HumanoidRootPart").Position
- local list = game.Players:GetChildren()
- local root = nil
- local temp = nil
- local human = nil
- local temp2 = nil
- for x = 1, #list do
- temp2 = list[x]
- if (temp2.className == "Player") and (temp2 ~= lp) then
- temp2 = temp2.Character
- temp = temp2:findFirstChild("HumanoidRootPart")
- human = temp2:findFirstChild("Humanoid")
- if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
- if (temp.Position - pos).magnitude < dist then
- root = temp
- dist = (temp.Position - pos).magnitude
- end
- end
- end
- end
- return root
- end
- if db == true then
- local root = FindTorso(dist)
- if root then
- local find = game.Players:FindFirstChild(root.Parent.Name)
- if find then
- local ray = Ray.new(lp.Character.PrimaryPart.Position,(lp.Character.PrimaryPart.Position-root.Position))
- local hit,pos = workspace:FindPartOnRayWithIgnoreList(ray,{lp.Character})
- if not hit then
- target(find)
- else
- if hit.CanCollide == true then
- db = false
- Goto(find)
- repeat until db == true
- target(find)
- else
- target(find)
- end
- end
- end
- end
- else
- break
- end
- end
- end
- function target(player)
- if player~=nil then
- local tool = nil
- local hum = lp.Character:WaitForChild("Humanoid")
- local hum2 = player.Character:WaitForChild("Humanoid")
- local root1 = lp.Character:WaitForChild("HumanoidRootPart")
- local root2 = player.Character:WaitForChild("HumanoidRootPart")
- local chatted = false
- while wait() do
- repeat until hum ~=nil and hum2 ~=nil
- local v1 = lp.Character
- local v2 = lp.Character
- local verify = player.Character:FindFirstChild("Humanoid").Health
- local verify2 = lp.Character:FindFirstChild("Humanoid").Health
- if v1 and v2 then
- if verify>0 then
- if verify2>0 then
- if db == true then
- local mag = (root1.Position-root2.Position).Magnitude
- if hum2.Jump==true then
- hum.Jump = true
- end
- if mag<=15 then
- local tools = lp.Backpack:GetChildren()
- if #tools>0 then
- tool = tools[1]
- tool.Parent = lp.Character
- tool:Activate()
- else
- if tool~=nil then
- if tool.ClassName=="Tool" then
- tool:Activate()
- end
- end
- end
- local frame = root2.CFrame*CFrame.new(-3,0,0)
- local mag = (root1.Position-root2.Position).Magnitude
- local ray = Ray.new(root1.Position,(root1.Position-player.Character.HumanoidRootPart.Position))
- local hit,position = workspace:FindPartOnRayWithIgnoreList(ray,{lp.Character})
- if not hit then
- local frame = root2.CFrame*CFrame.new(-3,0,0)
- local extraframe = root2.CFrame*CFrame.new(2,0,0)
- cam.CFrame = CFrame.new(cam.CFrame.Position,extraframe.Position)
- hum:MoveTo(frame.Position)
- else
- if hit then
- local extraframe = root2.CFrame*CFrame.new(2,0,0)
- cam.CFrame = CFrame.new(cam.CFrame.Position,extraframe.Position)
- local frame = root2.CFrame*CFrame.new(-3,0,0)
- print("hit "..hit.Name)
- Goto(nil,frame.Position)--test
- end
- end
- else
- local frame = root2.CFrame*CFrame.new(0,0,-7.5)
- local extraframe = root2.CFrame*CFrame.new(-2,0,0)
- local ray = Ray.new(lp.Character.PrimaryPart.Position,(lp.Character.PrimaryPart.Position-player.Character.PrimaryPart.Position))
- local hit,pos = workspace:FindPartOnRayWithIgnoreList(ray,{lp.Character})
- cam.CFrame = CFrame.new(cam.CFrame.Position,extraframe.Position)
- if hit then
- print("hit")
- Goto(nil,frame.Position)--test
- else
- if not hit then
- hum:MoveTo(frame.Position)
- end
- end
- end
- else
- break
- end
- else
- availPlayers = {}
- if #currentOuts>0 then
- for i = 1,#currentOuts do
- if currentOuts[i]~=nil then
- currentOuts[i]:Destroy()
- end
- table.remove(currentOuts,i)
- end
- end
- for i = 1,#availPlayers do
- table.remove(availPlayers,i)
- end
- outlined=false
- break
- end
- else
- if chatted == false then chatted = true
- chat(player.Name.." is a noob")
- end
- if tool~=nil then
- tool.Parent = lp.Backpack
- end
- for i = 1,#currentOuts do
- if currentOuts[i].Parent.Parent == player.Character then
- table.remove(currentOuts,i)
- end
- end
- for i = 1,#availPlayers do
- if availPlayers[i]==player.Name then
- table.remove(availPlayers,i)
- end
- end
- break
- end
- else
- break
- end
- end
- end
- end
- function outlineP()
- outlined = true
- local players = game.Players:GetChildren()
- for i = 1,#players do
- local player = players[i]
- local char = player.Character
- local outline = Instance.new("SelectionBox")
- outline.Color3 = Color3.new(255,0,0)
- outline.LineThickness = .1
- outline.SurfaceColor3 = Color3.new(172,0,0)
- outline.SurfaceTransparency = .9
- outline.Transparency = .3
- local root = char:FindFirstChild("HumanoidRootPart")
- if (root~=nil) then
- outline.Parent = root
- outline.Adornee = root
- table.insert(availPlayers,i,player)
- table.insert(currentOuts,i,outline)
- else
- outline:Destroy()
- end
- end
- end
- local mouse = lp:GetMouse()
- mouse.Button1Down:Connect(function()
- local pos = mouse.Hit.p
- local target = mouse.Target
- if target then
- if target.Parent:FindFirstChild("Humanoid")~=nil then
- local find = game.Players:FindFirstChild(target.Parent.Name)
- if (find~=nil) then
- if outlined == true then
- for o = 1,#availPlayers do
- if availPlayers[o].Name==find.Name then
- target(find)
- print("yes")
- end
- end
- else
- print("no outlined players")
- end
- end
- end
- else
- warn("no target selected")
- end
- end)
- lp.Chatted:Connect(function(msg)
- local text1 = ""
- local text2 = ""
- if string.lower(msg)=="/e outline" then
- local players = game.Players:GetChildren()
- if #currentOuts>0 then
- for i = 1,#currentOuts do
- if currentOuts[i]~=nil then
- currentOuts[i]:Destroy()
- end
- table.remove(currentOuts,i)
- end
- end
- if #availPlayers>0 then
- for i = 1,#availPlayers do
- table.remove(availPlayers,i)
- end
- end
- outlineP()
- for i = 1,#players do
- text1 = text1..players[i].Name..", "
- end
- local text2 = "[Autofight]: The player list is "..text1
- --////////////
- game:GetService("StarterGui"):SetCore("ChatMakeSystemMessage",{
- Text = text2..[[. The command for a specific player is "/e target PLAYER", you can use abbreviation as well.]];
- Color = Color3.new(0,175,0);
- Font = Enum.Font.SourceSansBold;
- FontSize = Enum.FontSize.Size18;
- })
- --////////////
- else
- local msg = string.lower(msg)
- if string.sub(msg,1,10)=="/e target " then
- local players = game.Players:GetChildren()
- if outlined == true then
- local name = string.lower(string.sub(msg,11,#msg))
- for i = 1,#players do
- local name2 = string.lower(players[i].Name)
- if string.sub(name2,1,#name)==name then
- for o = 1,#availPlayers do
- wait()
- if availPlayers[o].Name==players[i].Name then
- local ray = Ray.new(lp.Character.PrimaryPart.Position,(lp.Character.PrimaryPart.Position-players[i].Character.PrimaryPart.Position))
- local hit,pos = workspace:FindPartOnRayWithIgnoreList(ray,{lp.Character})
- if not hit then
- game:GetService("StarterGui"):SetCore("ChatMakeSystemMessage",{
- Text = "[Autofight]: Now targeting "..players[i].Name..". make sure Shift Lock is on and dont move.";
- Color = Color3.new(0,128,128);
- Font = Enum.Font.SourceSansBold;
- FontSize = Enum.FontSize.Size18;
- })
- db = true
- target(players[i])
- else
- game:GetService("StarterGui"):SetCore("ChatMakeSystemMessage",{
- Text = "[Autofight]: Now targeting "..players[i].Name..". make sure Shift Lock is on and dont move.";
- Color = Color3.new(0,128,128);
- Font = Enum.Font.SourceSansBold;
- FontSize = Enum.FontSize.Size18;
- })
- db = false
- Goto(players[i])
- repeat until db == true
- target(players[i])
- end
- end
- end
- end
- end
- else
- game:GetService("StarterGui"):SetCore("ChatMakeSystemMessage",{
- Text = "[Autofight]: No players outlined, use /e outline command to begin...";
- Color = Color3.new(255,0,0);
- Font = Enum.Font.SourceSansBold;
- FontSize = Enum.FontSize.Size18;
- })
- end
- else
- if string.lower(msg) == "/e stop" then
- if db == true then db = false
- else
- print("Not targeting anyone")
- print("AutoFight made by Indencito")
- end
- else
- local msg = string.lower(msg)
- if string.sub(msg,1,7) == "/e auto" then
- if string.sub(msg,9,#msg)~=nil then
- local dist = tonumber(string.sub(msg,9,#msg))
- if db == true then db = false end
- db = true
- auto(dist)
- end
- end
- end
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement