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

[Player detector] Issue with getting it to send to another computer

Started by plazter, 31 March 2013 - 07:43 PM
plazter #1
Posted 31 March 2013 - 09:43 PM
SOLVED - New code: http://pastebin.com/1erb1CQr by
theoriginalbit

Hello Pro's!

- now me and my friend have been trying and trying and trying over and over again with diffrent codes, but we have hitted this wall.. :/

we almost had it with this code

and then i tryed to make another code like this 1

rednet.open("back")
ID = 237

while true do
  m=peripheral.wrap("left")
   m.clear()
   m.setCursorPos(1,1)

event, ID, plaz = os.pullEvent()
event, ID, alt = os.pullEvent()
  if plaz == "rednet_message" then
	m.write("Plazter has entered the cave!")
  end
  if alt == "rednet_message" then
   m.write("AlternateLogic has entered the cave!")
end

end

The above is working just wont print :S and its not really giving me much to work on :)/>

Would appreciate a helping hand :D/>

Best regard Plazter!
Edited on 02 May 2013 - 05:56 AM
theoriginalbit #2
Posted 31 March 2013 - 09:49 PM
ok so the reason it will not print is because it hangs on the second pullEvent waiting for something to happen again, such as a rednet message.

are we able to see the script that sends this rednet message so we can better help you fix this one. :)/>
plazter #3
Posted 31 March 2013 - 09:57 PM
Here you go :)/>
Link

term.clear() term.setCursorPos(1,1)
while true do

rednet.open("left")
event, p1 = os.pullEvent()


if event == "player" then
  if p1 == 'Plazter' or 'AlternateLogic' then
    if p1 == 'AlternateLogic' then
	  rednet.send(240, 'alternatelogic')
	  end
    if p1 == 'Plazter' then
	  rednet.send(240, 'plaz')
	  end
    if p1 ~= 'Plazter' or 'AlternateLogic' then
	  rednet.send(240, 'unauthorized')
	  end
print("Player: " .. p1 .. " entered!")
rs.setOutput("bottom", false)
sleep(2)
rs.setOutput("bottom", true)
else
print(p1 .." tryed to enter the plazter cave!!")
end
end
end
theoriginalbit #4
Posted 31 March 2013 - 10:22 PM
Ok here are some fixes for you.

sender/detector

local ID = 240

term.clear()
term.setCursorPos(1,1)

rednet.open("left") -- only need to open once, not each loop

while true do
  local event, player = os.pullEventRaw('player') -- wait here for a player... reduces lag... using pullEventRaw means the program cannot be terminated

  if player == 'Plazter' or player == 'AlternateLogic' then
	rednet.send(ID, player)
	print("Player: "..player.." entered!")
	rs.setOutput("bottom", false)

	os.startTimer(2) -- the following 2 lines is a way to sleep without allowing program termination
	os.pullEventRaw('timer')

	rs.setOutput("bottom", true)
  else
	rednet.send(ID, "Unauthorized")
	print(player.." tryed to enter the plazter cave!!")
  end
end

receiver/output monitor

rednet.open("back")

local ID = 237
local mon = peripheral.wrap('left')
term.redirect(mon) -- make term calls go to the monitor
term.clear()
term.setCursorPos(1,1)

while true do
  local event, rid, msg = os.pullEvent('rednet_message') -- wait here for a rednet message... reduces lag...

  if rid == ID then
	write(msg.." has entered the cave!")
  end
end
plazter #5
Posted 31 March 2013 - 10:28 PM
Thank you alot TheOriginalBit!!

you are just awesome! :D/>
theoriginalbit #6
Posted 31 March 2013 - 10:32 PM
no problems… :)/> If you have any questions about how the code functions (although it wasn't much different than yours) just ask :)/>
plazter #7
Posted 31 March 2013 - 10:33 PM
Uhm.. before i did all this it was only able for me and alternatelogic to enter the cave.. i just saw that my town mate could enter it aswell :o/>
theoriginalbit #8
Posted 31 March 2013 - 10:35 PM
whops… change this line

if player == 'Plazter' or 'AlternateLogic' then


to this


if player == 'Plazter' or player == 'AlternateLogic' then

that was an oversight on my part, sorry… would you like me to explain WHY this happened?
plazter #9
Posted 31 March 2013 - 10:39 PM
whops… change this line

if player == 'Plazter' or 'AlternateLogic' then


to this


if player == 'Plazter' or player == 'AlternateLogic' then

that was an oversight on my part, sorry… would you like me to explain WHY this happened?

the more i get to know the better i will get to ;p and just saw that the monitor aint clearing :P/>(EDIT: i found the mistake :P/>)
theoriginalbit #10
Posted 31 March 2013 - 10:43 PM
the more i get to know the better i will get to ;p and just saw that the monitor aint clearing :P/>
it should… oh you mean each time? I thought you might have liked a log :P/> just move those clear and setCursorPos back into the while loop. :)/>
plazter #11
Posted 31 March 2013 - 10:50 PM
i
the more i get to know the better i will get to ;p and just saw that the monitor aint clearing :P/>
it should… oh you mean each time? I thought you might have liked a log :P/> just move those clear and setCursorPos back into the while loop. :)/>
Would like to make a log but meh it looks stupid when it stands on the same line and such xD
theoriginalbit #12
Posted 31 March 2013 - 10:54 PM
Would like to make a log but meh it looks stupid when it stands on the same line and such xD
You could always do a log file.

