Advertisement
Wassaa

packager args

Dec 7th, 2016
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.54 KB | None | 0 0
  1. args ={...}
  2. sides = {"front", "back", "left", "right", "top", "bottom"}
  3. directions = {"north", "south", "east", "west", "up", "down"}
  4. drops = {"dropup", "dropdown,", "drop"}
  5.  
  6. function settings()
  7.     if #args==3 then
  8.         for i = 1, 6 do
  9.             if string.lower(args[1]) == sides[i] then
  10.                 p=peripheral.wrap(args[1])
  11.                 print("peripheral side: "..tostring(args[1]))
  12.                 break
  13.             end
  14.         end
  15.         for i = 1, 6 do
  16.             if string.lower(args[2]) == directions[i] then
  17.                 turtleDir = args[2]
  18.                 print("chest to turtle direction: "..tostring(args[2]))
  19.                 break
  20.             end
  21.         end
  22.         for i = 1, 3 do
  23.             if string.lower(args[3]) == drops[i] then
  24.                 dropWay(string.lower(args[3]))
  25.                 print("chest to turtle direction: "..tostring(args[2]))
  26.                 break
  27.             end
  28.         end
  29.        
  30.        
  31.         if p ~= nil and turtleDir~= nil and drop ~= nil then
  32.             main()
  33.         else
  34.             print("something went wrong, try again")
  35.             L2U()
  36.         end
  37.     else
  38.         L2U()
  39.     end
  40. end
  41.  
  42. function dropWay(s)
  43.     if string.find(s, "up") then
  44.         drop = turtle.dropUp
  45.     elseif string.find(s, "down") then
  46.         drop = turtle.dropDown
  47.     else
  48.         drop = turtle.drop
  49.     end
  50. end
  51.  
  52. function L2U()
  53.     print('L2 Use my turtles, ARGS #1 <peripheral side> #2 <Chest to Turtle direction> #3 <drop Up/down/nothing>' )
  54.     print('viable sides: "front", "back", "left", "right", "top", "bottom"')
  55.     print ('viable directions: "north", "south", "east", "west", "up", "down"')
  56. end
  57. --p = peripheral.wrap("front")
  58. --turtleDir = ("West")
  59.  
  60. function cleanUp()
  61.     print("sweep sweep sweep WIP")
  62. end
  63.  
  64. function getStacks()
  65.     for i=1, p.getInventorySize() do
  66.         if p.getStackInSlot(i) ~= nil then
  67.             quantity = p.getStackInSlot(i).qty
  68.             --if quantity >= 9 then
  69.             if quantity >= 4 then
  70.                 doCrafting(i, quantity)
  71.                 print("crafting")
  72.             end
  73.         end
  74.     end
  75. end
  76.  
  77. function doCrafting(slot, n)
  78.     --craftNr = math.floor(n / 9)
  79.     craftNr = math.floor(n / 4)
  80.     p.pushItemIntoSlot(turtleDir,slot,craftNr, 1)
  81.     p.pushItemIntoSlot(turtleDir,slot,craftNr, 2)
  82.     p.pushItemIntoSlot(turtleDir,slot,craftNr, 5)
  83.     p.pushItemIntoSlot(turtleDir,slot,craftNr, 6)
  84.     --p.pushItemIntoSlot(turtleDir,slot,craftNr, 3)
  85.     --p.pushItemIntoSlot(turtleDir,slot,craftNr, 7)
  86.     --p.pushItemIntoSlot(turtleDir,slot,craftNr, 9)
  87.     --p.pushItemIntoSlot(turtleDir,slot,craftNr, 10)
  88.     --p.pushItemIntoSlot(turtleDir,slot,craftNr, 11)
  89.     if turtle.craft() then
  90.         pcall(drop)
  91.     else
  92.         pcall(cleanUp)
  93.         os.sleep(2)
  94.     end
  95. end
  96.  
  97.  
  98. function main()
  99.     quantity = 0
  100.     p.condenseItems()
  101.     while true do
  102.         getStacks()
  103.         p.condenseItems()
  104.         print("waiting 1")
  105.         os.sleep(0.4)
  106.     end
  107. end
  108.  
  109. settings()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement