Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- for a,b in pairs(peripheral.getNames()) do
- if peripheral.getType(b) == 'openperipheral_sensor' then
- prox = peripheral.wrap(b)
- break
- end
- end
- -- Create database if it doesn't exist
- if fs.exists("database") == false then
- term.clear()
- term.setCursorPos(11,4)
- print("Enter your In-game name here")
- term.setCursorPos(20,6)
- owner = read()
- ini = fs.open("database", "a")
- ini.writeLine(owner)
- ini.close()
- end
- term.clear()
- term.setCursorPos(13,4)
- print("Now logging to database \n open the file 'database' to see who visited")
- -- Loop through the database and store data in table
- function readTable()
- h = fs.open("database", "r")
- l = {}
- count = 0
- while true do
- local line = h.readLine()
- if line == nil then
- break
- end
- count = count + 1
- table.insert(l, line)
- end
- end
- -- Run the function one time to get everything into the table
- readTable()
- while true do
- owner = (l[1])
- example = http.get("http://www.timeapi.org/gmt/in+2+hours")
- everything = tostring(example.readAll())
- example.close()
- date = string.sub(everything, 1, 10)
- time = string.sub(everything, 12, 19)
- local targets = prox.getTargets()
- for name, basicDetails in pairs(targets) do
- lastLine = string.find(l[count], name)
- if lastLine == nil and name ~= owner then
- p = fs.open("database", "a")
- p.writeLine(name .. " " .. time .. " " .. date)
- p.close()
- table.insert(l, name .. " " .. time .. " " .. date)
- count = count + 1
- break
- end
- end
- -- Change this if you want to check for names more than once every 10 seconds. (Time API might not like it)
- sleep(10)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement