Advertisement
MrReps

Dj for computer craft (with advanced peripheral)

Nov 20th, 2021 (edited)
1,408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.57 KB | None | 0 0
  1. --MrRepside programm enjoy
  2. local storageName = "minecraft:barrel_3"
  3. local jukeBoxeName = "minecraft:jukebox_0"
  4. local routerName = "modularrouter:item_router_0"
  5. local chatboxName = "chatBox_4"
  6.  
  7.  
  8. local storage = peripheral.wrap(storageName)
  9. local chatbox = peripheral.wrap(chatboxName)
  10.  
  11.  
  12.  
  13. function GetMusicMessage()
  14.     local event, username, message = os.pullEvent("chat")
  15.     local find, numberFind = string.find(message, "DJ play")
  16.     if find == 1 and numberFind == 7 then
  17.         return 1, string.sub(message, 9)
  18.     else
  19.         find, numberFind = string.find(message, "DJ stop")
  20.         if find == 1 and numberFind == 7 then
  21.             return 2, nil
  22.         end
  23.     end
  24. end
  25.  
  26. function FindMusicPlace(musicName)
  27.     local list = storage.list()
  28.     for i=1,#list do
  29.         if string.find(list[i].name, musicName) then
  30.             print("trouvé le cd ici", list[i].name, i)
  31.             return i
  32.         end
  33.     end
  34.     return nil
  35. end
  36.  
  37. function PlayMusic(place, name)
  38.     storage.pushItems(routerName, place, 1)
  39.     chatbox.sendMessage("Hey I'm playing "..name)
  40. end
  41.  
  42. function StopMusic()
  43.     storage.pullItems(jukeBoxeName, 1)
  44. end
  45.  
  46. while true do
  47.     local mode, musicName = GetMusicMessage()
  48.     if mode == 1 then --joue
  49.         local musicslot = FindMusicPlace(musicName)
  50.         if musicName == nil or musicslot == nil then
  51.             chatbox.sendMessage("Didn't found the disc :(")
  52.         else
  53.             StopMusic()
  54.             PlayMusic(musicslot, musicName)
  55.         end
  56.     elseif mode == 2 then --Stop
  57.         StopMusic()
  58.     end
  59. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement