SA-MP Forums Archive
Can You Improve This Code? - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Can You Improve This Code? (/showthread.php?tid=270543)



Can You Improve This Code? - mastalol - 20.07.2011

I am Wanting To Know If Anyone Can Improve This Code or can tell me if its a good code.
(this does not include changing if(strcmp(cmdtext,"/vcmds",true) == 0))
Code:
pawn Код:
if(strcmp(cmdtext,"/vcmds",true) == 0)
    {
       if(IsPlayerVipType(playerid,1)) {
            SendClientMessage(playerid,red,"[_____________San Andreas MultiPlayGround VIP Player Commands_____________]");
            SendClientMessage(playerid,green,"Silver: /afk, /back, /f - Flips You Car");
            if(IsPlayerVipType(playerid,2)) {
                SendClientMessage(playerid,green,"Gold: /heal, /armor, /vr - Repairs Your Vehicle");
                if(IsPlayerVipType(playerid,3)) {
                    SendClientMessage(playerid,green,"Preimum: /vpgod,");
                }
            }
        }
        else SendClientMessage(playerid,red,"Only Vip's Can Use This Command");
        return 1;
    }
Quote:
Originally Posted by SCREENSHOTS



Re: Can You Improve This Code? - Grim_ - 20.07.2011

That code is perfectly fine, and personally, can't see any way of improving it. (Besides using ZCMD, and calling the variable directly (assuming that's what IsPlayerVIPType does))

At the below reply, it is true you could use the switch statement. However, how much better it would be, with the limited amount of code, is very minimal.


Re: Can You Improve This Code? - System64 - 20.07.2011

you just can do something like this

pawn Код:
YCMD:ahelp(playerid, params[], help)
{
    #pragma unused help
    #pragma unused params
    if(IsPlayerAdmin(playerid) || PlayerInfo[playerid][pAdmin] >= 1)
    {
        switch(PlayerInfo[playerid][pAdmin])
        {
            case 1: ShowPlayerDialog(playerid, 15, DIALOG_STYLE_MSGBOX, "Admin Komande!", "{00C0FF}/slap /kornjaca /explode /mute /unmute /freeze /unfreeze /crash /kick /ban /goto /gethere /setloc /gotoloc /gotojail /gotokomora /adminbaza /admino /sethp /o /a /getip /specon /specoff /vehid /remove /busi /disarm /onduty /offduty /put /eject", "Ok", "");
            case 2: ShowPlayerDialog(playerid, 16, DIALOG_STYLE_MSGBOX, "Admin Komande!", "{00C0FF}/slap /kornjaca /explode /mute /unmute /freeze /unfreeze /crash  /jail /unjail /kick /ban /goto /gethere /setloc /gotoloc /gotoammu /gotojail /gotokomora /adminbaza /admino /sethp /settime /givegun /weaponid /o /a /cc /cnn /uping /downing /godmodeon /godmodeoff /visible /getip /specon /specoff /vehid /remove /busi /disarm /onduty /offduty /put /eject", "Ok", "");
            case 3: ShowPlayerDialog(playerid, 17, DIALOG_STYLE_MSGBOX, "Admin Komande!", "{00C0FF}/slap /kornjaca /explode /mute /unmute /freeze /unfreeze /crash  /jail /unjail /kick /ban /goto /gethere /setloc /gotoloc /gotoammu /gotojail /gotokomora /adminbaza /admino /sethp /setscore /setkills /setdeaths /settime /givegun /weaponid /setmoney /o /a /cc /cnn /cnnn /uping /downing /godmodeon /godmodeoff /visible /getip /specon /specoff /vehid /remove /busi /disarm /onduty /offduty /put", "Ok", "");
        }
    }
    else SendClientMessage(playerid, COLOR_KRED, "Niste autorizirani za koriљtenje ove komande!");
    return 1;
}



Re: Can You Improve This Code? - mastalol - 20.07.2011

Quote:
Originally Posted by Grim_
Посмотреть сообщение
At the below reply, it is true you could use the switch statement. However, how much better it would be, with the limited amount of code, is very minimal.
i dont think there is a way to do dialogs without doing the case. or is there?


Re: Can You Improve This Code? - Grim_ - 20.07.2011

Quote:
Originally Posted by mastalol
Посмотреть сообщение
i dont think there is a way to do dialogs without doing the case. or is there?
There is:
pawn Код:
if( IsPlayerVIPType( playerid, 1 ) ) ShowPlayerDialog( ... );
else if( IsPlayerVIPType( playerid, 2 ) ) ShowPlayerDialog( ... );
else if( IsPlayerVIPType( playerid, 3 ) ) ShowPlayerDialog( ... );
However if you're going to be doing it that way, then you should go ahead and use a switch statement.


Re: Can You Improve This Code? - Rafa - 20.07.2011

dude how u will detect which player is vip i want to know only that and always im asking about that how the pawn will detect which player will be vip ? and how i can make to detect some player to give rights ?


Re: Can You Improve This Code? - mastalol - 20.07.2011

Quote:
Originally Posted by Rafa
Посмотреть сообщение
dude how u will detect which player is vip i want to know only that and always im asking about that how the pawn will detect which player will be vip ? and how i can make to detect some player to give rights ?
I dont quite understand you but if you are asking how my vip system works....

I use LUXADMIN

and its as simple as 1,2,3 xD

if(IsPlayerVipType(playerid,TYPE))
Type 1 = Silver
Type 2 = Gold
Type 3 = Premium


Re: Can You Improve This Code? - Rafa - 20.07.2011

yeah but i need to know how u will detect the player who is vip and u give him this right to use... :/


Re: Can You Improve This Code? - Daren_Jacobson - 20.07.2011

will IsPlayerVipType return true if you ask for level 1 and he is level 3?
If so then the only way I could improve it would be changing the "Flips You Car" to "Flips Your Car"


Re: Can You Improve This Code? - mastalol - 20.07.2011

Quote:
Originally Posted by Daren_Jacobson
Посмотреть сообщение
will IsPlayerVipType return true if you ask for level 1 and he is level 3?
If so then the only way I could improve it would be changing the "Flips You Car" to "Flips Your Car"
epic looked through it with a fine tooth comb XD

+ rep for finding typo