Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local alarm_state = false
- local function alarm()
- while true do
- if alarm_state == true then
- rs.setOutput('back', true)
- sleep(0)
- rs.setOutput('back', false)
- alarm_state = false
- end
- sleep(1)
- end
- end
- local sensor = peripheral.wrap('top')
- local monitor = peripheral.wrap('right')
- local x_sensor = 1285
- local y_sensor = 3416
- local z_sensor = 73
- local No_string = 1
- local No_column = 1
- local step_string = 6
- local step_column = 20
- local q_columns = 2
- local guests = {["name"] = {}, ["check"] = {}}
- local function printLog(text)
- local log = fs.open("log", "a")
- log.writeLine(text)
- print(text)
- log.close()
- end
- local function clear()
- monitor.clear()
- monitor.setCursorPos(1, 1)
- monitor.setTextScale(0.5)
- No_string = 1
- No_column = 1
- end
- local function next_string()
- No_string = No_string + 1
- monitor.setCursorPos(No_column, No_string)
- end
- local function next_column()
- if No_column ~= ((q_columns - 1) * step_column + 1) then
- No_column = No_column + step_column
- No_string = No_string - step_string
- else
- No_column = 1
- end
- monitor.setCursorPos(No_column, No_string)
- end
- local function location()
- local player_table = sensor.getPlayers()
- for k, v in pairs(guests["check"]) do
- guests["check"][k] = false
- end
- for k, v in pairs(player_table) do
- local player = v
- local player_info = sensor.getPlayerByUUID(player["uuid"])
- local search = false
- for index, guest in pairs(guests["name"]) do
- if guest == player["name"] then
- guests["check"][index] = true
- search = true
- end
- end
- if search == false then
- local q_guests = #guests["name"]
- guests["name"][q_guests + 1] = player["name"]
- guests["check"][q_guests + 1] = true
- alarm_state = true
- local log_text = textutils.formatTime(os.time()).." New guest: "..player["name"]
- printLog(log_text)
- end
- local x = math.modf(player_info["position"]["x"]) - 1
- local z = math.modf(player_info["position"]["y"]) - 1
- local y = math.modf(player_info["position"]["z"]) - 1
- local distance = math.sqrt(x*x + y*y + z*z)
- distance = math.modf(distance * 100) / 100
- monitor.write('Found '..player_info["name"])
- next_string()
- -- monitor.write("UUID")
- -- next_string()
- -- monitor.write(player_info["uuid"])
- -- next_string()
- -- monitor.write("Id")
- -- next_string()
- -- monitor.write(player_info["id"])
- -- next_string()
- monitor.write("Position")
- next_string()
- monitor.write(x + x_sensor..' '..z + z_sensor..' '..y + y_sensor)
- next_string()
- monitor.write("Distance")
- next_string()
- monitor.write(distance)
- next_string()
- monitor.write("---------")
- next_string()
- next_column()
- end
- for k, v in pairs(guests["check"]) do
- if v == false then
- local log_text = textutils.formatTime(os.time()).." "..guests["name"][k].." left."
- printLog(log_text)
- table.remove(guests["check"], k)
- table.remove(guests["name"], k)
- end
- end
- end
- local function mine()
- while true do
- clear()
- pcall(location)
- sleep(3)
- end
- end
- rs.setOutput('back', false)
- parallel.waitForAny(mine, alarm)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement