Advertisement
x8-bitx

Shop Item Server

Dec 8th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.35 KB | None | 0 0
  1.  
  2. --rednet details
  3. rside = "left"
  4. rednet.open(rside)
  5. shopId = 20
  6.  
  7. --Other info
  8. monitorSide = "top"
  9. term.redirect(peripheral.wrap(monitorSide))
  10. --empty container
  11. function emptyContainer()
  12.   if shell.run("empty") then
  13.     return true
  14.   else
  15.     return false
  16.   end
  17. end
  18. --pull item
  19. function pullItem(itm)
  20.   shell.run("pull "..itm)
  21. end
  22. function saleInfo(sa,sb)
  23.   print("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&")
  24.   print("Sold "..sa)
  25.   print("Category "..sb)
  26.   print("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&")
  27. end
  28. function packetInfo(ta,tb,tc)
  29.   print("##############################")
  30.   print("Found Packet:")
  31.   print("ID: "..ta)
  32.   print("Msg: "..tb)
  33.   print("Cat: "..tc)
  34.   print("##############################")
  35.  
  36. end
  37. function errorReport(as,ab,ag)
  38.   print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@")
  39.   print("UNKNOWN ERROR: Info Known:")
  40.   print("ID: "..as)
  41.   print("Message: "..ab)
  42.   print("Category: "..ag)
  43.   print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@")
  44. end
  45.  
  46. while true do
  47.   id, msg, cat = rednet.receive()
  48.   if id == shopId then
  49.     if cat == "pull" then
  50.       pullItem(msg)
  51.         rednet.send(shopId,"1")
  52.         sleep(.2)
  53.         rednet.send(shopId,"2")
  54.         --print sale
  55.         saleInfo(msg,cat)
  56.     elseif cat == "empty" then
  57.       emptyContainer()
  58.     else
  59.       errorReport(id,msg,cat)
  60.     end
  61.   else
  62.     packetInfo(id,msg,cat)
  63.   end
  64. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement