Locating a player's location.

Hey guys,

I’m trying to find a method of locating the players geometric location, for e.g. if they join the server from Australia it returns a value of Australia. Are there any binary modules or lua functions that can be of help? thanks in advance.

Here ya go

http://forum.facepunch.com/showthread.php?t=969950

^ thank you very much mate :slight_smile:

If you don’t want to use a module you can do something like this:

[lua]
local address = players ip
http.Get(‘http://freegeoip.net/json/’ … address, ‘’, function(contents, size)
local country = string.match(contents, regex )
end )
[/lua]

This obviously isn’t executable code. You’ll have to grab the players ip in the first line and then find a regex that will pull the country_name from the contents.

Here’s an example of what the site generates based on ip.
“{“city”: “Mountain View”, “region_code”: “CA”, “region_name”: “California”, “metrocode”: “807”, “zipcode”: “94043”, “longitude”: “-122.057”, “latitude”: “37.4192”, “country_code”: “US”, “ip”: “64.233.191.255”, “country_name”: “United States”}”

So you can see that it is pretty well laid out and it is possible to get a regex to grab the country_name information.

Here’s a little pattern that should grab it.

“country_name”:"(.-)"}