Loop mistake. - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Loop mistake. (
/showthread.php?tid=493378)
Loop mistake. -
Jimmy0wns - 08.02.2014
So, i've been trying to make an anti-cheat, currently at the RCON Login attempt, but instead of banning the player once, it bans him 50 times.
This is my code & loop:
pawn Код:
public OnRconLoginAttempt(ip[], password[], success)
{
if(!success)
{
new pip[24];
for(new i; i<MAX_PLAYERS; i++) //Loop through all players
{
GetPlayerIp(i, pip, sizeof(pip));
if(!strcmp(ip, pip, true)) //If a player's IP is the IP that failed the login
{
BanUser(i, "RCON Login Attempt", "Aaron");
}
}
}
return 1;
}
Re: Loop mistake. -
RajatPawar - 08.02.2014
You need to use a
'break' to break out of a loop.
The following code would work -
pawn Код:
public OnRconLoginAttempt(ip[], password[], success)
{
if(!success)
{
new pip[17];
for(new i; i<MAX_PLAYERS; i++) //Loop through all players
{
GetPlayerIp(i, pip, sizeof(pip));
if(!strcmp(ip, pip, true)) //If a player's IP is the IP that failed the login
{
BanUser(i, "RCON Login Attempt", "Aaron");
break;
}
}
}
return 1;
}
Secondly, a minor change, IPs are generally of 16 chars!
Re: Loop mistake. -
Jimmy0wns - 08.02.2014
Quote:
Originally Posted by Rajat_Pawar
You need to use a 'break' to break out of a loop.
The following code would work -
pawn Код:
public OnRconLoginAttempt(ip[], password[], success) { if(!success) { new pip[17]; for(new i; i<MAX_PLAYERS; i++) //Loop through all players { GetPlayerIp(i, pip, sizeof(pip)); if(!strcmp(ip, pip, true)) //If a player's IP is the IP that failed the login { BanUser(i, "RCON Login Attempt", "Aaron"); break; } } } return 1; }
Secondly, a minor change, IPs are generally of 16 chars!
|
Someone else helped me already, but thanks anyways!