AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Back Button For menu (https://forums.alliedmods.net/showthread.php?t=46125)

Nostrodamous 10-18-2006 22:37

Back Button For menu
 
ok i have no idea how to add a back button to my menu . can smeone help me ? here my main menu . can so meon show me the way to add a back button , after picking from this main menu it breaks down into every weapon , i want it to go back here if the user hits 9
Code:
public type_menu(id, level , cid) {  if(!cmd_access(id , level , cid , 0))  {   return PLUGIN_HANDLED;  }  else  {   format(menu, 191, "[Practice]^n^n1. Rifles^n2. SMG's^n3. Pistol's^n4. Nades^n^n0: Exit" );   show_menu(id , keys, menu, -1, "type_menu")   return PLUGIN_CONTINUE;  }  return PLUGIN_HANDLED; } public type_show(id , key) {  if(key == 0) // Rifles  {   rifle_menu(id);  }  else  {   if(key  == 1) // SMG's   {    smg_menu(id);   }   else   {    if(key == 2) // Pistol's    {     pistol_menu(id);    }    else    {     if(key == 3) // Nade's     {      nade_menu(id);     }     else           {      if(key == 4) // exit      {       return PLUGIN_HANDLED;      }     }    }   }  }  return PLUGIN_CONTINUE; }

k007 10-18-2006 23:47

Re: Back Button For menu
 
look at the source code of the plugin called weapon menu by bender and xeroblood

TheNewt 10-19-2006 00:20

Re: Back Button For menu
 
That, no offense by the way, is really bad scripting.
Use switch(key) instead of 'if' over and over again. Also looks like you aren't defining key in the function either.
Code:
 if(!cmd_access(id , level , cid , 0))  {   return PLUGIN_HANDLED;  }  else  {   format(menu, 191, "[Practice]^n^n1. Rifles^n2. SMG's^n3. Pistol's^n4. Nades^n^n0: Exit" );   show_menu(id , keys, menu, -1, "type_menu")   return PLUGIN_CONTINUE;  }
could be
Code:
if(!cmd_access(id , level , cid , 0))     return; format(menu, 191, "[Practice]^n^n1. Rifles^n2. SMG's^n3. Pistol's^n4. Nades^n^n0: Exit"); show_menu(id , keys, menu, -1, "type_menu")

This is called branching.
Code:
if(key == 0) // Rifles  {   rifle_menu(id);  }  else  {   if(key  == 1) // SMG's   {    smg_menu(id);   }   else   {    if(key == 2) // Pistol's    {     pistol_menu(id);    }    else    {     if(key == 3) // Nade's     {      nade_menu(id);     }     else           {      if(key == 4) // exit      {       return PLUGIN_HANDLED;      }     }    }   }  }
Branching = Bad!!!

Use this instead.
Code:
switch(key) {     case 0: rifle_menu(id);     //Rifles     case 1: smg_menu(id);       //Semimachine Guns     case 2: pistol_menu(id);    //Pistols     case 3: nade_menu(id);      //Grenades     //You don't need case 4     //Hitting any unassigned key will exit the menu anyways }

Nostrodamous 10-19-2006 01:53

Re: Back Button For menu
 
kool , ill use the case switches. I know about them but im not comfortable using them because i never tried them before. but my code is like 800 lines now (a huge in game comand menu) so , i should use them. can you pease tell me why that number 4 isnt neccesary? and can you tell me how to make a back and exit button using the case statements u used .
other than that it sounds good :) thanks for helping :up: +karma


EDIT; OMG ! the case switches already cut out 100 lines from my code :o
i cant believe i didnt use these before . oh can you show me the right way to do a else stateent with a case switch ?

Zenith77 10-19-2006 12:08

Re: Back Button For menu
 
Store what there menu page/postion is through a global var. You can find more information by searching for like the AMXX menu template (it's not offical, but was used for a long while and still is).

Code:
new gPlayerMenuPosition[33]; public MyMenuHook(id, key) {      switch (key)      {            case 8:                  ShowMenu(id, --gPlayerMenuPosition[id]); // Backward                  case 9:                   ShowMenu(id, ++gPlayerMenuPosition[id]); // Forward      } }

Nostrodamous 10-19-2006 16:06

Re: Back Button For menu
 
can you tell me why it says "can only have 1 line following a case statemet" . how can i make it accept more then one line or is it imposable?

SweatyBanana 10-19-2006 16:55

Re: Back Button For menu
 
->

Code:

public MyMenuHook(id, key)
{
    switch (key)
    {
          case 8:
          {
                ShowMenu(id, --gPlayerMenuPosition[id]); // Backward
                //Another line of code can be here now because of the braces
          }
     
          case 9:
          {
                  ShowMenu(id, ++gPlayerMenuPosition[id]); // Forward
                //Another line of code can be here now because of the braces
          }
    }
}


Zenith77 10-19-2006 17:44

Re: Back Button For menu
 
Oh woops, added that while I was at school ^^.

TheNewt 10-19-2006 20:26

Re: Back Button For menu
 
800 lines?? Judging from like the 50 lines I just compressed for you to like 5-10 lines, it could be just a 400 line project? Its not the size, its the effeciancy of the plugin that matters.
You can make either a very small plugin, or a very effeciant one. Some cases could have both.
O.o I currently had a 3600'ish line plugin, I was able to compress it to 3100, and get rid of a few mysql bugs in the process. :P

k007 10-19-2006 20:40

Re: Back Button For menu
 
you guys didn't figure it out yet? it's raphero with his BattleField Mod lulz, :)


All times are GMT -4. The time now is 04:55.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.