Advertisement
Guest User

Untitled

a guest
Mar 1st, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. term.clear()
  2.  
  3. networked=false
  4.  
  5. if peripheral.isPresent("left") then
  6. if peripheral.getType("left") == "modem" then
  7. networked=true
  8. end
  9. end
  10.  
  11. function findPeripheral()
  12. local dd = false
  13. local mon = false
  14. if peripheral.isPresent("right") then
  15. if peripheral.getType("right") == "drive" then
  16. doit=true
  17. end
  18. end
  19. if peripheral.isPresent("top") then
  20. if peripheral.getType("top") == "monitor" then
  21. mon=true
  22. end
  23. end
  24. if mon and doit then
  25. return true
  26. end
  27. end
  28.  
  29. function playMusic()
  30. if findPeripheral() then
  31. if disk.hasAudio("right") then
  32. disp = peripheral.wrap("top")
  33. name = disk.getAudioTitle("right")
  34. disk.playAudio("right")
  35.  
  36. local xx,yy = disp.getSize()
  37. xx = (xx/2)
  38. local offX = string.len(name)/2
  39.  
  40. disp.clear()
  41. disp.setCursorPos(xx-offX,yy/2)
  42. disp.write(name)
  43. else
  44. term.write("no disk found!")
  45. end
  46. end
  47. end
  48.  
  49. if networked then
  50.  
  51. rednet.open("left")
  52. term.write("Networked mode - waiting for signal from client...")
  53. while true do
  54. local id,msg = rednet.receive()
  55. if id == 19 then
  56. if msg == "play" then
  57. playMusic()
  58. end
  59. if msg == "stop" then
  60. disk.stopAudio("right")
  61. end
  62. if msg == "eject" then
  63. disk.stopAudio("right")
  64. disk.eject("right")
  65. end
  66. if msg == "restart" then
  67. disk.stopAudio("right")
  68. disk.startAudio("right")
  69. end
  70. end
  71. sleep(1)
  72. end
  73. else
  74. playMusic()
  75. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement