Advertisement
Guest User

startup

a guest
Oct 19th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.45 KB | None | 0 0
  1. mainId = 2
  2. stationName = "Oak"
  3. stationZone = 1
  4.  
  5. mon = peripheral.wrap("monitor_1")
  6. mag = peripheral.wrap("back")
  7. rfid = peripheral.wrap("top")
  8. rednet.open("right")
  9.  
  10. function midPrint(text,sety)
  11.   x,y = mon.getSize()
  12.   len = string.len(text)
  13.   setx = (x/2)-(len/2)+1
  14.   mon.setCursorPos(setx,sety)
  15.   mon.write(text)
  16. end
  17.  
  18. rfid.scan()
  19.  
  20. while true do
  21.   mon.clear()
  22.   midPrint("Station " .. stationName,2)
  23.   mag.setInsertCardLight(true)
  24.   event,data = os.pullEvent()
  25.   mag.setInsertCardLight(false)
  26.   if event == "mag_swipe" then
  27.     toSend = "2-" .. data .. "-" .. stationZone
  28.     print(toSend)
  29.     rednet.send(mainId,toSend)
  30.     sId, msg = rednet.receive()
  31.     if msg == "invalid" then
  32.       midPrint("Sortie Interdite",4)
  33.       os.sleep(3)
  34.     else
  35.       midPrint("A bientot",4)
  36.       redstone.setOutput("bottom",true)
  37.       os.sleep(5)
  38.       redstone.setOutput("bottom",false)
  39.     end
  40.     os.reboot()
  41.   elseif event == "rfid_scan_done" then
  42.     rfid.scan(3)
  43.   elseif event == "rfid_detected" then
  44.     if data ~= "top" then
  45.       toSend = "5-" .. data .. "-" .. stationZone
  46.       rednet.send(mainId,toSend)
  47.       sId, msg = rednet.receive()
  48.       if msg == "invalid" then
  49.         midPrint("Sortie interdite",4)
  50.         os.sleep(3)
  51.       else
  52.         midPrint("Au revoir " .. data,4)
  53.         redstone.setOutput("bottom",true)
  54.         os.sleep(5)
  55.         redstone.setOutput("bottom",false)
  56.       end
  57.     end
  58.     os.reboot()
  59.   end
  60. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement