Advertisement
johnnic431

Receipt API

Jun 25th, 2015
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.61 KB | None | 0 0
  1. --[[Shop Receipt API
  2.  
  3. Sylvyrfysh - All Rights Reserved
  4. Unauthorized copying, and/or redistribution of this file, via any medium without express written permission of Sylvyrfysh (Nicholas Johnson) is strictly prohibited
  5. Proprietary and confidential
  6. Written by Nicholas Johnson <johnnic431@gmail.com>, June 24 2015
  7.  
  8. ]]
  9.  
  10. --[[ ex.
  11. ----Milianlou's  Shop----
  12.  
  13. Item                Price
  14. Item1                 f25
  15. Item2                 f30
  16.  
  17. Total                 f55
  18.  
  19. Created at Day 6 12:55
  20.  
  21. --Thanks for shopping!--
  22. ]]
  23.  
  24. local printer=peripheral.wrap("left")
  25. local line=4;
  26.  
  27. local function checkEnd(line)
  28.     if line==25 then
  29.         printer.endPage()
  30.         line=1;
  31.         if not printer.newPage() then return false; end
  32.         printer.setPageTitle("Receipt")
  33.     end
  34. end
  35.  
  36. local function writeLeft(str,line)
  37.     checkEnd(line)
  38.     printer.setCursorPos(1,line)
  39.     printer.write(str)
  40. end
  41.  
  42. local function writeRight(str,line)
  43.     checkEnd(line)
  44.     printer.setCursorPos(26-#str,tonumber(line) or line)
  45.     printer.write(str)
  46. end
  47.  
  48. function printReceipt(cart)
  49.     if not printer.newPage() then return false; end
  50.     printer.setPageTitle("Receipt")
  51.     printer.setCursorPos(1,1)
  52.     printer.write("----Milianlou's  Shop----")
  53.     printer.setCursorPos(1,3)
  54.     printer.write("Item                Price")
  55.     local tPrice=0;
  56.     for t,y in pairs(cart) do
  57.         writeLeft(y["itemName"],line)
  58.         price="f"..y["price"]
  59.         writeRight(price,line)
  60.         line=line+1;
  61.         tPrice=tPrice+y["price"]
  62.     end
  63.     line=line+1;
  64.     writeLeft("Total",line)
  65.     writeRight("f"..tPrice,line)
  66.     line=line+1
  67.     writeLeft("Created at Day "..os.day().." "..os.time(),line)
  68.     printer.endPage()
  69.     return true
  70. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement