kamilosxd678

[MC-CC] Tickets seller

Sep 24th, 2012
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.35 KB | None | 0 0
  1. ---- Ticket selling machine
  2. ---- Tickets are being sold as labeled floppys
  3. ---- and can be further used on station to get a train to a demanded destination
  4. -- os.pullEvent = os.pullEventRaw
  5. ---- Config
  6. -- Sides of components
  7. sides = {}
  8. sides[1] = "right" -- Monitor
  9. sides[2] = "back"  -- Checking the payment
  10. sides[3] = "top"   -- Sending the floppy
  11. sides[4] = "left"  -- Floppy side
  12. -- Filenames
  13. files = {}
  14. files[1] = "infopanel" -- Monitor text
  15. files[2] = "stations"  -- Station list
  16. -- Monitor on the right is being used as a information panel
  17. mon = peripheral.wrap(sides[1])
  18.  
  19. ---- Functions
  20. -- Writing on information panel
  21. function writeInfo()
  22.  monX, monY = mon.getSize()
  23.  mon.clear()
  24.  file = fs.open(files[1], "r")
  25.  x = file.readLine()
  26.  i = 1
  27.  while not (x == nil) do
  28.   if not(i > monY) then
  29.    mon.setCursorPos(1,i)
  30.    mon.write(x)
  31.    i = i+1
  32.   end
  33.   x = file.readLine()
  34.  end
  35.  file.close()
  36. end
  37. -- Get ticket
  38. function getTicket(station)
  39.  if not disk.isPresent(sides[4]) then
  40.   rs.setOutput(sides[3], true)
  41.   os.sleep(1)
  42.   rs.setOutput(sides[3], false)
  43.  elseif disk.getLabel(sides[4]) == "cmd:shutdown" then
  44.   shell.exit()
  45.  end
  46.  write("Wybrano stacje " .. station .. "\n")
  47.  disk.setLabel(sides[4], station)
  48.  disk.eject(sides[4])
  49. end
  50. -- Stations validate
  51. function validateInput(input)
  52.  if input == "cmd:shutdown" then
  53.   return true
  54.  end
  55.  file = fs.open(files[2], "r")
  56.  x = file.readLine()
  57.  input = string.lower(input)
  58.  while not (x == nil) do
  59.   if x == input then
  60.    return true
  61.   end
  62.   x = file.readLine()
  63.  end
  64.  return false
  65. end
  66.  
  67.  
  68. ---- Main program
  69. writeInfo()
  70. term.clear()
  71. term.setCursorPos(1,1)
  72. write("Prosze umiescic 1 sticky resin w skrzyni na dole\n")
  73. while true do
  74.  if rs.getInput(sides[2]) then
  75.   term.clear()
  76.   term.setCursorPos(1,1)
  77.   write("Prosze podac nazwe stacji docelowej:\n")
  78.   input = read()
  79.   while not validateInput(input) do
  80.    write("Prosze podac PRAWIDLOWA nazwe stacji docelowej!\n")
  81.    input = read()
  82.   end
  83.   getTicket(input)
  84.   write("Dziekujemy za skorzystanie z naszych uslug! Zapraszamy ponownie! \n")
  85.   write("Bilet powinien znajdowac sie w twoim ekwipunku!\n")
  86.   write("W przypadku, gdy Twoj ekwipunek jest pelny bilet znajduje sie na ziemi\n")
  87.   os.sleep(2)
  88.   term.clear()
  89.   term.setCursorPos(1,1)
  90.   write("Prosze umiescic 1 sticky resin w skrzyni na dole\n")
  91.  end
  92.  os.sleep(1)
  93. end
Advertisement
Add Comment
Please, Sign In to add comment