[Include] Player country lookup
#1

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:

pawn Code:
#include <country>
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
Reply
#2

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
Reply
#3

Nice, i recommend to next update the function:

pawn Code:
native IsProxyIP(playerid);
Reply
#4

Upload to pastebin..
Reply
#5

LoLz nice I'll use this in my public server
Reply
#6

Nice!
Is it possible to get player time zone ??
Reply
#7

Pastebin, cause I said so.

http://pastebin.com/V6ekVfFj

Quote:
Originally Posted by Excel™
View Post
Nice!
Is it possible to get player time zone ??
There is a possible method, but it would require additional code.
Reply
#8

Nice one, Emmet_. No need using GeoIP And that databases for uploading!
Reply
#9

Hmm, now to implement a time system that goes by a players location!

EDIT: Please merge, double posted!
Reply
#10

Emmet, this is more correct, yours got my location wrong! Tested a few ips, found another one that was incorrect too...
Reply
#11

Quote:
Originally Posted by Crayder
View Post
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?
Reply
#12

I like it, I'll use it for my up-coming server!
Reply
#13

Quote:
Originally Posted by Emmet_
View Post
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...
Reply
#14

It doesn't work for me, Country : Unknown, City and Region : Unknown.
Reply
#15

Quote:
Originally Posted by streetpeace
View Post
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.
Reply
#16

Good job like allways emmet! Also great work on the infinity gaming's script unfornatly alex closed down but ye the script was awesome
Reply
#17

Private Paste ID: rScAHfWC
This is a private paste. If you created this paste, please login to view it.
Reply
#18

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
View Post
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.
Reply
#19

Now we're back!

I think you should add the "country_code" to this.
Reply
#20

Country code would be useful too. I could also add conversion functions, e.g:

pawn Code:
country = GetCountryName(COUNTRY_US);

print(country);
Would output:

Code:
United States
Country codes can also save space. I can store the country code instead of the full country name.
Reply


Forum Jump:


Users browsing this thread: