Advertisement
Rolcam

Computercraft/Computronics Tape DJ Program - Play

Sep 4th, 2023 (edited)
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.81 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 \"play #\" 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("Playing 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.         tape = peripheral.wrap("tape_drive_0")
  18.         -- Displays a "Now Playing" message on the connected monitor
  19.         print("Now Playing: " .. tape.getLabel())
  20.         term.redirect(mon)
  21.         term.setTextColor(colors.orange)
  22.         print("Now Playing:")
  23.         print(tape.getLabel())
  24.         term.redirect(ter)
  25.     elseif args[1] == "2" then
  26.         print("Playing Drive 2")
  27.         tape = peripheral.wrap("tape_drive_1")
  28.         print("Now Playing: " .. tape.getLabel())
  29.         term.redirect(mon)
  30.         term.setTextColor(colors.orange)
  31.         print("Now Playing:")
  32.         print(tape.getLabel())
  33.         term.redirect(ter)
  34.     elseif args[1] == "3" then
  35.         print("Playing Drive 3")
  36.         tape = peripheral.wrap("tape_drive_2")
  37.         print("Now Playing: " .. tape.getLabel())
  38.         term.redirect(mon)
  39.         term.setTextColor(colors.orange)
  40.         print("Now Playing:")
  41.         print(tape.getLabel())
  42.         term.redirect(ter)
  43.     elseif args[1] == "all" then
  44.         print("Playing All Drives. This is a bad idea, but you're the DJ, not me...")
  45.         -- Drive 1
  46.         tape = peripheral.wrap("tape_drive_0")
  47.         if args[2] == nil then
  48.             tape.seek(-tape.getSize())
  49.         elseif args[2] == "hot" then
  50.             term.setTextColor(colors.orange)
  51.             print("hot parameter used! Not rewinding the tapes!")
  52.             term.setTextColor(colors.white)
  53.         else
  54.             term.setTextColor(colors.red)
  55.             print("Parameter 2 Invalid! Using Default Value...")
  56.             term.setTextColor(colors.white)
  57.             tape.seek(-tape.getSize())
  58.         end
  59.         print("Now Playing: " .. tape.getLabel())
  60.         term.redirect(mon)
  61.         term.setTextColor(colors.orange)
  62.         print("Now Playing:")
  63.         print(tape.getLabel())
  64.         term.redirect(ter)
  65.         tape.play()
  66.         -- Drive 2
  67.         tape = peripheral.wrap("tape_drive_1")
  68.         if args[2] == nil then
  69.             tape.seek(-tape.getSize())
  70.         elseif args[2] == "hot" then
  71.             term.setTextColor(colors.orange)
  72.             print("hot parameter used! Not rewinding the tapes!")
  73.             term.setTextColor(colors.white)
  74.         else
  75.             term.setTextColor(colors.red)
  76.             print("Parameter 2 Invalid! Using Default Value...")
  77.             term.setTextColor(colors.white)
  78.             tape.seek(-tape.getSize())
  79.         end
  80.         print("Now Playing: " .. tape.getLabel())
  81.         term.redirect(mon)
  82.         term.setTextColor(colors.orange)
  83.         print(tape.getLabel())
  84.         term.redirect(ter)
  85.         -- Drive 3
  86.         tape.play()
  87.         tape = peripheral.wrap("tape_drive_2")
  88.         if args[2] == nil then
  89.             tape.seek(-tape.getSize())
  90.         elseif args[2] == "hot" then
  91.             term.setTextColor(colors.orange)
  92.             print("hot parameter used! Not rewinding the tapes!")
  93.             term.setTextColor(colors.white)
  94.         else
  95.             term.setTextColor(colors.red)
  96.             print("Parameter 2 Invalid! Using Default Value...")
  97.             term.setTextColor(colors.white)
  98.             tape.seek(-tape.getSize())
  99.         end
  100.         print("Now Playing: " .. tape.getLabel())
  101.         term.redirect(mon)
  102.         term.setTextColor(colors.orange)
  103.         print(tape.getLabel())
  104.         term.redirect(ter)
  105.     else
  106.         term.setTextColor(colors.red)
  107.         print("Error: Parameter 1 Invalid! Please select a valid drive!")
  108.         term.setTextColor(colors.white)
  109.     end
  110.     -- Rewinds and plays the tape for the selected drive
  111.     if args[2] == nil then
  112.         if tape == nil then
  113.             sleep(0.1)
  114.         else
  115.             tape.seek(-tape.getSize())
  116.         end
  117.     elseif args[2] == "hot" then
  118.         term.setTextColor(colors.orange)
  119.         print("hot parameter used! Not rewinding the tape!")
  120.         term.setTextColor(colors.white)
  121.     else
  122.         term.setTextColor(colors.red)
  123.         print("Parameter 2 Invalid! Using Default Value...")
  124.         term.setTextColor(colors.white)
  125.         tape.seek(-tape.getSize())
  126.     end
  127.     if tape == nil then
  128.         sleep(0.1)
  129.     else
  130.         tape.play()
  131.     end
  132. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement