Advertisement
kurruk

Lower Storage

May 21st, 2013
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.19 KB | None | 0 0
  1. p = peripheral.wrap("back")
  2. m = peripheral.wrap("left")
  3.  
  4. if os.getComputerLabel() == nil then
  5.   os.setComputerLabel("lower")
  6. end
  7.  
  8. thing = "cobble"
  9. Output = 2 -- 2 = North, 3 = South, 4 = West, 5 = East
  10.  
  11. data = p.list(1)
  12. m.open(49794)
  13.  
  14. function split(str, delim, maxNb)
  15.   if string.find(str, delim) == nil then
  16.     return { str }
  17.   end
  18.  
  19.   if maxNb == nil or maxNb < 1 then
  20.     maxNb = 0
  21.   end
  22.  
  23.   local result = {}
  24.   local pat = "(.-)" ..delim.. "()"
  25.   local nb = 0
  26.   local lastPos
  27.  
  28.   for part, pos in string.gmatch(str, pat) do
  29.     nb = nb + 1
  30.     result[nb] = part
  31.     lastPos = pos
  32.     if nb == maxNb then
  33.       break
  34.     end
  35.   end
  36.  
  37.   if nb ~= maxNb then
  38.     result[nb + 1] = string.sub(str,lastPos)
  39. end
  40.  
  41.   return result
  42.  
  43. end
  44.  
  45.  
  46. for k, v in pairs(data) do
  47.   id = k
  48.   print(k)
  49. end
  50.  
  51. while true do
  52.     event, side, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  53.     print(message)
  54.     Table = {}
  55.     Table = split(message, ":")
  56.     item = tostring(Table[1])
  57.     amount = tonumber(Table[2])
  58.     print(item)
  59.     print(amount)
  60.     if item == thing then
  61.         p.extract(1,id,Output,amount)
  62.         m.transmit(32036, 49794, thing..":"..tostring(amount))
  63.     end
  64. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement