Advertisement
superkh

OpenCCSensor Loger

May 12th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.60 KB | None | 0 0
  1. os.loadAPI("ocs/apis/sensor")
  2.  
  3. local w, h = term.getSize()
  4. local timeL = ( 5 )*60 -- time in mins
  5. local logf = "log1" --log file
  6. local prox = sensor.wrap("right")
  7.  
  8. local function scan()
  9.     m = prox.getTargets()
  10.     for k , v in pairs(m) do
  11.         if v.IsPlayer then
  12.             local player = prox.getTargetDetails(k)
  13.             if fs.exists(logf) then file = fs.open(logf, "a") else file = fs.open(logf, "w") end
  14.             file.write("Username: "..player["Username"].."\n")
  15.             file.write(tostring("Position: "..textutils.serialize(player["Position"])).."\n")
  16.             file.write("Health: "..tostring(player["Health"]).."\n")
  17.             file.write("FoodLevel: "..tostring(player["FoodLevel"]).."\n")
  18.             file.write("Gamemode: "..tostring(player["Gamemode"]).."\n")
  19.             file.write("IsAirborne: "..tostring(player["IsAirborne"]).."\n")
  20.             file.write(textutils.formatTime( os.time(), true ) .. "\n \n")
  21.             file:close()
  22.         end  
  23.     end
  24. end
  25. local function setup()
  26.     term.setCursorPos(1,1)
  27.     term.setBackgroundColor(colors.black)
  28.     term.setTextColor(colors.white)
  29.     term.clear()
  30.     print("Starting Log:")
  31.     print("Hit: Q to quit, L to open Log")
  32. end
  33. function main()
  34.     setup()
  35.     t = os.startTimer(timeL)
  36.     while true do
  37.         local arg = {os.pullEvent() }
  38.         if arg[1]=="timer" and arg[2] == t then
  39.             scan()
  40.             t = os.startTimer(timeL)
  41.         elseif arg[1]=="char" and arg[2]=="l" then
  42.             shell.run("edit",logf)
  43.             setup()
  44.         elseif arg[1]=="char" and arg[2]=="q" then
  45.             break
  46.         end
  47.     end
  48. end
  49. local ok, err = pcall(main)
  50. if not ok then
  51.     term.setBackgroundColor(colors.black)
  52.     term.clear()
  53.     term.setCursorPos(1,1)
  54.     term.setTextColor(colors.white)
  55.     print(err)
  56. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement