Thread: [Include] Player country lookup
View Single Post
Old 24/06/2014, 08:16 PM   #1
Emmet_
Guest
 
Posts: n/a
Default Player country lookup

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

Last edited by Emmet_; 22/03/2015 at 03:02 PM.
  Reply With Quote