Advertisement
Rolcam

Computercraft/Computronics Tape DJ Program - Swap and Hot Swap

Sep 4th, 2023 (edited)
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.37 KB | None | 0 0
  1. args = {...}
  2. -- Change this to any connected monitor you want to use for system output
  3. mon = peripheral.wrap("monitor_2")
  4. -- This is the terminal's screen. Do not touch this!
  5. ter = term.current()
  6. -- If there are no arguments in the command then...
  7. if args == nil then
  8. term.setTextColor(colors.red)
  9. print("Warning: No parameters given!")
  10. print("Use \"swap #\" to select a drive")
  11. -- Otherwise, if there are arguments, if they match the case do...
  12. else
  13.     if args[1] == "1" then
  14.         print("Swapping to Drive 1")
  15.         -- Sets the tape command to refer to the connected tape drive. Change this to whatever drive you want to use
  16.         -- Copy this if/elseif section to connect more drives
  17.         -- Stops the other tapes and rewinds them. If the 'hot' argument is given as the second argument, it will not rewind them
  18.         if args[2] == nil then
  19.             tape = peripheral.wrap("tape_drive_1")
  20.             tape.stop()
  21.             tape.seek(-tape.getSize())
  22.             tape = peripheral.wrap("tape_drive_2")
  23.             tape.stop()
  24.             tape.seek(-tape.getSize())
  25.         elseif args[2] == "hot" then
  26.             tape = peripheral.wrap("tape_drive_1")
  27.             tape.stop()
  28.             tape = peripheral.wrap("tape_drive_2")
  29.             tape.stop()
  30.         end
  31.             tape = peripheral.wrap("tape_drive_0")
  32.         -- Displays a "Now Playing" message on the connected monitor
  33.         print("Now Playing: " .. tape.getLabel())
  34.         term.redirect(mon)
  35.         term.setTextColor(colors.orange)
  36.         print("Swapping to:")
  37.         print(tape.getLabel())
  38.         term.redirect(ter)
  39.     elseif args[1] == "2" then
  40.         print("Swapping to Drive 2")
  41.         if args[2] == nil then
  42.             tape = peripheral.wrap("tape_drive_0")
  43.             tape.stop()
  44.             tape.seek(-tape.getSize())
  45.             tape = peripheral.wrap("tape_drive_2")
  46.             tape.stop()
  47.             tape.seek(-tape.getSize())
  48.         elseif args[2] == "hot" then
  49.             tape = peripheral.wrap("tape_drive_0")
  50.             tape.stop()
  51.             tape = peripheral.wrap("tape_drive_2")
  52.             tape.stop()
  53.         end
  54.         tape = peripheral.wrap("tape_drive_1")
  55.         print("Now Playing: " .. tape.getLabel())
  56.         term.redirect(mon)
  57.         term.setTextColor(colors.orange)
  58.         print("Swapping to:")
  59.         print(tape.getLabel())
  60.         term.redirect(ter)
  61.     elseif args[1] == "3" then
  62.         print("Swapping to Drive 3")
  63.         if args[2] == nil then
  64.             tape = peripheral.wrap("tape_drive_0")
  65.             tape.stop()
  66.             tape.seek(-tape.getSize())
  67.             tape = peripheral.wrap("tape_drive_1")
  68.             tape.stop()
  69.             tape.seek(-tape.getSize())
  70.         elseif args[2] == "hot" then
  71.             tape = peripheral.wrap("tape_drive_0")
  72.             tape.stop()
  73.             tape = peripheral.wrap("tape_drive_1")
  74.             tape.stop()
  75.         end
  76.         tape = peripheral.wrap("tape_drive_2")
  77.         print("Now Playing: " .. tape.getLabel())
  78.         term.redirect(mon)
  79.         term.setTextColor(colors.orange)
  80.         print("Swapping to:")
  81.         print(tape.getLabel())
  82.         term.redirect(ter)
  83.     end
  84.     -- Rewinds and plays the tape for the selected drive. If the 'hot' argument is given, it won't rewind the tape before playing
  85.     if args[2] == nil then
  86.         tape.seek(-tape.getSize())
  87.     elseif args[2] == "hot" then
  88.         print("Hot Swapping")
  89.     end
  90.     tape.play()
  91. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement