Advertisement
Chronno

Computercraft - DJMcTurtle 1.0

Jan 28th, 2013
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.01 KB | None | 0 0
  1.     -- Check out this program in action on my Youtube page
  2.     -- http://www.youtube.com/user/chronnotrigg
  3.     -- Last edit 12-06-15 6:18pm
  4.      
  5.     Slot = 0
  6.     st = 0
  7.     local plays = { ... }
  8.     pSlot = 0
  9.      
  10.     function setup()
  11.       turtle.up()
  12.       turtle.select(16)
  13.       turtle.placeDown()
  14.     end
  15.      
  16.     function teardown()
  17.       turtle.select(16)
  18.       turtle.digDown()
  19.       turtle.down()
  20.     end
  21.      
  22.     function gui(T)
  23.             term.clear()
  24.             term.setCursorPos(1,1)
  25.             print("Press E to exit, any other key to skip")
  26.             term.setCursorPos(1,3)
  27.             print("Currently ")
  28.             term.setCursorPos(11,3)
  29.             print(disk.getLabel("bottom"))
  30.     end
  31.      
  32.     function play(S)
  33.             turtle.select(S)
  34.             turtle.dropDown()
  35.             gui()
  36.             disk.playAudio("bottom")
  37.     end
  38.      
  39.     function stop(S)
  40.             disk.stopAudio("bottom")
  41.             turtle.select(S)
  42.             turtle.suckDown()
  43.     end
  44.      
  45.     function getSlot()
  46.             Slot = math.random(1,15)
  47.             if Slot == pSlot then
  48.                     getSlot()
  49.             else
  50.                     pSlot = Slot
  51.             end
  52.             if turtle.getItemCount(Slot) == 0 then
  53.                     getSlot()
  54.             end
  55.     end
  56.      
  57.     function sleep()
  58.             if disk.getLabel("bottom") == "C418 - mall" then
  59.                     os.sleep(202)
  60.             elseif disk.getLabel("bottom") == "C418 - mellohi" then
  61.                     os.sleep(101)
  62.             elseif disk.getLabel("bottom") == "C418 - wait" then
  63.                     os.sleep(243)
  64.             elseif disk.getLabel("bottom") == "C418 - ward" then
  65.                     os.sleep(256)
  66.             elseif disk.getLabel("bottom") == "C418 - 13" then
  67.                     os.sleep(183)
  68.             elseif disk.getLabel("bottom") == "C418 - cat" then
  69.                     os.sleep(190)
  70.             elseif disk.getLabel("bottom") == "C418 - blocks" then
  71.                     os.sleep(350)
  72.             elseif disk.getLabel("bottom") == "C418 - chirp" then
  73.                     os.sleep(190)
  74.             elseif disk.getLabel("bottom") == "C418 - far" then
  75.                     os.sleep(179)
  76.             elseif disk.getLabel("bottom") == "C418 - stal" then
  77.                     os.sleep(155)
  78.             elseif disk.getLabel("bottom") == "C418 - strad" then
  79.                     os.sleep(193)
  80.             elseif disk.getLabel("bottom") == "C418 - 11" then
  81.                     os.sleep(76)
  82.             elseif disk.getLabel("bottom") == "Valve - Still Alive" then
  83.                     os.sleep(181)
  84.             elseif disk.getLabel("bottom") == "pg.stillalive" then
  85.                     os.sleep(181)
  86.             elseif disk.getLabel("bottom") == "Valve - Want You Gone" then
  87.                     os.sleep(146)
  88.             elseif disk.getLabel("bottom") == "pg.wantyougone" then
  89.                     os.sleep(146)
  90.             elseif disk.getLabel("bottom") == "Valve - Radio Loop" then
  91.                     os.sleep(26)
  92.             elseif disk.getLabel("bottom") == "pg.radioloop" then
  93.                     os.sleep(26)
  94.             else
  95.                     os.sleep(240)
  96.             end
  97.     end
  98.      
  99.     function compu()
  100.             local event, arg1=os.pullEvent("char")
  101.             if arg1=="e" then
  102.                     stop(Slot)
  103.                     st = 1
  104.             else
  105.                     os.sleep(0)
  106.             end
  107.     end
  108.      
  109.     disk.stopAudio("bottom")
  110.     turtle.suckDown()
  111.     if plays[1] == 0 then
  112.             print("argument must be greater than 0")
  113.     elseif plays[1] == plays[111] then
  114.             plays[1] = 0
  115.     end
  116.     setup()
  117.     for i=1,plays[1] do
  118.             if st == 1 then
  119.                     break
  120.             end
  121.             getSlot()
  122.             play(Slot)
  123.             parallel.waitForAny(compu, sleep)
  124.             stop(Slot)
  125.     end
  126.     teardown()
  127.     term.clear()
  128.     term.setCursorPos(1,1)
  129.     print("Playback Finished")
  130.     return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement