Advertisement
Elmoren

Untitled

Jul 30th, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 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. number = 1
  30. for k,v in pairs(ae.getAvailableItems()) do
  31. if string.find(string.upper(v.name),name) then
  32. names[number] = v.name
  33. ids[number] = v.id
  34. qty[number] = v.qty
  35. number = number + 1
  36. end
  37. end
  38. gl.clear()
  39. idsl = 0
  40. for i = 1,#ids do
  41. if string.len(ids[i]) > idsl then
  42. idsl = string.len(ids[i])
  43. end
  44. end
  45. qtyl = 0
  46. for i = 1,#ids do
  47. if string.len(qty[i]) > qtyl then
  48. qtyl = string.len(qty[i])
  49. end
  50. end
  51. namesl = 0
  52. for i = 1,#ids do
  53. if string.len(names[i]) > namesl then
  54. namesl = string.len(names[i])
  55. end
  56. end
  57. num = 0
  58. idslen = idsl * 10
  59. qtylen = qtyl * 10
  60. nameslen = namesl * 6
  61. width = 30 + idslen + qtylen + nameslen
  62. heigth = (#ids * 10) + 15
  63. gl.addBox(20,5,width,heigth,40,0.5)
  64. gl.addText(30,10,"num",0x369de1)
  65. gl.addText(30 + 30,10,"id",0xf0371e)
  66. gl.addText(30 + 30 + idslen,10,"qty",0xffc703)
  67. gl.addText(30 + 30 + idslen + qtylen,10,"name",0x637b4b)
  68. for i = 1,#names do
  69. gl.addText(30,20 + num ,string.sub(i,1,string.len(i)),0x369de1)
  70. gl.addText(30 + 30,20 + num ,string.sub(ids[i],1,string.len(ids[i])),0xf0371e)
  71. gl.addText(30 + 30 + idslen,20 + num ,string.sub(qty[i],1,string.len(qty[i])),0xffc703)
  72. gl.addText(30 + 30 + idslen + qtylen,20 + num ,names[i],0x637b4b)
  73. num = num + 10
  74. end
  75. waiting = true
  76. if waiting then
  77. evt2, cmd2 = os.pullEvent("chat_command")
  78. i = 0
  79. mots = {}
  80. for mot in string.gmatch(cmd2, "%S+") do
  81. mots[i] = mot
  82. i = i + 1
  83. end
  84. if mots[0] == "num" then
  85. cust = {}
  86. cust["id"] = tonubmer(ids[mots[1]])
  87. cust["qty"] = tonubmer(mots[2])
  88. cust["dmg"] = -1
  89. ae.extractItem(cust, "east")
  90. gl.clear()
  91. else
  92. waiting = false
  93. gl.clear()
  94. os.reboot()
  95. break
  96. end
  97. end
  98. end
  99. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement