Advertisement
Rolcam

Computercraft Vending System V1

Jun 29th, 2021 (edited)
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.28 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw
  2. side2 = "back"
  3. term.clear()
  4. term.setCursorPos(1,1)
  5. print("Please Insert Vend Pass")
  6. event, side = os.pullEvent("disk")
  7. print("Pass Inserted")
  8. print("Beginning Security Check")
  9. sleep(0.5)
  10. if fs.exists("disk/startup") then
  11.         term.setTextColor(colors.red)
  12.         print("WARNING: Startup Program Detected!")
  13.         c = 0
  14.         while tk == 1 do
  15.             -- If a program called startup_#### doesn't exist then:
  16.             if not fs.exists("startup_" .. c) then
  17.                 -- resets security variable
  18.                 tk = 0
  19.                 -- stores a copy of the startup program to the computer as "startup_####"
  20.                 shell.run("copy disk/startup", "startup_" .. c)
  21.             else
  22.                 -- Increases the number by 1
  23.                 sleep(0.1)
  24.                 c = c + 1
  25.             end
  26.         -- Deletes the startup program on the floppy disk
  27.         shell.run("delete disk/startup")
  28.         print("Program logged and deleted!")
  29.         sleep(0.5)
  30.         print("Confiscating disk...")
  31.         sleep(0.5)
  32.         -- Ejects disk then reboots the computer
  33.         disk.eject(side)
  34.         os.reboot()
  35.         end
  36.     end
  37.     -- Checks if a data disk was inserted or if a random object was inserted instead
  38.     if not disk.hasData(side) then
  39.         term.setTextColor(colors.red)
  40.         print("Warning: Invalid Object Detected!")
  41.         sleep(0.5)
  42.         print("Confiscating item. Please see zoo staff for retrieval")
  43.         sleep(2)
  44.         disk.eject("bottom")
  45.         os.reboot()
  46.     end
  47.     if not fs.exists("disk/.credits") then
  48.         term.setTextColor(colors.red)
  49.         print("Disk doesn't have credit pass data!")
  50.         sleep(0.5)
  51.         print("Confiscating disk. Please see zoo staff for retrieval")
  52.         sleep(2)
  53.         disk.eject("bottom")
  54.         os.reboot()
  55.     end
  56. rID = disk.getID(side)
  57.     if rID == 5 or rID == 11 then
  58.         term.setTextColor(colors.red)
  59.         term.clear()
  60.         term.setCursorPos(1,1)
  61.         print("Admin Card Detected")
  62.         print("Additional Options Unlocked")
  63.         sleep(2)
  64.     end
  65. while true do
  66.    
  67.     --Checks Balance
  68.     creditDat = fs.open("disk/.credits","r")
  69.     credits2 = creditDat.readLine()
  70.     creditDat.close()
  71.    
  72.     -- Main Screen
  73.     term.clear()
  74.     term.setCursorPos(1,1)
  75.     term.setTextColor(colors.yellow)
  76.     print("Condemned Zoo Vending Machine System V1\n ")
  77.     credits = tonumber(credits2)
  78.     print("You currently have ".. credits .." credits on your card")
  79.     if credits > 0 then
  80.         print("Please select your requested item #")
  81.         print("1 - Splash Health Potion II - 50 credits")
  82.         print("2 - Saddles - 10 credits")
  83.         print("3 - Diamond Horse Armor - 20 credits")
  84.         print("4 - End Transaction")
  85.         if rID == 5 or rID == 11 then
  86.             term.setTextColor(colors.orange)
  87.             print("5 - Enter Maintenance Mode")
  88.         end
  89.         term.setTextColor(colors.yellow)
  90.         input = read()
  91.         if input == "1" then
  92.             if rs.testBundledInput(side2, colors.lime) == false then
  93.                 if credits >= 50 then
  94.                     credits = credits - 50
  95.                     creditUp = fs.open("disk/.credits","w")
  96.                     creditUp.writeLine(credits)
  97.                     creditUp.close()
  98.                     print("Now Vending Item 1")
  99.                     rs.setBundledOutput(side2, colors.white)
  100.                     sleep(0.1)
  101.                     rs.setBundledOutput(side2, 0)
  102.                     sleep(1)
  103.                     print("Check chest for item")
  104.                     sleep(2)
  105.                  end
  106.             else
  107.                 term.setTextColor(colors.red)
  108.                 print("Sold Out :(")
  109.                 sleep(2)
  110.             end      
  111.         elseif input == "2" then
  112.             if rs.testBundledInput(side2, colors.pink) == false then
  113.                 if credits >= 10 then
  114.                     credits = credits - 10
  115.                     creditUp = fs.open("disk/.credits","w")
  116.                     creditUp.writeLine(credits)
  117.                     creditUp.close()
  118.                     print("Now Vending Item 2")
  119.                     rs.setBundledOutput(side2, colors.orange)
  120.                     sleep(0.1)
  121.                     rs.setBundledOutput(side2, 0)
  122.                     sleep(1)
  123.                     print("Check chest for item")
  124.                     sleep(2)
  125.                  end
  126.             else
  127.                 term.setTextColor(colors.red)
  128.                 print("Sold Out :(")
  129.                 sleep(2)
  130.             end
  131.         elseif input == "3" then
  132.             if rs.testBundledInput(side2, colors.gray) == false then
  133.                 if credits >= 20 then
  134.                     credits = credits - 20
  135.                     creditUp = fs.open("disk/.credits","w")
  136.                     creditUp.writeLine(credits)
  137.                     creditUp.close()
  138.                     print("Now Vending Item 3")
  139.                     rs.setBundledOutput(side2, colors.magenta)
  140.                     sleep(0.1)
  141.                     rs.setBundledOutput(side2, 0)
  142.                     sleep(1)
  143.                     print("Check chest for item")
  144.                     sleep(2)
  145.                  end
  146.             else
  147.                 term.setTextColor(colors.red)
  148.                 print("Sold Out :(")
  149.                 sleep(2)
  150.             end      
  151.         elseif input == "4" then
  152.             term.clear()
  153.             term.setCursorPos(1,1)
  154.             print("Thank you for using the condemned zoo vending system")
  155.             print("Don't forget to take your pass")
  156.             sleep(5)
  157.             print("Auto ejecting pass")
  158.             sleep(2)
  159.             disk.eject(side)
  160.             os.reboot()
  161.         elseif input == "5" and (rID == 5 or rID == 11) then
  162.             print("Entering Maintenance Mode")
  163.             break
  164.         else
  165.             term.setTextColor(colors.red)
  166.             print("Invalid Selection")
  167.             sleep(2)
  168.         end
  169.  
  170.     else
  171.         term.setTextColor(colors.red)
  172.         print("You are out of credits")
  173.         disk.setLabel(side,"Empty Pass")
  174.         sleep(0.5)
  175.         print("Confiscating empty pass")
  176.         sleep(0.5)
  177.         print("See guest services for a new credit pass")
  178.         sleep(2)
  179.         disk.eject(side)
  180.         os.reboot()
  181.     end
  182. end        
  183.            
  184.    
  185.    
  186.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement