Advertisement
sanovskiy

warpctl

Aug 19th, 2014
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.06 KB | None | 0 0
  1. function split(pString, pPattern)
  2.   local Table = {}
  3.   local fpat = "(.-)" .. pPattern
  4.   local last_end = 1
  5.   local s, e, cap = pString:find(fpat, 1)
  6.   while s do
  7.     if s ~= 1 or cap ~= "" then
  8.       table.insert(Table,cap)
  9.     end
  10.     last_end = e+1
  11.     s, e, cap = pString:find(fpat, last_end)
  12.   end
  13.   if last_end <= #pString then
  14.     cap = pString:sub(last_end)
  15.     table.insert(Table, cap)
  16.   end
  17.   return Table
  18. end
  19.  
  20. args = {...}
  21. action = args[1] or "error"
  22.  
  23. TYPE_WARP = "warpcore"
  24. if action=="on" or action=="off" then
  25.   local mode = 0
  26.   if action=="on" then
  27.     mode = 1
  28.   end
  29.   local peripherals = peripheral.getNames()
  30.   for i = 1,#peripherals do
  31.     if peripheral.getType(peripherals[i]) == TYPE_WARP then
  32.       local core = peripheral.wrap(peripherals[i])
  33.       core.set_mode(mode)
  34.       local id = split(peripherals[i],"_")
  35.       if #id>1 then
  36.         id = '#'..id[2]
  37.       else
  38.         id = 'at '..peripherals[i]
  39.       end
  40.       print("WarpCore "..id.." powered "..action)
  41.     end
  42.   end
  43. else
  44.   print("Usage: warpctl <on|off>")
  45. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement