Advertisement
Guest User

zara

a guest
Mar 6th, 2015
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.44 KB | None | 0 0
  1. --Variables
  2. local iS = peripheral.wrap("back")
  3. local iO = peripheral.wrap("left")
  4. local m = peripheral.wrap("monitor_38")
  5. local dataL = {}
  6.  
  7. --Functions
  8.  
  9. function load()
  10.  local file = fs.open("data","r")
  11.  if file ~= nil then
  12.  local data = file.readAll()
  13.  file.close()
  14.  return textutils.unserialize(data)
  15.  end
  16. end
  17.  
  18. function tfc()
  19. mmsg("Charging        ",2,2,8)
  20. cha = true
  21. k = 0
  22. while cha do
  23.  itz = iS.list(0)
  24.  if itz ~= nil then
  25.   for itzst, kk in pairs(itz) do
  26.    for it0, st in pairs(dataL) do
  27.     for i = 1, 27 do
  28.      if itzst == st[i] then
  29.       for j = 1, 26 do
  30.        if dataL[it0][j] == itzst then
  31.         mmsg("     "..(26-j)*(3.7).."%      ",1,3,64)
  32.         k = 1
  33.        end
  34.       end
  35.      end
  36.     end
  37.     if it0 == itzst then
  38.      mmsg("   Complete           ",1,3,64)
  39.      sleep(0.5)    
  40.      mmsg("                   ",1,3,1)
  41.      mmsg("MFSU Empty       ",2,2,8)
  42.      sleep(0.2)
  43.      iS.extract(0,itzst,1,1)
  44.      iO.setOutput(colors.green)
  45.      cha = false    
  46.     end
  47.    end
  48.   end
  49.   if k == 0 then cha = false end
  50.  end
  51.  sleep(0.2)
  52. end
  53. end  
  54.  
  55. function msg(mes,h,j,col)
  56.  term.setCursorPos(h,j)
  57.  term.setTextColor(col)
  58.  print(mes)
  59. end
  60.  
  61. function mmsg(mes,h,j,col)
  62.  m.setCursorPos(h,j)
  63.  m.setTextColor(col)
  64.  m.write(mes)
  65. end
  66.  
  67. function extract()
  68.  ev = os.pullEvent("redstone")
  69.  itz = iS.list(0)
  70.  for v , t in pairs(itz) do
  71.   iS.extract(0,v,1,1)
  72.  end
  73. mmsg("                   ",1,3,1)
  74. mmsg("MFSU Empty       ",2,2,8)
  75. iO.setOutput(colors.green)
  76. sleep(2.7)
  77. end
  78.  
  79. function input()
  80. p = true
  81.  while p do
  82.   k = 0
  83.   l = iS.list(1)
  84.   if l ~= nil then
  85.    for itsS , kk in pairs(l) do
  86.     for it0 , st in pairs(dataL) do
  87.      for j = 1, 27 do
  88.       if itsS == st[j] then
  89.        k = 1
  90.        mmsg("Put in MFSU   ",2,2,8)
  91.        iS.extract(1,itsS,0,1)
  92.        iO.setOutput(colors.red)
  93.        sleep(0.2)
  94.        tfc()
  95.       end
  96.      end
  97.     end
  98.    end
  99.    if k == 0 then p = false end
  100.    else p = false
  101.   end
  102.   sleep(0.2)
  103.  end
  104. end
  105.  
  106. --Code
  107. m.clear()
  108. term.clear()
  109. msg("Working",5,1,colors.lime)
  110. mmsg("Working",5,1,colors.lime)
  111. dataL = load()
  112. if dataL ~= nil then
  113. while true do
  114.  msg("Wait for item",3,2,8)
  115.  ev, p1 = os.pullEvent()
  116.  if ev == "redstone" then
  117.   sleep(0.2)
  118.   tfc()
  119.   sleep(2.7)
  120.   parallel.waitForAny(input,extract)
  121.  end
  122.  if (ev == "key") and ( p1 == 16 ) then
  123.   iO.setOutput(0)
  124.   msg("Stopped",5,3,colors.red)
  125.   mmsg("Stopped",5,5,colors.red)
  126.   break
  127.  end
  128. end
  129. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement