24.06.2014, 20:16
(
Last edited by Emmet_; 22/03/2015 at 03:02 PM.
)
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:
"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:
The functions will only work after the lookup is complete.
Test script
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
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>
pawn Code:
public OnLookupComplete(playerid, country[], region[], city[])
{
return 1;
}
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));
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;
}
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