Advertisement
Doob

[OpenComputers] robotrader

Nov 18th, 2016
705
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.05 KB | None | 0 0
  1. local trading = require("component").trading
  2. local cls = require("term").clear
  3. local E = require("event")
  4. local s, e, i, o = 1
  5. local t = trading.getTrades()
  6.  
  7. if t.n == 0 then
  8.   print("I don't see the villagers.")
  9.   os.exit()
  10. end
  11.  
  12. while true do
  13.   t = trading.getTrades()
  14.   if t[s].isEnabled() then
  15.     cls()
  16.     print("#"..s)
  17.     o, i, i2 = t[s].getOutput(), t[s].getInput()
  18.     print("You:      "..i.label.." ["..i.size.."]")
  19.     if i2 then
  20.       print("          "..i2.label.." ["..i2.size.."]")
  21.     end
  22.     print("\nVillager: "..o.label.." ["..o.size.."]")
  23.     if o.enchantments then
  24.       for k = 1, #o.enchantments do
  25.         print("\t", o.enchantments[k].label)
  26.       end
  27.     end
  28.   end
  29.   e = {E.pull("key_down")}
  30.   if e[4] == 200 then
  31.     if s == t.n then
  32.       s = 1
  33.     else
  34.       s = s + 1
  35.     end
  36.   elseif e[4] == 208 then
  37.     if s == 1 then
  38.       s = t.n
  39.     else
  40.       s = s - 1
  41.     end
  42.   elseif e[4] == 28 then
  43.     print(t[s].trade())
  44.     E.pull("key_down")
  45.     t = trading.getTrades()
  46.   else
  47.     os.exit()
  48.   end
  49. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement