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


^ thank you very much mate :slight_smile:

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

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

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”: “”, “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.