AstolfoFate

tradepostTurtle.lua

Mar 24th, 2021 (edited)
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.81 KB | None | 0 0
  1. --[[
  2. opTradeBot ID = 424
  3. traderA ID = 425
  4. traderB ID = 426
  5. tradingpostServerID = 427
  6. ]]
  7.  
  8. -- listen for offerA
  9. -- check chest of offerA, scan items, interpret data
  10. -- send data to traderB
  11. -- listen for offerB
  12. -- check chest of offerB, scan items, interpret data
  13. -- send data to traderA
  14.  
  15. --The turtle needs to tell the traders what's inside the other's chest.
  16.  
  17. --[[local maxChestSlots = 54
  18. local chest = {} -- 9w x 6h]]
  19. --local turtleID = os.getComputerID()
  20. --[[
  21. OFFER A's chest is on the turtle's RIGHT
  22. A's HOLDING chest is on the turtle's TOP
  23. Offer B's chest is on the turtle's LEFT
  24. B's HOLDING chest is on the turtle's BOTTOM
  25. ]]
  26.  
  27. rednet.open("left")
  28. --network listener
  29. while true do
  30.   id, sendermsg = rednet.receive()
  31.   -- Trader A submit
  32.   -- goes through Trader A's chest (right) then deposits into A's holding chest (top)
  33.   if id == 427 and sendermsg == "offerA" then
  34.     -- turn right
  35.     turtle.turnRight()
  36.     -- loop code 4 times, because the turtle only holds 16 slots. We need to do the process 4 times to allow for 54 chest slots
  37.     for i = 1, 4 do
  38.       -- loop this code 16 times, for the amount of slots in the turtle.
  39.       -- get details of each item as they are transferred to the holding chest and send to the server
  40.       for i = 1, 16 do
  41.         turtle.select(i)
  42.         turtle.suck()
  43.         local data = turtle.getItemDetail(i)
  44.         if data then
  45.           rednet.send(427, "offerAItem: "..data.name)
  46.           rednet.send(427, "offerADamage: "..data.damage)
  47.           rednet.send(427, "offerACount: "..data.count)
  48.         end
  49.         --drops items into chest above the turtle. https://computercraft.info/wiki/Turtle.dropUp
  50.         turtle.dropUp()
  51.       end
  52.     end
  53.     -- Done doing stuff, turn left back to how it was positioned before.
  54.     turtle.turnLeft()
  55.  
  56.     -- Trader B submit
  57.     -- goes through all inventory and drops (hopefully into a chest)
  58.   elseif id == 427 and sendermsg == "offerB" then
  59.     turtle.turnLeft()
  60.     for i = 1, 4 do
  61.       for i = 1, 16 do
  62.         turtle.select(i)
  63.         turtle.suck()
  64.         local data = turtle.getItemDetail(i)
  65.         if data then
  66.           rednet.send(427, "offerBItem: "..data.name)
  67.           rednet.send(427, "offerBDamage: "..data.damage)
  68.           rednet.send(427, "offerBCount: "..data.count)
  69.         end
  70.         turtle.dropDown()
  71.       end
  72.     end
  73.     turtle.turnRight()
  74.     -- Decline
  75.   elseif id == 427 and sendermsg == "decline" then
  76.     -- TraderA return
  77.     turtle.turnRight()
  78.     for i = 1, 4 do
  79.       for i = 1, 16 do
  80.         turtle.select(i)
  81.         turtle.suckUp()
  82.         turtle.drop()
  83.       end
  84.     end
  85.     turtle.turnLeft()
  86.     -- TraderB return
  87.     turtle.turnLeft()
  88.     for i = 1, 4 do
  89.       for i = 1, 16 do
  90.         turtle.select(i)
  91.         turtle.suckDown()
  92.         turtle.drop()
  93.       end
  94.     end
  95.     turtle.turnRight()
  96.     -- Accept
  97.   elseif id == 427 and sendermsg == "tradeAuthorized" then
  98.     -- Get Trader B's items from holding chest and deliver to trader A's chest
  99.     turtle.turnRight()
  100.     for i = 1, 4 do
  101.       for i = 1, 16 do
  102.         turtle.select(i)
  103.         turtle.suckDown()
  104.         turtle.drop()
  105.       end
  106.     end
  107.     turtle.turnLeft()
  108.     -- Get Trader A's items from holding chest and deliver to trader B's chest
  109.     turtle.turnLeft()
  110.     for i = 1, 4 do
  111.       for i = 1, 16 do
  112.         turtle.select(i)
  113.         turtle.suckUp()
  114.         turtle.drop()
  115.       end
  116.     end
  117.     turtle.turnRight()
  118.   end
  119. end
  120.  
  121.   --turtle.suck(number)
  122.   --turtle.suckUp(number)
  123.   --turtle.suckDown(number)
  124.   --turtle.drop() drops items in front of turtle. if a chest is DIRECTLY IN FRONT of the turtle, it will place it in the chest.
  125.   --turtle.dropUp()
  126.   --turtle.dropDown()
  127.   --turtle.select(num) selects slot to act on. A handy dandy tip is to do a for loop and do turtle.select(i)
  128.  
Add Comment
Please, Sign In to add comment