Menu, optimizing it
#1

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..?
Reply
#2

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");
}
Reply
#3

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);
            }
Reply
#4

What if the player exits the menu though?
Reply
#5

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
Reply
#6

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
Reply
#7

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

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

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..
Reply
#9

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.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)