help with admins command
#1

This is my command
Код:
CMD:admins(playerid,params[])
{
	for(new i=0;i<MAX_PLAYERS;i++)
	{
	    new string[1000],astring[50],count,admin[80];
	    if(PlayerInfo[i][pAdmin] >= 1 && PlayerInfo[i][pAdminHide] == 0)
	    {
	        if(PlayerInfo[i][pAdmin] == 1) { admin = "Admin level [ 1 ]"; }
        	else if(PlayerInfo[i][pAdmin] == 4) { admin = "Admin level [ 4 ]"; }
        	else if(PlayerInfo[i][pAdmin] == 2) { admin = "Admin level  [ 2 ]"; }
        	else if(PlayerInfo[i][pAdmin] == 3) { admin = "Admin level  [ 3 ]"; }
        	else if(PlayerInfo[i][pAdmin] == 6) { admin = "[ CO-OWNER ]";}
        	else if(PlayerInfo[i][pAdmin] == 7) { admin = "[ OWNER]";}
			else if(PlayerInfo[i][pAdmin] == 5) { admin = "[ HEAD-ADMIN]";}
			format(string,1000,"%s {FFFFFF}%s {FF0000}%s[ID: %d]\n",string,admin,PlayerName(i),i);
			count++;
			format(astring,sizeof(astring),"Online admins(%d):",count);
	    }
	    if(count >=1)
	    {
	        ShowPlayerDialog(playerid, 21323123, DIALOG_STYLE_MSGBOX, astring, string, "{FFFFFF}Close","");
	    }
     	else
	    {
	        SendClientMessage(playerid,0xFF0000FF,"there are no online admins!" );
			return 1;
	    }
	}
	return 1;
}
Can someone tell me when count is bigger than 0 why server return there are no online admins and opens admins dialog ?
Reply
#2

Код:
CMD:admins(playerid,params[])
{
	for(new i=0;i<MAX_PLAYERS;i++)
	{
	    new string[1000],astring[50],count,admin[80];
	    if(PlayerInfo[i][pAdmin] > 0 && PlayerInfo[i][pAdminHide] == 0)
	    {
	        if(PlayerInfo[i][pAdmin] == 1) { admin = "Admin level [ 1 ]"; }
        	else if(PlayerInfo[i][pAdmin] == 4) { admin = "Admin level [ 4 ]"; }
        	else if(PlayerInfo[i][pAdmin] == 2) { admin = "Admin level  [ 2 ]"; }
        	else if(PlayerInfo[i][pAdmin] == 3) { admin = "Admin level  [ 3 ]"; }
        	else if(PlayerInfo[i][pAdmin] == 6) { admin = "[ CO-OWNER ]";}
        	else if(PlayerInfo[i][pAdmin] == 7) { admin = "[ OWNER]";}
			else if(PlayerInfo[i][pAdmin] == 5) { admin = "[ HEAD-ADMIN]";}
			format(string,1000,"%s {FFFFFF}%s {FF0000}%s[ID: %d]\n",string,admin,PlayerName(i),i);
			count++;
			format(astring,sizeof(astring),"Online admins(%d):",count);
	    }
	    if(count  == 1)
	    {
	        ShowPlayerDialog(playerid, 21323123, DIALOG_STYLE_MSGBOX, astring, string, "{FFFFFF}Close","");
	    }
     	else
	    {
	        SendClientMessage(playerid,0xFF0000FF,"there are no online admins!" );
			return 1;
	    }
	}
	return 1;
}
try this
Reply
#3

You've done some poor coding there, lad. You should decide whether to show a dialog or not AFTER your player loop there. Other way it'll show you a message upon first user you get (ID 0) if he's not an admin since you won't get count++ done.
Here's how I'd do it, maybe:

Код:
CMD:admins(playerid,params[])
{
	for(new i=0;i<MAX_PLAYERS;i++)
	{
	    new string[1000],astring[50],count,admin[80];
	    if(PlayerInfo[i][pAdmin] >= 1 && PlayerInfo[i][pAdminHide] == 0)
	    {
	        if(PlayerInfo[i][pAdmin] == 1) { admin = "Admin level [ 1 ]"; }
        	else if(PlayerInfo[i][pAdmin] == 4) { admin = "Admin level [ 4 ]"; }
        	else if(PlayerInfo[i][pAdmin] == 2) { admin = "Admin level  [ 2 ]"; }
        	else if(PlayerInfo[i][pAdmin] == 3) { admin = "Admin level  [ 3 ]"; }
        	else if(PlayerInfo[i][pAdmin] == 6) { admin = "[ CO-OWNER ]";}
        	else if(PlayerInfo[i][pAdmin] == 7) { admin = "[ OWNER]";}
			else if(PlayerInfo[i][pAdmin] == 5) { admin = "[ HEAD-ADMIN]";}
			format(string,1000,"%s {FFFFFF}%s {FF0000}%s[ID: %d]\n",string,admin,PlayerName(i),i);
			count++;
			format(astring,sizeof(astring),"Online admins(%d):",count);
	    }
	}
        //I do all these count checks AFTER the loop; it barely makes sense other way around.
        if(count >=1)
	    {
	        ShowPlayerDialog(playerid, 21323123, DIALOG_STYLE_MSGBOX, astring, string, "{FFFFFF}Close","");
	    }
     	else
	    {
	        SendClientMessage(playerid,0xFF0000FF,"there are no online admins!" );
			return 1;
	    }
	return 1;
}
Reply
#4

you both have some serious mistakes in code.
it must be written before loop, like this:
PHP код:
CMD:admins(playerid,params[])
{
    new 
string[1000],astring[50],count,admin[80]; // this must be here (up before loop)
    
for(new i=0;i<MAX_PLAYERS;i++)
    {
        if(
PlayerInfo[i][pAdmin] >= && PlayerInfo[i][pAdminHide] == 0)
        {
            if(
PlayerInfo[i][pAdmin] == 1) { admin "Admin level [ 1 ]"; }
            else if(
PlayerInfo[i][pAdmin] == 4) { admin "Admin level [ 4 ]"; }
            else if(
PlayerInfo[i][pAdmin] == 2) { admin "Admin level  [ 2 ]"; }
            else if(
PlayerInfo[i][pAdmin] == 3) { admin "Admin level  [ 3 ]"; }
            else if(
PlayerInfo[i][pAdmin] == 6) { admin "[ CO-OWNER ]";}
            else if(
PlayerInfo[i][pAdmin] == 7) { admin "[ OWNER]";}
            else if(
PlayerInfo[i][pAdmin] == 5) { admin "[ HEAD-ADMIN]";}
            
format(string,1000,"%s {FFFFFF}%s {FF0000}%s[ID: %d]\n",string,admin,PlayerName(i),i);
            
count++;
            
format(astring,sizeof(astring),"Online admins(%d):",count);
        }
    }
    if(
count >=1)
    {
        
ShowPlayerDialog(playerid21323123DIALOG_STYLE_MSGBOXastringstring"{FFFFFF}Close","");
    }
    else
    {
        
SendClientMessage(playerid,0xFF0000FF,"there are no online admins!" );
        return 
1;
    }
    return 
1;

p.s. also using lower dialog id will be better.
Reply
#5

Thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)