Advertisement
tmkop

gameshow

May 19th, 2025 (edited)
414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.00 KB | None | 0 0
  1. local chestStorage = "minecraft:chest_44"
  2. local roundTime = 15
  3.  
  4. local RED = 0xCE3232
  5. local LIGHT_BLUE = 0x6EA5F0
  6. local CYAN = 0x406CAB
  7. local BLUE = 0x1E385D
  8. local LIGHT_GRAY = 0x487EC9
  9. local GRAY = 0x6099EA
  10.  
  11.  
  12. local all_food_file = fs.open("/cooking/allFoods.dat","r")
  13. local all_foods_raw = all_food_file.readAll()
  14. local all_foods = {}
  15. local made_foods = {}
  16. local made_names = {}
  17. for line in all_foods_raw:gmatch("[^\r\n]+") do table.insert(all_foods,line) end
  18. all_food_file.close()
  19.  
  20. local stations_file = fs.open("/cooking/stations.dat","r")
  21. local stations_data = stations_file.readAll()
  22. local stations = textutils.unserialize(stations_data)
  23. stations_file.close()
  24.  
  25. for i,s in pairs(stations) do
  26.     local mp = peripheral.wrap(s.monitor)
  27.     mp.setPaletteColor(colors.red,RED)
  28.     mp.setPaletteColor(colors.lightBlue,LIGHT_BLUE)
  29.     mp.setPaletteColor(colors.blue,BLUE)
  30.     mp.setPaletteColor(colors.cyan,CYAN)
  31.     mp.setPaletteColor(colors.gray,GRAY)
  32.     mp.setPaletteColor(colors.lightGray,LIGHT_GRAY)
  33. end
  34.  
  35. function fillBottom(m_p,color,i)
  36.     stations[i].bottom_c = color
  37.     local old_c = m_p.getBackgroundColor()
  38.     m_p.setBackgroundColor(color)
  39.     m_p.setCursorPos(1,8)
  40.     m_p.write(string.rep(" ",8))
  41.     m_p.setCursorPos(13,8)
  42.     m_p.write(string.rep(" ",8))
  43.     m_p.setBackgroundColor(old_c)
  44. end
  45.  
  46. function setTime(m_p,seconds,i)
  47.     local old_bgc = m_p.getBackgroundColor()
  48.     m_p.setBackgroundColor(stations[i].bottom_c)
  49.     local s = math.max(0,seconds)
  50.     m_p.setCursorPos(9,8)
  51.     if s < 10 then
  52.         m_p.write(string.format("%04.2f", s))
  53.     else
  54.         m_p.write(string.format("%04.1f", s))
  55.     end
  56.     m_p.setBackgroundColor(old_bgc)
  57. end
  58.  
  59. function setFoods(m_p,foods)
  60.     m_p.setCursorPos(17,2)
  61.     m_p.write(string.format("%03d", math.floor(foods)))
  62. end
  63.  
  64. function setPlayersRemaining(m_p,people)
  65.     m_p.setCursorPos(2,2)
  66.     m_p.write(string.format("%02d", math.floor(people)))
  67. end
  68.  
  69. for i,s in pairs(stations) do
  70.     local m = s.monitor
  71.     local mp = peripheral.wrap(m)
  72.    
  73.     mp.setBackgroundColor(colors.lightBlue)
  74.     mp.setTextColor(colors.black)
  75.     mp.clear()
  76.     mp.setTextScale(1.5)
  77.    
  78.     mp.setCursorPos(1,1)
  79.     mp.setBackgroundColor(colors.white)
  80.     mp.clearLine()
  81.     mp.write("       Chef "..i)
  82.     mp.setBackgroundColor(colors.lightBlue)
  83.     mp.setCursorPos(1,2)
  84.     mp.write(string.char(2)..string.format("%02d", #stations).."/"..string.format("%02d",#stations))
  85.     mp.setCursorPos(14,2)
  86.     mp.write("FDs")
  87.    
  88.    
  89.     mp.setCursorPos(7,4)
  90.     mp.setBackgroundColor(colors.red)
  91.     mp.clearLine()
  92.     mp.write("NOT READY")
  93.     mp.setBackgroundColor(colors.lightBlue)
  94.  
  95.     stations[i].ready = false
  96.     stations[i].alive = true
  97.     stations[i].primed = false
  98.     stations[i].bottom_c = colors.lightBlue
  99.    
  100.     setPlayersRemaining(mp,#stations)
  101.     setFoods(mp,0)
  102.     fillBottom(mp,colors.yellow,i)
  103.     setTime(mp,roundTime,i)
  104. end
  105.  
  106. function anyUnready()
  107.     local allReady = true
  108.     for i,s in pairs(stations) do
  109.         if (not s.ready) then
  110.             allReady = false
  111.         end
  112.     end
  113.     return not allReady
  114. end
  115.  
  116. for i,s in pairs(stations) do
  117.     local mp = peripheral.wrap(s.monitor)
  118.     mp.setBackgroundColor(colors.red)
  119.     mp.setCursorPos(17,1)
  120.     mp.write("RMV")
  121.     mp.setBackgroundColor(colors.lightBlue)
  122. end
  123.  
  124. while anyUnready() do
  125.     local event, side, x, y = os.pullEvent("monitor_touch")
  126.  
  127.     for i,s in pairs(stations) do
  128.         local mp = peripheral.wrap(s.monitor)
  129.        
  130.         if s.monitor == side then
  131.             if x > 11 and y == 1 then
  132.                 mp.setBackgroundColor(colors.black)
  133.                 mp.clear()
  134.                 stations[i] = nil
  135.                 s.ready = false
  136.                 s.alive = false
  137.             else
  138.                 s.ready = true
  139.             end
  140.         end
  141.        
  142.         if s.ready then
  143.             mp.setCursorPos(8,4)
  144.             mp.clearLine()
  145.             mp.setTextColor(colors.green)
  146.             mp.write("READY!")
  147.             mp.setTextColor(colors.black)
  148.             fillBottom(mp,colors.green,i)
  149.             setTime(mp,roundTime,i)
  150.         end
  151.     end
  152. end
  153.  
  154. function getAmountAlive()
  155.     local num_alive = 0
  156.     for i,s in pairs(stations) do
  157.         if s.alive then
  158.             num_alive = num_alive + 1
  159.         end
  160.     end
  161.     return num_alive
  162. end
  163.  
  164. for i,s in pairs(stations) do
  165.     local mp = peripheral.wrap(s.monitor)
  166.     mp.setCursorPos(1,4)
  167.     mp.clearLine()
  168.     mp.setCursorPos(17,1)
  169.     mp.setBackgroundColor(colors.white)
  170.     mp.write("   ")
  171.     mp.setBackgroundColor(colors.lightBlue)
  172.     setPlayersRemaining(mp,getAmountAlive())
  173.     mp.setCursorPos(6,2)
  174.     mp.write(getAmountAlive())
  175. end
  176.  
  177.  
  178. function contains(table,E)
  179.     for _,e in pairs(table) do if e == E then return true end end
  180.     return false
  181. end
  182.  
  183. function kill(i)
  184.     local s = stations[i]
  185.     s.alive = false
  186.     local mp = peripheral.wrap(s.monitor)
  187.    
  188.     fillBottom(mp,colors.red,i)
  189.     setTime(mp,0,i)
  190.    
  191.     mp.setCursorPos(1,3)
  192.     mp.clearLine()
  193.     mp.setCursorPos(1,4)
  194.     mp.clearLine()
  195.     mp.setCursorPos(1,5)
  196.     mp.clearLine()
  197.     mp.setCursorPos(1,6)
  198.     mp.clearLine()
  199.     mp.setCursorPos(1,7)
  200.     mp.clearLine()
  201. end
  202.  
  203. function center_text(t, width)
  204.     local text = t
  205.     if not t then text = "" end
  206.     local padding = math.floor((width - #text) / 2)
  207.     return string.rep(" ", padding) .. text .. string.rep(" ", padding+1)
  208. end
  209.  
  210.  
  211. local t1 = os.epoch("utc")/1000
  212.  
  213. while getAmountAlive() > 1 do
  214.     local t2 = os.epoch("utc")/1000
  215.     for i,s in pairs(stations) do
  216.         local mp = peripheral.wrap(s.monitor)
  217.         setFoods(mp,#made_foods)
  218.        
  219.         if s.alive then
  220.  
  221.             if s.primed then
  222.                 fillBottom(mp,colors.green,i)
  223.                 setTime(mp,roundTime+t1-t2,i)
  224.             else
  225.                 fillBottom(mp,colors.yellow,i)
  226.                 setTime(mp,roundTime+t1-t2,i)
  227.             end
  228.             setPlayersRemaining(mp,getAmountAlive())
  229.             local bp = peripheral.wrap(s.barrel)
  230.             local submission = bp.getItemDetail(1)
  231.                
  232.             local fd5 = made_names[#made_names-4]
  233.             local fd4 = made_names[#made_names-3]
  234.             local fd3 = made_names[#made_names-2]
  235.             local fd2 = made_names[#made_names-1]
  236.             local fd1 = made_names[#made_names]
  237.                                              
  238.             mp.setCursorPos(1,3)
  239.             mp.setTextColor(colors.gray)
  240.             mp.write(center_text(fd5,19))
  241.            
  242.             mp.setCursorPos(1,4)
  243.             mp.setTextColor(colors.lightGray)
  244.             mp.write(center_text(fd4,19))
  245.            
  246.             mp.setCursorPos(1,5)
  247.             mp.setTextColor(colors.cyan)
  248.             mp.write(center_text(fd3,19))
  249.            
  250.             mp.setCursorPos(1,6)
  251.             mp.setTextColor(colors.blue)
  252.             mp.write(center_text(fd2,19))
  253.            
  254.             mp.setCursorPos(1,7)
  255.             mp.setTextColor(colors.black)
  256.             mp.write(center_text(fd1,19))
  257.            
  258.             mp.setTextColor(colors.black)
  259.            
  260.             if submission then
  261.                 local sub_name = submission.name
  262.                 if contains(all_foods,sub_name) then
  263.                     if contains(made_foods,sub_name) then
  264.                         kill(i)
  265.                     else
  266.                         made_foods[#made_foods+1] = sub_name
  267.                        made_names[#made_names+1] = submission.displayName
  268.                         bp.pushItems(chestStorage, 1)
  269.                         s.primed = true
  270.                         fillBottom(mp,colors.green,i)
  271.                     end
  272.                 end
  273.             end
  274.         else
  275.             setTime(mp,0,i)
  276.         end
  277.     end
  278.     if roundTime+t1-t2 < 0 then
  279.         t1 = os.epoch("utc")/1000
  280.         for i,s in pairs(stations) do
  281.             if s.alive and not s.primed then
  282.                 kill(i)
  283.             else
  284.                 s.primed = false
  285.                 local mp = peripheral.wrap(s.monitor)
  286.                 fillBottom(mp,colors.white,i)
  287.             end
  288.         end
  289.     end
  290.     sleep(0)  
  291. end
  292.  
  293.  
  294. print("EOF")
  295.  
  296.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement