←  Ask a Pro

ComputerCraft | Programmable Computers for Minecraft

»

Player Detector List

dobbylego's Photo dobbylego 09 Jan 2013

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
Quote

Meni's Photo Meni 10 Jan 2013

 dobbylego, on 09 January 2013 - 02:19 PM, said:

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?
Quote

crazyguymgd's Photo crazyguymgd 10 Jan 2013

 dobbylego, on 09 January 2013 - 02:19 PM, said:

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?
Quote

dobbylego's Photo dobbylego 10 Jan 2013

Meni- What ever is easier to build with... any suggestions?

crazyguymgd- Ya how would I do that?
Quote

crazyguymgd's Photo crazyguymgd 10 Jan 2013

Here's a good page to read to get you started :)
http://computercraft.info/wiki/Fs.open
Quote

KaoS's Photo KaoS 10 Jan 2013

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
Quote

dobbylego's Photo dobbylego 11 Jan 2013

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?
Quote

KaoS's Photo KaoS 12 Jan 2013

I have never used misc peripherals so I cannot help you there... sorry
Quote

dobbylego's Photo dobbylego 12 Jan 2013

Ok thanks for trying thow :)
Quote

KaoS's Photo KaoS 13 Jan 2013

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
Quote

W00dyR's Photo W00dyR 13 Jan 2013

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
Quote

remiX's Photo remiX 13 Jan 2013

 W00dyR, on 13 January 2013 - 02:14 AM, said:

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.
Quote

dobbylego's Photo dobbylego 17 Jan 2013

Cool! Thank you guys for all the help!
Quote

dobbylego's Photo dobbylego 27 Mar 2013

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?
Quote

KaoS's Photo KaoS 27 Mar 2013

relative to the sensor
Quote