Jump to content




OpenPeripherals Sensor Player Data

peripheral computer

1 reply to this topic

#1 HandieAndy

  • New Members
  • 2 posts

Posted 15 November 2016 - 11:29 AM

So, as the title suggests, I am trying to detect players around a sensor, and retrieve the name and relative position of the player. However, I am having a bit of trouble with the sensor's
getPlayers()
and
getPlayerByName()
functions. I use the first to get the list of players, but because of testing, I can just index the first element, as there will be only one player, which works out fine. Then I use that name in the second function to try to get some more precise information about that player, but this function just returns a table of functions as elements, as I have found by trying to print the keys and values. Here's the exact test code I have:
local p = peripheral.wrap("back")

local name = p.getPlayers()[1].name
local data = p.getPlayerByName(name)

for i in pairs(data) do
  print(i)
end
The problem is, the output of that snippet is this:
listSources
getAdvancedMethodsData
all
listMethods
doc
keys
basic
select
single
How do I go from this list of methods to getting the relative position of the player, if I know their name?

#2 HandieAndy

  • New Members
  • 2 posts

Posted 15 November 2016 - 06:44 PM

Actually, I found the answer to this. For anyone who might stumble across this later, to access the position data, simply get the table with
p.getPlayerByName(name).all().position






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users