Advertisement
Gazer29

Command

Jan 16th, 2024 (edited)
694
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.46 KB | Gaming | 0 0
  1. -- Function to start the computer
  2. function startComputer()
  3.     print("Towns are starting...")
  4.     local Utility = require("Utility")
  5.     local McAPI   = require("McAPI")
  6.     if Utility and McAPI then
  7.         McAPI.ScoreSet("StartUp", "AllTowns", 1)
  8.     end
  9. end
  10.  
  11. -- Function to stop the computer
  12. function stopComputer()
  13.     print("Towns are stopping...")
  14.     local Utility = require("Utility")
  15.     local McAPI   = require("McAPI")
  16.     if Utility and McAPI then
  17.         McAPI.ScoreSet("StartUp", "AllTowns", 0)
  18.         McAPI.ScoreSet("Restart", "AllTowns", 1)
  19.     end
  20. end
  21.  
  22. -- Function to reboot the computer
  23. function rebootComputer()
  24.     print("Towns are rebooting...")
  25.     local Utility = require("Utility")
  26.     local McAPI   = require("McAPI")
  27.     if Utility and McAPI then
  28.         McAPI.ScoreSet("StartUp", "AllTowns", 1)
  29.         McAPI.ScoreSet("Restart", "AllTowns", 1)
  30.     end
  31. end
  32.  
  33. -- Function to update Stats
  34. function statsComputer()
  35.     print("Updating Stats...")
  36.     local Utility = require("Utility")
  37.     local McAPI   = require("McAPI")
  38.     if Utility and McAPI then
  39.         while true do
  40.             local Alltowns = Utility.FindAllTowns()
  41.             McAPI.ScoreSet("Towns", "AllTowns", #Alltowns)
  42.             os.sleep(10)
  43.         end
  44.     end
  45. end
  46.  
  47. -- Function to SelfDestruct the town
  48. function SelfDestruct()
  49.     local Utility = require("Utility")
  50.     local townNames = "Defaults\\townNames.json"
  51.     local x,y,z = gps.locate()
  52.     local townFolder = "Town_X"..x.."Y"..y.."Z"..z
  53.     local town = "Towns\\"..townFolder.."\\"
  54.     local SettingsFile = town.."SET_X"..x.."Y"..y.."Z"..z..".json"
  55.     local adminFile = "AdminSettings.json"
  56.     Utility.LoadFiles(SettingsFile,adminFile,"")
  57.  
  58.     print("Computer will Self Destruct in 5 seconds")
  59.     os.sleep(5)
  60.     local townNamesList = Utility.readJsonFile(townNames)
  61.     local Settings = Utility.readJsonFile(SettingsFile)
  62.     if townNamesList and townNamesList.used and Settings and Settings.town.name ~= nil then
  63.         townNamesList.used[Settings.town.name] = nil
  64.         Utility.writeJsonFile(townNames,townNamesList)
  65.     end
  66.     Utility.SelfDestruct()
  67. end
  68.  
  69. local function RandomGen()
  70.     local Utility = require("Utility")
  71.     local McAPI     = require("McAPI")
  72.     local adminFile = "AdminSettings.json"
  73.     local x,y,z = gps.locate()
  74.  
  75.     while true do
  76.         local Alltowns = Utility.FindAllTowns()
  77.         if #Alltowns > 0 then
  78.             local RandomTown = Alltowns[math.random(1, #Alltowns)]
  79.             local Admin = Utility.readJsonFile(adminFile)
  80.             local result, message, score = commands.scoreboard.players.get("GenState", "AllTowns")
  81.             if Admin and score == 2 then
  82.                 local OpLocation = Utility.findNewTownLocation(Utility.FindOtherTowns(RandomTown.folderName), Admin.generation.minDistance,Admin.generation.maxDistance, {x = RandomTown.x, z = RandomTown.z}, Admin.generation.spread)
  83.                 if OpLocation then
  84.                     Utility.SpawnTown(OpLocation.x,OpLocation.y,OpLocation.z,McAPI.GetComputerId(x, y, z))
  85.                     os.sleep(60)
  86.                 end
  87.             end
  88.             if Admin and score == 3 then
  89.                 local result, message, score = commands.exec("list")
  90.                 local playerList = {}
  91.                 if result then
  92.                     -- Splitting the string at ': ' to isolate the player names
  93.                     function ExtractPlayerNames(inputstr)
  94.                         local names = {}
  95.                         local pattern = "online: (.+)$"
  96.                         local players = string.match(inputstr, pattern)
  97.                         if players then
  98.                             for name in string.gmatch(players, "([^, ]+)") do
  99.                                 table.insert(names, name)
  100.                             end
  101.                         end
  102.                         return names
  103.                     end
  104.                     playerList = ExtractPlayerNames(message[1])
  105.                 end
  106.  
  107.                 if #playerList > 0 then
  108.                     for i,v in ipairs(playerList) do
  109.                         local result, message, score = commands.scoreboard.players.get(v, "useCarrot")
  110.                         if score > 0 then
  111.                             local a,b,c = commands.data.get.entity(v)
  112.                             local c= b[1]
  113.                             local d=string.match(c, 'Pos:.-.]')
  114.                             local xa,ya,za = string.match(d, "(%--%d*%.?%d+).,.(%--%d*%.?%d+).,.(%--%d*%.?%d+)")
  115.                             local xa,ya,za = Utility.round(xa),Utility.round(ya),Utility.round(za)
  116.                            
  117.                             local result, message, score = commands.data.get.entity(v,"Dimension")
  118.                             local result1, message1, score1 = commands.data.get.entity(v,"playerGameType")
  119.                             if score1 == 1 and string.match(message[1],"minecraft:overworld") then
  120.                                 Utility.SpawnTown(xa,ya,za,McAPI.GetComputerId(x, y, z))
  121.                             end
  122.                         end
  123.                     end
  124.                     commands.exec("scoreboard players reset * useCarrot")
  125.                 end
  126.             end
  127.         end
  128.         os.sleep(10)
  129.     end
  130. end
  131.  
  132. function Install()
  133.     print("Installing...")
  134.     --get json
  135.     shell.run("pastebin get 4nRg9CHU json")
  136.     --get gitget
  137.     shell.run("pastebin get W5ZkVYSi gitget")
  138.     --use gitget to get repo
  139.     shell.run("gitget Quackers29 CC-Towns main")
  140.     --reboot
  141.     os.sleep(2)
  142.     startComputer()
  143.     print("Rebooting...")
  144.     os.sleep(2)
  145.     os.reboot()
  146. end
  147.  
  148. function Update()
  149.     shell.run("gitget Quackers29 CC-Towns main")
  150. end
  151.  
  152. function ChangeName(newName)
  153.     local Utility = require("Utility")
  154.     local x,y,z = gps.locate()
  155.     local townFolder = "Town_X"..x.."Y"..y.."Z"..z
  156.     local town = "Towns\\"..townFolder.."\\"
  157.     local SettingsFile = town.."SET_X"..x.."Y"..y.."Z"..z..".json"
  158.     local adminFile = "AdminSettings.json"
  159.     Utility.LoadFiles(SettingsFile,adminFile,"")
  160.     Utility.ChangeName(newName)
  161.     os.reboot()
  162. end
  163.  
  164. function EditSettings()
  165.     local x,y,z = gps.locate()
  166.     local townFolder = "Town_X"..x.."Y"..y.."Z"..z
  167.     local town = "Towns\\"..townFolder.."\\"
  168.     local SettingsFile = town.."SET_X"..x.."Y"..y.."Z"..z..".json"
  169.     shell.run("edit "..SettingsFile)
  170. end
  171.  
  172. -- Main function to handle command-line argument
  173. function main(arg1, arg2)
  174.     if arg1 == "start" then
  175.         startComputer()
  176.     elseif arg1 == "stop" then
  177.         stopComputer()
  178.     elseif arg1 == "reboot" then
  179.         rebootComputer()
  180.     elseif arg1 == "stats" then
  181.         statsComputer()
  182.     elseif arg1 == "remove" then
  183.         SelfDestruct()
  184.     elseif arg1 == "generation" then
  185.         RandomGen()
  186.     elseif arg1 == "install" then
  187.         Install()
  188.     elseif arg1 == "update" then
  189.         Update()
  190.     elseif arg1 == "edit" then
  191.         EditSettings()
  192.     elseif arg1 == "name" then
  193.         if arg2 ~= "" or arg2 ~= nil then
  194.             ChangeName(arg2)
  195.         end
  196.     else
  197.         print("Invalid argument. Please use '<start|stop|reboot|stats|remove|generation|install|update|edit>'.")
  198.     end
  199. end
  200.  
  201. -- Get command-line argument
  202. local args = { ... }
  203. local arg1 = args[1]
  204. local arg2 = args[2]
  205.  
  206. -- Check if a command is provided
  207. if arg1 then
  208.     main(arg1, arg2)
  209. else
  210.     print("Usage: lua program <start|stop|reboot|stats|remove|generation|install|update|edit>")
  211. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement