/admins command help -
ZBits - 23.12.2013
Fixed
Re: /admins command help -
park4bmx - 23.12.2013
pawn Code:
COMMAND:admins(playerid, params[])
{
new AStr[240],FStr[240],CounT=0;
for(new i=0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i) && pInfo[i][pAdmin] >= 1)
{
new name[MAX_PLAYER_NAME];CounT++;
GetPlayerName(i, name, sizeof(name));
format(AStr, sizeof(AStr), "%s(%d)\n",name,i);
strcat(FStr, AStr, sizeof(FStr));
}
}
if(CounT>0){
SendClientMessage(playerid,0x9BBDDEAA,"Present Staff Members:");
SendClientMessage(playerid,0x9BBDDEAA,FStr);
}else SendClientMessage(playerid,0x9BBDDEAA,"No Admins online");
return 1;
}
you are running the code while looping every player, it needed to be outside the loop.
Re: /admins command help -
Threshold - 23.12.2013
This is a more efficient usage of the code:
pawn Code:
COMMAND:admins(playerid, params[])
{
new str[30], count = 0;
for(new i=0; i < MAX_PLAYERS; i++)
{
if(!IsPlayerConnected(i)) continue;
if(pInfo[i][pAdmin] < 1) continue;
if(count == 0) SendClientMessage(playerid,0x9BBDDEAA,"Present Staff Members:");
new name[MAX_PLAYER_NAME];
GetPlayerName(i, name, sizeof(name));
format(str, sizeof(str), "%s(%d)", name, i);
SendClientMessage(playerid, 0x9BBDDEAA, str);
count++;
}
if(count == 0) return SendClientMessage(playerid,0x9BBDDEAA,"No Admins online");
return 1;
}
Re: /admins command help -
ZBits - 23.12.2013
Both of them worked.
Thanks
Re: /admins command help -
ZBits - 23.12.2013
Is there any possible way of showing 4 admins in online line and the other in other lines?
like
"Admins1,Admins2,Admin3,Admins4" (then new line),
"Admin5, Admins6.... and so on"
?
Re: /admins command help -
mamorunl - 23.12.2013
Yes. Keep another counter with the currently found admins and check if the modulo of the number of admins and 4 is 0 (4 % 4 == 0, 8 % 4 == 0) and then print the string and concat another.
It will not work with the code of benzoAMG, as he prints it directly to the screen and once outputted, there is no turning back in this language.
Re: /admins command help -
ZBits - 24.12.2013
Mind explaining with the code and comments?, I didnt quite get that.
Re: /admins command help -
Threshold - 24.12.2013
Well I assumed he was wanting a line-by-line output, as he wasn't very clear about what he wanted in his original post.
With that being said, hopefully this will work:
Without Comments:
pawn Code:
CMD:admins(playerid, params[])
{
new fstr[130], str[30], count = 0;
SendClientMessage(playerid, 0x9BBDDEAA, "Present Staff Members:");
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(!IsPlayerConnected(i)) continue;
if(pInfo[i][pAdmin] < 1) continue;
count++;
new name[MAX_PLAYER_NAME];
GetPlayerName(i, name, sizeof(name));
format(str, sizeof(str), "%s(%d)", name, i);
if(((count - 1) % 4) != 0) strins(str, ", ", 0);
strcat(fstr, str);
if(count % 4 == 0)
{
SendClientMessage(playerid, 0x9BBDDEAA, fstr);
format(fstr, sizeof(fstr), "");
}
if(i == (MAX_PLAYERS - 1))
{
if(strlen(fstr)) SendClientMessage(playerid, 0x9BBDDEAA, fstr);
}
}
if(count == 0) return SendClientMessage(playerid,0x9BBDDEAA,"No Admins online");
return 1;
}
With Comments:
pawn Code:
CMD:admins(playerid, params[]) //When a player types the command '/admins'.
{
new fstr[130], str[30], count = 0; //Create our full string, temporary string and admin count variables.
SendClientMessage(playerid, 0x9BBDDEAA, "Present Staff Members:"); //Send the 'Present Staff Members' message.
for(new i = 0; i < MAX_PLAYERS; i++) //Start a loop through all player ids.
{
if(!IsPlayerConnected(i)) continue; //If the player with the ID isn't connected, skip it and do the next one.
if(pInfo[i][pAdmin] < 1) continue; //If the player is not an admin, skip them and do the next player.
count++; //We have found an admin, so increase the count by 1.
new name[MAX_PLAYER_NAME]; //Create a variable to store the admin's name in.
GetPlayerName(i, name, sizeof(name)); //Get the admin's name, and store it.
format(str, sizeof(str), "%s(%d)", name, i); //This is what we will see for each admin, their name and their id.
if(((count - 1) % 4) != 0) strins(str, ", ", 0); //If we are not starting a new line yet, insert ', ' into the string, to separate the admin names.
strcat(fstr, str); //Insert the temporary string, into the full string.
if(count % 4 == 0) //If we have reached 4 admins on one line...
{
SendClientMessage(playerid, 0x9BBDDEAA, fstr); //Send the full string
format(fstr, sizeof(fstr), ""); //Empty the full string, so we can continue on another line.
}
if(i == (MAX_PLAYERS - 1)) //If we've reached the end of the loop, but we haven't reached a full line...
{
if(strlen(fstr)) SendClientMessage(playerid, 0x9BBDDEAA, fstr); //Send the remaining admin names if the string isn't empty.
}
}
if(count == 0) return SendClientMessage(playerid,0x9BBDDEAA,"No Admins online"); //If there were no admins found, return the 'No Admins Online' message.
return 1;
}
Re: /admins command help -
mamorunl - 24.12.2013
Instead of these lines:
pawn Code:
if(i == (MAX_PLAYERS - 1))
{
if(strlen(fstr)) SendClientMessage(playerid, 0x9BBDDEAA, fstr);
}
You could've just put it right outside the for loop and check the length (strlen) of the fstr string and if it is higher than 0, just print it. It saves you the weird if-statement.
Re: /admins command help -
ZBits - 24.12.2013
Quote:
Originally Posted by BenzoAMG
Well I assumed he was wanting a line-by-line output, as he wasn't very clear about what he wanted in his original post.
With that being said, hopefully this will work:
Without Comments:
pawn Code:
CMD:admins(playerid, params[]) { new fstr[130], str[30], count = 0; SendClientMessage(playerid, 0x9BBDDEAA, "Present Staff Members:"); for(new i = 0; i < MAX_PLAYERS; i++) { if(!IsPlayerConnected(i)) continue; if(pInfo[i][pAdmin] < 1) continue; count++; new name[MAX_PLAYER_NAME]; GetPlayerName(i, name, sizeof(name)); format(str, sizeof(str), "%s(%d)", name, i); if(((count - 1) % 4) != 0) strins(str, ", ", 0); strcat(fstr, str); if(count % 4 == 0) { SendClientMessage(playerid, 0x9BBDDEAA, fstr); format(fstr, sizeof(fstr), ""); } if(i == (MAX_PLAYERS - 1)) { if(strlen(fstr)) SendClientMessage(playerid, 0x9BBDDEAA, fstr); } } if(count == 0) return SendClientMessage(playerid,0x9BBDDEAA,"No Admins online"); return 1; }
With Comments:
pawn Code:
CMD:admins(playerid, params[]) //When a player types the command '/admins'. { new fstr[130], str[30], count = 0; //Create our full string, temporary string and admin count variables. SendClientMessage(playerid, 0x9BBDDEAA, "Present Staff Members:"); //Send the 'Present Staff Members' message. for(new i = 0; i < MAX_PLAYERS; i++) //Start a loop through all player ids. { if(!IsPlayerConnected(i)) continue; //If the player with the ID isn't connected, skip it and do the next one. if(pInfo[i][pAdmin] < 1) continue; //If the player is not an admin, skip them and do the next player. count++; //We have found an admin, so increase the count by 1. new name[MAX_PLAYER_NAME]; //Create a variable to store the admin's name in. GetPlayerName(i, name, sizeof(name)); //Get the admin's name, and store it. format(str, sizeof(str), "%s(%d)", name, i); //This is what we will see for each admin, their name and their id. if(((count - 1) % 4) != 0) strins(str, ", ", 0); //If we are not starting a new line yet, insert ', ' into the string, to separate the admin names. strcat(fstr, str); //Insert the temporary string, into the full string. if(count % 4 == 0) //If we have reached 4 admins on one line... { SendClientMessage(playerid, 0x9BBDDEAA, fstr); //Send the full string format(fstr, sizeof(fstr), ""); //Empty the full string, so we can continue on another line. } if(i == (MAX_PLAYERS - 1)) //If we've reached the end of the loop, but we haven't reached a full line... { if(strlen(fstr)) SendClientMessage(playerid, 0x9BBDDEAA, fstr); //Send the remaining admin names if the string isn't empty. } } if(count == 0) return SendClientMessage(playerid,0x9BBDDEAA,"No Admins online"); //If there were no admins found, return the 'No Admins Online' message. return 1; }
|
This Code reutrns with just
"Present Staff Members"
"No message at all", when there are admins. And when there are no admins is says
"Present Staff Members"
'No Admins online"
^ how do i make it so it only shows "No Admins online"?