Jayex_Designs

dispenseDisplay

Jun 19th, 2021 (edited)
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.94 KB | None | 0 0
  1. rednet.open("bottom")
  2.  
  3. Display = peripheral.wrap("top")
  4.  
  5. DisplayWidth, DisplayHeight = Display.getSize()
  6.  
  7.  
  8.  
  9. function PrintPrices()
  10.     Display.clear()
  11.     Display.setTextScale(1)
  12.  
  13.     local prices = {
  14.         ["1"] = {
  15.             ["price"] = 1,
  16.             ["display"] = "Iron Ingots",
  17.             ["color"] = "8"
  18.         },
  19.         ["2"] = {
  20.             ["price"] = 10,
  21.             ["display"] = "Iron Blocks",
  22.             ["color"] = "8"
  23.         },
  24.         ["3"] = {
  25.             ["price"] = 14,
  26.             ["display"] = "Diamonds",
  27.             ["color"] = "3"
  28.         },
  29.         ["4"] = {
  30.             ["price"] = 144,
  31.             ["display"] = "Netherite Scrap",
  32.             ["color"] = "e"
  33.         }
  34.     }
  35.  
  36.     Display.setCursorPos(2,2)
  37.     local text = "Potato Prices"
  38.     Display.blit(text, string.rep("0", string.len(text)), string.rep("f", string.len(text)))
  39.     Display.setCursorPos(1,3)
  40.     Display.blit(string.rep("-", DisplayWidth), string.rep("0", DisplayWidth), string.rep("f", DisplayWidth))
  41.  
  42.     local lowestElementPos = 0
  43.  
  44.     for key, val in pairs(prices) do
  45.         Display.setCursorPos(2, 4 + tonumber(key) * 2)
  46.         text = val["display"]
  47.         Display.blit(text, string.rep(val["color"], string.len(text)), string.rep("f", string.len(text)))
  48.         text = " " .. string.rep("-", DisplayWidth - 6 - string.len(val["display"]) - string.len(tostring(val["price"]))) .. " "
  49.         Display.blit(text, string.rep("0", string.len(text)), string.rep("f", string.len(text)))
  50.         text = tostring("1:" .. val["price"])
  51.         Display.blit(text, string.rep("1", string.len(text)), string.rep("f", string.len(text)))
  52.  
  53.         local _, y = Display.getCursorPos()
  54.         if y > lowestElementPos then
  55.             lowestElementPos = y
  56.         end
  57.     end
  58.  
  59.     Display.setCursorPos(2, lowestElementPos + 3)
  60.     text = "New payment options soon!"
  61.     Display.blit(text, string.rep("0", string.len(text)), string.rep("f", string.len(text)))
  62.     Display.setCursorPos(2, lowestElementPos + 5)
  63.     text = "Prices may change"
  64.     Display.blit(text, string.rep("0", string.len(text)), string.rep("f", string.len(text)))
  65. end
  66.  
  67.  
  68. function ProcessingTransaction()
  69.     Display.clear()
  70.     Display.setTextScale(1)
  71.  
  72.     Display.setCursorPos(1, math.floor(DisplayHeight/2))
  73.     local text = "Please wait for the"
  74.     text = string.rep(" ", (DisplayWidth-string.len(text))/2) .. text
  75.     Display.blit(text, string.rep("0", string.len(text)), string.rep("f", string.len(text)))
  76.     Display.setCursorPos(1, math.floor(DisplayHeight/2)+1)
  77.     text = "transaction to finish"
  78.     text = string.rep(" ", (DisplayWidth-string.len(text))/2) .. text
  79.     Display.blit(text, string.rep("0", string.len(text)), string.rep("f", string.len(text)))
  80. end
  81.  
  82.  
  83. function LimitReached(time)
  84.     local resetTime = 1000 * 60 * 5
  85.  
  86.     local timeLeft = math.floor((resetTime - (os.epoch('utc') - time))/1000)
  87.  
  88.     while timeLeft > 0 do
  89.         timeLeft = math.floor((resetTime - (os.epoch('utc') - time))/1000)
  90.  
  91.         Display.clear()
  92.         Display.setTextScale(1)
  93.  
  94.         Display.setCursorPos(1, math.floor(DisplayHeight/2))
  95.         local text = "Limit reached"
  96.         text = string.rep(" ", (DisplayWidth-string.len(text))/2) .. text
  97.         Display.blit(text, string.rep("0", string.len(text)), string.rep("f", string.len(text)))
  98.         Display.setCursorPos(1, math.floor(DisplayHeight/2)+1)
  99.         text = "Wait " .. timeLeft .. " more seconds"
  100.         text = string.rep(" ", (DisplayWidth-string.len(text))/2) .. text
  101.         Display.blit(text, string.rep("0", string.len(text)), string.rep("f", string.len(text)))
  102.     end
  103. end
  104.  
  105.  
  106.  
  107. PrintPrices()
  108.  
  109. while true do
  110.     local id, message, protocol = rednet.receive()
  111.     if protocol == "printPrices" then
  112.         PrintPrices()
  113.     elseif protocol == "processingTransaction" then
  114.         ProcessingTransaction()
  115.     elseif protocol == "limitReached" then
  116.         LimitReached(message)
  117.     end
  118. end
Advertisement
Add Comment
Please, Sign In to add comment