SA-MP Forums Archive
loop not working for id 0 - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: loop not working for id 0 (/showthread.php?tid=78050)



loop not working for id 0 - StrickenKid - 16.05.2009

im making a /ignore command, and it the ignore list doesn't work for id 0 but every other id (already tested)

any help?

pawn Код:
if(strcmp(cmdtext, "/ignorelist",true) == 0 || strcmp(cmdtext, "/il",true) == 0)
    {
        SendClientMessage(playerid, 0x2641FEAA, "Ignoring:");
       
        for(new i=0; i<MAX_PLAYERS; i++)
        {
          if(MyIgnoredPlayers[playerid][i] >= 1)
            {
              GetPlayerName(i,playername,sizeof(playername));
              format(string, sizeof(string), "%s (%d)", playername, i);
              SendClientMessage(playerid, 0xFFFFFFAA, string);
                return 1;
            }
            else
            {
              SendClientMessage(playerid, COLOR_RED, "No One.");
              return 1;
            }
        }
      return 1;
    }



Re: loop not working for id 0 - Weirdosport - 16.05.2009

return 1; breaks the loop permanently, you need to use continue; or not use anything at all.

EDIT: But for else you'll still want to use return 1;


Re: loop not working for id 0 - MenaceX^ - 16.05.2009

pawn Код:
if(!strcmp(cmdtext,"/il",true)||!strcmp(cmdtext,"/ignorelist",true))
{
  new count=0;
  for(new i=0;i<MAX_PLAYERS;i++)
  {
    if(MyIgnoredPlayers[playerid][i] >= 1)
    {
      count++;
      GetPlayerName(i,playername,sizeof(playername));
      format(string, sizeof(string), "%s (%d)", playername, i);
      SendClientMessage(playerid, 0xFFFFFFAA, string);
    }
    else SendClientMessage(playerid, COLOR_RED, "No One.");
  }
  if(!count) return SendClientMessage(playerid, COLOR_RED, "No One.");
  return true;
}



Re: loop not working for id 0 - StrickenKid - 16.05.2009

^^ that just spamms "No One."


Re: loop not working for id 0 - MenaceX^ - 16.05.2009

My bad, it checks 200 times if someone is blocked, so it probably sent 200 messages of "None".
pawn Код:
if(!strcmp(cmdtext,"/il",true)||!strcmp(cmdtext,"/ignorelist",true))
{
  new count=0;
  for(new i=0;i<MAX_PLAYERS;i++)
  {
    if(MyIgnoredPlayers[playerid][i] >= 1)
    {
      count++;
      GetPlayerName(i,playername,sizeof(playername));
      format(string, sizeof(string), "%s (%d)", playername, i);
      SendClientMessage(playerid, 0xFFFFFFAA, string);
    }
  }
  if(!count) return SendClientMessage(playerid, COLOR_RED, "No One.");
  return true;
}



Re: loop not working for id 0 - Weirdosport - 16.05.2009

Or:

pawn Код:
if(!strcmp(cmdtext,"/il",true)||!strcmp(cmdtext,"/ignorelist",true))
{
  new count=0;
  for(new i=0;i<MAX_PLAYERS;i++)
  {
    if(MyIgnoredPlayers[playerid][i] >= 1)
    {
      GetPlayerName(i,playername,sizeof(playername));
      format(string, sizeof(string), "%s (%d)", playername, i);
      SendClientMessage(playerid, 0xFFFFFFAA, string);
    }
    else
    {
      SendClientMessage(playerid, COLOR_RED, "No One.");
      return 1;
    }
  }
  return 1;
}
The advantage being that it doesn't change a variable 200 times.


Re: loop not working for id 0 - Jefff - 16.05.2009

Код:
if(!strcmp(cmdtext, "/ignorelist",true) || !strcmp(cmdtext, "/il",true))
{
	SendClientMessage(playerid, 0x2641FEAA, "Ignoring:");
	new count;
	for(new i=0; i<GetMaxPlayers(); i++)
	{
		if(MyIgnoredPlayers[playerid][i] >= 1)
		{
			GetPlayerName(i,playername,sizeof(playername));
			format(string, sizeof(string), "%s (%d)", playername, i);
			SendClientMessage(playerid, 0xFFFFFFAA, string);
			count++;
		}
	}
	if(!count) SendClientMessage(playerid, COLOR_RED, "No One.");
	return 1;
}



Re: loop not working for id 0 - [eLg]Timmy - 16.05.2009

pawn Код:
if(!strcmp(cmdtext,"/ignorelist",true)||!strcmp(cmdtext,"/il",true))
{
  new count;
  SendClientMessage(playerid, 0xFFFFFFAA, "Ignoring:");
  for(new i=0;i<GetMaxPlayers();i++){
     if(MaxIgnoredPlayers[playerid][i] >= 1){
       if(count == 0) count = 1;
       GetPlayerName(i, playername, sizeof playername);
       format(string, sizeof string, "%s (%i)", playername, i);
       SendClientMessage(playerid, 0xFFFFFFAA, string);
     }
  }
  if(count == 0) SendClientMessage(playerid, 0xFFFFFFAA, "No one.");
  return true;
}
Then the variable only changes 1 time.



Re: loop not working for id 0 - Weirdosport - 16.05.2009

Why involve a variable at all? My solution = no variable necessary, and it's most in keeping with what he originally posted..


Re: loop not working for id 0 - Nero_3D - 16.05.2009

Quote:
Originally Posted by Weirdosport
Why involve a variable at all? My solution = no variable necessary, and it's most in keeping with what he originally posted..
Your code will stop after the first person which dont gets by the player ignored!

TimmehBoy's code use and extra if check and Jefff's code a always raising variable both should be on the same level

Here my solution, I use an already existing variable which need to be used and dont need an extra if check or raising
pawn Код:
if(strcmp(cmdtext, "/ignorelist", true) == 0 || strcmp(cmdtext, "/il", true) == 0)
    {
        SendClientMessage(playerid, 0x2641FEAA, "Ignoring:");
        string[0] = 0; //just for make sure that it works... not necessary if some factors are existing
        for(new i; i < MAX_PLAYERS; i++)
            if(MyIgnoredPlayers[playerid][i] >= 1)
            {
                GetPlayerName(i, playername, sizeof(playername));
                format(string, sizeof(string), "%s (%d)", playername, i);
                SendClientMessage(playerid, 0xFFFFFFAA, string);
            }
        if(!string[0]) SendClientMessage(playerid, COLOR_RED, "No One.");
        return true;
    }