String formating -
ajwar - 01.11.2013
pawn Код:
stock GeoIPLookFor(playerid)
{
new str[64],ip[16];
GetPlayerIp(playerid,ip,sizeof(ip));
format(str,64,"http://api.hostip.info/get_html.php?ip=%s",ip);
HTTP(playerid,HTTP_GET,str,"","GeoIPLookingFor");
return 1;
}
website returns:
Country: UNITED STATES (US)
City: Aurora, TX
IP: 12.215.42.19
pawn Код:
public GeoIPLookingFor(playerid, response_code, data[])
{
SetPVarString(playerid,"Player_Country",country);
return 1;
}
How could i make the Player_Country variable return 'UNITED STATES (US)'?
Re: String formating -
Konstantinos - 01.11.2013
It should work:
pawn Код:
public GeoIPLookingFor( playerid, response_code, data[ ] )
{
new
sz_Country[ 32 ]
;
strmid( sz_Country, data, 9, strfind( data, "City:", false ) - 1 );
SetPVarString( playerid, "Player_Country", sz_Country );
return 1;
}
Re: String formating -
ajwar - 01.11.2013
I use now
pawn Код:
stock GeoIPLookFor(playerid)
{
new str[64],ip[16];
GetPlayerIp(playerid,ip,sizeof(ip));
format(str,64,"api.hostip.info/get_html.php?ip=%s",ip);
HTTP(playerid,HTTP_GET,str,"","GeoIPLookingFor");
return 1;
}
public GeoIPLookingFor( playerid, response_code, data[ ] )
{
new
sz_Country[ 32 ]
;
strmid( sz_Country, data, 9, strfind( data, "City:", false ) - 1 );
SetPVarString( playerid, "Player_Country", sz_Country );
PlayerCountry[playerid] = sz_Country;
SendClientMessage(playerid,-1, sz_Country);
return 1;
}
Line: SendClientMessage(playerid,-1, sz_Country); returns correctly, but the variable Player_Country returns nothing when i use it on OnPlayerConnect.
pawn Код:
GeoIPLookFor(playerid);
new pmsg[128];
GetPVarString(playerid, "Player_Country", pmsg, 128);// Get the msg string from the PVar
printf("Country: %s", pmsg);// will print 'Player Message: *message*'
[13:49:04] Country:
Any ideas?
Re: String formating -
Konstantinos - 01.11.2013
What's the point of storing the country to both PVar and variable? One would be better.
Anyways, use either:
pawn Код:
public GeoIPLookingFor( playerid, response_code, data[ ] )
{
strmid( PlayerCountry[ playerid ], data, 9, strfind( data, "City:", false ) - 1 );
SetPVarString( playerid, "Player_Country", PlayerCountry[ playerid ] );
return 1;
}
Or:
pawn Код:
public GeoIPLookingFor( playerid, response_code, data[ ] )
{
new
sz_Country[ 32 ]
;
strmid( sz_Country, data, 9, strfind( data, "City:", false ) - 1 );
SetPVarString( playerid, "Player_Country", sz_Country );
strcat( ( PlayerCountry[ playerid ][ 0 ] = '\0', PlayerCountry[ playerid ] ), sz_Country, 32 );
return 1;
}
However, it might fail to show the country in-time due to the time is needed for the HTTP to get the data and call GeoIPLookingFor.