Advertisement
tomte55

MCEMA

Oct 20th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.69 KB | None | 0 0
  1. if component.isAvailable("internet") then
  2.     os.execute(pastebin get -f 3wMMSbNv pass.lua)
  3. end
  4.  
  5. local tArgs ={...}
  6. local nologArg =tArgs[1]
  7.  
  8. local component = require("component")
  9. local term      = require("term")
  10. local computer  = require("computer")
  11. local event     = require("event")
  12. local sides     = require("sides")
  13. local gpu = component.gpu
  14.  
  15. title = "<|MCEMA|>"
  16.  
  17. local colors = { blue = 0x4286F4, purple = 0xB673d6, red = 0xC14141, green = 0xDA841, black = 0x000000, white = 0xFFFFFF, grey = 0x47494C, lightGrey = 0xBBBBBB}
  18.  
  19. local rs = component.redstone
  20. local cb = computer.beep
  21.  
  22. local dist = 3
  23.  
  24. local pt = 0
  25. local t = computer.uptime
  26.  
  27. local sensors = {}
  28.  
  29. local allowedPlayers = {"tomte55", "FisKtryne"}
  30. local mobs = {"Zombie", "Spider", "Creeper", "Skeleton", "Skeleton Horse", "Ancient Golem", "Enderman", "Bliss", "Bat", "Cow", "Pig", "Sheep", "Wolf", "Chicken"}
  31. local mobs_checked = {}
  32.  
  33. local passing = "NULL"
  34.  
  35. local line_string = "----------------------------------------------------------------------------------------------------------------------------------------------------------------"
  36.  
  37. local count = 1
  38. local opened = 0
  39. local logged = 0
  40.  
  41. local time = os.time()*1000/60/60-6000
  42. local day = time/24000
  43.  
  44. local door = 0
  45.  
  46. local x, y = gpu.maxResolution()
  47.  
  48. if x > 80 then
  49.     if y > 25 then
  50.         gpu.setResolution(80, 25)
  51.     end
  52. end
  53.  
  54. local w, h = gpu.getResolution()
  55.  
  56. if gpu.getDepth() > 1 then
  57.     color = true
  58. end
  59.  
  60. if color then
  61.     gpu.setBackground(colors.grey)
  62. end
  63.  
  64. function line()
  65.     if color then
  66.         gpu.setForeground(colors.blue)
  67.     end
  68.     print(string.sub(line_string, 1, w))
  69.     if color then
  70.         gpu.setForeground(colors.white)
  71.     end
  72. end
  73.  
  74. function bind_sensors()
  75.     sensors = {}
  76.     count = 1
  77.     for address, _ in component.list("motion") do
  78.         table.insert(sensors, address)
  79.         address = string.sub(address, 1, 8)
  80.         sensor = "Sensor " .. count .. " - " .. address
  81.         term.setCursor(math.floor(w/2-string.len(tostring(sensor))/2+1), count+1)
  82.         print(sensor)
  83.         count = count+1
  84.     end
  85.  
  86.     if #sensors == 0 then
  87.         count = 2
  88.         term.setCursor(math.floor(w/2-string.len("Error no sensors")/2+1), 2)
  89.         if color then
  90.             gpu.setForeground(colors.red)
  91.         end
  92.         term.write("Error no sensors")
  93.         if color then
  94.             gpu.setForeground(colors.white)
  95.         end
  96.     end
  97.     term.setCursor(1, 1)
  98.     line()
  99.     term.setCursor(math.floor(w/2-string.len(title)/2+1), 1)
  100.     if color then
  101.         gpu.setForeground(colors.red)
  102.     end
  103.     print(title)
  104.     if color then
  105.         gpu.setForeground(colors.green)
  106.     end
  107.     term.setCursor(1, count+1)
  108.     line()
  109.     term.setCursor(1, count+2)
  110. end
  111.  
  112. function detect()
  113.     term.write("")
  114.     local _,address,xdist,_,ydist,name = term.pull("motion")
  115.     door = 0
  116.     if xdist < dist and xdist > -dist and ydist > -dist and ydist < dist then
  117.         for i=1, #sensors do
  118.             door = door + 1
  119.             if address == sensors[i] then
  120.                 passing = name
  121.                 log()
  122.                 for j=1, #allowedPlayers do
  123.                     if name == allowedPlayers[j] then
  124.                         open()
  125.                     end
  126.                 end
  127.             end
  128.         end
  129.     end
  130. end
  131.  
  132. function log()
  133.     if passing ~= nologArg then
  134.         for i=1, #mobs do
  135.             if passing ~= mobs[i] then
  136.                 table.insert(mobs_checked, passing)
  137.             end
  138.         end
  139.         if #mobs_checked == #mobs then
  140.             mobs_checked = {}
  141.             logged = logged + 1
  142.             if opened < 1 then
  143.                 line()
  144.             end
  145.             log_text = "User: " .. passing .. " | " .. "Time: " .. os.date("%I:%M %p") .. " | " .. "Day: " .. math.floor(day)
  146.             local x, y = term.getCursor()
  147.             term.setCursor(math.floor(w/2-string.len(tostring(log_text))/2+1), y)
  148.             print(log_text)
  149.             line()
  150.             opened = opened + 1
  151.         end
  152.     end
  153. end
  154.  
  155. function open()
  156.     rs.setOutput(sides.top, 15)
  157.     os.sleep(2)
  158.     rs.setOutput(sides.top, 0)
  159. end
  160.  
  161. term.clear()
  162. bind_sensors()
  163.  
  164. while true do
  165.     detect()
  166. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement