Advertisement
Poppamunz

DJ Playlist

Jun 15th, 2014
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.02 KB | None | 0 0
  1. --DJ Playlist by Poppamunz
  2. --This program will loop music discs in a playlist-type fashion.
  3. --Usage:
  4. --Place a turtle next to a disk drive. (Wired modems won't work)
  5. --Place all the music discs you want to loop in the turtle's inventory.
  6. --Run this program on the turtle.
  7.  
  8. length = {
  9. ["C418 - strad"] = 188,
  10. ["C418 - 13"] = 178,
  11. ["C418 - cat"] = 185,
  12. ["C418 - blocks"] = 345,
  13. ["C418 - chirp"] = 185,
  14. ["C418 - far"] = 174,
  15. ["C418 - mall"] = 197,
  16. ["C418 - mellohi"] = 96,
  17. ["C418 - stal"] = 150,
  18. ["C418 - ward"] = 251,
  19. ["C418 - 11"] = 71,
  20. ["C418 - wait"] = 238,
  21. ["portalgun:wantyougone"] = 141,
  22. ["portalgun:stillalive"] = 176}
  23.  
  24. assert(turtle,"Program must be run on a turtle.")
  25.  
  26. for k,v in pairs(redstone.getSides()) do
  27.     if peripheral.getType(v) == "drive" then
  28.         side = v
  29.         break
  30.     end
  31. end
  32.  
  33. if side == "left" then
  34.     turtle.turnLeft()
  35.     drive = peripheral.wrap("front")
  36. elseif side == "right" then
  37.     turtle.turnRight()
  38.     drive = peripheral.wrap("front")
  39. elseif side == "back" then
  40.     turtle.turnRight()
  41.     turtle.turnRight()
  42.     drive = peripheral.wrap("front")
  43. elseif side == "top" then
  44.     top = true
  45.     drive = peripheral.wrap("top")
  46. elseif side == "bottom" then
  47.     bottom = true
  48.     drive = peripheral.wrap("bottom")
  49. else
  50.     drive = peripheral.wrap("front")
  51. end
  52.  
  53. function getItem()
  54.     if top then
  55.         turtle.suckUp()
  56.     elseif bottom then
  57.         turtle.suckDown()
  58.     else
  59.         turtle.suck()
  60.     end
  61. end
  62. function putItem()
  63.     if top then
  64.         turtle.dropUp()
  65.     elseif bottom then
  66.         turtle.dropDown()
  67.     else
  68.         turtle.drop()
  69.     end
  70. end
  71. function getItemToEmptySlot()
  72.     for i=1, 16 do
  73.         if turtle.getItemCount(i) == 0 then
  74.             turtle.select(i)
  75.             getItem()
  76.             break
  77.         end
  78.     end
  79. end
  80. getItemToEmptySlot()
  81. turtle.select(1)
  82. selectedSlot = 1
  83. while true do
  84.     putItem()
  85.     if drive.hasAudio() then
  86.         print("Now playing: ",drive.getAudioTitle())
  87.         drive.playAudio()
  88.         sleep(length[drive.getAudioTitle()])
  89.     end
  90.     getItem()
  91.     if selectedSlot == 16 then
  92.         selectedSlot = 1
  93.     else
  94.         selectedSlot = selectedSlot + 1
  95.     end
  96.     turtle.select(selectedSlot)
  97. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement