Advertisement
Wyvern67

Computercraft Door

Jun 11th, 2018
1,642
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.75 KB | None | 0 0
  1. os.loadAPI("redstone")
  2.  
  3.  
  4. local mon = peripheral.wrap("monitor_2")
  5. if not mon then
  6.     mon = term
  7. end
  8.  
  9. pri = peripheral.wrap("printer_0")
  10. if not pri then
  11.     insult = nil
  12. end
  13.  
  14. local tArgs = { ... }
  15. local opt = getOpt(tArgs)
  16. if #tArgs == 0 then
  17.     opt.b = true
  18.     opt.w = false
  19.     opt.l = true
  20. end
  21.  
  22. local function printUsage()
  23.     print( "Usage:" )
  24. end
  25.  
  26. function timestamp()
  27.     file=http.get("http://wyvern67.free.fr/Minecraft/scripts/time.php")
  28.     if not file then print("Url invalide") return false end
  29.     sTime = file.readLine(1)
  30.     file.close()
  31.     return sTime
  32. end
  33.  
  34. function getOpt(tArgs)
  35.     local function isOption(text)
  36.         --if text starts with a dash like "-something" consider it an option
  37.         if (text == nil) or (string.sub(text, 0, 1) == "-") then
  38.             return true
  39.         else
  40.             return false
  41.         end
  42.     end
  43.     local opt = {}
  44.     local i = 1
  45.     while i <= #tArgs do
  46.         if isOption(tArgs[i]) then
  47.             if isOption(tArgs[i+1]) then
  48.                 --if no argument (no next arg or it's an option too)
  49.                 --interpret like options.something = true
  50.                 opt[string.sub(tArgs[i], 2)] = true
  51.             else
  52.                 --interpret like options.something = value
  53.                 opt[string.sub(tArgs[i], 2)] = tArgs[i+1]
  54.                 i = i+1 --skip the next arg, it was the argument for -something
  55.             end
  56.         else
  57.             --if not an option
  58.             --aka a random arg, do options[number] = argument
  59.             table.insert(opt, tArgs[i])
  60.         end
  61.  
  62.         i = i+1
  63.     end
  64.     return opt
  65. end
  66.  
  67. function table.search(t, value)
  68.     for i,v in pairs(t) do
  69.         if v == value then
  70.             return i
  71.         end
  72.     end
  73.     return false
  74. end
  75.  
  76. local whitelist = {
  77.     "Wyvern67",
  78.     "uncle_pete",
  79.     "herbzah",
  80.     "Mrairs",
  81.     "StoneHammers",
  82.     "SystemProcess",
  83.     "wifeisaggro",
  84.     "Sh4dow_G4ming",
  85.     "moneyslow"
  86. }
  87. local function isWhitelisted(name)
  88.     return table.search(whitelist, name)
  89. end
  90.  
  91. local blacklist = {
  92.     "posterierman",
  93. }
  94. local function isBlacklisted(name)
  95.     return table.search(blacklist, name)
  96. end
  97.  
  98. local function allowEntry()
  99.     rs.setOutput("back", false)
  100.     rs.setOutput("front", true)
  101. end
  102. local function denyEntry()
  103.     rs.setOutput("front", false)
  104.     rs.setOutput("back", true)
  105. end
  106. local function pressurePlates()
  107.     if rs.getInput("right") then
  108.         print("Pressure plates")
  109.     end
  110.     return rs.getInput("right")
  111. end
  112.  
  113. local db = [[___________       __        
  114. \_   _____/____ _/  |_      
  115.  |    __)_\__  \\   __\    
  116.  |        \/ __ \|  |      
  117. /_______  (____  /__|      
  118.         \/     \/          
  119.   _________.__    .__  __  
  120.  /   _____/|  |__ |__|/  |_
  121.  \_____  \ |  |  \|  \   __\
  122.  /        \|   Y  \  ||  |  
  123. /_______  /|___|  /__||__|  
  124.         \/      \/        
  125. ]]
  126. function dickbutt(text)
  127.     pri.newPage()
  128.     pri.setPageTitle("Message from Wyvern67")
  129.     text = text .. "\n"
  130.     local i = 1
  131.     for line in string.gmatch(text, "(.-)\n") do
  132.         pri.setCursorPos(1,i)
  133.         pri.write(line)
  134.         i = i+1
  135.     end
  136.     pri.endPage()
  137. end
  138.  
  139. function insult(text)
  140.     pri.newPage()
  141.     pri.setPageTitle("Message from Wyvern67")
  142.     if pri.getPaperLevel == 0 then
  143.         text = [[You got this printer out
  144. of paper. Are you
  145. happy about yourself?]]
  146.     end
  147.     if pri.getInkLevel == 0 then
  148.         text = [[You got this printer out
  149. of paper. Are you
  150. happy about yourself?]]
  151.     end
  152.     text = text .. "\n"
  153.     local i = 3
  154.     for line in string.gmatch(text, "(.-)\n") do
  155.         pri.setCursorPos(1,i)
  156.         pri.write(line)
  157.         i = i+1
  158.     end
  159.     pri.endPage()
  160. end
  161.  
  162. local function print_monitor(text)
  163.     print(text)
  164.     if mon and mon.getCursorPos and mon.write and mon.setCursorPos then
  165.         local x,y = mon.getCursorPos()
  166.         mon.write(text)
  167.         mon.setCursorPos(10,y+1)
  168.     end
  169. end
  170. print_monitor("")
  171.  
  172. s = peripheral.wrap("top")
  173. local lastInsulted = ""
  174.  
  175. while true do
  176.     mon.clear()
  177.     mon.setCursorPos(10, 3)
  178.     local players = s.getPlayers()
  179.     local nPlayers = #players
  180.  
  181.     if nPlayers > 0 then
  182.         local player
  183.         local entry = true
  184.         local welcome = {}
  185.         local knowEverybody = true
  186.         --Parsing players
  187.  
  188.         for i,v in pairs(players) do
  189.             player = v.name
  190.             if opt.b then
  191.                 if isBlacklisted(player) then
  192.                     entry = false
  193.                     welcome = {player}
  194.                     break
  195.                 end
  196.             end
  197.  
  198.             if opt.w then
  199.                 entry = entry and isWhitelisted(player)
  200.             end
  201.  
  202.             if i>1 and opt.l then
  203.                 local h = fs.open("logs", "a")
  204.                 local txt = timestamp() .. ": " .. player
  205.                 h.writeLine(txt)
  206.                 print(txt)
  207.                 h.close()
  208.             end
  209.            
  210.             if isWhitelisted(player) then
  211.                 welcome[#welcome+1] = "bro #"..table.search(whitelist, player)
  212.             else
  213.                 welcome[#welcome+1] = player
  214.                 knowEverybody = false
  215.             end
  216.         end
  217.  
  218.         --Allow or deny entry based on players inside the gates
  219.         if entry then
  220.             --Prepare entry message according to the players
  221.             local message = "Welcome, " .. welcome[1]
  222.             for i=2, #welcome-1 do
  223.                 message = message .. ", " .. welcome[i]
  224.             end
  225.             if #welcome > 1 then
  226.                 message = message .. " and " .. welcome[#welcome]
  227.             end
  228.             message = message .. "."
  229.             --Actual entry script
  230.             allowEntry()
  231.             print_monitor(message)
  232.  
  233.             if knowEverybody == false then
  234.                 print_monitor("Although I do not know")
  235.                 print_monitor("everybody, you are still")
  236.                 print_monitor("welcome :).")
  237.             end
  238.  
  239.             while #s.getPlayers() == nPlayers do
  240.                 if pressurePlates() then
  241.                     rs.setOutput("back", true)
  242.                 else
  243.                     rs.setOutput("back", false)
  244.                 end
  245.                 sleep()
  246.             end
  247.         else
  248.             denyEntry()
  249.             print_monitor("Sorry. " .. welcome[1] .. ", you aren't")
  250.             print_monitor("allowed here.")
  251.             print_monitor("You need to leave. :/")
  252.             if insult and lastInsulted ~= welcome[1] then
  253.                 print_monitor("The owner left you a personnal")
  254.                 print_monitor("message.")
  255.                 print_monitor("Please, take it.")
  256.                 insult("fuck off " .. welcome[1])
  257.                 lastInsulted = welcome[1]
  258.             end
  259.  
  260.             while #s.getPlayers() == nPlayers do
  261.                 sleep()
  262.             end
  263.         end
  264.         rs.setOutput("back", true)
  265.         rs.setOutput("front", false)
  266.     end
  267.     sleep(0.1)
  268. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement