SA-MP Forums Archive
Adding 'PROMOTION' to /setrank - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Adding 'PROMOTION' to /setrank (/showthread.php?tid=635342)



Adding 'PROMOTION' to /setrank - ross8839 - 05.06.2017

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!!


Re: Adding 'PROMOTION' to /setrank - Bwandon - 05.06.2017

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.


Re: Adding 'PROMOTION' to /setrank - Vince - 05.06.2017

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]); 



Re: Adding 'PROMOTION' to /setrank - ross8839 - 05.06.2017

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