| closedMenu in plugin |
| Started by Tank on 11-18-2008, 05:16 PM |
Threads: 59
Joined: Jan 2007
I am working on a plugin where I want to implement a menu. It's a menu with 3 choises. From several people I already noticed that menu's aren't that easy to do and I think I am not quite sure what I got myself into but I wanted to give it a go.rnrnDoes anyone know a good tutorial on creating menu's or perhaps have an old plugin which contains a menu and a lot of commenting?rnrnI checked several plugins using a menu and it seemed russian to me. Again, it's a long shot but perhaps someone has some good information which could guide me through this.
Threads: 11
Joined: Dec 2007
This is how i do a simple menu. (It is my method there can be a thousand others)nn
#include <amxmodx>nn#define MENU_TITLE "yTITLE :^n"nnpublic plugin_init()n{n // Plugin registrationn register_plugin("Test Menu", "1.0", "h0_noMan");n n // Function that display the Menun register_clcmd("showmenu", "display_Menu", ADMIN_KICK, "Display the Menu");n n // First you have to register the menun // 1023 (i always use 1023 here)n // "display" is the name of the function called when a player hit a key when the menu is displayedn register_menucmd(register_menuid(MENU_TITLE), 1023, "control_Choice");n}nn// This function will display the menunpublic display_Menu(id)n{n // It will contain the text of the Menun new szMenuBody[512];nn // If you want to allow the choice 0,1,2,3,4 (00011111 in binary => 31 in decimal)n // If you want to allow 0,2,4 (00010101 in binary => 21 in decimal)n new mkeys = 31 ;n n // Content of the Menun new Len = format( szMenuBody, 511, MENU_TITLE );n n // ^n is for a new Linen // w is for white text (y for yellow)n Len += format( szMenuBody[Len], 511-Len, "^nw1. Choice 1");n Len += format( szMenuBody[Len], 511-Len, "^nw2. Choice 2");n Len += format( szMenuBody[Len], 511-Len, "^nw3. Choice 3");n Len += format( szMenuBody[Len], 511-Len, "^nw4. Choice 4");n Len += format( szMenuBody[Len], 511-Len, "^nw5. Choice 5");n n // Display Menun // 25 is the time in seconds the menu will be displayedn show_menu( id, mkeys, szMenuBody, 25);n}nn// This function will be called when a player make a choicenpublic control_Choice(id, key)n{n if(key==0)n client_print(id, print_chat, "You have selected choice number 1");n else if(key==1)n client_print(id, print_chat, "You have selected choice number 2");n else if(key==2)n client_print(id, print_chat, "You have selected choice number 3");n else if(key==3)n client_print(id, print_chat, "You have selected choice number 4");n else if(key==4)n client_print(id, print_chat, "You have selected choice number 5");n}Threads: 59
Joined: Jan 2007
Thanks a lot for this quick respond. Im going to light one up and give it a go.
Threads: 75
Joined: Nov 2007
There is also menu generator in AMXX studio dont know if thats useful....
Threads: 59
Joined: Jan 2007
LOL, that is also a good addition. In coding I have two goals, creating the plugins which don't excist or don't work like the way they work and learning how to code properly.rnrnI'll guess I'll use the menu generator when Im with my hands in my hair and as a final solution. Thanks for pointing out though, it seems amxx studio has so much options I never used before.
Threads: 103
Joined: May 2005
if you want lots of commenting and stuff you can try the tutorial on the allied modders forumnnhttp://forums.alliedmods.net/showthread.php?t=46364
Threads: 59
Joined: Jan 2007
// If you want to allow the choice 0,1,2,3,4 (00011111 in binary => 31 in decimal)rn // If you want to allow 0,2,4 (00010101 in binary => 21 in decimal)rn new mkeys = 31 ;rnrnI fricking love you h0_noMan, just hoped you could explain above posted.rnrnI created a menu by your guide script and it works :D Just wanted to add more options then 5 and I have no idea how you come from 0,2,4 to 00010101 to 21. When I just combine 0, 2 and 4 in binary code together I still end up with 20, not 21.rnrnSame goes for 0,1,2,3,4.....basicly would like to understand this so I can add more and more optionsThreads: 11
Joined: Dec 2007
Each bits of the mkeys allow (1) or not (0) a choice.nnKey : 9876543210nBinary : 0000000000nnWhen you press the 1 in the menu, it use the 0 key.nFor the 2, it use the 1 key.n...nnExemple 1:nn1. Choice An2. Choice Bn3. Choice Cn9. LeavennFor this menu, i have to allow the following keys : 0,1,2,8nThe mkeys should be : 0100000111 (263 in binary)nnExemple 2:nn1. Choice An2. Choice Bn3. Choice Cn4. Choice Dn5. Choice En6. Choice Fn9. LeavennFor this menu, i have to allow the following keys : 0,1,2,3,4,5,8nThe mkeys should be : 0100011111 (287 in binary)
Threads: 59
Joined: Jan 2007
HAHAH, thank you so much. I quickly read through your postrnrn
Each bits of the mkeys allow (1) or not (0) a choice.rnrnKey : 9876543210rnBinary : 0000000000rnrnrnOverlooked that part, which eventually made me start converting decimal into binary and comparing the numbers in the answer you gave me. But all I have to do is place a 1 for the key I want to enable, with in mind that I have to take one off.rnrnThanks for the explaining, now I can increase my menu in my melee plugin :D
Threads: 59
Joined: Jan 2007
I still have a few questions and hopefully you all are still willing to explain. Im using the menu h0 noMan posted.rnrnThe first one is how to close a menu?rn Im using this:rnrn
Len += format(szMenuBody[Len],511,"^nw0. /rExit menu")rnrnAnd then in the choice_menu_function:rnrnelse if (key == 9) // Exit menurn {rn menu_setprop(display_menu_main, MPROP_EXIT, MEXIT_ALL)rn menu_display(id, display_menu_main, 0)rn }rnrnHowever this is not working for me.rnrnIm creating a information menu plugin where people can find all information related to my server in one menu. I go from menu to menu. If I choice an option in the menu, how would I have to show the begin menu?rnrnDo I do like this? So the set_task opens the menu again?:rnrnelse if (key == 4) // Weapon Modrn {rn client_print(id,print_chat, "[B.A.M INFO] Server rules")rn client_print(id,print_chat, "[B.A.M INFO] Server rules")rn client_print(id,print_chat, "[B.A.M INFO] Server rules")rn set_task(set_task(0.1,"display_menu_main",id)rn }Threads: 11
Joined: Dec 2007
I never used to 0 Option in a Menu.nnTo show the key attribued to you exit choice, try displaying the key in your choice_menu_function.nnset_task is a good way to reopen a new menu.
Threads: 59
Joined: Jan 2007
Well, it's working with the 0 key. I basicly got connecting menu's, one option opens a new menu. With 0 in the sub menu's I can return to the main menu.rnrnThere is only an issue on how to close the menu. If I place this in the function_choice:rnrn
menu_setprop(display_menu_main, MPROP_EXIT, MEXIT_ALL)rnrn menu_display(id, display_menu_main, 0)rnrnrnI get several compiling errors. Am I doing something wrong here?rnrnOne last question, show_menu(id,mkeys,szMenuBody,25)rn25 sets the time it's shown. Will this set it unlimited until close by user?rnrnshow_menu(id,mkeys,szMenuBody,0)Threads: 59
Joined: Jan 2007
It seems to automatically set 0 as close menu. I have no setting for the 0 key, but once I press it, it does close the menu. Guess that one is fixed although quite weird.
Threads: 11
Joined: Dec 2007
It is automatically set to 0 when you use the menu_setprop(xxx, MPROP_EXIT, MEXIT_ALL)nnIf you want to set the menu timer to unlimited just replace the 25 by -1.
Threads: 59
Joined: Jan 2007
Well, thats the whole thing. Im not using anything. In the function_choice I actually commented as text and still it works. If I press 0 it closes the menu and for all the others it worked as well.nnThanks for the -1 advice, that will really finish off my plugin :D

