Advertisement
ecco7777

CC easy storage turtle

Apr 10th, 2017
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.56 KB | None | 0 0
  1. inv=peripheral.wrap("bottom")
  2. termXMax,termYMax=term.getSize()
  3. inv.condense()
  4. function scanItems()
  5. slots=inv.getSizeInventory()
  6. itemInSlot={}
  7. itemByName={}
  8. itemByNum={}
  9. itemById={}
  10. itemByAmount={}
  11. itemListed={}
  12. i2=1
  13. for i=0,slots-1 do
  14. term.clear()
  15. term.setCursorPos(1,1)
  16. term.write("Scan Slot"..tostring(i).." of "..tostring(slots))
  17. itemInSlot[i]=inv.getStackInSlot(i)
  18. sleep(0)
  19. if itemInSlot[i]~=nil then
  20. itemInSlot[i]["slot"]=i
  21. itemByName[itemInSlot[i]["name"]]=itemInSlot[i]
  22.  
  23. if itemById[itemInSlot[i]["id"]]==nil then
  24. itemByAmount[itemInSlot[i]["id"]]=itemInSlot[i]
  25. itemByNum[i2]=itemByAmount[itemInSlot[i]["id"]]
  26. i2=i2+1
  27. else
  28. itemByAmount[itemInSlot[i]["id"]]["qty"]=itemByAmount[itemInSlot[i]["id"]]["qty"]+itemInSlot[i]["qty"]
  29. end
  30. itemById[itemInSlot[i]["id"]]=itemInSlot[i]
  31. end
  32. end
  33. i=i2
  34. for i2=1,i-1 do
  35. itemByNum[i2]=itemByAmount[itemByNum[i2]["id"]]
  36. end
  37. end
  38.  
  39. function getItem(id,qty,slot)
  40. inv.pushIntoSlot("up",id,qty,slot)
  41. end
  42.  
  43. function itemAvarible(id,qty)
  44. itemAvarible=false
  45. if itemByAmount[id]~=nil then
  46. if itemByAmount[id]["qty"]>=qty then
  47. itemAvarible=true
  48. end
  49. end
  50. return itemAvarible
  51. end
  52.  
  53. scanItems()
  54. term.clear()
  55. pos=1
  56. mem={}
  57. strmem=""
  58. menuSelect=1
  59. itemSelect=2
  60. key=2
  61. while true do
  62. if #keys.getName(key)==1 then
  63. mem[pos]=keys.getName(key)
  64. pos=pos+1
  65. end
  66. if key==57 then
  67. mem[pos]=" "
  68. pos=pos+1
  69. end
  70. if keys.getName(key)=="backspace" then
  71. if pos>1 then
  72. mem[pos-1]=""
  73. pos=pos-1
  74. end
  75. end
  76. if key==203 then
  77. if menuSelect>1 then
  78. menuSelect=menuSelect-1
  79. end
  80. end
  81. if key==205 then
  82. if menuSelect<4 then
  83. menuSelect=menuSelect+1
  84. end
  85. end
  86. if key==200 then
  87. if itemSelect>2 then
  88. itemSelect=itemSelect-1
  89. end
  90. end
  91. if key==200 then
  92. if itemSelect<yPos then
  93. itemSelect=itemSelect+1
  94. end
  95. end
  96.  
  97. term.setCursorPos(1,1)
  98. strmem=""
  99. yPos=2
  100.  
  101. for i=1,#mem do
  102. strmem=strmem..mem[i]
  103. end
  104. term.clear()
  105. term.write(strmem)
  106. for i=1,#itemByNum do
  107. if string.find(string.lower(itemByNum[i]["name"]),strmem) then
  108. term.setCursorPos(2,yPos)
  109. term.write(itemByNum[i]["name"])
  110. term.setCursorPos(termXMax-#tostring(itemByNum[i]["qty"]),yPos)
  111. term.write(tostring(itemByNum[i]["qty"]))
  112. itemListed[yPos]=itemByNum[i]
  113. yPos=yPos+1
  114. end
  115. end
  116. term.setCursorPos(1,itemSelect)
  117. term.write(">")
  118. term.setCursorPos(1,termYMax)
  119. if menuSelect==1 then term.write("[Get] Craft  Dispose  addRecipe ") end
  120. if menuSelect==2 then term.write(" Get [Craft] Dispose  addRecipe ") end
  121. if menuSelect==3 then term.write(" Get  Craft [Dispose] addRecipe ") end
  122. if menuSelect==4 then term.write(" Get  Craft  Dispose [addRecipe]") end
  123. event, key=os.pullEvent("key")
  124. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement