kamilosxd678

[MC-CC] Tickets validator

Sep 24th, 2012
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.30 KB | None | 0 0
  1. ---- Ticket validating machine
  2. ---- Tickets are being sold as labeled floppys
  3. ---- and are 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] = "bottom" -- Floppy
  9. sides[2] = "back"   -- Transposer
  10. sides[3] = "left"   -- Dispersers
  11. sides[4] = "right"  -- Rail management
  12. -- Rails' dispersers' colors
  13. rails = {}
  14. rails[1] = colors.white
  15. rails[2] = colors.orange
  16. rails[3] = colors.magenta
  17. rails[4] = colors.lightBlue
  18. rails[5] = colors.yellow
  19. rails[6] = colors.lime
  20. rails[7] = colors.pink
  21. rails[8] = colors.gray
  22. transColor = colors.lightGray
  23. platforms = {}
  24. platforms[1] = "I"
  25. platforms[2] = "II"
  26. platforms[3] = "II"
  27. platforms[4] = "III"
  28. platforms[5] = "III"
  29. platforms[6] = "IV"
  30. platforms[7] = "IV"
  31. platforms[8] = "V"
  32. ---- Functions
  33. -- Check ticket
  34. function checkTicket()
  35.  station = disk.getLabel(sides[1])
  36.  write("Wybrano stacje " .. station .. "\n")
  37.  process(station)
  38.  rs.setOutput(sides[2], true)
  39.  os.sleep(0.2)
  40.  rs.setOutput(sides[2], false)
  41. end
  42. -- Main processing function
  43. function process(station)
  44.  if station == "swiatynia" then
  45.   disperse(1)
  46.  elseif station == "wioska" then
  47.   disperse(2)
  48.   manageRails(station)
  49.  elseif station == "krater" then
  50.   disperse(2)
  51.   manageRails(station)
  52.  elseif station == "arena" then
  53.   disperse(7)
  54.  end
  55. end
  56. -- Disperser processing function
  57. function disperse(rail)
  58.  rs.setBundledOutput(sides[3], rails[rail])
  59.  os.sleep(0.2)
  60.  rs.setBundledOutput(sides[3], transColor)
  61.  write("Twoj wagon zostal podstawiony na tor nr " .. rail .. " przy peronie " .. platforms[rail] .. "\n")
  62. end
  63. -- Rail managing function
  64. function manageRails(station)
  65.  if station == "krater" then
  66.   rs.setBundledOutput(sides[4], colors.orange)
  67.   os.sleep(1)
  68.   rs.setBundledOutput(sides[4], colors.black)
  69.  end
  70.  if station == "wioska" then
  71.   rs.setBundledOutput(sides[4], colors.white)
  72.   os.sleep(1)
  73.   rs.setBundledOutput(sides[4], colors.black)
  74.  end
  75. end
  76. -- //BLANK
  77. -- //\BLANK
  78.  
  79.  
  80. ---- Main program
  81. term.clear()
  82. term.setCursorPos(1,1)
  83. write("Prosze umiescic bilet w stacji\n")
  84. while true do
  85.  if disk.isPresent(sides[1]) then
  86.   checkTicket()
  87.   os.sleep(3)
  88.   term.clear()
  89.   term.setCursorPos(1,1)
  90.   write("Prosze umiescic bilet w stacji\n")
  91.  end
  92.  os.sleep(1)
  93. end
Advertisement
Add Comment
Please, Sign In to add comment