Mariomarco

ACS

Feb 2nd, 2013
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.14 KB | None | 0 0
  1. rednet.open("left")
  2. rednet.open("right")
  3. local RedPath = "ACS.Give."
  4. local Player1 = "Jensoo7"
  5. local Player2 = "Mariomarco"
  6. local TransID = 0
  7. local TransCount = 0
  8. local AllItemCount = 0
  9. local function CountAllItems()
  10. term.write("4")
  11.     local Var1 = 1
  12.     local Var2 = 0
  13.     while Var1 <= 16 do
  14.         Var2 = Var2 + turtle.getItemCount(Var1)
  15.         Var1 = Var1 + 1
  16.     end
  17.     Var1 = 1
  18.     AllItemCount = Var2
  19. end
  20. local function GiveItems()
  21. term.write("5")
  22.     if TransID == 1 then
  23.         local Var1 = 1
  24.         while Var1 <= 16 do
  25.             turtle.select(Var1)
  26.             turtle.dropDown()
  27.             Var1 = Var1 + 1
  28.         end
  29.         Var1 = 1
  30.     elseif TransID == 2 then
  31.         local Var1 = 1
  32.         while Var1 <= 16 do
  33.             turtle.select(Var1)
  34.             turtle.drop()
  35.             Var1 = Var1 + 1
  36.         end
  37.         Var1 = 1
  38.     end
  39. end
  40. local function TransferAction()
  41. term.write("6")
  42.     local SlotsItemCount
  43.     turtle.select(1)
  44.     turtle.suckUp()
  45.     CountAllItems()
  46.     while not(AllItemCount == TransCount) do
  47.         CountAllItems()
  48.         term.write(AllItemCount .. "|" .. TransCount)
  49.         AllItemCount = tonumber(AllItemCount)
  50.         TransCount = tonumber(TransCount)
  51.         if AllItemCount > TransCount  then
  52.             turtle.select(1)
  53.             turtle.transferTo(16, AllItemCount - TransCount)
  54.             turtle.select(16)
  55.             turtle.dropUp()
  56.         elseif AllItemCount  < TransCount  then
  57.             local oldItemC = AllItemCount
  58.             turtle.suckUp()
  59.             CountAllItems()
  60.             if AllItemCount - oldItemC == 0 then
  61.                 AllItemCount = TransCount
  62.                 term.write("NEI")
  63.             end
  64.         end
  65.     end
  66.     GiveItems()
  67. end
  68. while redstone.getInput("back") == false do
  69.     local SID, message, Dist = rednet.receive(12)
  70.     if not(message == nil) then
  71.     term.write(message)
  72.     if not(string.match(message,RedPath .. Player1)== nil)  then
  73.      TransID = 1
  74.     elseif not(string.match(message,RedPath .. Player2) == nil) then
  75.      TransID = 2
  76.     else
  77.      TransID = 0
  78.     end
  79.     if not(TransID == 0) then
  80.     term.write("1")
  81.         if not(string.match(message, os.getComputerLabel()) == nil) then
  82.             term.write("2")
  83.             local I = 641
  84.             while I > 0 do
  85.                 I = I -1
  86.                 if not(string.match(message, I) == nil) then
  87.                     TransCount = string.match(message, I)
  88.                     I = 0
  89.                     TransferAction()
  90.                     term.write("3")
  91.                 end
  92.             end
  93.         end
  94.     end
  95.     end
  96. end
Advertisement
Add Comment
Please, Sign In to add comment