Advertisement
Guest User

startup

a guest
Mar 31st, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.75 KB | None | 0 0
  1. rednet.open("bottom")
  2. local sensor = peripheral.wrap("back")
  3. local monitor = peripheral.wrap("top")
  4. monitor.setTextScale(0.5)
  5.  
  6. if rs.getInput("top") then
  7.   return
  8. end
  9.  
  10. rs.setOutput("front",false)
  11.  
  12. function getCartAt(x,y,z)
  13.   local carts = sensor.getMinecartIds()
  14.  
  15.   for num, id in pairs(carts) do
  16.     local cart
  17.     pcall(function() cart = sensor.getMinecartData(id) end)
  18.     if cart then
  19.       local pos = cart.position
  20.       if (math.abs(x - pos.x) < 1.0) and (math.abs(y - pos.y) < 1.0) and (math.abs(z - pos.z) < 1.0) then
  21.         return cart
  22.       end
  23.     end
  24.   end
  25.   return nil
  26. end
  27.  
  28. local cart = nil
  29.  
  30. os.startTimer(1)
  31.  
  32. while true do
  33.   local event, senderId, message = os.pullEvent()
  34.  
  35.   if event == "timer" then
  36.     monitor.clear()
  37.  
  38.     cart2 = getCartAt(1,1,-1)
  39.     if cart2 then
  40.       rs.setOutput("right",true)
  41.       os.sleep(0.5)
  42.       rs.setOutput("right",false)
  43.     end
  44.    
  45.     cart = getCartAt(1,1,1)
  46.     --if cart then
  47.       --print(cart.position.x..", "..cart.position.y..", "..cart.position.z)
  48.       --os.sleep(10000)
  49.     --end
  50.     if cart then
  51.       if cart.riddenBy then
  52.         local username = cart.riddenBy.username
  53.         local heldItem = cart.riddenBy.heldItem
  54.         local validTicket = false
  55.         local destination = "none"
  56.         local ticketid = "ID: ungueltig"
  57.         if heldItem then
  58.           if heldItem.printout then
  59.             local text = heldItem.printout.text
  60.             if text then
  61.               destination = text[1]
  62.               ticketid = text[2]
  63.               validTicket = true
  64.             end
  65.           end
  66.         end
  67.         if validTicket then
  68.           monitor.setCursorPos(1,1)
  69.           monitor.write("Gute Fahrt nach")
  70.           monitor.setCursorPos(1,2)
  71.           monitor.write(destination)
  72.           monitor.setCursorPos(1,3)
  73.           monitor.write(username..".")
  74.           monitor.setCursorPos(1,5)
  75.           monitor.write(ticketid)
  76.           print("abfahrt")
  77.           rednet.broadcast("abfahrt")
  78.           rs.setOutput("front",true)
  79.           os.sleep(3)
  80.           rs.setOutput("front",false)
  81.         else
  82.           monitor.setCursorPos(1,1)
  83.           monitor.write("Wilkommen")
  84.           monitor.setCursorPos(1,2)
  85.           monitor.write(username)
  86.           monitor.setCursorPos(1,4)
  87.           monitor.write("Die Fahrkarte")
  88.           monitor.setCursorPos(1,5)
  89.           monitor.write("vorzeigen bitte.")
  90.         end
  91.       end
  92.     else
  93.       rs.setOutput("left",true)
  94.       os.sleep(0.1)
  95.       rs.setOutput("left",false)
  96.     end
  97.  
  98.     os.startTimer(1)
  99.   end
  100.  
  101.   if event == "rednet_message" then
  102.     if message then
  103.       if message == "abfahrt" then
  104.         print("Wait 3 sec...")
  105.         os.sleep(3)
  106.       end
  107.     end
  108.   end
  109. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement