Question about a case statement
#1

PHP код:
CMD:makeadmin(playeridparams[])
{
    new 
targetidlevel;
    if(
sscanf(params"ui"targetidlevel)) return SendClientMessage(playerid, -1"/makeadmin [playerid/partofname] [level]");
    if(!(-
level 1000000)) return SendClientMessage(playerid, -1"The max admin level is 999999!");
    
    if(!
IsPlayerConnected(targetid)) return SendClientMessage(playerid, -1"That player is not currently online!");
    new 
alevel[20], astr[128], sendername[MAX_PLAYER_NAME];
    if(
IsPlayerAdmin(playerid) || PlayerInfo[playerid][pAdmin] >= 99999)
    {
        switch(
level)
        {
            case 
0:
            {
                
GetPlayerName(playeridsendernamesizeof(sendername));
                
format(astrsizeof(astr), "You have been demoted by Admin %s"sendername);
                
SendClientMessage(targetid, -1astr);
                
GetPlayerName(targetidsendernamesizeof(sendername));
                
format(astrsizeof(astr), "You have demoted %s of their Admin rank."sendername);
                
SendClientMessage(playerid, -1astr);
                
PlayerInfo[targetid][pAdmin] = level;
                return 
1;
            }
            case 
1alevel "Moderator";
            case 
2alevel "Junior Admin";
            case 
3alevel "General Admin";
            case 
4alevel "Senior Admin";
            case 
5alevel "Lead Admin";
            case 
6alevel "Head Admin";
            case 
1337alevel "Executive Admin";
            case 
9999alevel "Co-Owner";
            case 
99999alevel "Owner";
            case 
999999alevel "GOD!";
            default: return 
SendClientMessage(playerid, -1"You have entered an invalid level. (0 - 6, 1337, 9999, 99999, or 999999)");
        }
        
GetPlayerName(playeridsendernamesizeof(sendername));
        
format(astrsizeof(astr), "You have been made into a %s by Admin %s!"alevelsendername);
        
SendClientMessage(targetid, -1astr);
        
GetPlayerName(targetidsendernamesizeof(sendername));
        
format(astrsizeof(astr), "You have made %s into a %s!"sendernamealevel);
        
SendClientMessage(playerid, -1astr);
        
PlayerInfo[targetid][pAdmin] = level;
    }
    else
    {
        
SendClientMessage(playerid, -1"You do not meet the admin requirements to use this command!");
    }
    return 
1;

pawn Код:
Is this line unnecessary:
if(!(-1 < level < 1000000)) return SendClientMessage(playerid, -1, "The max admin level is 999999!");
because of how default is used in the case statement? default:
return SendClientMessage(playerid, -1, "You have entered an invalid level. (0 - 6, 1337, 9999, 99999, or 999999)");  I was starting to wonder about this.
Reply
#2

Well it will be needed only when he try to make a level which is not between that values.
Reply
#3

Quote:
Originally Posted by Clad
Посмотреть сообщение
Well it will be needed only when he try to make a level which is not between that values.
ahh okay thank you.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)