Advertisement
EnterYourName

CCWelcome

Oct 14th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.29 KB | None | 0 0
  1. -- CCWelcome
  2. os.loadAPI("ocs/apis/sensor")
  3.  
  4. local worldsensor = sensor.wrap("left")
  5. local proximitysensor = sensor.wrap("right")
  6. local monitor = peripheral.wrap("top")
  7.  
  8. function printf(object)
  9.  
  10.     print(textutils.serialize(object))
  11.  
  12. end
  13.  
  14. local replaceNames = {
  15.     ["Qwertiiiiiii"] = "Nina",
  16.     ["zamunda63"] = "Dennis",
  17.     ["leLucy"] = "lucy",
  18.     ["Schokimann"] = "Paul",
  19. }
  20.  
  21. function clearLine()
  22.     local w,_ = monitor.getSize()
  23.     local x,y = monitor.getCursorPos()
  24.  
  25.     local toFill = ""
  26.  
  27.     for i=2,w-2 do
  28.  
  29.         toFill = toFill.." "
  30.  
  31.     end
  32.  
  33.     monitor.setCursorPos(2,y)
  34.     monitor.write(toFill)
  35.  
  36.     monitor.setCursorPos(x,y)
  37. end
  38.  
  39. function printPlayerLine(targetName, target)
  40.  
  41.  
  42.     local type = target.Name
  43.  
  44.     if type == "Player" then
  45.  
  46.         local name = targetName
  47.  
  48.         local nameToGreet
  49.  
  50.         if replaceNames[name] ~= nil then
  51.             nameToGreet = replaceNames[name]
  52.         else
  53.             nameToGreet = name
  54.         end
  55.  
  56.  
  57.         if name == "Qwertiiiiiii" then
  58.             monitor.write("Welcome home, ")
  59.             monitor.setTextColor(colors.yellow)
  60.             monitor.write(nameToGreet)
  61.         else
  62.             monitor.write("Welcome, ")
  63.             monitor.setTextColor(colors.yellow)
  64.             monitor.write(nameToGreet)
  65.  
  66.         end
  67.  
  68.         monitor.setTextColor(colors.white)
  69.  
  70.     end
  71.  
  72. end
  73.  
  74. local lastLine = 0
  75. monitor.clear()
  76.  
  77. local w,h = monitor.getSize()
  78.  
  79. monitor.setBackgroundColor(colors.lightBlue)
  80.  
  81. for i=1,h+1 do
  82.  
  83.     if i == 1 or i == h+1 then
  84.  
  85.         monitor.clearLine()
  86.  
  87.     else
  88.  
  89.         monitor.setCursorPos(1,i)
  90.         monitor.write(" ")
  91.         monitor.setCursorPos(w,i)
  92.         monitor.write(" ")
  93.  
  94.     end
  95.  
  96. end
  97.  
  98. monitor.setBackgroundColor(colors.black)
  99.  
  100. function preparePrintM(line)
  101.     monitor.setCursorPos(3,line)
  102.     clearLine()
  103. end
  104.  
  105. function getTime()
  106.  
  107.     local time = os.time()
  108.     return textutils.formatTime(time, false)
  109.  
  110. end
  111.  
  112. function printEnv()
  113.  
  114.     local line = h-3
  115.     local environment = worldsensor.getTargetDetails("CURRENT")
  116.  
  117.     preparePrintM(line)
  118.  
  119.  
  120.     if environment.Daytime then
  121.         monitor.setTextColor(colors.yellow)
  122.         monitor.write("Today ")
  123.     else
  124.         monitor.setTextColor(colors.gray)
  125.         monitor.write("Tonight ")
  126.     end
  127.  
  128.     monitor.setTextColor(colors.white)
  129.  
  130.     if environment.Thundering then
  131.  
  132.         monitor.write("is a stormy ")
  133.  
  134.     elseif environment.Raining then
  135.  
  136.         monitor.write("is a rainy ")
  137.  
  138.     else
  139.  
  140.         if time == "day" then
  141.  
  142.             monitor.write("is a sunny ")
  143.  
  144.         else
  145.  
  146.             monitor.write("is a clear ")
  147.  
  148.         end
  149.  
  150.     end
  151.  
  152.     if environment.Daytime then
  153.         monitor.write("day")
  154.     else
  155.         monitor.write("night")
  156.     end
  157.  
  158.     line = line+1
  159.     preparePrintM(line)
  160.  
  161.     monitor.write("It's "..getTime())
  162.  
  163. end
  164.  
  165. while true do
  166.  
  167.     local proxtargets = proximitysensor.getTargets()
  168.  
  169.     local line = 3
  170.  
  171.     for k,v in pairs(proxtargets) do
  172.  
  173.         preparePrintM(line)
  174.         printPlayerLine(k,v)
  175.         line = line + 1
  176.  
  177.     end
  178.  
  179.     while line < lastLine do
  180.  
  181.         monitor.setCursorPos(1,line)
  182.         clearLine()
  183.         line = line + 1
  184.  
  185.     end
  186.  
  187.     lastLine = line
  188.  
  189.     printEnv()
  190.  
  191.     sleep(1)
  192.  
  193. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement