Making an Admin's list
#1

Hello, As you can see from the topic title, I'd like to come up with a command that shows all online administrators on the list, I have been using Karagon's script for a while to learn how things work etc, but I cannot get this command to work.

Код:
cmd(admins, playerid, params[])
{
	if(IsPlayerConnected(playerid))
	{
		SendClientMessage(playerid, -1, "");
		SendClientMessage(playerid, COLOR_ADMIN, "Online Administrators:");
		for(new i = 0; i < MAX_PLAYERS; i++)
		{
			if(IsPlayerConnected(i))
			{
				if(GetPVarInt(playerid, "AdminLevel") <= 1338)
				{
					new admtext[64], sendername[MAX_PLAYER_NAME];
					if(GetPVarInt(playerid, "AdminLevel") == 1337) { admtext = "Head Administrator"; }
					GetPlayerName(i, sendername, sizeof(sendername));
					return 1;
				}
				else
				{
                    SendClientMessage(playerid, COLOR_ADMIN, "No online staff members currently found.");
                    return 1;
				}
			}
		}
	}
    return 1;
}
When sent in game, the command just returns - Current Administrators: and that's it.

I've been trying to figure this out for a long time and have had no luck.

If you could help me out or at least where I'm going wrong, I'd appreciate that.


Thanks guys.
Reply
#2

Could you show the CMD that you used to set your admin level in the script first?
Reply
#3

Quote:
Originally Posted by Mark_Samp
Посмотреть сообщение
Could you show the CMD that you used to set your admin level in the script first?
This is the command I used, it works fine and gives the other player the level specified. It's just the one command above to list the Admins that is bugging me... I just can't get it working.
Код:
cmd(agive, playerid, params[])
{
	// If player is not admin, returns value of 0
	if(GetPVarInt(playerid, "AdminLevel") == 0) return 0;

	// Makes sure player is admin before allowing promotion of another player
	if(GetPVarInt(playerid, "AdminLevel") == 1337)
	{
	    new ID; new string[120];
		if(sscanf(params, "u", ID)) return SendClientMessage(playerid, COLOR_ERROR, "Usage: /agive [ID]");
		if(!IsPlayerConnected(ID)) return SendClientMessage(playerid, COLOR_ERROR, "Unknown ID.");
		if(GetPVarInt(ID, "AdminLevel") == 1337) return SendClientMessage(playerid, COLOR_ERROR, "Error: That player is already an Administrator.");
		IRC_Say(gGroupID, IRC_CHANNEL, string);
		SendClientMessage(ID, COLOR_ADMIN, "You are now a member of the staff team.");
		SendClientMessage(ID, COLOR_ADMIN, "Do /adcmds for a list of your commands.");
		SetPVarInt(ID, "AdminLevel", 1337);
	}
	return 1;
}
The aforementioned command to get the players who are Admin allows for the script to compile as well so that has slumped me too.

Thanks for the reply by the way, I've been doing other things since I've been trying to get this working so I've not really played around with anything else.
Reply
#4

You're not sending any message if there's an admin online. Your just grabbing the variable and defining admtext. You need to format a string and send it oncertainly you've confirmed there's an administrator online.
Reply
#5

Hmm, where are you sending the messages if the loop find any admin?
Reply
#6

PHP код:
cmd(adminsplayeridparams[])
{
    if(
IsPlayerConnected(playerid))
    {
        
SendClientMessage(playerid, -1"");
        
SendClientMessage(playeridCOLOR_ADMIN"Online Administrators:");
        for(new 
0MAX_PLAYERSi++)
        {
            if(
IsPlayerConnected(i))
            {
                if(
GetPVarInt(playerid"AdminLevel") <= 1338)
                {
                    new 
admtext[64], sendername[MAX_PLAYER_NAME];
                    if(
GetPVarInt(playerid"AdminLevel") == 1337) { admtext "Head Administrator"; }
                    
GetPlayerName(isendernamesizeof(sendername));
                    new 
tstr[128];
                    
format(tstr128"%s (%s)"sendernameadmtext);
                    
SendClientMessage(playeridCOLOR_ADMINtstr);
                    return 
1;
                }
                else
                {
                    
SendClientMessage(playeridCOLOR_ADMIN"No online staff members currently found.");
                    return 
1;
                }
            }
        }
    }
    return 
1;

Reply
#7

What is a command engine?
Reply
#8

Quote:
Originally Posted by introzen
Посмотреть сообщение
You're not sending any message if there's an admin online. Your just grabbing the variable and defining admtext. You need to format a string and send it oncertainly you've confirmed there's an administrator online.
Quote:
Originally Posted by Jamester
Посмотреть сообщение
PHP код:
cmd(adminsplayeridparams[])
{
    if(
IsPlayerConnected(playerid))
    {
        
SendClientMessage(playerid, -1"");
        
SendClientMessage(playeridCOLOR_ADMIN"Online Administrators:");
        for(new 
0MAX_PLAYERSi++)
        {
            if(
IsPlayerConnected(i))
            {
                if(
GetPVarInt(playerid"AdminLevel") <= 1338)
                {
                    new 
admtext[64], sendername[MAX_PLAYER_NAME];
                    if(
GetPVarInt(playerid"AdminLevel") == 1337) { admtext "Head Administrator"; }
                    
GetPlayerName(isendernamesizeof(sendername));
                    new 
tstr[128];
                    
format(tstr128"%s (%s)"sendernameadmtext);
                    
SendClientMessage(playeridCOLOR_ADMINtstr);
                    return 
1;
                }
                else
                {
                    
SendClientMessage(playeridCOLOR_ADMIN"No online staff members currently found.");
                    return 
1;
                }
            }
        }
    }
    return 
1;

This has worked perfectly. Thank you for doing this. I take it I can just repeat the lines and it'll just print them if there's more than one Administrator online? Like the following:

Код:
cmd(admins, playerid, params[])
{
    if(IsPlayerConnected(playerid))
    {
        SendClientMessage(playerid, -1, "");
        SendClientMessage(playerid, COLOR_ADMIN, "Online Staff Members:");
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            if(IsPlayerConnected(i))
            {
                if(GetPVarInt(playerid, "AdminLevel") <= 1338)
                {
                    new admtext[64], sendername[MAX_PLAYER_NAME];
                    if(GetPVarInt(playerid, "AdminLevel") == 1337) { admtext = "Head Administrator"; }
                    if(GetPVarInt(playerid, "AdminLevel") == 4) { admtext = "Senior Administrator"; }
                    if(GetPVarInt(playerid, "AdminLevel") == 3) { admtext = "Administrator"; }
                    if(GetPVarInt(playerid, "AdminLevel") == 2) { admtext = "Moderator"; }
                    if(GetPVarInt(playerid, "AdminLevel") == 1) { admtext = "Moderator"; }
                    GetPlayerName(i, sendername, sizeof(sendername));
                    new tstr[128];
                    format(tstr, 128, "%s {FFFFFF}- %s", sendername, admtext);
                    SendClientMessage(playerid, COLOR_ADMIN, tstr);
                    return 1;
                }
                else
                {
                    SendClientMessage(playerid, COLOR_ADMIN, "No online staff members currently found.");
                    return 1;
                }
            }
        }
    }
    return 1;
}
Hopefully this will work just fine, as I have more than just one Administrator for the server.
Thanks again, everyone who has assisted with the problem.
Reply
#9

That should work exactly as intended, I don't see anything wrong. But, you could replace the if statements with a switch statement
PHP код:
switch(GetPVarInt(playerid"AdminLevel") {
    case 
1..2admtext "Moderator"
    
// etc...

EDIT: Just looked through the loop something is wrong.
PHP код:
// you loop check print the admin etc...
return 1
same thing with the no admins also

PHP код:
cmd(adminsplayeridparams[])
{
    if(
IsPlayerConnected(playerid))
    {
        
SendClientMessage(playerid, -1"");
        
SendClientMessage(playeridCOLOR_ADMIN"Online Staff Members:");
        new 
count;
        for(new 
0MAX_PLAYERSi++)
        {
            if(
IsPlayerConnected(i))
            {
                if(
GetPVarInt(playerid"AdminLevel") <= 1338)
                {
                    new 
admtext[64], sendername[MAX_PLAYER_NAME];
                    if(
GetPVarInt(playerid"AdminLevel") == 1337) { admtext "Head Administrator"; }
                    if(
GetPVarInt(playerid"AdminLevel") == 4) { admtext "Senior Administrator"; }
                    if(
GetPVarInt(playerid"AdminLevel") == 3) { admtext "Administrator"; }
                    if(
GetPVarInt(playerid"AdminLevel") == 2) { admtext "Moderator"; }
                    if(
GetPVarInt(playerid"AdminLevel") == 1) { admtext "Moderator"; }
                    
GetPlayerName(isendernamesizeof(sendername));
                    new 
tstr[128];
                    
format(tstr128"%s {FFFFFF}- %s"sendernameadmtext);
                    
SendClientMessage(playeridCOLOR_ADMINtstr);
                    
count++;
                }
            }
        }
        if(
count == 0)
            
SendClientMessage(playeridCOLOR_ADMIN"No online staff members currently found.");
    }
    return 
1;

Reply
#10

Quote:
Originally Posted by Jamester
Посмотреть сообщение
That should work exactly as intended, I don't see anything wrong. But, you could replace the if statements with a switch statement
PHP код:
switch(GetPVarInt(playerid"AdminLevel") {
    case 
1..2admtext "Moderator"
    
// etc...

EDIT: Just looked through the loop something is wrong.
PHP код:
// you loop check print the admin etc...
return 1
same thing with the no admins also

PHP код:
cmd(adminsplayeridparams[])
{
    if(
IsPlayerConnected(playerid))
    {
        
SendClientMessage(playerid, -1"");
        
SendClientMessage(playeridCOLOR_ADMIN"Online Staff Members:");
        new 
count;
        for(new 
0MAX_PLAYERSi++)
        {
            if(
IsPlayerConnected(i))
            {
                if(
GetPVarInt(playerid"AdminLevel") <= 1338)
                {
                    new 
admtext[64], sendername[MAX_PLAYER_NAME];
                    if(
GetPVarInt(playerid"AdminLevel") == 1337) { admtext "Head Administrator"; }
                    if(
GetPVarInt(playerid"AdminLevel") == 4) { admtext "Senior Administrator"; }
                    if(
GetPVarInt(playerid"AdminLevel") == 3) { admtext "Administrator"; }
                    if(
GetPVarInt(playerid"AdminLevel") == 2) { admtext "Moderator"; }
                    if(
GetPVarInt(playerid"AdminLevel") == 1) { admtext "Moderator"; }
                    
GetPlayerName(isendernamesizeof(sendername));
                    new 
tstr[128];
                    
format(tstr128"%s {FFFFFF}- %s"sendernameadmtext);
                    
SendClientMessage(playeridCOLOR_ADMINtstr);
                    
count++;
                }
            }
        }
        if(
count == 0)
            
SendClientMessage(playeridCOLOR_ADMIN"No online staff members currently found.");
    }
    return 
1;

Two people now appear on the list when testing (don't have more than two people available to test atm) but with different admin levels they still appear as the top one, Not sure why this is?

Any clues?

Thanks for the help.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)