SA-MP Forums Archive
/admins doesn't update list! - 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: /admins doesn't update list! (/showthread.php?tid=650477)



/admins doesn't update list! - ivndosos - 28.02.2018

So when an admin leaves the game, His name will still be shown on the admins list!

Код:
CMD:admins(playerid, params[])
{
      if(connected[playerid] == true) return GameTextForPlayer(playerid, "~r~Spawn First", 5000, 5);
      if(pInfo[playerid][Admin] < 1) return SendClientMessage(playerid, -1, "{C3C3C3}(INFO) You don't have the priviliges to use this command.");
      new str[128], count=0;
	  for(new j = 1; j <= 3; j++)
	  {
		  for(new i = 0; i < MAX_PLAYERS; i++)
		  {
			  if(pInfo[i][Admin] == j)
			  {
				 format(str, 256, "{66ff99}%s (level: %d)", PlayerName[i], pInfo[i][Admin]);
				 SendClientMessage(playerid, -1, str);
				 count ++;
			  }
		  }
	  }
	  format(str, sizeof(str), "{66ff99}There are currently %d admins online.", count);
	  SendClientMessage(playerid, -1, str);
	  return 1;
}



Re: /admins doesn't update list! - PepsiCola23 - 28.02.2018

so if you type /admins when that admin is offline,his name is still there?


Re: /admins doesn't update list! - ivndosos - 28.02.2018

yeah


Re: /admins doesn't update list! - Thundey - 28.02.2018

Just add this line in your script. I haven't tested it, but it should work accordingly now.

Код:
   	if(count == 0)
	SendClientMessage(playerid,COLOR_WHITE,"There are currently no administrators online.");
	return 1;
}



Re: /admins doesn't update list! - Dayrion - 28.02.2018

Quote:
Originally Posted by Thundey
Посмотреть сообщение
Just add this line in your script. I haven't tested it, but it should work accordingly now.

Код:
   	if(count == 0)
	SendClientMessage(playerid,COLOR_WHITE,"There are currently no administrators online.");
	return 1;
}
If you don't know what the problem is ; you really shouldn't answer or at least try to coherent answer. By the way, there is no offense on that.

The problem is here:
PHP код:
for(new 0MAX_PLAYERSi++) 
You shouldn't loop through 0 to 1000 (by default) but only through connected players.
PHP код:
for(new iGetPlayerPoolSize(); <= ji++) 



Re: /admins doesn't update list! - DTV - 28.02.2018

If the name still shows up after they've logged out, I'm guessing it's because you don't clear player variables when a player logs out or logs in, otherwise it wouldn't show up. Not to mention, you're using an unnecessary loop to check their admin level, you can simply check if their admin level isn't 0, also you're just looping through MAX_PLAYERS and not checking to see if the player's online or not.

pawn Код:
CMD:admins(playerid, params[])
{
      if(connected[playerid] == true) return GameTextForPlayer(playerid, "~r~Spawn First", 5000, 5);
      if(pInfo[playerid][Admin] < 1) return SendClientMessage(playerid, -1, "{C3C3C3}(INFO) You don't have the priviliges to use this command.");
      new str[128], count=0;
      for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)  //better loop as it doesn't go through every player slot, just the max playerid on the server
      {
           if(!IsPlayerConnected(i)) { continue; } //skips any playerids that aren't onine
           if(pInfo[i][Admin] != 0)
       {
            format(str, 256, "{66ff99}%s (level: %d)", PlayerName[i], pInfo[i][Admin]); //str is not 256 long as you declared it to be 128, either change this line or increase the str to 256
        SendClientMessage(playerid, -1, str);
            count ++;
       }
   
     }
     format(str, sizeof(str), "{66ff99}There are currently %d admins online.", count);
     SendClientMessage(playerid, -1, str);
     return 1;
}



Re: /admins doesn't update list! - rolex - 28.02.2018

Fixed post:

Код:
for(new i, j = GetPlayerPoolSize(); i <= j; i++)
is really better if you have a lot of slots.


Re: /admins doesn't update list! - Sew_Sumi - 28.02.2018

^^ You should mention on why the change in str handling regarding the size...


Re: /admins doesn't update list! - rolex - 28.02.2018

I did a mistake. I've not read post above mine.


Re: /admins doesn't update list! - ivndosos - 01.03.2018

Quote:
Originally Posted by DTV
Посмотреть сообщение
If the name still shows up after they've logged out, I'm guessing it's because you don't clear player variables when a player logs out or logs in, otherwise it wouldn't show up. Not to mention, you're using an unnecessary loop to check their admin level, you can simply check if their admin level isn't 0, also you're just looping through MAX_PLAYERS and not checking to see if the player's online or not.

pawn Код:
CMD:admins(playerid, params[])
{
      if(connected[playerid] == true) return GameTextForPlayer(playerid, "~r~Spawn First", 5000, 5);
      if(pInfo[playerid][Admin] < 1) return SendClientMessage(playerid, -1, "{C3C3C3}(INFO) You don't have the priviliges to use this command.");
      new str[128], count=0;
      for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)  //better loop as it doesn't go through every player slot, just the max playerid on the server
      {
           if(!IsPlayerConnected(i)) { continue; } //skips any playerids that aren't onine
           if(pInfo[i][Admin] != 0)
       {
            format(str, 256, "{66ff99}%s (level: %d)", PlayerName[i], pInfo[i][Admin]); //str is not 256 long as you declared it to be 128, either change this line or increase the str to 256
        SendClientMessage(playerid, -1, str);
            count ++;
       }
   
     }
     format(str, sizeof(str), "{66ff99}There are currently %d admins online.", count);
     SendClientMessage(playerid, -1, str);
     return 1;
}
worked thanks