This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
mattie078's profile picture

Visitor Database?

Started by mattie078, 15 June 2014 - 01:12 PM
mattie078 #1
Posted 15 June 2014 - 03:12 PM
For my Tekkit Lite server I want to see who and when visits my base, like in the old direwolf20 video's.
We have CCSensors so that's not a problem at all. And I want to see it on a monitor.

Greets Matthijs
theoriginalbit #2
Posted 15 June 2014 - 03:26 PM
what is the code you have so far? what are the problems you're having? we can't help you with the program without information.
mattie078 #3
Posted 15 June 2014 - 03:55 PM
I don't have anything yes, I don't know how to start with something I never worked on. I know the CCsensors but that's it.
TheOddByte #4
Posted 16 June 2014 - 11:24 AM
Which peripheral are you using for the sensor? OpenCCSensors? OpenPeripheral?
It's easier for us to help you if we have more information. ( I'm kinda unsure if there is a sensor block in OpenPeripheral :P/> )
Edited on 16 June 2014 - 09:25 AM
mattie078 #5
Posted 16 June 2014 - 03:59 PM
OpenCCSensors, from the minecraft version 1.4.7 , also computercraft version 1.5

This is the sensor if you're still unsure http://www.computercraft.info/wiki/index.php?title=OpenCCSensors
Edited on 16 June 2014 - 02:07 PM
TheOddByte #6
Posted 16 June 2014 - 09:48 PM
So this would basically do what you want

local prox = peripheral.wrap( "<side" )
local visitors = {}

local monitor

--# Find a monitor
for _, name in ipairs( peripheral.getNames() ) do
	if peripheral.getType( name ) == "monitor" then
		monitor = peripheral.wrap( name )
	end
end

while true do
	--# Get all targets and then insert them into the visitors table
	local targets = prox.getTargets()
	for name, _ in pairs( targets ) do
		local n = {}
		n.name = name
		n.timestamp = textutils.formatTime( os.time() )
		table.insert( visitors, n )
	end

	--# Loop through the visitor table and draw the stuff xP
	monitor.clear()
	for i = 1, #visitors do
		monitor.setCursorPos( 1, i )
		monitor.write( visitors[i].name .. " | " .. visitors[i].timestamp )
	end
end
This is ofcourse very basic and it would go out of the screen if there are too many visitors :P/>
If you're unsure how monitors work I can tell you that it basically has all the term functions

local monitor = peripheral.wrap( "<Side>" )

monitor.clear()
monitor.write( "Hello" )
monitor.setCursorPos( 1, 1 )
local w, h = monitor.getSize()
monitor.setCursorBlink( true )

etc.
You can also redirect the terminal to the monitor, and since you're using CC 1.5 I believe you can still use term.restore :P/>

local monitor = peripheral.wrap( "<Side>" )
term.redirect( monitor ) 
term.write( "This is going to be written on the monitor" )
term.restore()
term.write( "This is going to be written in the terminal" )
Edited on 16 June 2014 - 07:51 PM
Lyqyd #7
Posted 16 June 2014 - 10:03 PM
The first line of the above script needs to be changed to:


os.loadAPI("ocs/apis/sensor")
local prox = sensor.wrap("side")

Of course, replace "side" with the actual side name.
TheOddByte #8
Posted 16 June 2014 - 10:50 PM
The first line of the above script needs to be changed to:


os.loadAPI("ocs/apis/sensor")
local prox = sensor.wrap("side")

Of course, replace "side" with the actual side name.
oops forgot x)
mattie078 #9
Posted 18 June 2014 - 09:37 AM
I have this now, http://pastebin.com/RiG9XpAj
only it still doesn't work. And I really don't know what I'm doing wrong here. I've never worked with CCsensors yet :\

Edited on 18 June 2014 - 07:39 AM
flaghacker #10
Posted 18 June 2014 - 12:00 PM
You have to change the "side" into the ACTUAL side, in your case "bottom".
mattie078 #11
Posted 18 June 2014 - 01:48 PM
You have to change the "side" into the ACTUAL side, in your case "bottom".

Some people can't read, if you saw that I posted a pastebin. There I have THE GOOD SIDE So I've you just clicked the link you know better by now.

Still is my question what am I doing wrong?
mattie078 #12
Posted 18 June 2014 - 02:02 PM
Ok got it working now, still I have some question, I want :
  • really badly a blacklist on some players (like me) so they don't spam around much
  • No mobs stay on there (because the sensor also detects mobs)
  • After 2 or 3 people it resets itself, I want that it stays always unless I manually reboot it
Edited on 18 June 2014 - 12:39 PM
flaghacker #13
Posted 19 June 2014 - 05:54 AM
You have to change the "side" into the ACTUAL side, in your case "bottom".

Some people can't read, if you saw that I posted a pastebin. There I have THE GOOD SIDE So I've you just clicked the link you know better by now.

Still is my question what am I doing wrong?

Indeed, you can't read. That can happen to everyone, so nothing wrong there. When I read that post, there was "sensor.wrap("side")".

What's worse is the fact that you quickly edit you pastebin, and then pretend I'm dumb.
Edited on 19 June 2014 - 03:57 AM
BytePointer #14
Posted 20 June 2014 - 06:08 AM
You have to change the "side" into the ACTUAL side, in your case "bottom".

Some people can't read, if you saw that I posted a pastebin. There I have THE GOOD SIDE So I've you just clicked the link you know better by now.

Still is my question what am I doing wrong?
Please calm down, people aren't going to want to reply to YOUR question if you're getting mad at people who try to help you.
Lyqyd #15
Posted 20 June 2014 - 02:57 PM
Everyone in this thread needs to calm down a bit. Don't get angry with the people trying to help you, and don't snap back at the question askers if they do, just move on to the next topic.