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

[Command computers] Get player table from @a

Started by Goof, 10 April 2015 - 08:22 PM
Goof #1
Posted 10 April 2015 - 10:22 PM
Hey!

me and some friends are testing the command computers, and tried to gather a table of players nearby, by using some command, and "@a[r=5]" – all players within 5 blocks from the computer…


But this just returned:

true
{}

Any solutions?


Thanks in Advance
MKlegoman357 #2
Posted 10 April 2015 - 10:47 PM
Dynamically getting a player list is sadly impossible by Command Computers.

EDIT: looks like it is possible, look below for the answer.
Edited on 11 April 2015 - 07:12 AM
HPWebcamAble #3
Posted 10 April 2015 - 10:52 PM
What command did you use?


Dynamically getting a player list is sadly impossible by Command Computers.

Well… It isn't impossible, but my solution isn't very elegant

You can run this command:

commands.exec("tp @a ~ ~ ~")

It should return true, then a table in this format:

{
  "Teleported player to x.0, y.0, z.0",
  "Teleported player2 to x.0, y.0, z.0",
  ect
}

You should be able to use a Lua pattern to get the player from each entry

If you use ~ ~ ~ as the location, it SHOULDN'T move the player, but your screen does jiggle a bit in 1.7, its fixed in MC 1.8

I was trying things like 'tellraw', but I think /tp is one of they only commands that gives you the names
Goof #4
Posted 10 April 2015 - 11:16 PM
well I just found out, that the "tell @a[r=5] @a[r=5]" actually Does return player names…
And then it just needs to be formatted into a table, and then its done!

This question is solved.
but.
Another question is revealed:
Is it possible to use /tell [computercraft] @a[r=5]
instead of spamming the players within 5 blocks?

like a 'fake-player'
?
HPWebcamAble #5
Posted 11 April 2015 - 12:21 AM
Thats why I used /tp, it doesn't output anything to other players
MKlegoman357 #6
Posted 11 April 2015 - 09:11 AM
-snip-

That's actually quite smart, didn't realize that some commands return player names..

well I just found out, that the "tell @a[r=5] @a[r=5]" actually Does return player names…
And then it just needs to be formatted into a table, and then its done!

This question is solved.
but.
Another question is revealed:
Is it possible to use /tell [computercraft] @a[r=5]
instead of spamming the players within 5 blocks?

like a 'fake-player'
?

I think Turtles were able to 'act' like fake-players, well at least bukkit permission plugins could forbid a turtle to place blocks. I think it was called '[ComputerCraft]'.
MKlegoman357 #7
Posted 11 April 2015 - 09:53 AM
I found that by using 'xp 0 @a' might actually return the player list without affecting anything. I only tested on SSP so I don't know what are the exact returns in a multi-player environment. Also, it shows the result for OPs if the gamerule 'commandBlockOutput' is set to true which can be quite annoying.
ItsRodrick #8
Posted 11 April 2015 - 03:43 PM
testfor @a[r=5] may work

(Mikkel, I remembered it when I was going to sleep xD)
HPWebcamAble #9
Posted 11 April 2015 - 04:44 PM
testfor @a[r=5] may work

(Mikkel, I remembered it when I was going to sleep xD)

I actually thought about that before and decided it wouldn't work

It does work :D/>
In 1.8 it returns 'Found player1 and player2 ect'

In 1.7 PLAYERS can't run it, but I'm pretty sure command blocks can


Nevermind, looks like we'll have to wait for 1.8 to use /testfor
Edited on 11 April 2015 - 08:58 PM
Wojbie #10
Posted 11 April 2015 - 10:12 PM
Sorry in 1.7 testfor on command computers returns only true/false and nothing in chat return. Can't get player list that way.