Guest User

startup

a guest
Feb 4th, 2015
306
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local alarm_state = false
  2.  
  3. local function alarm()
  4.   while true do
  5.     if alarm_state == true then
  6.       rs.setOutput('back', true)
  7.       sleep(0)
  8.       rs.setOutput('back', false)
  9.       alarm_state = false
  10.     end
  11.     sleep(1)
  12.   end
  13. end
  14.  
  15. local sensor = peripheral.wrap('top')
  16. local monitor = peripheral.wrap('right')
  17.  
  18. local x_sensor = 1285
  19. local y_sensor = 3416
  20. local z_sensor = 73
  21. local No_string = 1
  22. local No_column = 1
  23. local step_string = 6
  24. local step_column = 20
  25. local q_columns = 2
  26.  
  27. local guests = {["name"] = {}, ["check"] = {}}
  28.  
  29. local function printLog(text)
  30.   local log = fs.open("log", "a")
  31.  
  32.   log.writeLine(text)
  33.   print(text)
  34.  
  35.   log.close()
  36. end
  37.  
  38. local function clear()
  39.   monitor.clear()
  40.   monitor.setCursorPos(1, 1)
  41.   monitor.setTextScale(0.5)
  42.   No_string = 1
  43.   No_column = 1
  44. end
  45.  
  46. local function next_string()
  47.   No_string = No_string + 1
  48.   monitor.setCursorPos(No_column, No_string)
  49. end
  50.  
  51. local function next_column()
  52.   if No_column ~= ((q_columns - 1) * step_column + 1) then
  53.     No_column = No_column + step_column
  54.     No_string = No_string - step_string
  55.   else
  56.     No_column = 1
  57.   end
  58.  
  59.   monitor.setCursorPos(No_column, No_string)  
  60. end
  61.  
  62. local function location()  
  63.   local player_table = sensor.getPlayers()
  64.  
  65.  
  66.   for k, v in pairs(guests["check"]) do
  67.     guests["check"][k] = false
  68.   end
  69.  
  70.  
  71.   for k, v in pairs(player_table) do
  72.      local player = v
  73.      local player_info = sensor.getPlayerByUUID(player["uuid"])
  74.  
  75.          
  76.      local search = false
  77.      for index, guest in pairs(guests["name"]) do
  78.         if guest == player["name"] then
  79.           guests["check"][index] = true
  80.           search = true
  81.         end
  82.      end
  83.      if search == false then
  84.        local q_guests = #guests["name"]
  85.        guests["name"][q_guests + 1] = player["name"]
  86.        guests["check"][q_guests + 1] = true
  87.        alarm_state = true
  88.        
  89.        local log_text = textutils.formatTime(os.time()).."  New guest: "..player["name"]
  90.        printLog(log_text)
  91.      end
  92.      
  93.      
  94.      local x = math.modf(player_info["position"]["x"]) - 1
  95.      local z = math.modf(player_info["position"]["y"]) - 1
  96.      local y = math.modf(player_info["position"]["z"]) - 1
  97.      local distance = math.sqrt(x*x + y*y + z*z)
  98.      distance = math.modf(distance * 100) / 100
  99.          
  100.      monitor.write('Found '..player_info["name"])
  101.      next_string()  
  102.                                      
  103. --       monitor.write("UUID")
  104. --       next_string()
  105. --       monitor.write(player_info["uuid"])
  106. --       next_string()
  107.            
  108. --       monitor.write("Id")
  109. --       next_string()
  110. --       monitor.write(player_info["id"])
  111. --       next_string()
  112.                
  113.      monitor.write("Position")
  114.      next_string()
  115.      monitor.write(x + x_sensor..' '..z + z_sensor..' '..y + y_sensor)
  116.      next_string()
  117.        
  118.      monitor.write("Distance")
  119.      next_string()
  120.      monitor.write(distance)    
  121.      next_string()
  122.  
  123.      monitor.write("---------")
  124.      next_string()
  125.      
  126.      next_column()
  127.   end
  128.  
  129.    
  130.   for k, v in pairs(guests["check"]) do
  131.     if v == false then
  132.       local log_text = textutils.formatTime(os.time()).."  "..guests["name"][k].." left."
  133.       printLog(log_text)
  134.      
  135.       table.remove(guests["check"], k)
  136.       table.remove(guests["name"], k)
  137.     end
  138.   end
  139. end
  140.  
  141. local function mine()
  142.   while true do
  143.     clear()
  144.     pcall(location)
  145.  
  146.     sleep(3)
  147.   end
  148. end
  149.  
  150. rs.setOutput('back', false)
  151. parallel.waitForAny(mine, alarm)
RAW Paste Data