Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- RAC Media Player v2.0 by neonerZ (turtle-dj)
- -- More Info: https://www.youtube.com/watch?v=tfSSdY0jQQk
- --set variables
- chest="top" -- chest position
- drive="bottom" -- drive position
- modem="right" -- modem position
- radio="front" -- **YOU CAN NOT CHANGE THE RADIO POSITION IT MUST BE IN FRONT**
- radioCrystal="15254" -- item ID of radio crystal
- monitor = 3 -- ID of computer connected to monitor
- -- Feel free to do whatever you want with this.
- -- Edit it, incorporate it into your own project, eat it, I don't care.
- -- I only ask if you redistribute this or edit it/incorporate it into
- -- your own project you give me a shout out (In the case of including
- -- this into something you release. Send me a message, I'd love to
- -- check it out). This is only a friendly suggestion, you are
- -- welcome to be a jerk and claim this as your own
- -- don't edit below here
- c = peripheral.wrap(chest)
- r = peripheral.wrap(radio)
- rednet.open(modem)
- function scanTracks()
- data={}
- local slot
- local name
- local slots = c.getAllStacks()
- for i,j in pairs(slots) do
- slot = i
- name = j["name"]
- id = j["id"]
- data[name]=slot..":"..id
- end
- end
- function scanRadio()
- data={}
- local slot
- local name
- if peripheral.isPresent(radio) then
- local slots = r.getAllStacks()
- for i,j in pairs(slots) do
- slot = i
- if slot== null then
- return false
- else
- return true
- end
- end
- else
- return false
- end
- end
- function currentlyPlaying()
- if disk.isPresent(drive) then
- return disk.getAudioTitle(drive)
- elseif scanRadio() then
- local slots = r.getAllStacks()
- for i,j in pairs(slots) do
- slot = i
- name = j["name"]
- id = j["id"]
- end
- return name
- else
- return "none"
- end
- end
- function refreshTracks(id)
- scanTracks()
- -- for k,v in pairs(data) do print(k..":"..v) end
- data=textutils.serialize(data)
- rednet.send(id,data)
- end
- function playTrack(name,id)
- local slot
- local item
- local track
- stopPlayback(1)
- stopRadio(1)
- scanTracks()
- track=data[name]
- for k,v in string.gmatch(track, "(%w+):(.+)") do
- slot=k
- item=v
- end
- if item==radioCrystal then
- if chest=="bottom" then
- c.pushItem("up", slot, 1,1)
- else
- c.pushItem("down", slot, 1,1)
- end
- turtle.drop()
- redstone.setAnalogOutput(radio,7)
- rednet.send(id,"SUCCESS")
- else
- if chest=="bottom" then
- c.pushItem("up", slot, 1,1)
- turtle.dropUp()
- else
- c.pushItem("down", slot, 1,1)
- turtle.dropDown()
- end
- if disk.hasAudio(drive) then
- disk.playAudio(drive)
- rednet.send(id,"SUCCESS")
- else
- printError("NO DISC IN DRIVE")
- rednet.send(id,"FAILURE")
- stopTrack()
- end
- end
- end
- function play(id)
- if disk.isPresent(drive) then
- disk.playAudio(drive)
- rednet.send(id,"SUCCESS")
- elseif scanRadio() then
- redstone.setAnalogOutput(radio,7)
- rednet.send(id,"SUCCESS")
- else
- printError("NOTHING TO PLAY")
- rednet.send(id,"FAILURE")
- end
- end
- function stopTrack(eject)
- if disk.isPresent(drive) and eject == 1 then
- if drive=="top" then
- turtle.suckUp()
- for i = 1,16 do
- turtle.select(i)
- turtle.dropDown()
- end
- turtle.select(1)
- else
- turtle.suckDown()
- for i = 1,16 do
- turtle.select(i)
- turtle.dropUp()
- end
- turtle.select(1)
- end
- else
- disk.stopAudio(drive)
- return
- end
- end
- function stopRadio(eject)
- if scanRadio() and eject == 1 then
- turtle.suck()
- if chest=="bottom" then
- for i = 1,16 do
- turtle.select(i)
- turtle.dropDown()
- end
- else
- for i = 1,16 do
- turtle.select(i)
- turtle.dropUp()
- end
- turtle.select(1)
- end
- else
- redstone.setAnalogOutput(radio,0)
- return
- end
- end
- function stopPlayback(eject)
- --this stop is for the play function to use
- --does not send a redstone message confirming stop
- stopRadio()
- stopTrack(eject)
- end
- function stop(id,eject)
- --this stop will send back a confirmation that
- --the stop was successful
- stopRadio(eject)
- stopTrack(eject)
- rednet.send(id,"SUCCESS")
- end
- function radioVolume(volume,id)
- if redstone.getAnalogOutput(radio) > 0 and volume ==1 and redstone.getAnalogOutput(radio) < 15 then
- redstone.setAnalogOutput(radio,redstone.getAnalogOutput(radio)+1)
- rednet.send(id,"SUCCESS")
- end
- if redstone.getAnalogOutput(radio) > 0 and volume ==0 and redstone.getAnalogOutput(radio) > 1 then
- redstone.setAnalogOutput(radio,redstone.getAnalogOutput(radio)-1)
- rednet.send(id,"SUCCESS")
- end
- end
- local tArgs = {...}
- print("Starting up Turtle DJ")
- while true do
- local id, msg, dis = rednet.receive()
- turtle.select(1)
- local command
- local info
- for k,v in string.gmatch(msg, "(%w+):(.+)") do
- command=k
- info=v
- end
- print(command," : ",info)
- if command == "playt" and id==monitor then
- playTrack(info,monitor)
- end
- if command == "play" and id==monitor then
- play(monitor)
- end
- if command == "stopeject" and id==monitor then
- stop(monitor,1)
- end
- if command == "stop" and id==monitor then
- stop(monitor,0)
- end
- if command == "volume" and id==monitor then
- radioVolume(tonumber(info),monitor)
- print("cur:"..redstone.getAnalogOutput(radio))
- end
- if command == "scan" and id==monitor then
- refreshTracks(monitor)
- end
- if command == "alive" and id==monitor then
- rednet.send(monitor,"none")
- end
- if command == "track" and id==monitor then
- rednet.send(monitor,currentlyPlaying())
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement