Advertisement
Joshalot

CC - rgbSmartLights

Jan 25th, 2021
1,164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.93 KB | None | 0 0
  1. function Split(s, delimiter)
  2.     result = {};
  3.     for match in (s..delimiter):gmatch("(.-)"..delimiter) do
  4.         table.insert(result, match);
  5.     end
  6.     return result;
  7.   end
  8.  
  9. colorTable = {}
  10. colorTable['white'] = 25368
  11. colorTable['blue'] = 16
  12. colorTable['green'] = 768
  13. colorTable['red'] = 24576
  14. colorTable['purple'] = 24592
  15.  
  16. l1 = peripheral.wrap('colorful_lamp_0')
  17. l2 = peripheral.wrap('colorful_lamp_1')
  18. c = peripheral.find('chat_box')
  19.  
  20. while true do
  21.     event, side, user, message = os.pullEvent('chat_message')
  22.     messageSplit = Split(message, ' ')
  23.  
  24.     if messageSplit[1] == 'hey' and messageSplit[2] == 'google' and messageSplit[5] == 'lights' then
  25.         color = messageSplit[table.getn(messageSplit)]
  26.         c.say('Ok '..user..', setting lights to '..color)
  27.         l1.setLampColor(colorTable[color])
  28.         l2.setLampColor(colorTable[color])
  29.     else
  30.         c.say("I'm sorry, I don't undersand")
  31.     end
  32. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement