Advertisement
suramraja1

asdasd

Aug 14th, 2023
1,148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 17.21 KB | None | 0 0
  1. -- hi! feel free to use any of this code for your own projects or use the libary for your projects. i know its a little messy because i rushed it (with no sleep as well 😴) but it works well enough.
  2.  
  3. local Serverhop = {}; -- init
  4.  
  5. local API, ServerPages;
  6.  
  7. local function CreateFiles(FileName, File)
  8.     pcall(function()
  9.         makefolder("ServerHopper")
  10.         makefolder("ServerHopper//".. game.PlaceId)
  11.         writefile("ServerHopper//".. game.PlaceId .."//".. FileName ..".json", File)
  12.     end)
  13. end
  14.  
  15. function Serverhop:Normal(Logs, Amount)
  16.     if Amount == nil then Amount = tonumber(math.huge) end;
  17.     local JobIDs = {};
  18.     local function FetchJobIDs()
  19.         JobIDs = {os.date("*t").hour};
  20.         local _s = tick();
  21.         if Logs then rconsolename("serverhop-libary.lua ; seth.#0001 - ".. string.format("%02i:%02i %s", ((os.date("*t").hour % 24 - 1) % 12) + 1, os.date("*t").min, os.date("*t").hour % 24 < 12 and "AM" or "PM")) rconsoleprint("@@CYAN@@") rconsoleprint("[!] Awaiting for ".. Amount .." servers to be scraped. \n") end;
  22.         repeat
  23.             task.wait()
  24.             API = game:GetService("HttpService"):JSONDecode(game:HttpGet("https://games.roblox.com/v1/games/".. game.PlaceId .."/servers/Public?sortOrder=Asc&limit=100".. (ServerPages and "&cursor=".. ServerPages or ""))); -- servers api
  25.             for i, v in next, API["data"] do
  26.                 if v["id"] ~= game.JobId and v["playing"] ~= v["maxPlayers"] then
  27.                     if #JobIDs < Amount + 1 then
  28.                         table.insert(JobIDs, v["id"])
  29.                     end
  30.                 end
  31.             end
  32.             ServerPages = API.nextPageCursor
  33.         until not ServerPages or #JobIDs >= Amount + 1
  34.         if Logs then rconsoleprint("@@CYAN@@") rconsoleprint("[!] Successfully scraped ".. #JobIDs - 1 .." servers in ".. math.round(tick() - _s) .."s. \n") end;
  35.         return true;
  36.     end
  37.     if not isfile("ServerHopper//".. game.PlaceId .."//normal-jobids.json") then
  38.         FetchJobIDs()
  39.         CreateFiles("normal-jobids", game:GetService("HttpService"):JSONEncode(JobIDs))
  40.     end
  41.     JobIDs = game:GetService("HttpService"):JSONDecode(readfile("ServerHopper//".. game.PlaceId .."//normal-jobids.json"))
  42.     if JobIDs[1] ~= os.date("*t").hour then
  43.         FetchJobIDs()
  44.         writefile("ServerHopper//".. game.PlaceId .."//normal-jobids.json", game:GetService("HttpService"):JSONEncode(JobIDs))
  45.     end
  46.     local function RandomJobID()
  47.         return JobIDs[math.random(1, #JobIDs)]
  48.     end
  49.     local SelectedJobID = RandomJobID();
  50.     if Logs then rconsolename("serverhop-libary.lua ; seth.#0001 - ".. string.format("%02i:%02i %s", ((os.date("*t").hour % 24 - 1) % 12) + 1, os.date("*t").min, os.date("*t").hour % 24 < 12 and "AM" or "PM")) rconsoleprint("@@LIGHT_CYAN@@") rconsoleprint("[#] Server hopping to ".. SelectedJobID ..". \n") end;
  51.     game:GetService("TeleportService"):TeleportToPlaceInstance(game.PlaceId, SelectedJobID)
  52.     game:GetService("Players").LocalPlayer.OnTeleport:Connect(function(Status)
  53.         if Status == Enum.TeleportState.Failed then
  54.             if Logs then rconsoleprint("@@LIGHT_RED@@") rconsoleprint("[*] Failed to join ".. SelectedJobID .." finding new server. \n") end;
  55.             SelectedJobID = RandomJobID();
  56.             if Logs then rconsoleprint("@@LIGHT_CYAN@@") rconsoleprint("[#] Server hopping to ".. SelectedJobID ..". \n") end;
  57.             game:GetService("TeleportService"):TeleportToPlaceInstance(game.PlaceId, SelectedJobID)
  58.         end
  59.     end)
  60. end
  61.  
  62. function Serverhop:Dynamic(Logs, Amount)
  63.     if Amount == nil then Amount = tonumber(math.huge) end;
  64.     local JobIDs = {};
  65.     local OldJobIDs = {os.date("*t").hour};
  66.     local function FetchJobIDs()
  67.         JobIDs = {os.date("*t").hour};
  68.         local _s = tick();
  69.         if Logs then rconsolename("serverhop-libary.lua ; seth.#0001 - ".. string.format("%02i:%02i %s", ((os.date("*t").hour % 24 - 1) % 12) + 1, os.date("*t").min, os.date("*t").hour % 24 < 12 and "AM" or "PM")) rconsoleprint("@@CYAN@@") rconsoleprint("[!] Awaiting for ".. Amount .." servers to be scraped. \n") end;
  70.         repeat
  71.             task.wait()
  72.             API = game:GetService("HttpService"):JSONDecode(game:HttpGet("https://games.roblox.com/v1/games/".. game.PlaceId .."/servers/Public?sortOrder=Asc&limit=100".. (ServerPages and "&cursor=".. ServerPages or ""))); -- servers api
  73.             for i, v in next, API["data"] do
  74.                 if v["id"] ~= game.JobId and v["playing"] ~= v["maxPlayers"] and not table.find(OldJobIDs, v["id"]) then
  75.                     if #JobIDs < Amount + 1 then
  76.                         table.insert(JobIDs, v["id"])
  77.                     end
  78.                 end
  79.             end
  80.             ServerPages = API.nextPageCursor
  81.         until not ServerPages or #JobIDs >= Amount + 1
  82.         if Logs then rconsoleprint("@@CYAN@@") rconsoleprint("[!] Successfully scraped ".. #JobIDs - 1 .." servers in ".. math.round(tick() - _s) .."s. \n") end;
  83.         return true;
  84.     end
  85.     if not isfile("ServerHopper//".. game.PlaceId .."//old_dynamic-jobids.json") then
  86.         CreateFiles("old_dynamic-jobids", game:GetService("HttpService"):JSONEncode(OldJobIDs))
  87.     end
  88.     OldJobIDs = game:GetService("HttpService"):JSONDecode(readfile("ServerHopper//".. game.PlaceId .."//old_dynamic-jobids.json"))
  89.     if not isfile("ServerHopper//".. game.PlaceId .."//dynamic-jobids.json") then
  90.         FetchJobIDs()
  91.         CreateFiles("dynamic-jobids", game:GetService("HttpService"):JSONEncode(JobIDs))
  92.     end
  93.     JobIDs = game:GetService("HttpService"):JSONDecode(readfile("ServerHopper//".. game.PlaceId .."//dynamic-jobids.json"))
  94.     if JobIDs[1] ~= os.date("*t").hour or #JobIDs < 2 then
  95.         FetchJobIDs()
  96.         writefile("ServerHopper//".. game.PlaceId .."//dynamic-jobids.json", game:GetService("HttpService"):JSONEncode(JobIDs))
  97.         if #JobIDs < 2 then
  98.             writefile("ServerHopper//".. game.PlaceId .."//old_dynamic-jobids.json", game:GetService("HttpService"):JSONEncode({os.date("*t").hour}))
  99.         end
  100.     end
  101.     if OldJobIDs[1] ~= os.date("*t").hour then
  102.         FetchJobIDs()
  103.         writefile("ServerHopper//".. game.PlaceId .."//old_dynamic-jobids.json", game:GetService("HttpService"):JSONEncode({os.date("*t").hour}))
  104.     end
  105.     local function RandomJobID()
  106.         return JobIDs[math.random(1, #JobIDs)]
  107.     end
  108.     local SelectedJobID = RandomJobID();
  109.     if Logs then rconsolename("serverhop-libary.lua ; seth.#0001 - ".. string.format("%02i:%02i %s", ((os.date("*t").hour % 24 - 1) % 12) + 1, os.date("*t").min, os.date("*t").hour % 24 < 12 and "AM" or "PM")) rconsoleprint("@@LIGHT_CYAN@@") rconsoleprint("[#] Server hopping to ".. SelectedJobID ..". \n") end;
  110.     table.remove(JobIDs, table.find(JobIDs, SelectedJobID))
  111.     table.insert(OldJobIDs, SelectedJobID)
  112.     writefile("ServerHopper//".. game.PlaceId .."//old_dynamic-jobids.json", game:GetService("HttpService"):JSONEncode(OldJobIDs))
  113.     writefile("ServerHopper//".. game.PlaceId .."//dynamic-jobids.json", game:GetService("HttpService"):JSONEncode(JobIDs))
  114.     game:GetService("TeleportService"):TeleportToPlaceInstance(game.PlaceId, SelectedJobID)
  115.     game:GetService("Players").LocalPlayer.OnTeleport:Connect(function(Status)
  116.         if Status == Enum.TeleportState.Failed then
  117.             if Logs then rconsoleprint("@@LIGHT_RED@@") rconsoleprint("[*] Failed to join ".. SelectedJobID .." finding new server. \n") end;
  118.             SelectedJobID = RandomJobID();
  119.             if Logs then rconsoleprint("@@LIGHT_CYAN@@") rconsoleprint("[#] Server hopping to ".. SelectedJobID ..". \n") end;
  120.             table.remove(JobIDs, table.find(JobIDs, SelectedJobID))
  121.             table.insert(OldJobIDs, SelectedJobID)
  122.             writefile("ServerHopper//".. game.PlaceId .."//old_dynamic-jobids.json", game:GetService("HttpService"):JSONEncode(OldJobIDs))
  123.             writefile("ServerHopper//".. game.PlaceId .."//dynamic-jobids.json", game:GetService("HttpService"):JSONEncode(JobIDs))
  124.             game:GetService("TeleportService"):TeleportToPlaceInstance(game.PlaceId, SelectedJobID)
  125.         end
  126.     end)
  127. end
  128.  
  129. function Serverhop:Rejoin(Logs)
  130.     if Logs then rconsolename("severhop-libary.lua ; seth.#0001 - ".. string.format("%02i:%02i %s", ((os.date("*t").hour % 24 - 1) % 12) + 1, os.date("*t").min, os.date("*t").hour % 24 < 12 and "AM" or "PM")) rconsoleprint("@@LIGHT_CYAN@@") rconsoleprint("[#] Rejoining server. \n") end;
  131.     game:GetService("TeleportService"):TeleportToPlaceInstance(game.PlaceId, game.JobId)
  132.     game:GetService("Players").LocalPlayer.OnTeleport:Connect(function(Status)
  133.         if Status == Enum.TeleportState.Failed then
  134.             if Logs then rconsoleprint("@@LIGHT_RED@@") rconsoleprint("[*] Failed to rejoin. \n") end;
  135.         end
  136.     end)
  137. end
  138.  
  139. function Serverhop:LowPing(Logs, Amount, Ping)
  140.     if Ping == nil then Ping = 450 end;
  141.     if Amount == nil then Amount = tonumber(math.huge) end;
  142.     local JobIDs = {};
  143.     local function FetchJobIDs()
  144.         JobIDs = {os.date("*t").hour};
  145.         local _s = tick();
  146.         if Logs then rconsolename("serverhop-libary.lua ; seth.#0001 - ".. string.format("%02i:%02i %s", ((os.date("*t").hour % 24 - 1) % 12) + 1, os.date("*t").min, os.date("*t").hour % 24 < 12 and "AM" or "PM")) rconsoleprint("@@CYAN@@") rconsoleprint("[!] Awaiting for ".. Amount .." servers to be scraped. \n") end;
  147.         repeat
  148.             task.wait()
  149.             API = game:GetService("HttpService"):JSONDecode(game:HttpGet("https://games.roblox.com/v1/games/".. game.PlaceId .."/servers/Public?sortOrder=Asc&limit=100".. (ServerPages and "&cursor=".. ServerPages or ""))); -- servers api
  150.             for i, v in next, API["data"] do
  151.                 if v["id"] ~= game.JobId and v["playing"] ~= v["maxPlayers"] and v["ping"] ~= nil and v["ping"] <= Ping then
  152.                     if #JobIDs < Amount + 1 then
  153.                         table.insert(JobIDs, v["id"])
  154.                     end
  155.                 end
  156.             end
  157.         until not ServerPages or #JobIDs >= Amount + 1
  158.         if Logs then rconsoleprint("@@CYAN@@") rconsoleprint("[!] Successfully scraped ".. #JobIDs - 1 .." servers in ".. math.round(tick() - _s) .."s. \n") end;
  159.         return true;
  160.     end
  161.     if not isfile("ServerHopper//".. game.PlaceId .."//low_ping-jobids.json") then
  162.         FetchJobIDs()
  163.         CreateFiles("low_ping-jobids", game:GetService("HttpService"):JSONEncode(JobIDs))
  164.     end
  165.     JobIDs = game:GetService("HttpService"):JSONDecode(readfile("ServerHopper//".. game.PlaceId .."//low_ping-jobids.json"))
  166.     if JobIDs[1] ~= os.date("*t").hour then
  167.         FetchJobIDs()
  168.         writefile("ServerHopper//".. game.PlaceId .."//low_ping-jobids.json", game:GetService("HttpService"):JSONEncode(JobIDs))
  169.     end
  170.     local function RandomJobID()
  171.         return JobIDs[math.random(1, #JobIDs)]
  172.     end
  173.     local SelectedJobID = RandomJobID();
  174.     if Logs then rconsolename("serverhop-libary.lua ; seth.#0001 - ".. string.format("%02i:%02i %s", ((os.date("*t").hour % 24 - 1) % 12) + 1, os.date("*t").min, os.date("*t").hour % 24 < 12 and "AM" or "PM")) rconsoleprint("@@LIGHT_CYAN@@") rconsoleprint("[#] Server hopping to ".. SelectedJobID ..". \n") end;
  175.     game:GetService("TeleportService"):TeleportToPlaceInstance(game.PlaceId, SelectedJobID)
  176.     game:GetService("Players").LocalPlayer.OnTeleport:Connect(function(Status)
  177.         if Status == Enum.TeleportState.Failed then
  178.             if Logs then rconsoleprint("@@LIGHT_RED@@") rconsoleprint("[*] Failed to join ".. SelectedJobID .." finding new server. \n") end;
  179.             SelectedJobID = RandomJobID();
  180.             if Logs then rconsoleprint("@@LIGHT_CYAN@@") rconsoleprint("[#] Server hopping to ".. SelectedJobID ..". \n") end;
  181.             game:GetService("TeleportService"):TeleportToPlaceInstance(game.PlaceId, SelectedJobID)
  182.         end
  183.     end)
  184. end
  185.  
  186. function Serverhop:LowPlayers(Logs, Amount, Players)
  187.     if Players == nil then for i, v in next, game:GetService("HttpService"):JSONDecode(game:HttpGet("https://games.roblox.com/v1/games?universeIds=".. game.GameId))["data"] do Players = tonumber(v["maxPlayers"]) / 2 end end;
  188.     if Amount == nil then Amount = tonumber(math.huge) end;
  189.     local JobIDs = {};
  190.     local function FetchJobIDs()
  191.         JobIDs = {os.date("*t").hour};
  192.         local _s = tick();
  193.         if Logs then rconsolename("serverhop-libary.lua ; seth.#0001 - ".. string.format("%02i:%02i %s", ((os.date("*t").hour % 24 - 1) % 12) + 1, os.date("*t").min, os.date("*t").hour % 24 < 12 and "AM" or "PM")) rconsoleprint("@@CYAN@@") rconsoleprint("[!] Awaiting for ".. Amount .." servers to be scraped. \n") end;
  194.         repeat
  195.             task.wait()
  196.             API = game:GetService("HttpService"):JSONDecode(game:HttpGet("https://games.roblox.com/v1/games/".. game.PlaceId .."/servers/Public?sortOrder=Asc&limit=100".. (ServerPages and "&cursor=".. ServerPages or ""))); -- servers api
  197.             for i, v in next, API["data"] do
  198.                 if v["id"] ~= game.JobId and v["playing"] ~= v["maxPlayers"] and v["playing"] <= Players then
  199.                     if #JobIDs < Amount + 1 then
  200.                         table.insert(JobIDs, v["id"])
  201.                     end
  202.                 end
  203.             end
  204.         until not ServerPages or #JobIDs >= Amount + 1
  205.         if Logs then rconsoleprint("@@CYAN@@") rconsoleprint("[!] Successfully scraped ".. #JobIDs - 1 .." servers in ".. math.round(tick() - _s) .."s. \n") end;
  206.         return true;
  207.     end
  208.     if not isfile("ServerHopper//".. game.PlaceId .."//low_players-jobids.json") then
  209.         FetchJobIDs()
  210.         CreateFiles("low_players-jobids", game:GetService("HttpService"):JSONEncode(JobIDs))
  211.     end
  212.     JobIDs = game:GetService("HttpService"):JSONDecode(readfile("ServerHopper//".. game.PlaceId .."//low_players-jobids.json"))
  213.     if JobIDs[1] ~= os.date("*t").hour then
  214.         FetchJobIDs()
  215.         writefile("ServerHopper//".. game.PlaceId .."//low_players-jobids.json", game:GetService("HttpService"):JSONEncode(JobIDs))
  216.     end
  217.     local function RandomJobID()
  218.         return JobIDs[math.random(1, #JobIDs)]
  219.     end
  220.     local SelectedJobID = RandomJobID();
  221.     if Logs then rconsolename("serverhop-libary.lua ; seth.#0001 - ".. string.format("%02i:%02i %s", ((os.date("*t").hour % 24 - 1) % 12) + 1, os.date("*t").min, os.date("*t").hour % 24 < 12 and "AM" or "PM")) rconsoleprint("@@LIGHT_CYAN@@") rconsoleprint("[#] Server hopping to ".. SelectedJobID ..". \n") end;
  222.     game:GetService("TeleportService"):TeleportToPlaceInstance(game.PlaceId, SelectedJobID)
  223.     game:GetService("Players").LocalPlayer.OnTeleport:Connect(function(Status)
  224.         if Status == Enum.TeleportState.Failed then
  225.             if Logs then rconsoleprint("@@LIGHT_RED@@") rconsoleprint("[*] Failed to join ".. SelectedJobID .." finding new server. \n") end;
  226.             SelectedJobID = RandomJobID();
  227.             if Logs then rconsoleprint("@@LIGHT_CYAN@@") rconsoleprint("[#] Server hopping to ".. SelectedJobID ..". \n") end;
  228.             game:GetService("TeleportService"):TeleportToPlaceInstance(game.PlaceId, SelectedJobID)
  229.         end
  230.     end)
  231. end
  232.  
  233. function Serverhop:Instant(Logs)
  234.     local JobIDs = {};
  235.     for i, v in next, game:GetService("HttpService"):JSONDecode(game:HttpGet("https://games.roblox.com/v1/games/".. game.PlaceId .."/servers/Public?sortOrder=Asc&limit=100"))["data"] do
  236.         if v["id"] ~= game.PlaceId and v["playing"] ~= v["maxPlayers"] then
  237.             table.insert(JobIDs, v["id"])
  238.         end
  239.     end
  240.     local function RandomJobID()
  241.         return JobIDs[math.random(1, #JobIDs)]
  242.     end
  243.     local SelectedJobID = RandomJobID();
  244.     if Logs then rconsolename("serverhop-libary.lua ; seth.#0001 - ".. string.format("%02i:%02i %s", ((os.date("*t").hour % 24 - 1) % 12) + 1, os.date("*t").min, os.date("*t").hour % 24 < 12 and "AM" or "PM")) rconsoleprint("@@LIGHT_CYAN@@") rconsoleprint("[#] Server hopping to ".. SelectedJobID ..". \n") end;
  245.     game:GetService("TeleportService"):TeleportToPlaceInstance(game.PlaceId, SelectedJobID)
  246.     game:GetService("Players").LocalPlayer.OnTeleport:Connect(function(Status)
  247.         if Status == Enum.TeleportState.Failed then
  248.             if Logs then rconsoleprint("@@LIGHT_RED@@") rconsoleprint("[*] Failed to join ".. SelectedJobID .." finding new server. \n") end;
  249.             SelectedJobID = RandomJobID();
  250.             if Logs then rconsoleprint("@@LIGHT_CYAN@@") rconsoleprint("[#] Server hopping to ".. SelectedJobID ..". \n") end;
  251.             game:GetService("TeleportService"):TeleportToPlaceInstance(game.PlaceId, SelectedJobID)
  252.         end
  253.     end)
  254. end
  255.  
  256. function Serverhop:JoinJobID(Logs, JobID)
  257.     if Logs then rconsolename("severhop-libary.lua ; seth.#0001 - ".. string.format("%02i:%02i %s", ((os.date("*t").hour % 24 - 1) % 12) + 1, os.date("*t").min, os.date("*t").hour % 24 < 12 and "AM" or "PM")) rconsoleprint("@@LIGHT_CYAN@@") rconsoleprint("[#] Attempting to join ".. JobID ..". \n") end;
  258.     game:GetService("TeleportService"):TeleportToPlaceInstance(game.PlaceId, JobID)
  259.     game:GetService("Players").LocalPlayer.OnTeleport:Connect(function(Status)
  260.         if Status == Enum.TeleportState.Failed then
  261.             if Logs then rconsoleprint("@@LIGHT_RED@@") rconsoleprint("[*] Failed to join ".. JobID ..". \n") end;
  262.         end
  263.     end)
  264. end
  265.  
  266. return Serverhop;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement