MysticT

NBSPlayer

Jul 3rd, 2012
705
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.27 KB | None | 0 0
  1. -- NoteBlock Song Player
  2. -- by MysticT
  3.  
  4. -- load the nb and nbs apis
  5. if not nb then
  6.     os.loadAPI("nb")
  7.     if not nb then
  8.         print("Couldn't load nb api. Check if you installed it correctly.")
  9.         return
  10.     end
  11. end
  12. if not nbs then
  13.     os.loadAPI("nbs")
  14.     if not nbs then
  15.         print("Error loading nbs api. Check you installed it correctly.")
  16.         return
  17.     end
  18. end
  19.  
  20. -- detect a modem and connect
  21. local function connect()
  22.     for _,s in ipairs(rs.getSides()) do
  23.         if peripheral.isPresent(s) and peripheral.getType(s) == "modem" then
  24.             rednet.open(s)
  25.             return true
  26.         end
  27.     end
  28.     return false
  29. end
  30.  
  31. -- try to connect to rednet
  32. if not connect() then
  33.     print("No modem found")
  34.     return
  35. end
  36.  
  37. -- load and play an nbs file
  38. local function playFile(sPath)
  39.     local tSong, err = nbs.load(sPath)
  40.     if tSong then
  41.         print("Playing: ", tSong.name, " - by ", tSong.author)
  42.         if tSong.original_author ~= "" then
  43.             print("Original Author: ", tSong.original_author)
  44.         end
  45.         print("Lenght: ", tSong.lenght)
  46.         nb.playSong(tSong)
  47.         return true
  48.     end
  49.     return false, err
  50. end
  51.  
  52. -- Start Program
  53.  
  54. -- get arguments
  55. local tArgs = { ... }
  56. if #tArgs ~= 1 then
  57.     print("Usage: nbsplay <file>")
  58.     return
  59. end
  60.  
  61. -- play the file
  62. local ok, err = playFile(tArgs[1])
  63. if not ok then
  64.     return false, err
  65. end
Advertisement
Add Comment
Please, Sign In to add comment