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

Player Detector List

Started by dobbylego, 09 January 2013 - 01:19 PM
dobbylego #1
Posted 09 January 2013 - 02:19 PM
Hello people who read this!

I am trying to add a player detector to my password door so i know who tryed to access it, but what i cant figure out is how to actually make it write to a list on another program. Can anyone help me?

Thanks!
-Will
Meni #2
Posted 10 January 2013 - 09:14 AM
Hello people who read this!

I am trying to add a player detector to my password door so i know who tryed to access it, but what i cant figure out is how to actually make it write to a list on another program. Can anyone help me?

Thanks!
-Will
Using ccSonsors?
crazyguymgd #3
Posted 10 January 2013 - 09:46 AM
Hello people who read this!

I am trying to add a player detector to my password door so i know who tryed to access it, but what i cant figure out is how to actually make it write to a list on another program. Can anyone help me?

Thanks!
-Will

Save it to a file, then the other program can read in the file and do what it wants with that data?
dobbylego #4
Posted 10 January 2013 - 03:11 PM
Meni- What ever is easier to build with… any suggestions?

crazyguymgd- Ya how would I do that?
crazyguymgd #5
Posted 10 January 2013 - 04:36 PM
Here's a good page to read to get you started :)/>
http://computercraft.info/wiki/Fs.open
KaoS #6
Posted 10 January 2013 - 06:24 PM
basically you want to load openCCsensors, place your password accepting computer and place a sensor on one side of it, then open the computer in the Lua prompt while standing in the block where you will be accessing the password computer from normally, execute the following code:


os.loadAPI("ocs/apis/sensor")
s=sensor.wrap(sSide)
for k,v in pairs(s.getTargets()) do print("Username: "..k.."\nCDS: "..v.Position.x..", "..v.Position.Y..", "..v.Position.Z.."\n") end

and it will print out a list of detected players and their position relative to the sensor, your position is the one you need. in your actual password protecting program use coroutines to only allow people to enter a password if they are in that area (you can make it span multiple blocks). make your password protecting code into a function which accepts a parameter for the player name that way you can greet the player when you ask them for their password


os.loadAPI("ocs/apis/sensor")
local x=yourX
local y=yourY
local z=yourZ


local sense=coroutine.wrap(function()
  local s=sensor.wrap(sensorside)
  while true do
	local tResults=s.getTargets()
	for k,v in pairs(tResults) do
	  if v.Position.X==x and v.Position.Y==y and v.Position.Z==z then
		coroutine.yield(k)
		break
	  end
	end
	sleep(0.5)
  end
end)
local pass=nil
local running=false
local evts={}
while true do
  local r=sense(unpack(evts))
  if type(r)=="string" and running then
	pass(unpack(evts))
  elseif type(r)=="string" and not running then
	pass=coroutine.wrap(yourpasswordfunction)
	pass(r)
	running=true
  elseif type(r)~="string" and running
	pass=nil
    running=false
  end
  local evts={os.pullEvent()}
end

basically what that should do is run a coroutine constantly checking positions of detected players, if one is at the required position then it starts the 'yourpasswordfunction' function and keeps running it until there is no longer a player detected there, if no-one is there and then someone arrives then it starts the function over from the beginning

if you do not understand or if you have trouble executing any of the above feel free to ask
dobbylego #7
Posted 11 January 2013 - 06:14 PM
Ok… I feel REALLY stupid… I am trying to use this on a server with Direwolf20s pack and it only has the misc peripherals mod in it. Can it run a modifyed version of that code KaoS?
KaoS #8
Posted 12 January 2013 - 02:06 AM
I have never used misc peripherals so I cannot help you there… sorry
dobbylego #9
Posted 12 January 2013 - 02:00 PM
Ok thanks for trying thow :)/>
KaoS #10
Posted 13 January 2013 - 02:02 AM
all good. hope someone can help you out, in case you get OCS:

on line 13 I forgot something. just before the yield you need an os.queueEvent('someBShere') so that it resumes the coroutine.yield(), now that I think about it there is a better way to do this but this method would work too
W00dyR #11
Posted 13 January 2013 - 02:14 AM
If you read on this page:

http://www.computercraft.info/forums2/index.php?/topic/4587-cc1481mc146-miscperipherals-23/

It sais it emits the event "player" when someone right clicks it, with the player name as parameter.

so using something like


p = peripheral.wrap("<side>")
player, p1 = os.pullEvent()
print(p1)

should print the players name, I hope this helps out
remiX #12
Posted 13 January 2013 - 02:38 AM
If you read on this page:

http://www.computerc...peripherals-23/

It sais it emits the event "player" when someone right clicks it, with the player name as parameter.

so using something like


p = peripheral.wrap("<side>")
player, p1 = os.pullEvent()
print(p1)

should print the players name, I hope this helps out

Yes, p1 will be the username of the player that right clicks it, and player would be the event 'player'.

No need for wrapping it though.
dobbylego #13
Posted 17 January 2013 - 01:21 PM
Cool! Thank you guys for all the help!
dobbylego #14
Posted 27 March 2013 - 12:55 PM
KaoS I got openccsensors and I was going to use the program but do I need to change yourX, yourY and yourZ to the xyz of the world or relative to the sensor?
KaoS #15
Posted 27 March 2013 - 05:20 PM
relative to the sensor