Pandafuchs

printBahnhofMonitors

Sep 22nd, 2015
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.28 KB | None | 0 0
  1. trainWaitTime = 10
  2.  
  3. --Prints Texts on monitors and sets trains free
  4. function monitorPainting()
  5.     print("Monitorpainting wird gestartet....")
  6.     rednet.open("back")
  7.  
  8.     local monitors = nil
  9.     if os.getComputerLabel() == "Bahnhof1" then
  10.         monitors = {peripheral.wrap( "monitor_0" ),peripheral.wrap( "monitor_1" ),peripheral.wrap( "monitor_2" ),peripheral.wrap( "monitor_6" )}
  11.     elseif os.getComputerLabel() == "Bahnhof2" then
  12.         monitors = {peripheral.wrap( "monitor_3" ),peripheral.wrap( "monitor_4" ),peripheral.wrap( "monitor_7" ),peripheral.wrap( "monitor_8" )}
  13.     end
  14.    
  15.  
  16.            
  17.     local zugPlan = {}
  18.     myApi.executeTableFunction(monitors, "setTextScale",0.7)
  19.    
  20.     while true do
  21.         local senderId, message, protocol = rednet.receive()
  22.         local targets = textutils.unserialize(message)
  23.        
  24.         myApi.executeTableFunction(monitors, "clear")
  25.         myApi.executeTableFunction(monitors, "setTextColor", colors.white)
  26.         myApi.executeTableFunction(monitors, "setCursorPos", 1, 1)
  27.         myApi.executeTableFunction(monitors, "write", "Zug     Gleis     Ziel           ETA   Abfahrt")
  28.  
  29.         local zeile = 2
  30.         local nextZug = ""
  31.         for k, v in pairs( targets ) do
  32.             local gleis = myApi.getGleisFromPosX(v["Position"])
  33.             if string.find(k, "Locomotive") and (gleis ~= "?") then
  34.                 if zugPlan[k] == nil then
  35.                     zugPlan[k] = os.clock()
  36.                 end
  37.                
  38.                 if os.clock()-zugPlan[k] > trainWaitTime then
  39.                     if nextZug == "" or (os.clock()-zugPlan[nextZug]) < (os.clock()-zugPlan[k]) then
  40.                         nextZug = k
  41.                     end
  42.                 end
  43.                
  44.                 local ankunft = 0
  45.        
  46.                 if zugPlan[k] ~= nil then
  47.                     ankunft = (trainWaitTime - (os.clock()-zugPlan[k]))
  48.                     if ankunft < 0 then
  49.                         ankunft = 0
  50.                     end
  51.                 end
  52.                 myApi.executeTableFunction(monitors, "setCursorPos", 1, zeile)
  53.                 myApi.executeTableFunction(monitors, "write", myApi.fillMyString(v["RouteDestination"],5) .. "    " .. gleis .. "       Ölplattform    0min  ".. math.floor(ankunft) .."sek" )
  54.                
  55.                 if (trainWaitTime - (os.clock()-zugPlan[k])) < -1 then
  56.                     myApi.executeTableFunction(monitors, "setTextColor", colors.red)
  57.                     myApi.executeTableFunction(monitors, "write", " +" .. math.floor(math.abs(trainWaitTime - (os.clock()-zugPlan[k])) ) )
  58.                     myApi.executeTableFunction(monitors, "setTextColor", colors.white)
  59.                 end
  60.                
  61.                 zeile = zeile + 1
  62.            
  63.             end
  64.         end
  65.        
  66.         if nextZug ~= "" and colors.test(redstone.getBundledInput("bottom"), colors.lightGray) and (not colors.test(redstone.getBundledInput("bottom"), colors.red) ) then
  67.             if myApi.getGleisFromPosX( targets[nextZug]["Position"] ) == 1 then
  68.                 redstone.setBundledOutput("bottom", colors.white)
  69.             elseif myApi.getGleisFromPosX( targets[nextZug]["Position"] ) == 2 then
  70.                 redstone.setBundledOutput("bottom", colors.yellow)
  71.             elseif myApi.getGleisFromPosX( targets[nextZug]["Position"] ) == 3 then
  72.                 redstone.setBundledOutput("bottom", colors.lime)
  73.             elseif myApi.getGleisFromPosX( targets[nextZug]["Position"]) == 4 then
  74.                 redstone.setBundledOutput("bottom", colors.pink)
  75.             elseif myApi.getGleisFromPosX( targets[nextZug]["Position"] ) == 5 then
  76.                 redstone.setBundledOutput("bottom", colors.cyan)
  77.             end
  78.  
  79.             zugPlan[nextZug] = nil
  80.             nextZug = ""
  81.  
  82.             sleep(3)
  83.             redstone.setBundledOutput("bottom", 0)
  84.         else
  85.             sleep(0.5)
  86.             redstone.setBundledOutput("bottom", 0)
  87.         end
  88.  
  89.     end
  90. end
Advertisement
Add Comment
Please, Sign In to add comment