Advertisement
Elmoren

Untitled

Jul 30th, 2014
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. gl = peripheral.wrap("bottom")
  2. ae = peripheral.wrap("front")
  3. while true do
  4. evt, cmd = os.pullEvent("chat_command")
  5. words = {}
  6. i = 0
  7. waiting = false
  8. for word in string.gmatch(cmd, "%S+") do
  9. words[i] = word
  10. i = i + 1
  11. end
  12. if words[0] == "getitem" then
  13. if #words < 1 then
  14. waiting = false
  15. os.reboot()
  16. end
  17. n = ""
  18. if #words > 1 then
  19. for i=1,#words do
  20. n = n.." "..words[i]
  21. end
  22. else
  23. n = words[1]
  24. end
  25. name = string.upper(n)
  26. names = {}
  27. ids = {}
  28. qty = {}
  29. dmg = {}
  30. number = 1
  31. for k,v in pairs(ae.getAvailableItems()) do
  32. if string.find(string.upper(v.name),name) then
  33. names[number] = v.name
  34. ids[number] = v.id
  35. qty[number] = v.qty
  36. dmg[number] = v.dmg
  37. number = number + 1
  38. end
  39. end
  40. if #names < 1 then
  41. waiting = false
  42. gl.clear()
  43. os.reboot()
  44. end
  45. gl.clear()
  46. idsl = 0
  47. for i = 1,#ids do
  48. if string.len(ids[i]) > idsl then
  49. idsl = string.len(ids[i])
  50. end
  51. end
  52. qtyl = 0
  53. for i = 1,#ids do
  54. if string.len(qty[i]) > qtyl then
  55. qtyl = string.len(qty[i])
  56. end
  57. end
  58. namesl = 0
  59. for i = 1,#ids do
  60. if string.len(names[i]) > namesl then
  61. namesl = string.len(names[i])
  62. end
  63. end
  64. dmgl = 0
  65. for i = 1,#ids do
  66. if string.len(dmg[i]) > dmgl then
  67. dmgl = string.len(dmg[i])
  68. end
  69. end
  70. num = 0
  71. idslen = idsl * 10
  72. dmglen = dmgl * 10
  73. qtylen = qtyl * 10
  74. nameslen = namesl * 7
  75. width = 30 + idslen + qtylen + nameslen
  76. heigth = (#ids * 10) + 15
  77. gl.addBox(20,5,width,heigth,40,0.5)
  78. gl.addText(30,10,"num",0x369de1)
  79. gl.addText(30 + 30,10,"id",0xf0371e)
  80. gl.addText(30 + 20 + idslen,10,"dmg",0xf0371e)
  81. gl.addText(30 + 30 + idslen + dmglen,10,"qty",0xffc703)
  82. gl.addText(30 + 30 + idslen + dmglen + qtylen,10,"name",0x637b4b)
  83. for i = 1,#names do
  84. gl.addText(30,20 + num ,string.sub(i,1,string.len(i)),0x369de1)
  85. gl.addText(30 + 30,20 + num ,string.sub(ids[i],1,string.len(ids[i])),0xf0371e)
  86. gl.addText(30 + 20 + idslen,20 + num,string.sub(dmg[i],1,string.len(dmg[i])),0xf0371e)
  87. gl.addText(30 + 30 + idslen + dmglen,20 + num ,string.sub(qty[i],1,string.len(qty[i])),0xffc703)
  88. gl.addText(30 + 30 + idslen + dmglen + qtylen,20 + num ,names[i],0x637b4b)
  89. num = num + 10
  90. end
  91. waiting = true
  92. if waiting then
  93. evt2, cmd2 = os.pullEvent("chat_command")
  94. i = 0
  95. mots = {}
  96. for mot in string.gmatch(cmd2, "%S+") do
  97. mots[i] = mot
  98. i = i + 1
  99. end
  100. if mots[0] == "num" then
  101. if mots[1] == nil or mots[2] == nil then
  102. waiting = false
  103. gl.clear()
  104. os.reboot()
  105. break
  106. else
  107. if #mots == 3 then
  108. dmg = tonumber(mots[3])
  109. else
  110. dmg = -1
  111. end
  112. id = tonumber(mots[1])
  113. quantity = tonumber(mots[2])
  114. cust = {}
  115. cust["id"] = ids[id]
  116. cust["qty"] = quantity
  117. cust["dmg"] = dmg
  118. ae.extractItem(cust, "east")
  119. gl.clear()
  120. turtle.dropUp()
  121. end
  122. else
  123. waiting = false
  124. gl.clear()
  125. os.reboot()
  126. break
  127. end
  128. end
  129. end
  130. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement