12 posts
Posted 17 July 2013 - 09:02 PM
Okay so i've been being griefed on a server my someone breaking my stuff when I'm offline so I wanted a program to tell me who was at my base and I want it to save to a file, but I don't know how to go about that. I have to code that prints player names on the computer, that works but how do I make it save the player names to a file?
Spoiler
os.loadAPI("ocs/apis/sensor")
local prox = sensor.wrap("right")
local targets = prox.getTargets()
while true do
for name, basicDetails in pairs(targets) do
print("Found: " ..name)
end
sleep(45)
end
8543 posts
Posted 17 July 2013 - 09:14 PM
os.loadApi("ocs/apis/sensor")
local prox = sensor.wrap("right")
while true do
local targets = prox.getTargets()
local handle = io.open("playerLog", "a")
handle:write("\n"..os.time()..": "..os.clock().."\n")
for target in pairs(targets) do
local details = prox.getTargetDetails(target)
if details and details.PlayerName then
handle:write(details.PlayerName.."\n")
end
end
handle:close()
end
2217 posts
Location
3232235883
Posted 17 July 2013 - 09:32 PM
Lyqyd: you forgot to yeild / sleep
12 posts
Posted 17 July 2013 - 09:42 PM
Thanks, and all i should have to do to open it is h = io.open("playerLog", "r")
h.readAll()
?
8543 posts
Posted 17 July 2013 - 09:51 PM
PixelToast is right, my sample code doesn't sleep. If all you want to do is read the log, you can always just run `edit PlayerLog`.
12 posts
Posted 17 July 2013 - 09:53 PM
lol now I really feel like an idiot. I added sleep to it
12 posts
Posted 17 July 2013 - 10:35 PM
Ok that didn't work entirely as intended but after much trial and error I ended up getting it to work by replacing PlayerName with Username.