SA-MP Forums Archive
Menu, optimizing it - 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: Menu, optimizing it (/showthread.php?tid=110595)



Menu, optimizing it - [WS]Hyper - 27.11.2009

Ok so I wanna optimize my menu a little (save some lines) but dunno if this will work..

Right now it's like this (ignore the screwed up tabs):
pawn Код:
if(CurrentMenu == CopOnD)
    {
    switch(row)
    {
        case 0:
        {
            gTeam[playerid] = TEAM_WSPD;
            SetPlayerColor(playerid, COLOR_BLUE);
                SetPlayerSkin(playerid, 71);
            GivePlayerWeapon(playerid,24,100);
                GivePlayerWeapon(playerid,3,1);
                SendClientMessage(playerid, COLOR_WSPD, "You're on Cop Duty, shoot ($100) or jail ($150) some criminals");
            }
        case 1:
        {
            gTeam[playerid] = TEAM_WSPD;
                SetPlayerColor(playerid, COLOR_BLUE);
                SetPlayerSkin(playerid, 280);
                GivePlayerWeapon(playerid,24,100);
                GivePlayerWeapon(playerid,3,1);
                SendClientMessage(playerid, COLOR_WSPD, "You're on Cop Duty, shoot ($100) or jail ($150) some criminals");
            }
        case 2:
        {
            gTeam[playerid] = TEAM_WSPD;
                SetPlayerColor(playerid, COLOR_WSPD);
                SetPlayerSkin(playerid, 281);
                GivePlayerWeapon(playerid,24,100);
                GivePlayerWeapon(playerid,3,1);
                SendClientMessage(playerid, COLOR_BLUE, "You're on Cop Duty, shoot ($100) or jail ($150) some criminals");
            }
//etc...
Would it be possible to do it like this?:
pawn Код:
if(CurrentMenu == CopOnD)
    {
    switch(row)
    {
        gTeam[playerid] = TEAM_WSPD;
        SetPlayerColor(playerid, COLOR_BLUE);
        GivePlayerWeapon(playerid,24,100);
        GivePlayerWeapon(playerid,3,1);
        SendClientMessage(playerid, COLOR_WSPD, "You're on Cop Duty, shoot ($100) or jail ($150) some criminals");
        case 0:
        {
                SetPlayerSkin(playerid, 71);
            }
        case 1:
        {
                SetPlayerSkin(playerid, 280);
            }
        case 2:
        {
                SetPlayerSkin(playerid, 281);
            }
Or will this not work? If not, is there another way to not repeat the same code on every case..?


Re: Menu, optimizing it - Backwardsman97 - 27.11.2009

You can do it like that but not exactly how you had it. The way you had it the second time would cause errors because you can't have extra code in the switch part. But if you put it outside of the switch statement it will work.

pawn Код:
if(CurrentMenu == CopOnD)
{
    switch(row)
    {
        case 0:SetPlayerSkin(playerid, 71);
        case 1:SetPlayerSkin(playerid, 280);
        case 2:SetPlayerSkin(playerid, 281);
    }
    gTeam[playerid] = TEAM_WSPD;
    SetPlayerColor(playerid, COLOR_BLUE);
    GivePlayerWeapon(playerid,24,100);
    GivePlayerWeapon(playerid,3,1);
    SendClientMessage(playerid, COLOR_WSPD, "You're on Cop Duty, shoot ($100) or jail ($150) some criminals");
}



Re: Menu, optimizing it - Peter_Corneile - 27.11.2009

Why dont you put these lines in the command that you type to show menu ?

pawn Код:
if(strcmp("/menu",cmdtext,5) == 0)
{
        gTeam[playerid] = TEAM_WSPD;
        SetPlayerColor(playerid, COLOR_BLUE);
        GivePlayerWeapon(playerid,24,100);
        GivePlayerWeapon(playerid,3,1);
        SendClientMessage(playerid, COLOR_WSPD, "You're on Cop Duty, shoot ($100) or jail ($150) some criminals")
        ShowMenuForPlayer(CopOnD,playerid);
        return 1;
     
}
Something like this should do it and then remove the lines from the cases like this

pawn Код:
if(CurrentMenu == CopOnD)
    {
    switch(row)
    {
   
        case 0:
        {
                SetPlayerSkin(playerid, 71);
            }
        case 1:
        {
                SetPlayerSkin(playerid, 280);
            }
        case 2:
        {
                SetPlayerSkin(playerid, 281);
            }



Re: Menu, optimizing it - Backwardsman97 - 27.11.2009

What if the player exits the menu though?


Re: Menu, optimizing it - Peter_Corneile - 27.11.2009

Quote:
Originally Posted by Backwardsman97
What if the player exits the menu though?
Erm.. Yes then he would be set to the team even if he just types the command


Re: Menu, optimizing it - [WS]Hyper - 27.11.2009

Quote:
Originally Posted by ►Peter Corneile◄
Quote:
Originally Posted by Backwardsman97
What if the player exits the menu though?
Erm.. Yes then he would be set to the team even if he just types the command
= fail :P

Well thanks Backwardsman, that'll spare me some lines


Re: Menu, optimizing it - Niixie - 28.11.2009

[me=Niixie]suggests Dialog menus[/me]

http://forum.sa-mp.com/index.php?topic=134698.0


Re: Menu, optimizing it - [WS]Hyper - 29.11.2009

Quote:
Originally Posted by Niixie
[me=Niixie]suggests Dialog menus[/me]

http://forum.sa-mp.com/index.php?topic=134698.0
Lol then I'd have to convert a lot of menu's, and there's not much difference between both and I prefer using arrow keys since it goes faster..


Re: Menu, optimizing it - Niixie - 29.11.2009

Well, i dont think its faster. its the same.. and converting it to dialog isnt that hard, if you just get in the mood then it can go very well.