Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- The two corner points of an area
- AreaCoords = {{x=6187, y=0, z=-10215}, {x=6078, y=255, z=-10116}}
- -- List of player usernames to not log
- BlackListPlayers = {"zkb1325"}
- local pd = peripheral.find("playerDetector")
- if fs.exists("visitorLog.txt") then
- local visitorFile = fs.open("visitorLog.txt", "r")
- VisitorLog = visitorFile.readAll()
- visitorFile.close()
- VisitorLog = textutils.unserialize(VisitorLog)
- else
- VisitorLog = {}
- end
- CurrentlyVisiting = {}
- local function inArray(value, table)
- for i,v in ipairs(table) do
- if v == value then return true end
- end
- return false
- end
- local function saveVisitorLog()
- local visitorFile = fs.open("visitorLog.txt", "w")
- visitorFile.write(textutils.serialize(VisitorLog))
- visitorFile.close()
- end
- local function currentVisitors()
- -- return pd.getPlayersInRange(2)
- return pd.getPlayersInCoords(AreaCoords[1], AreaCoords[2])
- end
- local function updateActive()
- for i,v in pairs(CurrentlyVisiting) do
- if CurrentlyVisiting[i]["active"] and not inArray(i, currentVisitors()) then
- CurrentlyVisiting[i]["active"] = false
- table.insert(VisitorLog[i][CurrentlyVisiting[i]["lastIndex"]], 2, os.date("%b %d %G %I:%M:%S %p"))
- table.insert(VisitorLog[i][CurrentlyVisiting[i]["lastIndex"]], 3, os.clock() - CurrentlyVisiting[i]["visitedAt"])
- -- VisitorLog[i][CurrentlyVisiting[i]["lastDate"]] = os.date("%b %d %G %I:%M:%S %p")
- saveVisitorLog()
- print(i.." has left the area at "..os.date("%b %d %G %I:%M:%S %p"))
- end
- end
- end
- while true do
- sleep(1)
- for i,v in ipairs(currentVisitors()) do
- if not inArray(v, BlackListPlayers) then
- if not CurrentlyVisiting[v] then
- CurrentlyVisiting[v] = {}
- end
- if not VisitorLog[v] then
- VisitorLog[v] = {}
- end
- if not CurrentlyVisiting[v]["active"] then
- CurrentlyVisiting[v]["active"] = true
- CurrentlyVisiting[v]["visitedAt"] = os.clock()
- CurrentlyVisiting[v]["lastIndex"] = #VisitorLog[v]+1
- VisitorLog[v][CurrentlyVisiting[v]["lastIndex"]] = {os.date("%b %d %G %I:%M:%S %p")}
- saveVisitorLog()
- print(v.." has entered the area at "..os.date("%b %d %G %I:%M:%S %p"))
- end
- end
- end
- updateActive()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement