FairfaxGamingYT

Bike/Ped Hawk Beacon

Jul 10th, 2024
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.23 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.   setBundledOutput(colors.white, 200)
  33.  
  34. trafficLight = {}
  35. lightPOS = traffic.listBlockPos()
  36.  
  37. for i = 1, #lightPOS do
  38.   trafficLight[i] = lightPOS[i]
  39. end
  40.  
  41.  
  42.  
  43. function setLights(id,state,mode,forceClear)
  44.   -- F is the boolean for Flashing, S is the boolean for Steady/On
  45.   local f = false
  46.   local s = false
  47.  
  48.   --  Clear signal if flag to forceClear isn't set to false
  49.   if forceClear ~= false then
  50.     if (type(id) == "table") then
  51.       for itr = 1, #id do
  52.         traffic.clearStates(trafficLight[id[itr]][1],trafficLight[id[itr]][2],trafficLight[id[itr]][3])
  53.       end
  54.     elseif (type(id) == "string") then
  55.       traffic.clearStates(trafficLight[id][1],trafficLight[id][2],trafficLight[id][3])
  56.     end
  57.   end
  58.  
  59.   --  Determine mode
  60.   if mode ~= nil then
  61.     --    Flashing
  62.     if string.lower(mode) == "flash" then
  63.       s = true
  64.       f = true
  65.     --   Steady
  66.     elseif string.lower(mode) == "on" then
  67.       s = true
  68.       f = false
  69.       --    Off
  70.     else
  71.       s = false
  72.       f = false
  73.     end
  74.   else
  75.     s = false
  76.     f = false
  77.   end
  78.  
  79.   --  Apply to signal
  80.   if (type(id) == "table" and state ~= nil) then
  81.     for itr = 1, #id do
  82.       traffic.setState(trafficLight[id[itr]][1],trafficLight[id[itr]][2],trafficLight[id[itr]][3],state,s,f)
  83.     end
  84.  
  85.   elseif (type(id) == "string" and state ~= nil) then
  86.     traffic.setState(trafficLight[id][1],trafficLight[id][2],trafficLight[id][3],state,s,f)
  87.   end
  88. end
  89. -- key
  90. -- S Stright
  91. -- Y stright bulb
  92. -- T Turn Bulb
  93. -- L Left
  94. -- R Right
  95. -- Middle Frame
  96.  
  97.  
  98. -- north 1 LT, 2 YS , 3 YS , 4 RT
  99. -- south 5 LT, 6 YS, 7 YS , 8 RT
  100. -- east 9 L , 10 ML , 11 MR,12 R
  101. -- west 13 L, 14 R
  102.  
  103.  
  104.  local hawk = {1,2,3,4,5,6,}
  105.  local ped = {7,8}
  106.  local bike = {9,10}
  107.  
  108.  
  109. os.sleep(60)
  110. -- start script
  111.  
  112. setBundledOutput(colors.cyan, 200)
  113.  
  114. os.sleep(8)
  115.  
  116. local loop2 = thread.create(function()
  117.  
  118.     while true do
  119.      print("BP HAWK Beacon @ Sierra HWY (U.S. 6)")
  120. -- phase 1 sl&ss
  121. setLights(bike, "Red", "on") BIKE
  122. os.sleep(1)
  123. setLights(bike, "red", "off") BIKE
  124. os.sleep(35)
  125. setLights(hawk, "Yellow", "flashing") HAWK
  126. os.sleep(4)
  127. setLights(hawk, "Yellow", "on") HAWK
  128. os.sleep(3)
  129. setLights(hawk, "Red", "on") HAWK
  130. os.sleep(1)
  131. setLights(ped, "Cross", "on") PED
  132. os.sleep(5)
  133. setLights(bike, "Green", "on") BIKE
  134. os.sleep(12)
  135. setLights(ped, "DontCross", "flash")
  136. os.sleep(10)
  137. setLights(bike, "Yellow", "on")
  138. os.sleep(3)
  139. setLights(hawk, "Red", "flashing") HAWK
  140.      
  141.  
  142.      
  143.  
  144.     end
  145.  
  146.  
  147.   end)
  148.  
  149.  
  150.  
  151.  
  152.       thread.waitForAny({loop2})
  153.  
  154.  
  155.  
  156.  
Advertisement
Add Comment
Please, Sign In to add comment