FairfaxGamingYT

HAWK Fire Signal Beacon

Jul 10th, 2024
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.56 KB | None | 0 0
  1. local component = require("component");
  2.  
  3. local traffic = component.traffic_light_card;
  4. local os = require("os")
  5. local term = require("term")
  6.  
  7. local thread = require("thread")
  8.  
  9. -- local m = component.modem -- get primary modem component
  10. local sides = require("sides")
  11. local computer = require("computer")
  12.  
  13. local colors = require("colors")
  14. -- m.broadcast(455, "on")
  15. os.sleep(1)
  16.  
  17. trafficLight = {}
  18. lightPOS = traffic.listBlockPos()
  19.  
  20. for i = 1, #lightPOS do
  21.   trafficLight[i] = lightPOS[i]
  22. end
  23.  
  24. function setLights(id,state,mode,forceClear)
  25.   -- F is the boolean for Flashing, S is the boolean for Steady/On
  26.   local f = false
  27.   local s = false
  28.  
  29.   --  Clear signal if flag to forceClear isn't set to false
  30.   if forceClear ~= false then
  31.     if (type(id) == "table") then
  32.       for itr = 1, #id do
  33.         traffic.clearStates(trafficLight[id[itr]][1],trafficLight[id[itr]][2],trafficLight[id[itr]][3])
  34.       end
  35.     elseif (type(id) == "string") then
  36.       traffic.clearStates(trafficLight[id][1],trafficLight[id][2],trafficLight[id][3])
  37.     end
  38.   end
  39.  
  40.   --  Determine mode
  41.   if mode ~= nil then
  42.     --    Flashing
  43.     if string.lower(mode) == "flashing" then
  44.       s = true
  45.       f = true
  46.     --   Steady
  47.     elseif string.lower(mode) == "on" then
  48.       s = true
  49.       f = false
  50.       --    Off
  51.     else
  52.       s = false
  53.       f = false
  54.     end
  55.   else
  56.     s = false
  57.     f = false
  58.   end
  59.  
  60.   --  Apply to signal
  61.   if (type(id) == "table" and state ~= nil) then
  62.     for itr = 1, #id do
  63.       traffic.setState(trafficLight[id[itr]][1],trafficLight[id[itr]][2],trafficLight[id[itr]][3],state,s,f)
  64.     end
  65.  
  66.   elseif (type(id) == "string" and state ~= nil) then
  67.     traffic.setState(trafficLight[id][1],trafficLight[id][2],trafficLight[id][3],state,s,f)
  68.   end
  69. end
  70.  
  71.  
  72.  
  73.  
  74. term.clear()
  75. -- print("Traffic lights are starting! Lights are in flash mode")
  76. -- m.broadcast(455, colors.red, 200, sides.back)
  77. -- os.sleep(60);
  78. -- term.clear()
  79. -- print("Traffic lights are starting all lights are red!")
  80. -- m.broadcast(455, colors.green, 200, sides.back)
  81. -- os.sleep(1)
  82. -- m.broadcast(455, colors.green, 0, sides.back)
  83.  
  84. -- os.sleep(8)
  85.  
  86.  
  87.  
  88. function sleep(n)
  89.     os.sleep(n)
  90.   end
  91. console = "East Left"
  92.   time = os.date("*t")
  93.   cycledtime = time.hour .. ":" .. time.min
  94. local loop1 = thread.create(function()
  95.     while true  do
  96.    
  97.       time2 = os.date("*t")
  98.       term.clear()
  99.       print("Time Cycled: " .. cycledtime)
  100.       print("Current Time: " .. time2.hour .. ":" .. time2.min)
  101.       print("energy:" .. computer.energy())
  102.     --   if(computer.energy() <= 1489) then
  103.     --     m.broadcast(123, 1,1,1 , "OFF")
  104.     --     sleep(1)
  105.     --     computer.shutdown(false)
  106.     --   end
  107.     sleep(1)
  108.     end
  109.   end)
  110.  
  111. --   function setBundledOutput(color, state)
  112. --     m.broadcast(123, color, state, sides.back)
  113.  
  114. --   end
  115.  
  116.   HAWK = {1,2,3,4,5,6,7,8,9}
  117.   Fire = {10,11,12,12}
  118.   Warning = {13,14}
  119.  
  120.   local loop2 = thread.create(function()
  121.     while true do
  122.  
  123.        
  124.        
  125.        
  126.         setLights(HAWK, "Yellow", "flashing")
  127.         os.sleep(5)
  128.         setLights(Warning, "Yellow", "flashing")
  129.         setLights(HAWK, "Yellow", "on")
  130.         os.sleep(3)
  131.         setLights(HAWK, "Red", "on")
  132.         setLights(Fire, "Green", "on")
  133.         os.sleep(10)
  134.         setLights(Fire, "Yellow", "on")
  135.         os.sleep(3)
  136.         setLights(Fire, "Yellow", "flashing")
  137.         setLights(HAWK, "Red", "flashing")
  138.         os.sleep(10)
  139.         setLights(Warning, "Yellow", "off")
  140.    
  141.        
  142.  
  143.  
  144.  
  145.     end
  146.  
  147.   end)
  148.   thread.waitForAny({loop2})
  149.  
Advertisement
Add Comment
Please, Sign In to add comment