GamearooCodes

Ped crossing hawk beacon

Jul 9th, 2024 (edited)
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.97 KB | None | 0 0
  1. local component = require("component");
  2. local traffic = component.traffic_light_card
  3. local os = require("os")
  4. local thread = require("thread")
  5.  
  6. local sides = require("sides")
  7. local computer = require("computer")
  8.  
  9. -- Warning this script contains bulbs from a custom edited version of traffic control to use this script fine Left2 and Right2 for yellows and remove the 2 from that and it will work
  10.  
  11. local colors = require("colors")
  12.  
  13. local rs = component.redstone
  14.  
  15.  
  16. function setBundledOutput(color, state)
  17.  
  18.  
  19.     rs.setBundledOutput(sides.back, {[color] = state})
  20.  
  21.  
  22.  
  23.   end
  24.  
  25.  
  26.   function getBundledoutput(color)
  27.  
  28.    return  rs.getBundledInput(sides.back, color);
  29.  
  30.   end
  31.  
  32. trafficLight = {}
  33. lightPOS = traffic.listBlockPos()
  34.  
  35. for i = 1, #lightPOS do
  36.   trafficLight[i] = lightPOS[i]
  37. end
  38.  
  39.  
  40.  
  41. function setLights(id,state,mode,forceClear)
  42.   -- F is the boolean for Flashing, S is the boolean for Steady/On
  43.   local f = false
  44.   local s = false
  45.  
  46.   --  Clear signal if flag to forceClear isn't set to false
  47.   if forceClear ~= false then
  48.     if (type(id) == "table") then
  49.       for itr = 1, #id do
  50.         traffic.clearStates(trafficLight[id[itr]][1],trafficLight[id[itr]][2],trafficLight[id[itr]][3])
  51.       end
  52.     elseif (type(id) == "string") then
  53.       traffic.clearStates(trafficLight[id][1],trafficLight[id][2],trafficLight[id][3])
  54.     end
  55.   end
  56.  
  57.   --  Determine mode
  58.   if mode ~= nil then
  59.     --    Flashing
  60.     if string.lower(mode) == "flash" then
  61.       s = true
  62.       f = true
  63.     --   Steady
  64.     elseif string.lower(mode) == "on" then
  65.       s = true
  66.       f = false
  67.       --    Off
  68.     else
  69.       s = false
  70.       f = false
  71.     end
  72.   else
  73.     s = false
  74.     f = false
  75.   end
  76.  
  77.   --  Apply to signal
  78.   if (type(id) == "table" and state ~= nil) then
  79.     for itr = 1, #id do
  80.       traffic.setState(trafficLight[id[itr]][1],trafficLight[id[itr]][2],trafficLight[id[itr]][3],state,s,f)
  81.     end
  82.  
  83.   elseif (type(id) == "string" and state ~= nil) then
  84.     traffic.setState(trafficLight[id][1],trafficLight[id][2],trafficLight[id][3],state,s,f)
  85.   end
  86. end
  87. -- key
  88. -- S Stright
  89. -- Y stright bulb
  90. -- T Turn Bulb
  91. -- L Left
  92. -- R Right
  93. -- Middle Frame
  94.  
  95.  
  96. -- north 1 LT, 2 YS , 3 YS , 4 RT
  97. -- south 5 LT, 6 YS, 7 YS , 8 RT
  98. -- east 9 L , 10 ML , 11 MR,12 R
  99. -- west 13 L, 14 R
  100.  
  101.  
  102.  
  103. local hawk = {1,2,3,4};
  104. local ped = {5,6}
  105.  
  106.  
  107. os.sleep(60)
  108. -- start script
  109.  
  110. setBundledOutput(colors.cyan, 200)
  111.  
  112. os.sleep(20)
  113.  
  114.  
  115. local loop2 = thread.create(function()
  116.  
  117.     while true do
  118.    
  119.     setLights(hawk, "Yellow", "flash")
  120.     os.sleep(4)
  121.     setLights(hawk, "Yellow", "on")
  122.     os.sleep(3)
  123.     setLights(hawk, "Red", "on")
  124.     os.sleep(1)
  125.     setLights(ped,"Cross", "on")
  126.     os.sleep(10)
  127.     setLights(hawk, "Red", "flash")
  128.     setLights(ped,"DontCross", "flash")
  129.     os.sleep(5)
  130.     setLights(ped,"DontCross", "on")
  131.     setLights(hawk, "Red", "off")
  132.     os.sleep(60)
  133.    
  134.      
  135.  
  136.     end
  137.  
  138.  
  139.   end)
  140.  
  141.  
  142.  
  143.  
  144.       thread.waitForAny({loop2})
  145.  
  146.  
  147.  
Advertisement
Add Comment
Please, Sign In to add comment