Advertisement
LDDestroier

Untitled

May 17th, 2021
889
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- vend.lua
  2. local id = 95
  3. local m = peripheral.wrap("top")
  4.  
  5. local account, name
  6.  
  7. function button(food, price)
  8.     m.setBackgroundColor(colors.lime)
  9.     m.write("  ")
  10.     m.setBackgroundColor(colors.black)
  11.     m.write(food .. " x64 " .. price .. " Diamonds")
  12.     local x, y = m.getCursorPos()
  13.     m.setCursorPos(2,y+2)
  14. end
  15.  
  16. m.setBackgroundColor(colors.black)
  17. m.clear()
  18. m.setCursorPos(2,3)
  19. button("Cooked Beef","10")
  20. button("Pork","7")
  21. m.setCursorPos(2,1)
  22. m.write("Current Balance:$ ")
  23.  
  24. function getCash()
  25.     for i = 1,100 do
  26.         m.setCursorPos(i+17,1)
  27.         m.write(" ")
  28.     end
  29.  
  30.     if fs.exists("disk/accountInfo.lua") then
  31.         print("Found Card")
  32.         account = fs.open("disk/accountInfo.lua", "r")
  33.         name = account.readLine()
  34.         account.close()
  35.         print(name)
  36.         local num = bank.requestStatement("greenblock", name, id)
  37.         money = tonumber(num)
  38.         print(money)
  39.         m.setCursorPos(18, 1)
  40.         m.write("$")
  41.         m.setCursorPos(19, 1)
  42.         m.write(money)
  43.  
  44.     else
  45.         m.setCursorPos(18, 1)
  46.         m.write("Card Not Loaded")
  47.     end
  48. end
  49.  
  50. function printButtons()
  51.     button("Cooked Beef", "10")
  52.     button("Pork", "7")
  53. end
  54.  
  55. function giveItem(Nom, price)
  56.     if money >= price then
  57.         local sum = money - price
  58.         rednet.send(91,"beef")
  59.         bank.sendTransaction("greenblock", name, sum, id)
  60.     end
  61. end
  62.  
  63. printButtons()
  64.  
  65. while true do
  66.     local event, button, bx, by = os.pullEvent()
  67.     getCash()
  68.  
  69.     if bx == 2 and by == 3 then
  70.         giveItem("beef", 10)
  71.  
  72.     elseif bx == 2 and by == 5 then
  73.         giveitem("pork", 7)
  74.     end
  75. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement