Problem with my command
#1

PHP код:
CMD:giverank(playeridparams[])
{
    if(
PlayerFacInfo[playerid][Fac] >= 15)
    {
        new 
targetidlevel;
        if(
sscanf(params"ui"targetidlevel)) return SendClientMessage(playerid, -1"/giverank [playerid/partofname] [level]");
        if(!
IsPlayerConnected(targetid)) return SendClientMessage(playerid, -1"That player is not currently online!");
          if(!(-
level 20 )) return SendClientMessage(playerid, -1"The max level is 16!");
        new 
faclevel[20], astr[128], sendername[MAX_PLAYER_NAME];
        if(
PlayerInfo[playerid][pAdmin] == 99999 || PlayerFacInfo[playerid][Fac] == 15)
        {
            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);
                    
PlayerFacInfo[targetid][Fac] = level;
                    return 
1;
                }
                case 
1faclevel "Cadet In Training";
                case 
2faclevel "Cadet";
                case 
3faclevel "Officer";
                case 
4faclevel "Corporal";
                case 
5faclevel "Sergeant";
                case 
6faclevel "Sergeant Grade Two";
                case 
7faclevel "Lieutenant";
                case 
8faclevel "Inspector";
                case 
9faclevel "Captain";
                case 
10faclevel "Major";
                case 
11faclevel "Major Grade Two";
                case 
12faclevel "Commander";
                case 
13faclevel "Commissioner";
                case 
14faclevel "Chief Inspector";
                case 
15faclevel "Deputy Chief";
                case 
16faclevel "Chief";
                default: return 
SendClientMessage(playerid, -1"You have entered an invalid level. (0 - 16)");
            }
            
GetPlayerName(playeridsendernamesizeof(sendername));
            
format(astrsizeof(astr), "You have been made into a %s by Admin %s!"faclevelsendername);
            
SendClientMessage(targetid, -1astr);
            
GetPlayerName(targetidsendernamesizeof(sendername));
            
format(astrsizeof(astr), "You have made %s into a %s!"sendernamefaclevel);
            
SendClientMessage(playerid, -1astr);
            
PlayerFacInfo[targetid][Fac] = level;
            
PlayerFacInfo[targetid][FacType] = 1;
        }
    }
    else
    {
        
SendClientMessage(playerid, -1"You do not meet the level requirement for using this command!");
    }
    return 
1;

PHP код:
CMD:makepolicechief(playeridparams[])
{
    if(
PlayerInfo[playerid][pAdmin] >= 6)
    {
        new 
targetid;
         if(
sscanf(params"u"targetid)) return SendClientMessage(playerid, -1"/makepolicechief [playerid/partofname]");
        if(!
IsPlayerConnected(targetid)) return SendClientMessage(playerid, -1"That player is not currently online!");
        
PlayerFacInfo[targetid][Fac] = 16;
        
PlayerFacInfo[targetid][FacType] = 1;
        
SendClientMessage(targetidCOLOR_BLUE"You have been made into the police chief, congratulations!");
    }
    else
    {
        
SendClientMessage(playerid, -1"You do not meet the admin requirements to use this command!");
    }
    return 
1;

That is my code for a faction system I'm just now creating. One of my issues is that when I am a level 99999 admin I can't /giverank, but when I /makepolicechief myself I am able to use the /giverank command. I want it so level 99999 admins and or deputy chiefs/chiefs can use the command (Deputy chief being level 15 and chief being level 16). Whenever I use the command as a level 99999 admin it just tells me I don't meet the level requirement. Can anyone tell what's wrong or should I show some other code?
Reply
#2

pawn Код:
CMD:giverank(playerid, params[])
{
    if(IsPlayerConnected(playerid))
    {
        new targetid, level;
        if(sscanf(params, "ui", targetid, level)) return SendClientMessage(playerid, -1, "/giverank [playerid/partofname] [level]");
        if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, -1, "That player is not currently online!");
          if(!(-1 < level < 20 )) return SendClientMessage(playerid, -1, "The max level is 16!");
        new faclevel[20], astr[128], sendername[MAX_PLAYER_NAME];
        if(PlayerInfo[playerid][pAdmin] == 99999 || PlayerFacInfo[playerid][Fac] == 15)
        {
            switch(level)
            {
                case 0:
                {
                    GetPlayerName(playerid, sendername, sizeof(sendername));
                    format(astr, sizeof(astr), "You have been demoted by Admin %s", sendername);
                    SendClientMessage(targetid, -1, astr);
                    GetPlayerName(targetid, sendername, sizeof(sendername));
                    format(astr, sizeof(astr), "You have demoted %s of their Admin rank.", sendername);
                    SendClientMessage(playerid, -1, astr);
                    PlayerFacInfo[targetid][Fac] = level;
                    return 1;
                }
                case 1: faclevel = "Cadet In Training";
                case 2: faclevel = "Cadet";
                case 3: faclevel = "Officer";
                case 4: faclevel = "Corporal";
                case 5: faclevel = "Sergeant";
                case 6: faclevel = "Sergeant Grade Two";
                case 7: faclevel = "Lieutenant";
                case 8: faclevel = "Inspector";
                case 9: faclevel = "Captain";
                case 10: faclevel = "Major";
                case 11: faclevel = "Major Grade Two";
                case 12: faclevel = "Commander";
                case 13: faclevel = "Commissioner";
                case 14: faclevel = "Chief Inspector";
                case 15: faclevel = "Deputy Chief";
                case 16: faclevel = "Chief";
                default: return SendClientMessage(playerid, -1, "You have entered an invalid level. (0 - 16)");
            }
            GetPlayerName(playerid, sendername, sizeof(sendername));
            format(astr, sizeof(astr), "You have been made into a %s by Admin %s!", faclevel, sendername);
            SendClientMessage(targetid, -1, astr);
            GetPlayerName(targetid, sendername, sizeof(sendername));
            format(astr, sizeof(astr), "You have made %s into a %s!", sendername, faclevel);
            SendClientMessage(playerid, -1, astr);
            PlayerFacInfo[targetid][Fac] = level;
            PlayerFacInfo[targetid][FacType] = 1;
        }
    }
    else
    {
        SendClientMessage(playerid, -1, "You do not meet the level requirement for using this command!");
    }
    return 1;
}
Reply
#3

Quote:
Originally Posted by Lynn
Посмотреть сообщение
pawn Код:
CMD:giverank(playerid, params[])
{
    if(IsPlayerConnected(playerid))
    {
        new targetid, level;
        if(sscanf(params, "ui", targetid, level)) return SendClientMessage(playerid, -1, "/giverank [playerid/partofname] [level]");
        if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, -1, "That player is not currently online!");
          if(!(-1 < level < 20 )) return SendClientMessage(playerid, -1, "The max level is 16!");
        new faclevel[20], astr[128], sendername[MAX_PLAYER_NAME];
        if(PlayerInfo[playerid][pAdmin] == 99999 || PlayerFacInfo[playerid][Fac] == 15)
        {
            switch(level)
            {
                case 0:
                {
                    GetPlayerName(playerid, sendername, sizeof(sendername));
                    format(astr, sizeof(astr), "You have been demoted by Admin %s", sendername);
                    SendClientMessage(targetid, -1, astr);
                    GetPlayerName(targetid, sendername, sizeof(sendername));
                    format(astr, sizeof(astr), "You have demoted %s of their Admin rank.", sendername);
                    SendClientMessage(playerid, -1, astr);
                    PlayerFacInfo[targetid][Fac] = level;
                    return 1;
                }
                case 1: faclevel = "Cadet In Training";
                case 2: faclevel = "Cadet";
                case 3: faclevel = "Officer";
                case 4: faclevel = "Corporal";
                case 5: faclevel = "Sergeant";
                case 6: faclevel = "Sergeant Grade Two";
                case 7: faclevel = "Lieutenant";
                case 8: faclevel = "Inspector";
                case 9: faclevel = "Captain";
                case 10: faclevel = "Major";
                case 11: faclevel = "Major Grade Two";
                case 12: faclevel = "Commander";
                case 13: faclevel = "Commissioner";
                case 14: faclevel = "Chief Inspector";
                case 15: faclevel = "Deputy Chief";
                case 16: faclevel = "Chief";
                default: return SendClientMessage(playerid, -1, "You have entered an invalid level. (0 - 16)");
            }
            GetPlayerName(playerid, sendername, sizeof(sendername));
            format(astr, sizeof(astr), "You have been made into a %s by Admin %s!", faclevel, sendername);
            SendClientMessage(targetid, -1, astr);
            GetPlayerName(targetid, sendername, sizeof(sendername));
            format(astr, sizeof(astr), "You have made %s into a %s!", sendername, faclevel);
            SendClientMessage(playerid, -1, astr);
            PlayerFacInfo[targetid][Fac] = level;
            PlayerFacInfo[targetid][FacType] = 1;
        }
    }
    else
    {
        SendClientMessage(playerid, -1, "You do not meet the level requirement for using this command!");
    }
    return 1;
}
Thanks, much appreciated. What was wrong with my original code? I couldn't find what you changed and I would like to know what you did in order to prevent issues in the future.
Reply
#4

You had
pawn Код:
if(PlayerFacInfo[playerid][Fac] >= 15)
Inside the code twice, once at the top, and once farther down.
The one at the top, didn't specify or if the player is a Admin 99999, So I just changed that to if the Player is connected, then proceed, and pause to see if the player is either a Admin or Faction 15.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)