FairfaxGamingYT

SPUI Interchange

Jul 25th, 2024
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.27 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.  -- first pase
  105.  local straight - {1,2,3,4}
  106.  --second pase
  107.  local onramp - {5,6}
  108.  --third pase
  109.  local exit - {7,8,9,10}
  110.  
  111.  
  112. os.sleep(60)
  113. -- start script
  114.  
  115. setBundledOutput(colors.cyan, 200)
  116.  
  117. os.sleep(8)
  118.  
  119. local loop2 = thread.create(function()
  120.  
  121.     while true do
  122.      print("SPUI @ _______")
  123. -- phase 1 sl&ss
  124. setLights (straight, "StraightGreen", "on")
  125. os.sleep (15)
  126. setLights (straight, "StraightYellow", "on")
  127. os.sleep (4)
  128. setLights (straight, "StraightRed", "on")
  129. os.sleep (2)
  130. setLights (onramp, "GreenArrowLeft", "on")
  131. os.sleep (15)
  132. setLights (onramp, "YellowArrowLeft", "on")
  133. os.sleep (3)
  134. setLights (onramp, "RedArrowLeft", "on")
  135. os.sleep (2)
  136. setLights (exit, "GreenArrowLeft", "on")
  137. os.sleep (15)
  138. setLights (exit, "YellowArrowLeft", "on")
  139. os.sleep (4)
  140. setLights (exit, "RedArrowLeft", "on")
  141.  
  142.  
  143.      
  144.  
  145.     end
  146.  
  147.  
  148.   end)
  149.  
  150.  
  151.  
  152.  
  153.       thread.waitForAny({loop2})
  154.  
  155.  
  156.  
Advertisement
Add Comment
Please, Sign In to add comment