Advertisement
Guest User

startup

a guest
Mar 31st, 2015
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.60 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",true)
  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.     cart = getCartAt(-1,1,1)
  39.     --if cart then
  40.       --print(cart.position.x..", "..cart.position.y..", "..cart.position.z)
  41.       --os.sleep(10000)
  42.     --end
  43.     if cart then
  44.       if cart.riddenBy then
  45.         local username = cart.riddenBy.username
  46.         local heldItem = cart.riddenBy.heldItem
  47.         local validTicket = false
  48.         local destination = "none"
  49.         local ticketid = "ID: ungueltig"
  50.         if heldItem then
  51.           if heldItem.printout then
  52.             local text = heldItem.printout.text
  53.             if text then
  54.               destination = text[1]
  55.               ticketid = text[2]
  56.               validTicket = true
  57.             end
  58.           end
  59.         end
  60.         if validTicket then
  61.           monitor.setCursorPos(1,1)
  62.           monitor.write("Gute Fahrt nach")
  63.           monitor.setCursorPos(1,2)
  64.           monitor.write(destination)
  65.           monitor.setCursorPos(1,3)
  66.           monitor.write(username..".")
  67.           monitor.setCursorPos(1,5)
  68.           monitor.write(ticketid)
  69.           print("abfahrt")
  70.           rednet.broadcast("abfahrt")
  71.           rs.setOutput("front",false)
  72.           os.sleep(3)
  73.           rs.setOutput("front",true)
  74.         else
  75.           monitor.setCursorPos(1,1)
  76.           monitor.write("Wilkommen")
  77.           monitor.setCursorPos(1,2)
  78.           monitor.write(username)
  79.           monitor.setCursorPos(1,4)
  80.           monitor.write("Die Fahrkarte")
  81.           monitor.setCursorPos(1,5)
  82.           monitor.write("vorzeigen bitte.")
  83.         end
  84.       end
  85.     else
  86.       rs.setOutput("left",true)
  87.       os.sleep(0.1)
  88.       rs.setOutput("left",false)
  89.     end
  90.  
  91.     os.startTimer(1)
  92.   end
  93.  
  94.   if event == "rednet_message" then
  95.     if message then
  96.       if message == "abfahrt" then
  97.         print("Wait 3 sec...")
  98.         os.sleep(3)
  99.       end
  100.     end
  101.   end
  102. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement