Jump to content




[Command computers] Get player table from @a

command

9 replies to this topic

#1 Goof

  • Members
  • 751 posts

Posted 10 April 2015 - 09: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

#2 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

Posted 10 April 2015 - 09: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 by MKlegoman357, 11 April 2015 - 08:12 AM.


#3 HPWebcamAble

  • Members
  • 933 posts
  • LocationWeb Development

Posted 10 April 2015 - 09:52 PM

What command did you use?


View PostMKlegoman357, on 10 April 2015 - 09:47 PM, said:

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

#4 Goof

  • Members
  • 751 posts

Posted 10 April 2015 - 10: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'
?

#5 HPWebcamAble

  • Members
  • 933 posts
  • LocationWeb Development

Posted 10 April 2015 - 11:21 PM

Thats why I used /tp, it doesn't output anything to other players

#6 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

Posted 11 April 2015 - 08:11 AM

View PostHPWebcamAble, on 10 April 2015 - 09:52 PM, said:

-snip-

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

View PostMikk809h, on 10 April 2015 - 10:16 PM, said:

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]'.

#7 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

Posted 11 April 2015 - 08: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.

#8 ItsRodrick

  • Members
  • 72 posts
  • Location= gps.locate() or "unknown"

Posted 11 April 2015 - 02:43 PM

testfor @a[r=5] may work

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

#9 HPWebcamAble

  • Members
  • 933 posts
  • LocationWeb Development

Posted 11 April 2015 - 03:44 PM

View PostRodrickLord, on 11 April 2015 - 02:43 PM, said:

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 by HPWebcamAble, 11 April 2015 - 09:58 PM.


#10 Wojbie

  • Members
  • 631 posts
  • LocationKinda lost

Posted 11 April 2015 - 09: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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users