loop not working for id 0
#1

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;
    }
Reply
#2

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;
Reply
#3

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;
}
Reply
#4

^^ that just spamms "No One."
Reply
#5

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;
}
Reply
#6

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.
Reply
#7

Код:
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;
}
Reply
#8

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.
Reply
#9

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

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;
    }
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)