to open a file

local handle = fs.open('someFile', 'w')

when your program starts up

handle.write('===== New Instance ::: Day: '..os.day()..' Time: '..textutils.formatTime(os.time())..' =====\n')
handle.flush() -- write changes to the file

then when you want to add a log to the file

handle.write('Day: '..os.day()..' Time: '..textutils.formatTime(os.time())..' '..player..' attempted to access cave!\n')
handle.flush() -- write changes to the file
plazter #13
Posted 31 March 2013 - 10:59 PM
Would like to make a log but meh it looks stupid when it stands on the same line and such xD
You could always do a log file.

to open a file

local handle = fs.open('someFile', 'w')

when your program starts up

handle.write('===== New Instance ::: Day: '..os.day()..' Time: '..textutils.formatTime(os.time())..' =====\n')
handle.flush() -- write changes to the file

then when you want to add a log to the file

handle.write('Day: '..os.day()..' Time: '..textutils.formatTime(os.time())..' '..player..' attempted to access cave!\n')
handle.flush() -- write changes to the file

Wow.. so in the mainprogram (the startup for monitor) would have that fs.open in the while loop?
and then i create a file called log and place it in file i assume? :b sorry aint the best at understanding those things :)/>
theoriginalbit #14
Posted 31 March 2013 - 11:34 PM
Wow.. so in the mainprogram (the startup for monitor) would have that fs.open in the while loop?
and then i create a file called log and place it in file i assume? :b sorry aint the best at understanding those things :)/>
Yeh kinda. you wouldn't want to open the file in the loop.

Something like this would do (rename 'someFile' to whatever you want the log file to be called)


rednet.open("back")

local ID = 237
local mon = peripheral.wrap('left')
local handle = fs.open('someFile', 'w')

local function log(msg)
  h.write(msg..'\n')
  h.flush()
end

term.redirect(mon) -- make term calls go to the monitor

log('===== New Instance ::: Day: '..os.day()..' Time: '..textutils.formatTime(os.time())..' =====')
while true do
  term.clear()
  term.setCursorPos(1,1)
  local event, rid, msg = os.pullEvent('rednet_message') -- wait here for a rednet message... reduces lag...

  if rid == ID then
	write(msg.." has entered the cave!")
	log('Day: '..os.day()..' Time: '..textutils.formatTime(os.time())..' '..msg..' attempted to access cave!')
  else
	log('Day: '..os.day()..' Time: '..textutils.formatTime(os.time())..' Invalid message from: '..rid..' with the contents: '..msg)
  end
end

Any questions just ask.

Also I suggest if you wish to know more have a read of the PIL for everything related to Lua and the ComputerCraft wiki and the 'help' menu in-game for everything ComputerCraft related… These resources are where I think everyone needs to start, sadly most don't even know they exist, I guess its something that being a professional programmer gives you, you know that some of the best sources is the documentation and you read it religiously…
plazter #15
Posted 01 April 2013 - 12:22 AM
Thanks bit :D/>
theoriginalbit #16
Posted 01 April 2013 - 12:29 AM
no problems. and good luck :)/>
jumpingjoran #17
Posted 01 April 2013 - 03:05 AM
Maybe its a noob question but how does rednet detect players?
theoriginalbit #18
Posted 01 April 2013 - 03:07 AM
Maybe its a noob question but how does rednet detect players?
It doesn't… rednet sends the name of the player. the script that detects the player uses this

local event, player = os.pullEventRaw('player')
which is a peripheral that adds a player detecter into the game. that is activated (queues a 'player' event) by distance or right-clicking or something like that. I haven't used it myself, but this is the second time I've seen scripts use it…
jumpingjoran #19
Posted 01 April 2013 - 03:15 AM
Nice this is handy for pvp if someone is coming near you :)/>
Do u maybe have time for coding something else for me if u want? :$
theoriginalbit #20
Posted 01 April 2013 - 03:18 AM
Nice this is handy for pvp if someone is coming near you :)/>
Or has entered your base. the other usage I saw was starting up a mob farm.

Do u maybe have time for coding something else for me if u want? :$
If it is a small program or you have some code already and just need a bug fixed… if the latter post a new thread and I will help you there, if the former send me a PM so this thread is not clogged up with unrelated discussion.
jumpingjoran #21
Posted 01 April 2013 - 03:20 AM
Nice this is handy for pvp if someone is coming near you :)/>
Or has entered your base. the other usage I saw was starting up a mob farm.

oah yeah!! thats handy!
i PM u :3
plazter #22
Posted 01 May 2013 - 04:35 PM
whops… change this line

if player == 'Plazter' or 'AlternateLogic' then


to this


if player == 'Plazter' or player == 'AlternateLogic' then

that was an oversight on my part, sorry… would you like me to explain WHY this happened?

