Doob

rtrader robot

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