Raised This Month: $ Target: $400
 0% 

Back Button For menu


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Nostrodamous
BANNED
Join Date: Oct 2006
Old 10-18-2006 , 22:37   Back Button For menu
Reply With Quote #1

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; }
Nostrodamous is offline
k007
BANNED
Join Date: Mar 2006
Location: bacon?
Old 10-18-2006 , 23:47   Re: Back Button For menu
Reply With Quote #2

look at the source code of the plugin called weapon menu by bender and xeroblood
k007 is offline
Send a message via MSN to k007
TheNewt
Donor
Join Date: Jun 2006
Location: Where I live.
Old 10-19-2006 , 00:20   Re: Back Button For menu
Reply With Quote #3

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 }
__________________
Quote:
toe3_ left the chat room. (G-lined (AUTO Excessive connections from a single host.))

Last edited by TheNewt; 10-19-2006 at 00:26.
TheNewt is offline
Nostrodamous
BANNED
Join Date: Oct 2006
Old 10-19-2006 , 01:53   Re: Back Button For menu
Reply With Quote #4

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 +karma


EDIT; OMG ! the case switches already cut out 100 lines from my code
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 ?

Last edited by Nostrodamous; 10-19-2006 at 02:02.
Nostrodamous is offline
Zenith77
Veteran Member
Join Date: Aug 2005
Old 10-19-2006 , 12:08   Re: Back Button For menu
Reply With Quote #5

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      } }
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred
Zenith77 is offline
Nostrodamous
BANNED
Join Date: Oct 2006
Old 10-19-2006 , 16:06   Re: Back Button For menu
Reply With Quote #6

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?
Nostrodamous is offline
SweatyBanana
BANNED
Join Date: Sep 2005
Location: LOL
Old 10-19-2006 , 16:55   Re: Back Button For menu
Reply With Quote #7

->

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
           }
     }
}
SweatyBanana is offline
Send a message via AIM to SweatyBanana Send a message via Yahoo to SweatyBanana
Zenith77
Veteran Member
Join Date: Aug 2005
Old 10-19-2006 , 17:44   Re: Back Button For menu
Reply With Quote #8

Oh woops, added that while I was at school ^^.
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred
Zenith77 is offline
TheNewt
Donor
Join Date: Jun 2006
Location: Where I live.
Old 10-19-2006 , 20:26   Re: Back Button For menu
Reply With Quote #9

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.
__________________
Quote:
toe3_ left the chat room. (G-lined (AUTO Excessive connections from a single host.))
TheNewt is offline
k007
BANNED
Join Date: Mar 2006
Location: bacon?
Old 10-19-2006 , 20:40   Re: Back Button For menu
Reply With Quote #10

you guys didn't figure it out yet? it's raphero with his BattleField Mod lulz,
k007 is offline
Send a message via MSN to k007
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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