Adding 'PROMOTION' to /setrank
#1

So the below code, I want it to send a message when the user is made a higher rank than he is. For example, if my level is 4... and I'm made level 5... then it'll say promotion and it'll say derank if he gets lowered a level.

What it's doing at t he moment is sending the 'PROMOTION' message and then killing the command! Why?

pawn Код:
if(sscanf(params, "ui", id, rank)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /setrank [playerid] [rank] (1-5)");
    {
        if(PlayerInfo[playerid][pFacLeader] == 1 || PlayerInfo[playerid][pAdmin] == 4)
        {
            if(!IsPlayerConnected(id)) return SendClientMessage(playerid, COLOR_RED, "That player is not connected!");
            if(rank > 5) return SendClientMessage(playerid, COLOR_RED, "You can't set a rank higher than 5!");
            if(rank > PlayerInfo[playerid][pFacRank]) return SendClientMessage(playerid, COLOR_GREEN, "PROMOTION!");
            switch(rank)
            {
                case 1:
                {
                    switch(PlayerInfo[playerid][pFac])
                    {
                        case 1:
                        {
                            format(string, sizeof(string), "%s set your rank to Cadet!", pName);
                        }

                        case 2:
                        {
                            format(string, sizeof(string), "%s set your rank to Associate!", pName);
                        }

                        case 3:
                        {
                            format(string, sizeof(string), "%s set your rank to Associate!", pName);
                        }

                        case 4:
                        {
                            format(string, sizeof(string), "%s set your rank to Raw Recruit!", pName);
                        }

                        case 5:
                        {
                            format(string, sizeof(string), "%s set your rank to Raw Recruit!", pName);
                        }
                    }
                }
                case 2:
                {
                    switch(PlayerInfo[playerid][pFac])
                    {
                        case 1:
                        {
                            format(string, sizeof(string), "%s set your rank to Trooper!", pName);
                        }

                        case 2:
                        {
                            format(string, sizeof(string), "%s set your rank to Soldier!", pName);
                        }

                        case 3:
                        {
                            format(string, sizeof(string), "%s set your rank to Soldier!", pName);
                        }

                        case 4:
                        {
                            format(string, sizeof(string), "%s set your rank to Street Soldier!", pName);
                        }

                        case 5:
                        {
                            format(string, sizeof(string), "%s set your rank to Street Soldier!", pName);
                        }
                    }
                }

                case 3:
                {
                    switch(PlayerInfo[playerid][pFac])
                    {
                        case 1:
                        {
                            format(string, sizeof(string), "%s set your rank to Lieutenant!", pName);
                        }

                        case 2:
                        {
                            format(string, sizeof(string), "%s set your rank to Capo!", pName);
                        }

                        case 3:
                        {
                            format(string, sizeof(string), "%s set your rank to Capo!", pName);
                        }

                        case 4:
                        {
                            format(string, sizeof(string), "%s set your rank to Gang Fighter!", pName);
                        }

                        case 5:
                        {
                            format(string, sizeof(string), "%s set your rank to Gang Fighter!", pName);
                        }
                    }
                }

                case 4:
                {
                    switch(PlayerInfo[playerid][pFac])
                    {
                        case 1:
                        {
                            format(string, sizeof(string), "%s set your rank to Deputy Chief of Police!", pName);
                        }

                        case 2:
                        {
                            format(string, sizeof(string), "%s set your rank to Underboss!", pName);
                        }

                        case 3:
                        {
                            format(string, sizeof(string), "%s set your rank to Underboss!", pName);
                        }

                        case 4:
                        {
                            format(string, sizeof(string), "%s set your rank to Henchman!", pName);
                        }

                        case 5:
                        {
                            format(string, sizeof(string), "%s set your rank to Henchman!", pName);
                        }
                    }
                }

                case 5:
                {
                    switch(PlayerInfo[playerid][pFac])
                    {
                        case 1:
                        {
                            format(string, sizeof(string), "%s set your rank to Chief of Police!", pName);
                        }

                        case 2:
                        {
                            format(string, sizeof(string), "%s set your rank to Boss!", pName);
                        }

                        case 3:
                        {
                            format(string, sizeof(string), "%s set your rank to Boss!", pName);
                        }

                        case 4:
                        {
                            format(string, sizeof(string), "%s set your rank to Gang Leader!", pName);
                        }

                        case 5:
                        {
                            format(string, sizeof(string), "%s set your rank to Gang Leader!", pName);
                        }
                    }
I understand this probably isn't the easiest, nor the most efficient way of doing what I'm trying to do. If you have any suggestions on how I can improve that, that would help me out a lot...

I guess creating a save string... so instead of saving the variable as an int... save it as a variable... if any one knows how to do this, please suggest below!

Thanks in advance!!
Reply
#2

Return:
PHP код:
if(rank PlayerInfo[playerid][pFacRank]) return SendClientMessage(playeridCOLOR_GREEN"PROMOTION!"); 
Works:
PHP код:
if(rank PlayerInfo[playerid][pFacRank]) SendClientMessage(playeridCOLOR_GREEN"PROMOTION!"); 
You added 'return' to the promotion message- the rest of the command wasn't getting executed.
Reply
#3

Quote:
Originally Posted by ross8839
Посмотреть сообщение
Why?
Because you have a return right there. Return stops the function immediately.

Also use constant arrays to store the rank instead of repeating "set your rank to" a hundred times. If you ever wanted to change that message you'd have to change it in hundred different places which is far from ideal. Your current setup is also quite weird. Why not switch through factions first, then through ranks so you at least have them more or less together?

Something like this might work. It gets rid of the switch structure entirely. Not tested.

PHP код:
static const ranks[][][] = {
    
/* 0 */ "Cadet""Trooper""Lieutenant""Deputy Chief of Police""Chief of Police" },
    
/* 1 */ "Associate""Soldier",    "Capo",    "Underboss""Boss"    },    
    
/* 2 */ "Associate""Soldier""Capo""Underboss""Boss" },    
    
/* 3 */ "Raw Recruit""Street Soldier""Gang Fighter""Henchman""Gang Leader" },    
    
/* 4 */ "Raw Recruit""Street Soldier""Gang Fighter""Henchman""Gang Leader"    }    
};
format(stringsizeof(string), "%s set your rank to %s!"pNameranks[PlayerInfo[playerid][pFac] - 1][rank 1]); 
Reply
#4

Quote:
Originally Posted by Vince
Посмотреть сообщение
Because you have a return right there. Return stops the function immediately.

Also use constant arrays to store the rank instead of repeating "set your rank to" a hundred times. If you ever wanted to change that message you'd have to change it in hundred different places which is far from ideal. Your current setup is also quite weird. Why not switch through factions first, then through ranks so you at least have them more or less together?

Something like this might work. It gets rid of the switch structure entirely. Not tested.

PHP код:
static const ranks[][][] = {
    
/* 0 */ "Cadet""Trooper""Lieutenant""Deputy Chief of Police""Chief of Police" },
    
/* 1 */ "Associate""Soldier",    "Capo",    "Underboss""Boss"    },    
    
/* 2 */ "Associate""Soldier""Capo""Underboss""Boss" },    
    
/* 3 */ "Raw Recruit""Street Soldier""Gang Fighter""Henchman""Gang Leader" },    
    
/* 4 */ "Raw Recruit""Street Soldier""Gang Fighter""Henchman""Gang Leader"    }    
};
format(stringsizeof(string), "%s set your rank to %s!"pNameranks[PlayerInfo[playerid][pFac] - 1][rank 1]); 
I'm going to look in to this actually. Thank you!

+rep
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)