SHOW:
|
|
- or go back to the newest paste.
| 1 | - | os.loadAPI("ocs/apis/sensor")
|
| 1 | + | for a,b in pairs(peripheral.getNames()) do |
| 2 | if peripheral.getType(b) == 'openperipheral_sensor' then | |
| 3 | - | -- Wrap the sensor |
| 3 | + | prox = peripheral.wrap(b) |
| 4 | break | |
| 5 | - | for a,b in pairs(rs.getSides()) do |
| 5 | + | |
| 6 | - | if peripheral.getType(b) == 'sensor' then |
| 6 | + | |
| 7 | - | prox = sensor.wrap(b) |
| 7 | + | |
| 8 | -- Create database if it doesn't exist | |
| 9 | ||
| 10 | if fs.exists("database") == false then
| |
| 11 | term.clear() | |
| 12 | term.setCursorPos(11,4) | |
| 13 | print("Enter your In-game name here")
| |
| 14 | term.setCursorPos(20,6) | |
| 15 | owner = read() | |
| 16 | ini = fs.open("database", "a")
| |
| 17 | ini.writeLine(owner) | |
| 18 | ini.close() | |
| 19 | end | |
| 20 | ||
| 21 | term.clear() | |
| 22 | term.setCursorPos(13,4) | |
| 23 | print("Now logging to database \n open the file 'database' to see who visited")
| |
| 24 | ||
| 25 | -- Loop through the database and store data in table | |
| 26 | ||
| 27 | function readTable() | |
| 28 | h = fs.open("database", "r")
| |
| 29 | l = {}
| |
| 30 | count = 0 | |
| 31 | while true do | |
| 32 | local line = h.readLine() | |
| 33 | if line == nil then | |
| 34 | break | |
| 35 | end | |
| 36 | count = count + 1 | |
| 37 | table.insert(l, line) | |
| 38 | end | |
| 39 | end | |
| 40 | ||
| 41 | -- Run the function one time to get everything into the table | |
| 42 | readTable() | |
| 43 | ||
| 44 | while true do | |
| 45 | owner = (l[1]) | |
| 46 | example = http.get("http://www.timeapi.org/gmt/in+2+hours")
| |
| 47 | everything = tostring(example.readAll()) | |
| 48 | example.close() | |
| 49 | date = string.sub(everything, 1, 10) | |
| 50 | time = string.sub(everything, 12, 19) | |
| 51 | ||
| 52 | local targets = prox.getTargets() | |
| 53 | - | date = string.sub(everything, 1,10) |
| 53 | + | |
| 54 | - | time = string.sub(everything, 12,19) |
| 54 | + | |
| 55 | if lastLine == nil and name ~= owner then | |
| 56 | p = fs.open("database", "a")
| |
| 57 | p.writeLine(name .. " " .. time .. " " .. date) | |
| 58 | p.close() | |
| 59 | table.insert(l, name .. " " .. time .. " " .. date) | |
| 60 | count = count + 1 | |
| 61 | break | |
| 62 | end | |
| 63 | end | |
| 64 | -- Change this if you want to check for names more than once every 10 seconds. (Time API might not like it) | |
| 65 | sleep(10) | |
| 66 | end |