the more i get to know the better i will get to ;p and just saw that the monitor aint clearing :P/>(EDIT: i found the mistake :P/>)

i've tryed this on another server, and it will only let me in, + i wish to add more ppl, is that just writeing them in before the last "=="?
plazter #23
Posted 01 May 2013 - 04:53 PM
Hello pro's!

As you can tell of the topic, i've hitted a wall, i cant limit the acces with my player detector with my code, the code i've had help with before, but now i dont want it to send a message to another just limit it, it's my old code, and should work, but for some reason, people without thier name in the list still can acces to the room the code is: http://pastebin.com/iUvyND1P

and the code for you to see here:

term.clear() term.setCursorPos(1,1)
while true do
--rednet.open("left")
event, p1 = os.pullEvent()

if event == "player" then
  if p1 == 'Plazter' or player == 'hybridanden' then
   -- if p1 == 'AlternateLogic' then
   --   rednet.send(240, 'alternatelogic')
    --  end
  --  if p1 == 'Plazter' then
    --  rednet.send(240, 'plaz')
    --  end
   -- if p1 ~= 'Plazter' or 'AlternateLogic' then
    --  rednet.send(240, 'unauthorized')
    --  end
print("Player: " .. p1 .. " entered!")
rs.setOutput("bottom", true)
sleep(2)
rs.setOutput("bottom", false)
else
print(p1 .." tryed to enter the plazter cave!!")
end
end
end

Any 1 that can tell me why this happen? :)/>

Regards Plazter.
Lyqyd #24
Posted 01 May 2013 - 05:11 PM
Threads merged. Stick to one topic for questions about the same piece of code/idea.
plazter #25
Posted 01 May 2013 - 05:23 PM
Sorry, will do, its ok to change the title right?
SuicidalSTDz #26
Posted 01 May 2013 - 05:27 PM
Starting a new thread would be better. This thread can be used as future reference when people search their question before posting a new topic, thus preventing non-needed threads. If you change the title, then the thread is thrown into chaos since it pertains to a multitude of problems.
plazter #27
Posted 01 May 2013 - 05:30 PM
Starting a new thread would be better. This thread can be used as future reference when people search their question before posting a new topic, thus preventing non-needed threads. If you change the title, then the thread is thrown into chaos since it pertains to a multitude of problems.

this thread has been merged by lyqyd :)/>
SuicidalSTDz #28
Posted 01 May 2013 - 05:33 PM
Oh, you made this thread.. If the new problem pertains to the original, then I see no problem in changing the title.
theoriginalbit #29
Posted 02 May 2013 - 12:26 AM
i've tryed this on another server, and it will only let me in, + i wish to add more ppl, is that just writeing them in before the last "=="?
Hello pro's!

As you can tell of the topic, i've hitted a wall, i cant limit the acces with my player detector with my code, the code i've had help with before, but now i dont want it to send a message to another just limit it, it's my old code, and should work, but for some reason, people without thier name in the list still can acces to the room the code is: http://pastebin.com/iUvyND1P

and the code for you to see here:
-snip-

Any 1 that can tell me why this happen? :)/>

Regards Plazter.
Hmmm. Not too sure why, it should work fine… except that hybridanden would not be able to access due to you have player == 'hybridanden' instead of p1 == 'hybridanden' which is why only you can get in.
If you want to add more people to the list I suggest using this code, it makes it easier for you to add people in as you add their username to the table at the top of the code (add the name in lowercase)
Code: http://pastebin.com/cbePTK7b
plazter #30
Posted 02 May 2013 - 07:17 AM
i've tryed this on another server, and it will only let me in, + i wish to add more ppl, is that just writeing them in before the last "=="?
Hello pro's!

As you can tell of the topic, i've hitted a wall, i cant limit the acces with my player detector with my code, the code i've had help with before, but now i dont want it to send a message to another just limit it, it's my old code, and should work, but for some reason, people without thier name in the list still can acces to the room the code is: http://pastebin.com/iUvyND1P

and the code for you to see here:
-snip-

Any 1 that can tell me why this happen? :)/>

Regards Plazter.
Hmmm. Not too sure why, it should work fine… except that hybridanden would not be able to access due to you have player == 'hybridanden' instead of p1 == 'hybridanden' which is why only you can get in.
If you want to add more people to the list I suggest using this code, it makes it easier for you to add people in as you add their username to the table at the top of the code (add the name in lowercase)
Code: http://pastebin.com/cbePTK7b


- Wow bit, i will use that thanks man :D/>
theoriginalbit #31
Posted 02 May 2013 - 07:23 AM
- Wow bit, i will use that thanks man :D/>
No problems.
plazter #32
Posted 02 May 2013 - 07:36 AM
Uhm, error in line 20 tryed to "–" all the log things now it says error in line 22 oO


EDIT: Me being stupid, forgot a disk and that :P/>
theoriginalbit #33
Posted 02 May 2013 - 07:42 AM
EDIT: Me being stupid, forgot a disk and that :P/>
You could always just change the path it writes to, that was just an example path
plazter #34
Posted 02 May 2013 - 07:55 AM
yeah i could, but it works perfectly now :D/> Thanks :D/>