Advertisement
Elmoren

Untitled

Jul 30th, 2014
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 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. gl.clear()
  41. idsl = 0
  42. for i = 1,#ids do
  43. if string.len(ids[i]) > idsl then
  44. idsl = string.len(ids[i])
  45. end
  46. end
  47. qtyl = 0
  48. for i = 1,#ids do
  49. if string.len(qty[i]) > qtyl then
  50. qtyl = string.len(qty[i])
  51. end
  52. end
  53. namesl = 0
  54. for i = 1,#ids do
  55. if string.len(names[i]) > namesl then
  56. namesl = string.len(names[i])
  57. end
  58. end
  59. dmgl = 0
  60. for i = 1,#ids do
  61. if string.len(dmg[i]) > dmgl then
  62. dmgl = string.len(dmg[i])
  63. end
  64. end
  65. num = 0
  66. idslen = idsl * 10
  67. dmglen = dmgl * 10
  68. qtylen = qtyl * 10
  69. nameslen = namesl * 7
  70. width = 30 + idslen + qtylen + nameslen
  71. heigth = (#ids * 10) + 15
  72. gl.addBox(20,5,width,heigth,40,0.5)
  73. gl.addText(30,10,"num",0x369de1)
  74. gl.addText(30 + 30,10,"id",0xf0371e)
  75. gl.addText(30 + 20 + idslen,10,"dmg",0xf0371e)
  76. gl.addText(30 + 30 + idslen + dmglen,10,"qty",0xffc703)
  77. gl.addText(30 + 30 + idslen + dmglen + qtylen,10,"name",0x637b4b)
  78. for i = 1,#names do
  79. gl.addText(30,20 + num ,string.sub(i,1,string.len(i)),0x369de1)
  80. gl.addText(30 + 30,20 + num ,string.sub(ids[i],1,string.len(ids[i])),0xf0371e)
  81. gl.addText(30 + 20 + idslen,20 + num,string.sub(dmg[i],1,string.len(dmg[i])),0xf0371e)
  82. gl.addText(30 + 30 + idslen + dmglen,20 + num ,string.sub(qty[i],1,string.len(qty[i])),0xffc703)
  83. gl.addText(30 + 30 + idslen + dmglen + qtylen,20 + num ,names[i],0x637b4b)
  84. num = num + 10
  85. end
  86. waiting = true
  87. if waiting then
  88. evt2, cmd2 = os.pullEvent("chat_command")
  89. i = 0
  90. mots = {}
  91. for mot in string.gmatch(cmd2, "%S+") do
  92. mots[i] = mot
  93. i = i + 1
  94. end
  95. if mots[0] == "num" then
  96. if mots[1] == nil or mots[2] == nil then
  97. waiting = false
  98. gl.clear()
  99. os.reboot()
  100. break
  101. else
  102. if #mots == 3 then
  103. dmg = tonumber(mots[3])
  104. else
  105. dmg = -1
  106. end
  107. id = tonumber(mots[i])
  108. quantity = tonubmer(mots[2])
  109. cust = {}
  110. cust["id"] = ids[id]
  111. cust["qty"] = quantity
  112. cust["dmg"] = dmg
  113. ae.extractItem(cust, "east")
  114. gl.clear()
  115. turtle.dropUp()
  116. end
  117. else
  118. waiting = false
  119. gl.clear()
  120. os.reboot()
  121. break
  122. end
  123. end
  124. end
  125. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement