Advertisement
XDjackieXD

onoffclient.lua

Jul 6th, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local event = require('event')
  2. local fs = require('filesystem')
  3. local component = require('component')
  4. local net = component.modem
  5. local rs = component.redstone
  6. local running = true
  7.  
  8. -- Callbacks
  9. local function networkCallback(type, myaddr, senderaddress, port, distance, message)
  10.   -- print(myaddr .. " " .. senderaddress .. " " .. port .. " " .. distance .. " " .. message)
  11.   if port == 123 then
  12.     if message == "on" then
  13.       for k,v in component.list() do
  14.         if v == "colorful_lamp" then
  15.           component.proxy(k).setLampColor(31744)
  16.         end
  17.       end
  18.     elseif message == "off" then
  19.       for k,v in component.list() do
  20.         if v == "colorful_lamp" then
  21.           component.proxy(k).setLampColor(0)
  22.         end
  23.       end
  24.     end
  25.   end
  26. end
  27.  
  28.  
  29. -- Main Code
  30.  
  31. net.open(123)
  32.  
  33. event.listen("modem_message", networkCallback)
  34.  
  35. while running do
  36.   os.sleep(10)
  37. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement