Advertisement
AnonGaming

Untitled

Mar 3rd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.42 KB | None | 0 0
  1. -- Power Serv --
  2.  
  3.  
  4. rednet.open("top")
  5.  
  6. function split(pString, pPattern)
  7.    local Table = {}  -- NOTE: use {n = 0} in Lua-5.0
  8.    local fpat = "(.-)" .. pPattern
  9.    local last_end = 1
  10.    local s, e, cap = pString:find(fpat, 1)
  11.    while s do
  12.           if s ~= 1 or cap ~= "" then
  13.          table.insert(Table,cap)
  14.           end
  15.           last_end = e+1
  16.           s, e, cap = pString:find(fpat, last_end)
  17.    end
  18.    if last_end <= #pString then
  19.           cap = pString:sub(last_end)
  20.           table.insert(Table, cap)
  21.    end
  22.    return Table
  23. end
  24.  
  25. function enableLine(side,color)
  26.     redstone.setBundledOutput(side,colors.combine(redstone.getBundledOutput(side),color))
  27. end
  28. function disableLine(side,color)
  29.     redstone.setBundledOutput(side,colors.subtract(redstone.getBundledOutput(side),color))
  30. end
  31.  
  32.  
  33. local bays = {}
  34. bays["bay1"] = colors.white
  35.  
  36. local cmd = {}
  37.  
  38.  
  39. --power serv state
  40. function receiveState(senderID,messTab)
  41.     local serv = messTab[2]
  42.     local state = messTab[3]
  43.     local servCol = bays[serbv]
  44.     if state == "true" or state == true then
  45.         enableLine("right",servCol)
  46.     else
  47.         disableLine("right",servCol)
  48.     end
  49.    
  50. end
  51. cmd["power"] = receiveState
  52.  
  53. while true do
  54.    
  55.     senderID,message = rednet.receive(5)
  56.    
  57.     local messageTab = split(message," ")
  58.    
  59.     if cmd[messageTab[1]] then
  60.         cmd[messageTab[1]](senderID,messageTab);
  61.     end
  62.  
  63.    
  64. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement