Advertisement
Corbinhol

Trade Station Controller Installer

Sep 20th, 2022 (edited)
1,046
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.56 KB | None | 0 0
  1. --Redstone Controller Installer
  2. function download(code, location)
  3.     url = http.get("https://www.pastebin.com/raw/"..code)
  4.     f = fs.open(location,"w") --#opens file in write mode, has to be specified with location
  5.     f.write(url.readAll()) --#reads every byte of url and writes it to location
  6.     f.close() --# always close the file >:c
  7.     return true --#return true so function can be used in ifs
  8. end
  9.  
  10. if peripheral.getType("top")  ~= "modem" then
  11.     print("No Modem Found. Please Install Modem into back of computer then run the code again.");
  12. else
  13.     term.clear();
  14.     term.setCursorPos(1,1);
  15.  
  16.     local minecraftID;
  17.     local displayName;
  18.     local increment;
  19.     local color;
  20.  
  21.     while true do
  22.         term.clear();
  23.         term.setCursorPos(1,1)
  24.         print("Please enter the item id that you wish to add \n (Ex. minecraft:redstone) ALL LOWERCASE\n> ");
  25.         term.setCursorPos(3, 3)
  26.         minecraftID = read();
  27.  
  28.         print("Please enter the Display Name of the item that you wish to add (Ex. Redstone Dust)\n> ")
  29.         term.setCursorPos(3, 6)
  30.         displayName = read();
  31.  
  32.         print("Please Type the amount that you want to increment by. \n> ");
  33.         term.setCursorPos(3, 9)
  34.         increment = read();
  35.         term.clear();
  36.         term.setCursorPos(1,1)
  37.         print("===========================================");
  38.         print("Please Enter The Display Color");
  39.         print("===========================================");
  40.         print(" 1) White       2) Orange   3) Magenta");
  41.         print(" 4) Light Blue  5) yellow   6) lime");
  42.         print(" 7) Pink        8) Gray     9) Light Gray");
  43.         print("10) Cyan       11) Purple  12) Blue");
  44.         print("13) Brown      14) Green   15) Red");
  45.         print("===========================================");
  46.         print("> ")
  47.         term.setCursorPos(3, 10)
  48.        
  49.         while true do
  50.             color = tonumber(read());
  51.             if color == nil or color < 1 or color > 16 then
  52.                 print("Error Color Not Found. Try Again.")
  53.             else
  54.                 break;
  55.             end
  56.         end
  57.  
  58.         local displayColor;
  59.         if color == 1 then color = colors.white; displayColor = "White";
  60.         elseif color == 2 then color = colors.orange; displayColor = "Orange";
  61.         elseif color == 3 then color = colors.magenta; displayColor = "Magenta";
  62.         elseif color == 4 then color = colors.lightBlue; displayColor = "Light Blue";
  63.         elseif color == 5 then color = colors.yellow; displayColor = "Yellow";
  64.         elseif color == 6 then color = colors.lime; displayColor = "Lime";
  65.         elseif color == 7 then color = colors.pink; displayColor = "Pink";
  66.         elseif color == 8 then color = colors.gray; displayColor = "Gray";
  67.         elseif color == 9 then color = colors.lightGray; displayColor = "Light Gray";
  68.         elseif color == 10 then color = colors.cyan; displayColor = "Cyan";
  69.         elseif color == 11 then color = colors.purple; displayColor = "Purple";
  70.         elseif color == 12 then color = colors.blue; displayColor = "Blue";
  71.         elseif color == 13 then color = colors.brown; displayColor = "Brown";
  72.         elseif color == 14 then color = colors.green; displayColor = "Green";
  73.         elseif color == 15 then color = colors.red; displayColor = "Red";
  74.         end
  75.  
  76.         term.clear();
  77.         term.setCursorPos(1,1);
  78.         print("=========================================");
  79.         print("Is This Correct? [y/n]")
  80.         print("=========================================");
  81.         print("Item ID: " .. minecraftID);
  82.         print("Display Name: " .. displayName);
  83.         print("Increment: " .. increment);
  84.         print("Color: " .. displayColor);
  85.         print("=========================================");
  86.         print("> ")
  87.         term.setCursorPos(3, 9)
  88.         local answer = read();
  89.         if answer == "y" then break; end
  90.     end
  91.     local data = {};
  92.     data["itemID"] = minecraftID;
  93.     data["displayName"] = displayName;
  94.     data["increment"] = increment;
  95.     data["color"] = color;
  96.  
  97.     os.setComputerLabel("[" .. displayName .. "] Trade Station Controller");
  98.  
  99.     fs.delete("data.dat");
  100.     local file = fs.open("data.dat", "w");
  101.     file.write(textutils.serialize(data));
  102.     file.close();
  103.     fs.delete("/SmallGUI/init.lua")
  104.     print("Downloading SmallGUI Library...");
  105.     download("kY7CPumC", "/SmallGUI/init.lua");
  106.     fs.delete("startup.lua");
  107.     print("Downloading Trade Station Controller Program...");
  108.     download("bGmPju0E", "startup.lua");
  109.  
  110.     os.reboot();
  111. end
  112.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement