SA-MP Forums Archive
Help with switch/elseif - 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: Help with switch/elseif (/showthread.php?tid=642325)



Help with switch/elseif - DeathReaper - 28.09.2017

PHP код:
COMMAND:acmds(playeridparams[])
{
    if(
playerData[playerid][playerLoggedIn])
    {
        if(
playerData[playerid][playerLevel] >= 1)
        {
            new 
string[1400];
            
format(stringsizeof(string), "%s{98B0CD}LEVEL 4 COMMANDS{FFFFFF}\n/unban /teleport /ipban /level /setstats\n\n"string);
            
format(stringsizeof(string), "%s{98B0CD}LEVEL 3 COMMANDS{FFFFFF}\n/ban /v /vdestroy /get /vgoto /vbring /resetweapons\n/forcerules /cc /aheal \n/playerjailtime\n\n"string);
            
format(stringsizeof(string), "%s{98B0CD}LEVEL 2 COMMANDS{FFFFFF}\n/explode /vrespawn /(un)mute\n"string);
            
format(stringsizeof(string), "%s{98B0CD}LEVEL 1 COMMANDS{FFFFFF}\n/goto /aod /kick /jail /asay /playerstats /spec /specoff\n\n"string);
            
            
ShowPlayerDialog(playerid200DIALOG_STYLE_MSGBOX"Admin Commands"string"OK""");
            
            return 
1;
        }
    }
    return 
0;

That is code used for admin commands for now.

I want it to be modified in a way such that only level 4 can view all commands upto level 4 and level 2 to view all commands upto level 2 i.e., level 1 commands and level 2 commands.

Also, it should not be like all level 4 commands in 1 case , all commands upto level 3 in one case etc, because it would be hard to edit it later.

Is it possible to add something above each of these lines
PHP код:
format(stringsizeof(string), "%s{98B0CD}LEVEL x COMMANDS{FFFFFF}Commands here\n\n"string); 
to make it look like what I told.

Can elseif/switch statements be used for this?

Help is appreciated.


Re: Help with switch/elseif - Misiur - 28.09.2017

Normal "if" will suffice. Just wrap each line you want only for specific admins in an if conditional


Re: Help with switch/elseif - jlalt - 28.09.2017

if I am not wrong if will be more helpful here, as it can compare above / lower values than the var wanted too.
so your code would look like:

PHP код:
COMMAND:acmds(playeridparams[])
{
    if(
playerData[playerid][playerLoggedIn])
    {
        if(
playerData[playerid][playerLevel] >= 1)
        {
            new 
string[1400];
            if(
playerData[playerid][playerLevel] >= 4)
                
format(stringsizeof(string), "%s{98B0CD}LEVEL 4 COMMANDS{FFFFFF}\n/unban /teleport /ipban /level /setstats\n\n"string);
            if(
playerData[playerid][playerLevel] >= 3)
                
format(stringsizeof(string), "%s{98B0CD}LEVEL 3 COMMANDS{FFFFFF}\n/ban /v /vdestroy /get /vgoto /vbring /resetweapons\n/forcerules /cc /aheal \n/playerjailtime\n\n"string);
            if(
playerData[playerid][playerLevel] >= 2)
                
format(stringsizeof(string), "%s{98B0CD}LEVEL 2 COMMANDS{FFFFFF}\n/explode /vrespawn /(un)mute\n"string);
            if(
playerData[playerid][playerLevel] >= 1)
                
format(stringsizeof(string), "%s{98B0CD}LEVEL 1 COMMANDS{FFFFFF}\n/goto /aod /kick /jail /asay /playerstats /spec /specoff\n\n"string);
            
ShowPlayerDialog(playerid200DIALOG_STYLE_MSGBOX"Admin Commands"string"OK""");
            return 
1;
        }
    }
    return 
0;

Edit: @Misiur was faster ;-;