What is wrong with this /setplayercolor command?
#1

PHP код:
    if(strcmp(cmd"/setplayercolor"true) == 0)
    {
        if(
IsPlayerConnected(playerid))
        {
            if(
PlayerInfo[playerid][pAdmin] >= 4)
            {
                
tmp strtok(cmdtextidx);
                if(!
strlen(tmp))
                {
                    
SendClientMessage(playeridCOLOR_WHITE"USAGE: /setplayercolor [playerid] [color]");
                    
SendClientMessage(playeridCOLOR_GRAD1"Available colors: Red, Pink, Orange, Yellow, Cyan, Green, Blue, Black, White, Marker");
                    return 
1;
                }
                
giveplayerid ReturnUser(tmp);
                if(
IsPlayerConnected(giveplayerid))
                {
                    if(
giveplayerid != INVALID_PLAYER_ID)
                    {
                        new 
x_job[128];
                        
x_job strtok(cmdtextidx);
                        if(!
strlen(x_job))
                        {
                            
SendClientMessage(playeridCOLOR_WHITE"USAGE: /setplayercolor [playerid] [color]");
                            
SendClientMessage(playeridCOLOR_GRAD1"Available colors: Red, Pink, Orange, Yellow, Cyan, Green, Blue, Black, White, Marker");
                            return 
1;
                        }
                        if(
strcmp(x_job,"red",true) == 0SetPlayerColor(giveplayeridSCOLOR_RED);
                        else if(
strcmp(x_job,"pink",true) == 0SetPlayerColor(giveplayeridSCOLOR_PINK);
                        else if(
strcmp(x_job,"orange",true) == 0SetPlayerColor(giveplayeridSCOLOR_ORANGE);
                        else if(
strcmp(x_job,"yellow",true) == 0SetPlayerColor(giveplayeridSCOLOR_YELLOW);
                        else if(
strcmp(x_job,"cyan",true) == 0SetPlayerColor(giveplayeridSCOLOR_CYAN);
                        else if(
strcmp(x_job,"green",true) == 0SetPlayerColor(giveplayeridSCOLOR_GREEN);
                        else if(
strcmp(x_job,"blue",true) == 0SetPlayerColor(giveplayeridSCOLOR_BLUE);
                        else if(
strcmp(x_job,"black",true) == 0SetPlayerColor(giveplayeridSCOLOR_BLACK);
                        else if(
strcmp(x_job,"white",true) == 0SetPlayerColor(giveplayeridSCOLOR_WHITE);
                        else if(
strcmp(x_job,"marker",true) == 0SetPlayerColor(giveplayeridSCOLOR_MARKER);
                        
GetPlayerName(playeridsendernamesizeof(sendername));
                        
GetPlayerName(giveplayeridgiveplayersizeof(giveplayer));
                        
format(stringsizeof(string), "AdmWarning: %s has set %s's name color."sendernamegiveplayer);
                        
SendClientMessage(giveplayeridCOLOR_GRAD1"   Your name color has been set by an admin.");
                        
ABroadCast(COLOR_LIGHTREDstring1);
                        return 
1;
                    }
                    return 
1;
                }
                
SendClientMessage(playeridCOLOR_WHITE"You are not authorized to use this command.");
                return 
1;
               }
            
format(stringsizeof(string), "%d is not an active player!"giveplayerid);
            
SendClientMessage(playeridCOLOR_GRAD1string);
            return 
1;
        }
        return 
0;
    } 
This is the command, what exactly is wrong with it? Whenever an admin tries to use it, even if they're at the proper level to, it returns "You are not authorized to use this command." I don't understand why.
Reply
#2

I guess never mind, I just tested it in game and it's working fine now for some reason, but wasn't earlier. Thanks for looking though guys.
Reply
#3

If it doesn't work again, there's a solution to this. You got a few mistakes.

This is the correct version.

pawn Код:
if(strcmp(cmd, "/setplayercolor", true) == 0)
{
    if(IsPlayerConnected(playerid))
    {
        if(PlayerInfo[playerid][pAdmin] >= 4)
        {
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_WHITE, "USAGE: /setplayercolor [playerid] [color]");
                SendClientMessage(playerid, COLOR_GRAD1, "Available colors: Red, Pink, Orange, Yellow, Cyan, Green, Blue, Black, White, Marker");
                return 1;
            }
            giveplayerid = ReturnUser(tmp);
            if(IsPlayerConnected(giveplayerid))
            {
                if(giveplayerid != INVALID_PLAYER_ID)
                {
                    new x_job[128];
                    x_job = strtok(cmdtext, idx);
                    if(!strlen(x_job))
                    {
                        SendClientMessage(playerid, COLOR_WHITE, "USAGE: /setplayercolor [playerid] [color]");
                        SendClientMessage(playerid, COLOR_GRAD1, "Available colors: Red, Pink, Orange, Yellow, Cyan, Green, Blue, Black, White, Marker");
                        return 1;
                    }
                    if(strcmp(x_job,"red",true) == 0) SetPlayerColor(giveplayerid, SCOLOR_RED);
                    else if(strcmp(x_job,"pink",true) == 0) SetPlayerColor(giveplayerid, SCOLOR_PINK);
                    else if(strcmp(x_job,"orange",true) == 0) SetPlayerColor(giveplayerid, SCOLOR_ORANGE);
                    else if(strcmp(x_job,"yellow",true) == 0) SetPlayerColor(giveplayerid, SCOLOR_YELLOW);
                    else if(strcmp(x_job,"cyan",true) == 0) SetPlayerColor(giveplayerid, SCOLOR_CYAN);
                    else if(strcmp(x_job,"green",true) == 0) SetPlayerColor(giveplayerid, SCOLOR_GREEN);
                    else if(strcmp(x_job,"blue",true) == 0) SetPlayerColor(giveplayerid, SCOLOR_BLUE);
                    else if(strcmp(x_job,"black",true) == 0) SetPlayerColor(giveplayerid, SCOLOR_BLACK);
                    else if(strcmp(x_job,"white",true) == 0) SetPlayerColor(giveplayerid, SCOLOR_WHITE);
                    else if(strcmp(x_job,"marker",true) == 0) SetPlayerColor(giveplayerid, SCOLOR_MARKER);
                    GetPlayerName(playerid, sendername, sizeof(sendername));
                    GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
                    format(string, sizeof(string), "AdmWarning: %s has set %s's name color.", sendername, giveplayer);
                    SendClientMessage(giveplayerid, COLOR_GRAD1, "   Your name color has been set by an admin.");
                    ABroadCast(COLOR_LIGHTRED, string, 1);
                    return 1;
                }
                return 1;
            }
            else
            {
                format(string, sizeof(string), "%d is not an active player!", giveplayerid);
                SendClientMessage(playerid, COLOR_GRAD1, string);
            }
            return 1;
        }
        else SendClientMessage(playerid, COLOR_WHITE, "You are not authorized to use this command.");
        return 1;
    }
    return 0;
}
In the incorrect version, you know why that happens? You had to switch these 2 codes near the bottom. If it wasn't switched and the person you entered in the /setplayercolor command to set wasn't online, it would say not authorized. If they were online, it would work but send a 'not authorized command' because you never added the 'else SendClientMessage(playerid, COLOR_WHITE, "You are not authorized to use this command.");', but instead just 'SendClientMessage(playerid, COLOR_WHITE, "You are not authorized to use this command.");' You just need to carefully look at the code.

pawn Код:
SendClientMessage(playerid, COLOR_WHITE, "You are not authorized to use this command.");
                return 1;
               }
            format(string, sizeof(string), "%d is not an active player!", giveplayerid);
            SendClientMessage(playerid, COLOR_GRAD1, string);
            return 1;
Reply
#4

Quote:
Originally Posted by JustinAn
Посмотреть сообщение
If it doesn't work again, there's a solution to this. You got a few mistakes.

This is the correct version.

pawn Код:
if(strcmp(cmd, "/setplayercolor", true) == 0)
{
    if(IsPlayerConnected(playerid))
    {
        if(PlayerInfo[playerid][pAdmin] >= 4)
        {
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_WHITE, "USAGE: /setplayercolor [playerid] [color]");
                SendClientMessage(playerid, COLOR_GRAD1, "Available colors: Red, Pink, Orange, Yellow, Cyan, Green, Blue, Black, White, Marker");
                return 1;
            }
            giveplayerid = ReturnUser(tmp);
            if(IsPlayerConnected(giveplayerid))
            {
                if(giveplayerid != INVALID_PLAYER_ID)
                {
                    new x_job[128];
                    x_job = strtok(cmdtext, idx);
                    if(!strlen(x_job))
                    {
                        SendClientMessage(playerid, COLOR_WHITE, "USAGE: /setplayercolor [playerid] [color]");
                        SendClientMessage(playerid, COLOR_GRAD1, "Available colors: Red, Pink, Orange, Yellow, Cyan, Green, Blue, Black, White, Marker");
                        return 1;
                    }
                    if(strcmp(x_job,"red",true) == 0) SetPlayerColor(giveplayerid, SCOLOR_RED);
                    else if(strcmp(x_job,"pink",true) == 0) SetPlayerColor(giveplayerid, SCOLOR_PINK);
                    else if(strcmp(x_job,"orange",true) == 0) SetPlayerColor(giveplayerid, SCOLOR_ORANGE);
                    else if(strcmp(x_job,"yellow",true) == 0) SetPlayerColor(giveplayerid, SCOLOR_YELLOW);
                    else if(strcmp(x_job,"cyan",true) == 0) SetPlayerColor(giveplayerid, SCOLOR_CYAN);
                    else if(strcmp(x_job,"green",true) == 0) SetPlayerColor(giveplayerid, SCOLOR_GREEN);
                    else if(strcmp(x_job,"blue",true) == 0) SetPlayerColor(giveplayerid, SCOLOR_BLUE);
                    else if(strcmp(x_job,"black",true) == 0) SetPlayerColor(giveplayerid, SCOLOR_BLACK);
                    else if(strcmp(x_job,"white",true) == 0) SetPlayerColor(giveplayerid, SCOLOR_WHITE);
                    else if(strcmp(x_job,"marker",true) == 0) SetPlayerColor(giveplayerid, SCOLOR_MARKER);
                    GetPlayerName(playerid, sendername, sizeof(sendername));
                    GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
                    format(string, sizeof(string), "AdmWarning: %s has set %s's name color.", sendername, giveplayer);
                    SendClientMessage(giveplayerid, COLOR_GRAD1, "   Your name color has been set by an admin.");
                    ABroadCast(COLOR_LIGHTRED, string, 1);
                    return 1;
                }
                return 1;
            }
            else
            {
                format(string, sizeof(string), "%d is not an active player!", giveplayerid);
                SendClientMessage(playerid, COLOR_GRAD1, string);
            }
            return 1;
        }
        else SendClientMessage(playerid, COLOR_WHITE, "You are not authorized to use this command.");
        return 1;
    }
    return 0;
}
In the incorrect version, you know why that happens? You had to switch these 2 codes near the bottom. If it wasn't switched and the person you entered in the /setplayercolor command to set wasn't online, it would say not authorized. If they were online, it would work but send a 'not authorized command' because you never added the 'else SendClientMessage(playerid, COLOR_WHITE, "You are not authorized to use this command.");', but instead just 'SendClientMessage(playerid, COLOR_WHITE, "You are not authorized to use this command.");' You just need to carefully look at the code.

pawn Код:
SendClientMessage(playerid, COLOR_WHITE, "You are not authorized to use this command.");
                return 1;
               }
            format(string, sizeof(string), "%d is not an active player!", giveplayerid);
            SendClientMessage(playerid, COLOR_GRAD1, string);
            return 1;
Thanks man, that really helped me out. I appreciate your response, it actually helped me realize what I did wrong versus just telling me the correct code. Once again, thanks!
Reply
#5

The fact that you're not using sscanf and any command processor other than strcmp makes it wrong. Just saying :P

I recommend zcmd or ycmds (both are way easier and incredibly faster than strcmp) with sscanf (this is a must), sscanf makes checking parameters trivial in only one line of code and zcmd/dcmd/ycmd would be near to senseless without it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)