Advertisement
meuced

remote DJ play

Mar 22nd, 2013
659
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.85 KB | None | 0 0
  1. function split(str,pat)
  2.  
  3.         local t = {}
  4.         local fpat = "(.-)" .. pat
  5.         local last_end = 1
  6.         local s, e, cap = str:find(fpat, 1)
  7.         while s do
  8.                 if s ~= 1 or cap ~= "" then
  9.                         table.insert(t,cap)
  10.                 end
  11.                 last_end = e+1
  12.                 s, e, cap = str:find(fpat, last_end)
  13.         end
  14.         if last_end <= #str then
  15.                 cap = str:sub(last_end)
  16.                 table.insert(t, cap)
  17.         end
  18.         return t
  19. end
  20.  
  21. local message = {}
  22.  
  23. rednet.open("bottom")
  24.  
  25.  while true do
  26.         event, id, text = os.pullEvent()
  27.         if event == "rednet_message" then
  28.                 message = split(text,":")
  29.         if message[2] == "stop" then shell.run("dj stop")
  30.         elseif message[2] == "play" then shell.run("dj play "..message[1]) end
  31.         end
  32. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement