Looping
#1

Hey there I need help fast, so I was making a code like if players is from specific country he will not be able to join server (kicked). That countries are added with in-game cmd and saved in file, and loaded when server is started again. But my problem is this: I haven`t added any countries yet but no matter what country player is from he will be kicked, this is my code (I checked getting player`s country few times and its working perfectly (geolocation.inc))

Code:
	static country[50];
	GetPlayerCountry(playerid, country, sizeof(country));
	
	for(new i = 0; i < 200; i++)
       {
		if(!strcmp(country, vpncountry[i]))
		{
			hasvpn[playerid] = 1;
  		}
	}
	if(hasvpn[playerid] == 1)
	{
	        new stringaa[100];
	        format(stringaa, sizeof(stringaa), "--- Anti VPN ---  %s is kicked because of VPN", GetName(playerid));
	        printf(stringaa);
	        kick[playerid] = SetTimerEx("Kick", 1000, 0, "d", playerid);
	}
This code in under OnPlayerConnect. I could show loading and saving that countries list but and I haven`t added any of them but Iam still getting kicked.
Reply
#2

Code:
	static country[50];
	GetPlayerCountry(playerid, country, sizeof(country));
	printf("Player Country: %s",country);
	for(new i = 0; i < sizeof(vpncountry); i++)
       {
		if(!strcmp(country, vpncountry[i]) && !isnull(vpncountry[i]))
		{
                   printf("match (vpn country: %s)", vpncountry[i]);
	           new stringaa[100];
	           format(stringaa, sizeof(stringaa), "--- Anti VPN ---  %s is kicked because of VPN", GetName(playerid));
	           printf(stringaa);
	           kick[playerid] = SetTimerEx("Kick", 1000, 0, "d", playerid);
                   break;
  		}
	}
Paste the results.
Reply
#3

Comparing against an empty string will return 0.

pawn Code:
if(!isnull(vpncountry[i]) && !strcmp(country, vpncountry[i]))
If you ever change the size of `vpncountry` and not remember to change the value in the loop, it will throw a run time error. But if the file is empty, why loop at all? Read from the file and have a global variable as a counter. Then use this counter instead of < 200

If you kick directly, what is the point to store in player-array to begin with?
Reply
#4

Quote:
Originally Posted by Calisthenics
View Post
Comparing against an empty string will return 0.

pawn Code:
if(!isnull(vpncountry[i]) && !strcmp(country, vpncountry[i]))
If you ever change the size of `vpncountry` and not remember to change the value in the loop, it will throw a run time error. But if the file is empty, why loop at all? Read from the file and have a global variable as a counter. Then use this counter instead of < 200

If you kick directly, what is the point to store in player-array to begin with?
Omg I was just wondering how to check is that string empty, thank you
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)