GamearooCodes

Trafficlightadvanced

Dec 26th, 2024
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.56 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. leftturns = {1,2,3,4}
  104. strights = {5,6,7,8}
  105. nsright = {9,10}
  106. sright = {9}
  107. nright = {10}
  108.  
  109.  
  110. wm = {11}
  111. wl = {12}
  112. wr = {13}
  113.  
  114. el = {14}
  115. eml = {15}
  116. emr = {16}
  117. em = {15,16}
  118. er ={17}
  119.  
  120.  
  121.  
  122. os.sleep(60)
  123. -- start script
  124.  
  125. setBundledOutput(colors.cyan, 200)
  126.  
  127. os.sleep(8)
  128.  
  129. local loop2 = thread.create(function()
  130.  
  131. while true do
  132. print("Triffic light us18 Dirt Road")
  133. -- phase 1 sl&ss
  134. setLights(leftturns, "GreenArrowLeft", "on")
  135. os.sleep(12)
  136. setLights(leftturns, "YellowArrowLeft", "on")
  137. os.sleep(3)
  138. setLights(leftturns, "RedArrowLeft", "on")
  139. os.sleep(1)
  140. setLights(strights, "StraightGreen", "on")
  141. setLights(nsright, "YellowArrowRight", "flash")
  142. os.sleep(30)
  143. setLights(strights, "StraightYellow", "on")
  144. setLights(sright, "YellowArrowRight", "on")
  145. os.sleep(3)
  146. setLights(strights, "StraightRed", "on")
  147. setLights(sright, "RedArrowLeft", "on")
  148. os.sleep(1)
  149. setLights(wl, "GreenArrowLeft", "on")
  150. setLights(wm, "Green", "on")
  151. setLights(wm, "GreenArrowLeft", "on", false)
  152. setLights(wr, "Green", "on")
  153. setLights(nright, "GreenArrowRight", "on")
  154. os.sleep(20)
  155. setLights(wl, "YellowArrowLeft", "on")
  156. setLights(wm, "Yellow", "on")
  157. setLights(wr, "Yellow", "on")
  158. setLights(nright, "YellowArrowRight", "on")
  159. os.sleep(3)
  160. setLights(wl, "Red", "on")
  161. setLights(wm, "Red", "on")
  162. setLights(wr, "Red", "on")
  163. setLights(nright, "RedArrowRight", "on")
  164. os.sleep(1)
  165. setLights(el, "GreenArrowLeft", "on")
  166. setLights(em, "Green", "on")
  167. setLights(eml, "GreenArrowLeft", "on", false)
  168. setLights(emr, "GreenArrowRight", "on", false)
  169. setLights(er, "GreenArrowRight", "on")
  170. setLights(sright, "GreenArrowRight", "on")
  171. os.sleep(20)
  172. setLights(el, "YellowArrowLeft", "on")
  173. setLights(em, "Yellow", "on")
  174. setLights(er, "YellowArrowRight", "on")
  175. setLights(sright, "YellowArrowRight", "on")
  176. os.sleep(3)
  177. setLights(el, "Red", "on")
  178. setLights(em, "Red", "on")
  179. setLights(er, "Red", "on")
  180. setLights(sright, "RedArrowRight", "on")
  181. os.sleep(1)
  182.  
  183.  
  184.  
  185.  
  186.  
  187. end
  188.  
  189.  
  190. end)
  191.  
  192.  
  193.  
  194.  
  195. thread.waitForAny({loop2})
  196.  
  197.  
Advertisement
Add Comment
Please, Sign In to add comment