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

Is There a Way To Get The Coordinates of a Player?

Started by jjjhfam, 18 June 2015 - 06:46 PM
jjjhfam #1
Posted 18 June 2015 - 08:46 PM
More JARVIS fun. I want my JARVIS AI to send a message when I die and tell me where I was. Is it possible to get the coordinates of a player through ComputerCraft or another mod that interfaces with ComputerCraft?
SquidDev #2
Posted 18 June 2015 - 08:58 PM
It depends. You can use pocket computers and a GPS relay to track your position, a smaller range alternative would be to use OpenCCSensors' player sensor to track the position.
InDieTasten #3
Posted 18 June 2015 - 09:24 PM
#CommandComputer
jjjhfam #4
Posted 18 June 2015 - 10:41 PM
I've never used any of those suggestions. Could I get a summary of how I would have to use each one and/or your personal preference?
HPWebcamAble #5
Posted 19 June 2015 - 12:54 AM
Well, for a command computer, you can use this function:


function getPlayerPos(name)
  local state,result = commands.exec("/tp "..name.." ~ ~ ~")
  if not state then return false end
  return result[1]:match( "Teleported %S+ to (%d+%.?%d*),(%d+%.?%d*),(%d+%.?%d*)" )
end

It just takes advantage of the fact that running '/tp' says in chat 'teleported <player> to <location>'
KingofGamesYami #6
Posted 19 June 2015 - 01:37 AM
One thing to keep in mind when using HPWebcamAble's suggestion, the player will notice themselves being teleported - especially if you do it rapidly. It's fine if you get their position once per second, but higher than that is annoying.