SA-MP Forums

SA-MP Forums (https://forum.sa-mp.com/index.php)
-   Includes (https://forum.sa-mp.com/forumdisplay.php?f=83)
-   -   [Include] Player country lookup (https://forum.sa-mp.com/showthread.php?t=521843)

Emmet_ 24/06/2014 08:16 PM

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

Pottus 24/06/2014 08:32 PM

Re: Player country lookup
 
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

PT 24/06/2014 09:17 PM

Re: Player country lookup
 
Nice, i recommend to next update the function:

pawn Code:
native IsProxyIP(playerid);

iRaiDeN 25/06/2014 07:10 AM

Re: Player country lookup
 
Upload to pastebin..

Swedky 25/06/2014 05:05 PM

Respuesta: Player country lookup
 
LoLz nice :) I'll use this in my public server :rolleyes:

Excel™ 27/06/2014 04:06 AM

Re: Player country lookup
 
Nice!
Is it possible to get player time zone ??

Emmet_ 28/06/2014 12:56 AM

Re: Player country lookup
 
Pastebin, cause I said so.

http://pastebin.com/V6ekVfFj

Quote:

Originally Posted by Excel™ (Post 3097215)
Nice!
Is it possible to get player time zone ??

There is a possible method, but it would require additional code.

iFarbod 28/06/2014 06:03 AM

Re: Player country lookup
 
Nice one, Emmet_. No need using GeoIP And that databases for uploading!

Crayder 01/10/2014 09:35 PM

Re: Player country lookup
 
Hmm, now to implement a time system that goes by a players location!

EDIT: Please merge, double posted!

Crayder 01/10/2014 09:46 PM

Re: Player country lookup
 
Emmet, this is more correct, yours got my location wrong! Tested a few ips, found another one that was incorrect too...


All times are GMT. The time now is 12:06 PM.

Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.