Jump to content




Player Detector List



14 replies to this topic

#1 dobbylego

  • Members
  • 10 posts

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

#2 Meni

  • Members
  • 59 posts

Posted 10 January 2013 - 09:14 AM

View Postdobbylego, 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?

#3 crazyguymgd

  • Members
  • 139 posts
  • LocationUSA

Posted 10 January 2013 - 09:46 AM

View Postdobbylego, 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?

#4 dobbylego

  • Members
  • 10 posts

Posted 10 January 2013 - 03:11 PM

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

crazyguymgd- Ya how would I do that?

#5 crazyguymgd

  • Members
  • 139 posts
  • LocationUSA

Posted 10 January 2013 - 04:36 PM

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

#6 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

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

#7 dobbylego

  • Members
  • 10 posts

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?

#8 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 12 January 2013 - 02:06 AM

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

#9 dobbylego

  • Members
  • 10 posts

Posted 12 January 2013 - 02:00 PM

Ok thanks for trying thow :)

#10 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

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

#11 W00dyR

  • Members
  • 135 posts

Posted 13 January 2013 - 02:14 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

#12 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 13 January 2013 - 02:38 AM

View PostW00dyR, 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.

#13 dobbylego

  • Members
  • 10 posts

Posted 17 January 2013 - 01:21 PM

Cool! Thank you guys for all the help!

#14 dobbylego

  • Members
  • 10 posts

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?

#15 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 27 March 2013 - 05:20 PM

relative to the sensor





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users