Advertisement
Indie_Rogers

RedNet Point of Sale Test

May 5th, 2023 (edited)
785
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.79 KB | None | 0 0
  1. ---@diagnostic disable: lowercase-global
  2.  
  3. SLOT_COUNT = 16
  4.  
  5. -- Goes through each slot and checks which item slot matches the input (itemName)
  6. function getItemIndex(itemName)
  7.     for slot = 1, SLOT_COUNT, 1 do
  8.         local item = turtle.getItemDetail(slot)
  9.         if (item ~= nil) then
  10.             if(item["name"] == itemName) then
  11.                 return slot
  12.             end
  13.         end
  14.     end
  15. end
  16.  
  17.  
  18. function waitforsale()
  19.     local ignore, id = rednet.receive()
  20.     local itemIndex = getItemIndex("minecraft:" .. tostring(id))
  21.     if itemIndex ~= nil then
  22.         turtle.select(itemIndex)
  23.         turtle.drop()
  24.         rednet.broadcast("Item Dropped")
  25.     else
  26.         rednet.broadcast("Item Not Found")
  27.     end
  28. end
  29. while true do
  30.     turtle.suckUp()
  31.     waitforsale()
  32. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement