Advertisement
welplol34

Autofarm

Dec 6th, 2022 (edited)
12,756
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.66 KB | None | 0 0
  1. --//Autofarm
  2.  
  3. --//Variables
  4. local Player = game.Players.LocalPlayer;
  5. local Character = Player.Character:WaitForChild("Playermodel"):WaitForChild("Charmodel");
  6. local HRP = Character:WaitForChild("HumanoidRootPart");
  7. local ToggleKey = Enum.KeyCode.X
  8.  
  9. if game.Workspace:FindFirstChild("Live") then
  10. return
  11. end
  12.  
  13. --//Tables
  14. local Settings = {};
  15. local Used = {};
  16. local RarityTable = {
  17.     ["Legendary"] = 984;
  18.     ["Alpha"] = 994;
  19.     ["Omega"] = 999;
  20.     ["Core"] = 1000;
  21. };
  22.  
  23. --//Cooldowns
  24. local lastAttack = tick();
  25. local lastSell = tick();
  26.  
  27. --//Globals
  28. _G.Autofarm = true;
  29.  
  30. if _G.Autofarm == false then
  31.     return
  32. end
  33.  
  34. --//Services
  35. local UIS = game:GetService("UserInputService");
  36. local VIM =  game:GetService("VirtualInputManager");
  37. local Debris = game:GetService("Debris");
  38. local HttpService = game:GetService("HttpService");
  39.  
  40. --//Setup
  41. local Live = Instance.new("Folder");
  42. Live.Name = "Live";
  43. Live.Parent = game.Workspace;
  44.  
  45. local Explosions = Instance.new("Folder");
  46. Explosions.Name = "Explosions";
  47. Explosions.Parent = game.Workspace;
  48.  
  49. if isfile("NK_Settings.json") then
  50.     Settings = HttpService:JSONDecode(readfile("NK_Settings.json"));
  51. end
  52.  
  53. --//Toggle
  54. UIS.InputBegan:Connect(function(Key)
  55.     if Key.KeyCode == ToggleKey then
  56.         _G.Autofarm = not _G.Autofarm;
  57.     end
  58. end)
  59.  
  60. task.wait(7);
  61.  
  62. --hookfunction(print, function() return end)
  63. --hookfunction(warn, function() return end)
  64.  
  65. --//Functions
  66.  
  67. function getClosestMob()
  68.     local closestMob = nil;
  69.     local lastDistance = math.huge;
  70.     lastPart = nil;
  71.  
  72.     for _, Mob in pairs(Live:GetChildren()) do
  73.         if Mob:FindFirstChild("Tags") and (Mob:FindFirstChild("Hitbox") or Mob:FindFirstChild("Base") or Mob:FindFirstChild("HumanoidRootPart") or Mob:FindFirstChild("Main")) then
  74.  
  75.             local canContinue = true;
  76.  
  77.             if Mob:FindFirstChild("Status") and Mob:FindFirstChild("Status"):FindFirstChild("Debuff_Invincible") and closestMob ~= nil then
  78.                 canContinue = false;
  79.             end
  80.  
  81.             if canContinue == true then
  82.  
  83.             lastPart = Mob:FindFirstChild("Hitbox") or Mob:FindFirstChild("Base") or Mob:FindFirstChild("HumanoidRootPart") or Mob:FindFirstChild("Main")
  84.  
  85.             local currentDistance = (HRP.Position - lastPart.Position).Magnitude;
  86.            
  87.             if closestMob ~= nil and (currentDistance < lastDistance or closestMob:FindFirstChild("Status") and closestMob:FindFirstChild("Status"):FindFirstChild("Debuff_Invincible")) then
  88.             closestMob = Mob;
  89.             lastDistance = currentDistance;
  90.             elseif closestMob == nil then
  91.                 closestMob = Mob;
  92.                 lastDistance = currentDistance;
  93.             end
  94.         end
  95.     end
  96. end
  97.  
  98.     if closestMob ~= nil then
  99.         lastPart = closestMob:FindFirstChild("Hitbox") or closestMob:FindFirstChild("Base") or closestMob:FindFirstChild("HumanoidRootPart") or closestMob:FindFirstChild("Main");
  100.     end
  101.    
  102.     return closestMob, lastPart
  103. end
  104.  
  105. function pressKey(Key, Hold)
  106.     VIM:SendKeyEvent(Hold, Key, false, game);
  107. end
  108.  
  109. function checkChests()
  110.     for _, Chest in pairs(game.Workspace.Dungeon:GetDescendants()) do
  111.         if (findName(Chest.Name, "chest") or findName(Chest.Name, "_medical") and not findName(Chest.Name, "machine") or findName(Chest.Name, "_ammo") and not findName(Chest.Name, "machine") or findName(Chest.Name, "locker")) and
  112.         (Chest:FindFirstChild("Interact") and Chest:FindFirstChild("Interact"):IsA("BasePart") or
  113.         Chest:FindFirstChild("Chest") and Chest:FindFirstChild("Chest"):IsA("BasePart")) and not Chest:FindFirstChild("Opened") then
  114.  
  115.             local Part = Chest:FindFirstChild("Interact") or Chest:FindFirstChild("Chest");
  116.            
  117.             HRP.CFrame = Part.CFrame;
  118.  
  119.             local Distance = (HRP.Position - Part.Position).Magnitude;
  120.  
  121.             repeat task.wait() Distance = (HRP.Position - Part.Position).Magnitude until Distance <= 4
  122.  
  123.             local Times = findName(Chest.Name, "chest") and 30 or 10
  124.  
  125.             game.ReplicatedStorage.Ints.Interactcontrol:InvokeServer("Chestopen", Chest);
  126.  
  127.             local Opened = Instance.new("Folder");
  128.             Opened.Name = "Opened";
  129.             Opened.Parent = Chest;
  130.  
  131.             task.wait(1.47);
  132.         end
  133.     end
  134.  
  135.     return true
  136. end
  137.  
  138. function passRoom(Door)
  139.     local Part = Door:FindFirstChild("Interact") or Door:FindFirstChild("Part")
  140.     if Part == nil then
  141.         Part = Door:FindFirstChildWhichIsA("BasePart");
  142.     end
  143.     HRP.CFrame = Part.CFrame;
  144.  
  145.     task.wait();
  146.     game.ReplicatedStorage.Ints.Regiontrig:FireServer("Door", Door);
  147. end
  148.  
  149. function checkRoom()
  150.     local Empty = false;
  151.     local Door = nil;
  152.    
  153.     for _, v in pairs(game.Workspace.Dungeon:GetDescendants()) do
  154.         if findName(v.Name, "shrine") and v.Name ~= "Shrine" and v:FindFirstChildWhichIsA("BasePart") and v:FindFirstChildWhichIsA("BasePart").Name == "Interact" then
  155.                 HRP.CFrame = v:FindFirstChildWhichIsA("BasePart").CFrame;
  156.                 task.wait(0.1);
  157.                 v:FindFirstChildWhichIsA("BasePart").Purchase:FireServer();
  158.                 task.wait(1);
  159.                 v:Destroy();
  160.             end
  161.  
  162.             if v.Name == "Midnight_Shrineend" and v:FindFirstChild("Interact") then
  163.                 HRP.CFrame = v:FindFirstChild("Interact").CFrame;
  164.                 task.wait(0.1);
  165.                 v:FindFirstChild("Interact").Purchase:FireServer();
  166.                 task.wait(20);
  167.                 v:Destroy();
  168.             end
  169.            
  170.         if v.Name == "Nextroomind" and v.Enabled == true then
  171.             Empty = true;
  172.             Door = v.Parent;
  173.         end
  174.     end
  175.  
  176.     return Empty, Door
  177. end
  178.  
  179. function collectBundles()
  180.     for _, Bundle in pairs(Player.Character:GetChildren()) do
  181.         if Bundle.Name == "Pickup" and Bundle:FindFirstChild("Pickupbase") then
  182.             Bundle.Pickupbase.CFrame = HRP.CFrame
  183.         end
  184.     end
  185. end
  186.  
  187. function getYLevel()
  188.     local Y = 1.7;
  189.     if Explosions:FindFirstChild("ExplodingBarrel") then
  190.         Y = 40;
  191.     end
  192.  
  193.     return Y
  194. end
  195.  
  196. function startFarm()
  197.  
  198.     collectBundles();
  199.     local closestMob, Part = getClosestMob();
  200.  
  201.     if closestMob ~= nil then
  202.         local Y = 0;
  203.     HRP.CFrame = Part.CFrame * CFrame.new(0, Y, 3);
  204.     if findName(closestMob.Name, "heart") and closestMob:FindFirstChild("Interact") then
  205.         closestMob.Interact.Purchase:FireServer();
  206.         closestMob.Interact.Name = "Used";
  207.     end
  208.     Attack(Part);
  209.     else
  210.  
  211.         local Y = getYLevel();
  212.         if Y == 40 then
  213.             --HRP.CFrame = HRP.CFrame * CFrame.new(0, Y, 0);
  214.         end
  215.         local isRoomEmpty, Door = checkRoom();
  216.  
  217.     if isRoomEmpty == true and Door ~= nil then
  218.         checkChests();
  219.             passRoom(Door)
  220.     end
  221.  
  222.     end
  223.  
  224. end
  225.  
  226. function Attack(lastPart)
  227.     local Distance = (HRP.Position - lastPart.Position).Magnitude;
  228.  
  229.     if Distance <= 10 and tick() - lastAttack > 0.1 then
  230.         Player.Character.Gunmain.Guninput:FireServer(
  231.             "Melee",
  232.             tick(),
  233.             HRP.CFrame,
  234.             math.random(0, 1000),
  235.             1,
  236.             {},
  237.             false
  238.         )
  239.        
  240.         Player.Character.Gunmain.Guninput:FireServer(
  241.             "Melee",
  242.             tick(),
  243.             HRP.CFrame,
  244.             math.random(0, 1000),
  245.             2,
  246.             {},
  247.             true
  248.         )
  249.         lastAttack = tick();
  250.     end
  251.    
  252. end
  253.  
  254. function findName(Name, Find)
  255.     return string.find(string.lower(Name), Find)
  256. end
  257.  
  258. function updateMobs()
  259.     for _, Mob in pairs(game.Workspace.Dungeon:GetDescendants()) do
  260.         if Mob:FindFirstChild("Tags") and not findName(Mob.Name, "barrel") and not findName(Mob.Name, "propane") and not findName(Mob.Name, "sludge") and not findName(Mob.Name, "cannon") and not findName(Mob.Name, "firepad") and not findName(Mob.Name, "conveyor") and not findName(Mob.Name, "sidepress") and not findName(Mob.Name, "pressfast") then
  261.             Mob.Parent = Live;
  262.         elseif findName(Mob.Name, "barrel") then
  263.             if Mob:FindFirstChild("Explosivedeath") then
  264.                
  265.                 if #Explosions:GetChildren() <= 3 then
  266.                 local Explosion = Instance.new("Folder");
  267.                 Explosion.Name = "ExplodingBarrel";
  268.                 Explosion.Parent = Explosions;
  269.                 Debris:AddItem(Explosion, 1);
  270.                 end
  271.  
  272.                 task.spawn(function()
  273.                     task.wait(1)
  274.                     if Mob and Mob:FindFirstChild("Explosivedeath") then
  275.                         Mob.Explosivedeath:Destroy();
  276.                     end
  277.                 end)
  278.  
  279.             end
  280.         end
  281.     end
  282. end
  283.  
  284. --//Update
  285. task.spawn(function()
  286.     while true do
  287.         task.spawn(function()
  288.         updateMobs();
  289.         end)
  290.         task.wait(0.17);
  291.     end
  292. end)
  293.  
  294. --//Farm
  295. task.spawn(function()
  296.     while true do
  297.         if _G.Autofarm == true then
  298. startFarm();
  299.  
  300. task.spawn(function() -- Autosell
  301.     if Settings.AutoSell == true and tick() - lastSell > 15 then
  302.  
  303.         for _,v in pairs(Player.Guns:GetChildren()) do
  304.             if v:FindFirstChild("Slot") and v.Slot.Value == 0 then
  305.  
  306.                 if Settings.RarityFilter ~= nil and Settings.RarityFilter ~= "" then
  307.                      if Player.Sessionstats.Guncache:FindFirstChild(v.Name) and Player.Sessionstats.Guncache:FindFirstChild(v.Name).Stats.Tags.Raritynum.Value < RarityTable[Settings.RarityFilter] then
  308.                 game.ReplicatedStorage.Ints.Purchasecontrol:InvokeServer("Sellgun", v)
  309.                 end
  310.                     end
  311.  
  312.                     if Settings.RarityFilter == nil or Settings.RarityFilter == "" then
  313.                         game.ReplicatedStorage.Ints.Purchasecontrol:InvokeServer("Sellgun", v)
  314.                         end
  315.             end
  316.             task.wait(0.1)
  317.         end
  318.  
  319.         for _,v in pairs(Player.Gear:GetChildren()) do
  320.             if v:FindFirstChild("Slot") and v.Slot.Value == 0 then
  321.  
  322.                 if Settings.RarityFilter ~= nil and Settings.RarityFilter ~= "" then
  323.                      if Player.Sessionstats.Guncache:FindFirstChild(v.Name) and Player.Sessionstats.Guncache:FindFirstChild(v.Name).Stats.Tags.Raritynum.Value < RarityTable[Settings.RarityFilter] then
  324.                 game.ReplicatedStorage.Ints.Purchasecontrol:InvokeServer("Sellgun", v)
  325.                 end
  326.                     end
  327.  
  328.                     if Settings.RarityFilter == nil or Settings.RarityFilter == "" then
  329.                         game.ReplicatedStorage.Ints.Purchasecontrol:InvokeServer("Sellgun", v)
  330.                         end
  331.             end
  332.             task.wait(0.1)
  333.         end
  334.         lastSell = tick();
  335.     end
  336. end)
  337.     end
  338.     task.wait();
  339. end
  340. end)
  341.  
  342. --//Auto Pickup
  343. game.Workspace.ChildAdded:Connect(function(Child)
  344.     repeat task.wait()
  345.     if Child.Name == "Lootbundle" and _G.Autofarm == true then
  346.                 game.ReplicatedStorage.Ints.Interactcontrol:InvokeServer(
  347.                     "Gunopen",
  348.                     "Unequip",
  349.                     Child:GetChildren()[1],
  350.                     "Gunitem"
  351.                 )
  352.     end
  353. until Child == nil
  354. end)
  355.  
  356. --//Rejoin
  357. Player.PlayerGui.Run.Dead.Return.Changed:Connect(function()
  358.     if Player and Player:FindFirstChild("PlayerGui") and Player.PlayerGui.Run.Dead.Return.Visible == true then
  359.         task.wait(1.7);
  360. game.ReplicatedStorage.Ints.Regiontrig:FireServer("Leave");
  361.     end
  362. end)
  363.  
  364. --//Finished Run
  365. Player.PlayerGui.Run.Runend.Return.Changed:Connect(function()
  366.     if Player and Player:FindFirstChild("PlayerGui") and Player.PlayerGui.Run.Runend.Return.Visible == true then
  367.         task.wait(1.7);
  368.         if Settings.NextRegion == false or game.ReplicatedStorage.World.Dungeondata.Location.Value == "Junction" or (Settings.LeaveAtRegion ~= nil and Settings.LeaveAtRegion ~= "") and game.ReplicatedStorage.World.Dungeondata.Location.Value == Settings.LeaveAtRegion then
  369. game.ReplicatedStorage.Ints.Regiontrig:FireServer("Leave");
  370.         else
  371.             game.ReplicatedStorage.Ints.Regiontrig:FireServer("Votenext");
  372.         end
  373.     end
  374. end)
  375.  
  376. --//Load Script
  377. syn.queue_on_teleport([[
  378.     repeat task.wait() until game:IsLoaded();
  379.  
  380.     local Player = game.Players.LocalPlayer;
  381.  
  382.     task.wait(7);
  383.  
  384.     repeat task.wait() until not Player.PlayerGui:FindFirstChild("Intro");
  385.  
  386.     loadstring(game:HttpGet("https://pastebin.com/raw/FNw0Q7Dm"))();
  387. ]])
  388.  
  389. task.wait(3);
  390. local Hitbox = Player.Character.Playermodel.Hitbox;
  391.  
  392. task.spawn(function()
  393.     while true do
  394.         Hitbox.Parent = nil;
  395.         task.wait(10);
  396.         Hitbox.Parent = Player.Character.Playermodel;
  397.         task.wait(1);
  398.     end
  399. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement