Advertisement
AnonGaming

Untitled

Mar 3rd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. --Power Manager
  2. rednet.open("back")
  3.  
  4. function split(pString, pPattern)
  5. local Table = {} -- NOTE: use {n = 0} in Lua-5.0
  6. local fpat = "(.-)" .. pPattern
  7. local last_end = 1
  8. local s, e, cap = pString:find(fpat, 1)
  9. while s do
  10. if s ~= 1 or cap ~= "" then
  11. table.insert(Table,cap)
  12. end
  13. last_end = e+1
  14. s, e, cap = pString:find(fpat, last_end)
  15. end
  16. if last_end <= #pString then
  17. cap = pString:sub(last_end)
  18. table.insert(Table, cap)
  19. end
  20. return Table
  21. end
  22.  
  23.  
  24.  
  25.  
  26. local powerServers = {}
  27.  
  28.  
  29. powerServers["bay1"] = {}
  30. powerServers["bay1"]["serverID"] = 0
  31. powerServers["bay1"]["active"] = false
  32.  
  33.  
  34. function sendState(serv,state)
  35.  
  36. rednet.send(powerSerers[serv]["serverID"],"power "..serv.." "..state)
  37. powerSerers[serv]["active"] = state
  38.  
  39. end
  40.  
  41.  
  42. local cmd = {}
  43.  
  44.  
  45.  
  46. --setState bay1 state
  47. function setState(args)
  48. local serv = args[2]
  49. local state = args[3]
  50.  
  51. sendState(serv,sate)
  52.  
  53. end
  54. cmd["setState"] = setState
  55.  
  56. --getState bay1
  57. function getState(args)
  58. local serv = args[2]
  59. end
  60. cmd["getState"] = getState
  61.  
  62.  
  63. while true do
  64.  
  65. senderID,message = rednet.receive(5)
  66.  
  67. local messageTab = split(message," ")
  68.  
  69. if cmd[messageTab[1]] then
  70. cmd[messageTab[1]](messageTab);
  71. end
  72.  
  73.  
  74. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement