Player country lookup - Emmet_ - 24.06.2014
Player country lookup
This include uses
this API service to retrieve a player's country, city and region name. There are no external databases required, just plug-n-play!
Usage
Simply include it at the top of your script:
And then use the following callback:
pawn Code:
public OnLookupComplete(playerid, country[], region[], city[])
{
return 1;
}
"country" is the player's country, and "city" is the player's city. "region" differs from country (in USA, it would be the state, in Canada it would be the province, etc).
There are also 3 functions:
pawn Code:
forward GetPlayerCountry(playerid, country[], size = sizeof(country));
forward GetPlayerRegion(playerid, region[], size = sizeof(region));
forward GetPlayerCity(playerid, city[], size = sizeof(city));
The functions will only work after the lookup is complete.
Test script
pawn Code:
#include <a_samp>
#include <country>
public OnLookupComplete(playerid, country[], region[], city[])
{
new
string[128];
format(string, sizeof(string), "Hello there, you're from \"%s\" and currently live in \"%s\".", country, city);
SendClientMessage(playerid, 0xFFFFFFFF, string);
return 1;
}
Works under any operating system (doesn't work for localhost).
Accuracy
I am not sure about the accuracy, but it seemed to be very accurate when I was running it on my public server. The lookup will not be conducted if the player is running on localhost, or if the IP is unknown.
I highly doubt that the site will become unavailable any time soon, since I've been using it for years without any issues. If I absolutely need to, I'll host it under my own domain.
Download
Pastebin
Re: Player country lookup -
Pottus - 24.06.2014
Will be useful for a lot of people but I have a suggestion for you next include, integrate the radio yellow pages.
http://dir.xiph.org/yp.xml
Re: Player country lookup -
PT - 24.06.2014
Nice, i recommend to next update the function:
pawn Code:
native IsProxyIP(playerid);
Re: Player country lookup -
iRaiDeN - 25.06.2014
Upload to pastebin..
Respuesta: Player country lookup -
Swedky - 25.06.2014
LoLz nice

I'll use this in my public server
Re: Player country lookup -
Excel™ - 27.06.2014
Nice!
Is it possible to get player time zone ??
Re: Player country lookup - Emmet_ - 28.06.2014
Pastebin, cause I said so.
http://pastebin.com/V6ekVfFj
Quote:
Originally Posted by Excel™
Nice!
Is it possible to get player time zone ??
|
There is a possible method, but it would require additional code.
Re: Player country lookup -
iFarbod - 28.06.2014
Nice one,
Emmet_. No need using GeoIP And that databases for uploading!
Re: Player country lookup -
Crayder - 01.10.2014
Hmm, now to implement a time system that goes by a players location!
EDIT: Please merge, double posted!
Re: Player country lookup -
Crayder - 01.10.2014
Emmet, this is more correct, yours got my location wrong! Tested a few ips, found another one that was incorrect too...
Re: Player country lookup - Emmet_ - 01.10.2014
Quote:
Originally Posted by Crayder
Emmet, this is more correct, yours got my location wrong! Tested a few ips, found another one that was incorrect too...
|
City/region detection might be a little off, did it return the correct country?
Re: Player country lookup -
PinEvil - 01.10.2014
I like it, I'll use it for my up-coming server!
Re: Player country lookup -
Crayder - 02.10.2014
Quote:
Originally Posted by Emmet_
City/region detection might be a little off, did it return the correct country?
|
Yea it returns the right state on most of them, I ran about 50, only 4 had the wrong us state, all ip's were from US only...
BTW, do you plan on making any type of GMT returns for this, or do you think you can help me find an api that returns the gmt?
EDIT: Found this, but it would require each server owner to register :/, I found a few more but most have very low limts, ******'s API has a limit of 2500 queries per day which would be ok if we saved each players timezone and didnt send queries each time they connect...
Re : Player country lookup -
streetpeace - 03.10.2014
It doesn't work for me, Country : Unknown, City and Region : Unknown.
Re: Re : Player country lookup -
Neil. - 07.10.2014
Quote:
Originally Posted by streetpeace
It doesn't work for me, Country : Unknown, City and Region : Unknown.
|
On first post:
Quote:
The lookup will not be conducted if the player is running on localhost, or if the IP is unknown.
|
It's practically the same on my side where everything on the lookup returns an 'Unknown' when hosting it locally.
Re: Player country lookup -
daniscape - 08.10.2014
Good job like allways emmet! Also great work on the infinity gaming's script unfornatly alex closed down but ye the script was awesome
Re: Player country lookup -
Kar - 22.03.2015
Private Paste ID: rScAHfWC
This is a private paste. If you created this paste, please login to view it.
Re: Player country lookup - Emmet_ - 22.03.2015
Updated! Please re-download as I've fixed a few bugs.
This include will not work on older versions due to an update in the API.
Quote:
Originally Posted by Kar
Private Paste ID: rScAHfWC
This is a private paste. If you created this paste, please login to view it.
|
Fixed. I actually thought that Private pastes were viewable only for those who had the link. Sorry haha.
Re: Player country lookup -
Crayder - 22.03.2015
Now we're back!
I think you should add the "country_code" to this.
Re: Player country lookup - Emmet_ - 22.03.2015
Country code would be useful too. I could also add conversion functions, e.g:
pawn Code:
country = GetCountryName(COUNTRY_US);
print(country);
Would output:
Country codes can also save space. I can store the country code instead of the full country name.