72 posts
Posted 05 April 2015 - 03:04 AM
hello i am trying to find out if this is possible i have a command i am using on the new command computers. not sure if it is a mod adding this command or vanilla but its a gps command it gives out a long string of info as follows {success player name found at x y z } is there a way to get just the player name and gps data from that output. the command is commands.exec("gps @p") which might be added with forge essentials
3057 posts
Location
United States of America
Posted 05 April 2015 - 04:57 AM
Could you provide an exact result? This is possible to do with patterns, but they are very picky. For example, are there commas between x, y, and z? If so, are there spaces? Does it return decimals? I could go on, but it's much easier if you simply post the output of the command. As in run it, copy/paste result here.
If you wish to attempt this yourself, you'll want to use the string.match function, which is well documented. You'll also need to understand patterns to an extent, which can be a little hard to understand.
72 posts
Posted 05 April 2015 - 07:50 AM
commands.exec("gps @p")
returns
{
"SUCCESS: username is at x, y, z in dim 0 with gamemode creative",
}
1023 posts
Posted 05 April 2015 - 08:41 AM
Just showing this is possible without using actual lua patterns or string.match.
text = commands.exec("gps @p")
player = text:sub(10, ({text:find(" is at")})[1]-1)
x = text:sub(({text:find(" is at ")})[2]+1,({text:find(",")})[1]-1)
text = text:sub(({text:find(",")})[1]+2,#text)
y = text:sub(1,({text:find(",")})[1]-1)
text = text:sub(({text:find(",")})[1]+2,#text)
z = text:sub(1,({text:find(" in dim ")})[1]-1)
As a side note patterns are probably much much better than this… lol. I was just bored and felt like throwing this together.
Edited on 05 April 2015 - 06:46 AM
3057 posts
Location
United States of America
Posted 05 April 2015 - 01:30 PM
local str = "SUCCESS: username is at x, y, z in dim 0 with gamemode creative"
local user, x, y, z = str:match( "SUCCESS: (%S+) is at (%d+), (%d+), (%d+)" )
note: This will break if x, y, z are decimal values.
Edited on 05 April 2015 - 11:30 AM
72 posts
Posted 05 April 2015 - 04:34 PM
so far as i have seen it only gives whole values
72 posts
Posted 05 April 2015 - 04:55 PM
found out it returns two values the true/false then the table so the code looks like so
bul,str=commands.exec("gps @p")
local user, x, y, z = textutils.serialize(str):match( "SUCCESS: (%S+) is at (%d+), (%d+), (%d+)" )
and it works like a charm now to use it in a table to track users and there gps so long as it is a new user or there gps positions have changed
Edited on 05 April 2015 - 02:56 PM