Advertisement
msmikesc

aeretrieve

Apr 17th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. args = {...}
  2.  
  3. modem = peripheral.wrap("top")
  4. chest = peripheral.wrap("right")
  5. replyGlobal = 1
  6. modemport = 3
  7.  
  8. function main()
  9.  
  10. me = peripheral.wrap("back")
  11.  
  12. if args[1] == "1" then
  13. searchSimple(args[2], 1)
  14. elseif args[1] == "2" then
  15. searchLong(args[2], 1)
  16. else
  17. modem.open(modemport)
  18.  
  19. while true do
  20. local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  21.  
  22. replyGlobal = replyChannel
  23.  
  24.  
  25.  
  26. if string.sub(message, 0, 4) == "send" then
  27. status, errormessage = pcall(sendItem, message)
  28. elseif string.sub(message, 0, 5) == "clear" then
  29. status, errormessage = pcall(clearItems)
  30. end
  31.  
  32. if status then
  33. modem.transmit(replyGlobal, modemport, "Done")
  34. else
  35. modem.transmit(replyGlobal, modemport, errormessage)
  36. modem.transmit(replyGlobal, modemport, "Done")
  37. end
  38.  
  39. end
  40. end
  41.  
  42. end
  43.  
  44. function searchSimple(input, amount)
  45.  
  46. lowerinput = string.lower(input)
  47.  
  48. allitems = me.listAvailableItems()
  49.  
  50. for key, proptable in pairs(allitems) do
  51.  
  52. name = string.lower(proptable.name)
  53.  
  54. if string.match(name, lowerinput) then
  55. items = me.findItems(proptable.name.."@"..proptable.damage)
  56.  
  57. for itemnum,item in pairs(items) do
  58.  
  59. itemmeta = item.getMetadata()
  60.  
  61. if(itemmeta.count > 0) then
  62. item.export("right", amount)
  63. modem.transmit(replyGlobal, modemport, "Item " .. itemmeta.displayName .. " found")
  64. else
  65. modem.transmit(replyGlobal, modemport, "Item " .. itemmeta.displayName .. " found but none available")
  66. end
  67. end
  68. end
  69.  
  70.  
  71. end
  72. end
  73.  
  74. function searchLong(input, amount)
  75.  
  76. lowerinput = string.lower(input)
  77.  
  78. allitems = me.listAvailableItems()
  79.  
  80. for key, proptable in pairs(allitems) do
  81.  
  82. item = me.findItem(proptable)
  83.  
  84. itemmeta = item.getMetadata()
  85.  
  86. name = string.lower(itemmeta.displayName)
  87.  
  88. if string.match(name, lowerinput) then
  89.  
  90. if(itemmeta.count > 0) then
  91. item.export("right", amount)
  92. else
  93. print("Item " .. itemmeta.displayName .. " found but none available")
  94. end
  95. end
  96.  
  97. end
  98. end
  99.  
  100. function justWords(str)
  101. local t = {}
  102. local function helper(word)
  103. table.insert(t, word)
  104. return ""
  105. end
  106. if not str:gsub("%w+", helper):find"%S" then
  107. return t
  108. end
  109. end
  110.  
  111. function recombineName(table, index)
  112.  
  113. searched = ""
  114.  
  115. for k,v in pairs(table) do
  116. if k == index then
  117. searched = v
  118. end
  119. if k > index then
  120. searched = searched .. " " .. v
  121. end
  122. end
  123.  
  124. return searched
  125. end
  126.  
  127. function sendItem(message)
  128.  
  129. chattable = justWords(message)
  130.  
  131. word1 = chattable[2]
  132.  
  133. if tonumber(word1) ~= nil then
  134. amount = tonumber(word1)
  135. item = recombineName(chattable, 3)
  136. else
  137. amount = 1
  138. item = recombineName(chattable, 2)
  139. end
  140.  
  141. searchSimple(item, amount)
  142. end
  143.  
  144. function clearItems()
  145.  
  146. for i = 1, 54 do
  147. chest.pushItems("north", i)
  148. end
  149.  
  150. end
  151.  
  152. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement