Advertisement
NekoTiki

Energy to Online

Dec 4th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.81 KB | None | 0 0
  1. local uid = ""
  2. local ePilon = ""
  3.  
  4. for key, side in pairs(peripheral.getNames()) do
  5.     if peripheral.getType(side) == "draconic_rf_storage" then
  6.         ePilon = peripheral.wrap(side)
  7.     end
  8. end
  9.  
  10. function setUsername()
  11.     term.setTextColor(colors.lightBlue)
  12.     print("Choose a username.")
  13.     term.setTextColor(colors.lime)
  14.     term.write("> ")
  15.     term.setTextColor(colors.yellow)
  16.     username = read()
  17.     if username == "" then
  18.         term.setTextColor(colors.red)
  19.         print("\nUsername can't be blank.\n")
  20.         setUsername()
  21.     end
  22.  
  23.     request = http.post("https://rodre.nekotiki.fr/setenergyname.php", "uid=" .. uid .. "&username=" .. username)
  24.     data = request.readAll()
  25.     if data == "false" then
  26.         term.setTextColor(colors.red)
  27.         print("\nUsername Already Taken.\n")
  28.         setUsername()
  29.     else
  30.         term.setTextColor(colors.lime)
  31.         print("\nUsername as been set.\n")
  32.  
  33.         fUid = fs.open("uid", "w")
  34.         fUid.write(uid)
  35.         fUid.close()
  36.     end
  37. end
  38.  
  39. function startProgram()
  40.     if fs.exists("uid") then
  41.         fUid = fs.open("uid", "r")
  42.         uid = fUid.readAll()
  43.         fUid.close()
  44.     else
  45.         request = http.get("https://rodre.nekotiki.fr/getenergyuid.php")
  46.         data = request.readAll()
  47.         uid = data
  48.    
  49.         setUsername()
  50.     end
  51.  
  52.     term.setTextColor(colors.yellow)
  53.     write("Your UID: ")
  54.     term.setTextColor(colors.lime)
  55.     print(uid)
  56.    
  57.     while true do
  58.         request = http.post("https://rodre.nekotiki.fr/setenergy.php", "uid=" .. uid .. "&energy=" .. ePilon.getEnergyStored() .. "&energyPerTick=" .. ePilon.getTransferPerTick())
  59.         sleep(5)
  60.     end
  61. end
  62.  
  63. if ePilon == "" then
  64.     term.setTextColor(colors.red)
  65.     term.write("No Draconic Pylon Found.\n")
  66. else
  67.     startProgram()
  68. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement