Advertisement
Guest User

startup.lua

a guest
Mar 6th, 2023
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.49 KB | None | 0 0
  1. --different possible groupings and their
  2. --corresponding greetings
  3. local groupings = {
  4.     {"kaibochan"},
  5.     {"kaibochan", "sethrl"},
  6.     {"sethrl"},
  7.     {"N0LIF3RRE3"},
  8.     {"kaibochan", "N0LIF3RRE3"},
  9.     {"N0LIF3RRE3", "sethrl"},
  10.     {"kaibochan", "N0LIF3RRE3", "sethrl"},
  11. }
  12.  
  13. local greetings = {
  14.     "Welcome back, Kai",
  15.     "Welcome, disciples",
  16.     "Hey cutie ;-)",
  17.     "ICEJJPICK!?",
  18.     "ADHD squad B-)",
  19.     "TWO CUTIES!?\nAT MY BASE!?",
  20.     "What's up CS squad",
  21. }
  22.  
  23. local settings = {
  24.     {
  25.         ["scale"] = 1,
  26.         ["textColor"] = colors.lime,
  27.         ["bgColor"] = colors.black,
  28.     },
  29.     {
  30.         ["scale"] = 1,
  31.         ["textColor"] = colors.yellow,
  32.         ["bgColor"] = colors.black,
  33.     },
  34.     {
  35.         ["scale"] = 2,
  36.         ["textColor"] = colors.pink,
  37.         ["bgColor"] = colors.black,  
  38.     },
  39.     {
  40.         ["scale"] = 2,
  41.         ["textColor"] = colors.black,
  42.         ["bgColor"] = colors.white,
  43.     },
  44.     {
  45.         ["scale"] = 2,
  46.         ["textColor"] = colors.red,
  47.         ["bgColor"] = colors.black,
  48.     },
  49.     {
  50.         ["scale"] = 1,
  51.         ["textColor"] = colors.red,
  52.         ["bgColor"] = colors.white,
  53.     },
  54.     {
  55.         ["scale"] = 1,
  56.         ["textColor"] = colors.lightBlue,
  57.         ["bgColor"] = colors.black,
  58.     },
  59. }
  60.  
  61. --default text displayed when no players
  62. local defaultText = "Biopunk"
  63.  
  64. local defaultSettings = {
  65.     ["scale"] = 2,
  66.     ["textColor"] = colors.lime,
  67.     ["bgColor"] = colors.black,
  68. }
  69.  
  70. function main()
  71.     --find peripherals
  72.     monitor = peripheral.find("monitor")
  73.     playerDetector = peripheral.find("playerDetector")
  74.    
  75.     --sort each grouping for easy comparison
  76.     for i, group in ipairs(groupings) do
  77.         table.sort(group)
  78.     end
  79.    
  80.     while true do
  81.         --only activate once every 1/8 of a second
  82.         sleep(1/8)
  83.        
  84.         monitor.clear()
  85.         monitor.setCursorPos(1, 1)
  86.        
  87.         --get a sorted list of nearby players
  88.         local players = playerDetector.getPlayersInCubic(2, 2, 2)
  89.         table.sort(players)
  90.        
  91.         --if no players nearby, display default
  92.         --text
  93.         if #players == 0 then
  94.             monitor.setTextScale(defaultSettings.scale)
  95.             monitor.setTextColor(defaultSettings.textColor)
  96.             monitor.setBackgroundColor(defaultSettings.bgColor)
  97.             monitor.write(defaultText)
  98.         else
  99.             local foundGroup
  100.            
  101.             --iterate through all different groups
  102.             for i, group in ipairs(groupings) do
  103.                 foundGroup = true
  104.                
  105.                 --iterate through names within the
  106.                 --current group, checking for a
  107.                 --match, then printing the
  108.                 --corresponding greeting
  109.                 if #players ==  #group then
  110.                     for j, name in ipairs(group) do
  111.                         if players[j] ~= name then
  112.                             foundGroup = false
  113.                         end
  114.                     end
  115.                 else
  116.                     foundGroup = false
  117.                 end
  118.                
  119.                 if foundGroup then
  120.                     monitor.setTextScale(settings[i].scale)
  121.                     monitor.setTextColor(settings[i].textColor)
  122.                     monitor.setBackgroundColor(settings[i].bgColor)
  123.                     monitor.write(greetings[i])
  124.                     break
  125.                 end
  126.             end
  127.         end
  128.     end
  129. end
  130.  
  131. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement