Advertisement
Raphsod

BetterRefuel

Nov 2nd, 2022 (edited)
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.52 KB | Gaming | 0 0
  1.     --//Declarar variables // Nivel de combustible actual y anterior
  2.     fuelLevel = 0
  3.     fuelLevel2 = 0
  4.     --//Funciones que se usarán en el menú (última instrucctión escrita)
  5.     local function PressAnyKey()
  6.         print("")
  7.         print("press any key to continue...")
  8.         os.pullEvent("key")
  9.     end
  10.    
  11.     local function Clear()
  12.         term.clear()
  13.         term.setCursorPos(1, 1)
  14.     end
  15.    
  16.     local function DropItem(i)
  17.         --//Si queda algún item en el espacio seleccionado, lo transfiere al último espacio o bien lo suelta/tira/droppea.
  18.         if turtle.getItemCount(i) ~= 0 then
  19.             if not(turtle.transferTo(16)) then
  20.                 Clear()
  21.                 print("I can't move this item from slot ".. i .." to slot 16.")
  22.                 print("Should i drop it?")
  23.                 print("1.- KEEP IT ...please...")
  24.                 print("2.- DROP IT")
  25.                 dropIt = read()
  26.                 if dropIt == "2" then
  27.                     turtle.dropUp()
  28.                     Clear()
  29.                 elseif dropIt == "1" then
  30.                     print("Ok, i'll keep it where it is.")
  31.                     PressAnyKey()
  32.                     Clear()
  33.                 else
  34.                     print("That's not one of the options, but ok, i'll drop it.")
  35.                     PressAnyKey()
  36.                     Clear()
  37.                     turtle.drop()
  38.                 end
  39.             end
  40.         end
  41.     end
  42.    
  43.     local function Consume(i)
  44.         if turtle.refuel() then
  45.             fuelLevel2 = turtle.getFuelLevel()
  46.             DropItem(i)
  47.         else
  48.             DropItem(i)
  49.         end
  50.     end
  51.    
  52.     --//Bucle de acciones, Selecciona el espacio especificado en "i" y si es válido, lo consume como combustible.
  53.     --// "i" hace referencia al espacio en el inventario de la tortuga
  54.     local function Refuel()
  55.         fuelLevel = turtle.getFuelLevel()
  56.         for i = 1, 15, 1 do
  57.             turtle.select(i)
  58.             Consume(i)
  59.         end
  60.         fuelLevel2 = turtle.getFuelLevel()
  61.         --//Imprime el nivel de combustible si ya ha cambiado respecto a la última vez.
  62.         if fuelLevel ~= fuelLevel2 then
  63.             print("I'm done...")
  64.             print("")
  65.             print("My fuel level is now: ".. fuelLevel2 ..".")
  66.         else
  67.             print("There was no fuel available for me to use, and my fuel level stayed at: " .. fuelLevel2 .. ".")
  68.         end
  69.        
  70.     end
  71.    
  72. --//MainMenu
  73.     while true do
  74.         Clear()
  75.         print("Do you want to give me some fuel?")
  76.         print("1.- YES")
  77.         print("2.- MAYBE LATER")
  78.         selection = read()
  79.         if selection == "1" then
  80.             Clear()
  81.             print("Please place fuel in my inventory, except for the bottom right slot, that's for me to use.")
  82.             PressAnyKey()
  83.             Clear()
  84.             Refuel()
  85.             PressAnyKey()
  86.            
  87.         elseif selection == "2" then
  88.             print("See you later then.")
  89.             PressAnyKey()
  90.             break
  91.         else
  92.             print("Please enter the number 1 or 2 depending on what you want to do.")
  93.             PressAnyKey()
  94.         end
  95.     end
  96. --//pastebin run HYa4eY5t
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement