Advertisement
BlueMond

MPclient

Aug 6th, 2014
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.54 KB | None | 0 0
  1. local version = 1.4
  2. local filename = "music"
  3. local paste = "CSEcjQ7n"
  4. local curTimer = nil
  5. local playing = false
  6.  
  7. local function update()
  8.     local url = "http://pastebin.com/raw.php?i="..paste
  9.     local temp = http.get(url)
  10.     local ver = temp.readLine()
  11.     if tonumber(string.sub(ver, 17)) ~= version then
  12.         fs.delete(filename)
  13.         shell.run("pastebin get "..paste.." "..filename)
  14.         shell.run(filename)
  15.         return true
  16.     end
  17.     return false
  18. end
  19.  
  20. local test = update()
  21. if test == true then
  22.     error()
  23. end
  24. rednet.open("top")
  25. local times = {}
  26. times.blocks = 345
  27. times.far = 174
  28. times.mall = 197
  29. times.strad = 188
  30. times.wait = 238
  31.  
  32. local songs = {"blocks", "far", "mall", "strad", "wait"}
  33. local CurrentSong = 0
  34.  
  35. local function clearSong()
  36.     term.setCursorPos(2,5)
  37.     write("                                                ")
  38. end
  39.  
  40. local function writeSong()
  41.     clearSong()
  42.     term.setCursorPos(17,5)
  43.     write("-"..songs[CurrentSong].."-")
  44. end
  45.  
  46. local function pasteScreen()
  47.     shell.run("clear")
  48.     print("version: "..version)
  49.     print("+----------~Computercraft Music Player~----------+")
  50.     print("|                                                |")
  51.     print("|       Current Song:                            |")
  52.     print("|                                                |")
  53.     print("|                                                |")
  54.     print("|       <-Previous      >Play       Next->       |")
  55.     print("|                                                |")
  56.     print("+------------------------------------------------+")
  57. end
  58.  
  59. local function previousSong()
  60.     if CurrentSong == 1 or CurrentSong == 0 then
  61.         CurrentSong = 5
  62.     else
  63.         CurrentSong = CurrentSong - 1
  64.     end
  65.     writeSong()
  66.     rednet.broadcast(songs[CurrentSong])
  67.     curTimer = os.startTimer(times[songs[CurrentSong]])
  68. end
  69.  
  70. local function nextSong()
  71.     if CurrentSong == 5 or CurrentSong == 0 then
  72.         CurrentSong = 1
  73.     else
  74.         CurrentSong = CurrentSong + 1
  75.     end
  76.     writeSong()
  77.     rednet.broadcast(songs[CurrentSong])
  78.     curTimer = os.startTimer(times[songs[CurrentSong]])
  79. end
  80.  
  81. local function togglePlay()
  82.     if CurrentSong == 0 then
  83.         CurrentSong = 1
  84.     end
  85.     writeSong()
  86.     rednet.broadcast(songs[CurrentSong])
  87.     curTimer = os.startTimer(times[songs[CurrentSong]])
  88. end
  89.  
  90. pasteScreen()
  91. while true do
  92.     local e, p1, x, y = os.pullEvent()
  93.     if e == "mouse_click" then
  94.         if y == 7 then
  95.             if x >= 9 and x <= 18 then
  96.                 previousSong()
  97.             elseif x >= 25 and x <= 29 then
  98.                 togglePlay()
  99.             elseif x >= 37 and x <= 42 then
  100.                 nextSong()
  101.             end
  102.         end
  103.     end
  104.     if e == "timer" and p1 == curTimer then
  105.         nextSong()
  106.     end
  107. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement