| closedtranslation for a menu |
| Started by Tank on 12-14-2008, 08:42 PM |
Threads: 59
Joined: Jan 2007
I created a simple plugin to test the use of menu's in a plugin.nnDescription plugin:nIt's a plugin which through a bind a client is shown a menu where it can make different choices. All the choices are client_chat messages providing information about the game, the server plugins or clan related information.nnQuestions(I have a few):nnQuestion 1:nAt this point I just coded all the messages shown in the menu through cvars. Is there any way to change the language shown in the menu without having to copy paste and translate the entire code for each added language? nnI've been looking at the afk_kicker and the dod_teammanager plugins since they work with a translate file, but neither of them use a menu shown to the client. Seaches made on allied modders also didn't gave me any result.nnQuestion 2:nIf I have this menu:nn1. choice 1n2. choice 2nnAnd choice 1 leads to another menu page, do I just create a new menu? That's what I have done with my current version.nnQuestion 3:nI use this method (tnx again :D) link for my menu, but I would like to know how I can create a second menu page?nn
npublic display_menu_pluginsenabled(id)n{n new szMenuBody[512]n new mkeys = 543n new Len = format(szMenuBody,511,plugins)n n Len += format(szMenuBody[Len],511,"^n
1. woption")n Len += format(szMenuBody[Len],511,"^n
2. woption")n Len += format(szMenuBody[Len],511,"^n
3. woption")n Len += format(szMenuBody[Len],511,"^n
4. woption")n Len += format(szMenuBody[Len],511,"^n
5. woption")n Len += format(szMenuBody[Len],511,"^n
6. woption")n Len += format(szMenuBody[Len],511,"^n
7. woption")n Len += format(szMenuBody[Len],511,"^n
8. woption")n Len += format(szMenuBody[Len],511,"^n
9. woption")n Len += format(szMenuBody[Len],511,"^n
0. woption")n//What do I do now? Im stuck since there is no key 11, do I just link it to another menu for the second page?n n show_menu(id,mkeys,szMenuBody,59)n}nThreads: 75
Joined: Jun 2006
First off to have different languages for your menu all you need to use is the lang features. So, you can look at TK Revenge to see a bit more of this but here is the gist of it:rnrn
public plugin_init()rn{rn ...your codernrn register_dictionary("yourdictionary.txt")rnrn ...your codern}rnrnNow whenever you want to print something out such as client print or menu print or whenever you do the following:rnrnclient_print(id, print_chat, "%L",id,"DICTIONARY_SENTENCE",username)rnrnTo explain the above he is what it would look like if you were only doing it for english:rnrnclient_print(id, print_chat, "My Name is %s",username)rnrnSo, the %L tell the plugin to use the dictionary registered, next you have the id of the player calling the item, so in amxmodx players can tell it what language to show output in, lets say french. Next you have the shall we say defined name of the string we are going to use, in this case DICTIONARY_SENTANCE, and finally we have the output for the %s or username.rnrnGood so far, alright, so now here is what you would have in yourdictionary.txtrnrn[en]rnDICTIONARY_SENTENCE = My Name is %s!rnrn[fr]rnDICTIONARY_SENTENCE = Jaime mapel %s!rnrnOk all good for that! rnrnNext lesson, to fix the problem with 11 key, of which there is none. What you need to do is split it up into different functions and that will cover different keys:rnrnnew menu_position[33] = {0, ...}rnrnpublic plugin_init()rn{rn register_clcmd("dod_show_menu","menu_show",0,"- display menu")rn register_menucmd(register_menuid("Menu"),1024,"handle_menu")rn}rnrnpublic menu_show(id, level, cid)rn{rn if(!cmd_access(id, level, cid, 1))rn return PLUGIN_HANDLEDrnrn menu_one(id)rnrn return PLUGIN_HANDLEDrn}rnrnrnpublic handle_menu(id,key)rn{rn switch(key+menu_position[id])rn {rn case 1: // Do somethingrn case 2: // Do somethingrn case 3: // Do somethingrn case 4: // Do somethingrn case 5: // Do somethingrn case 6: // Do somethingrn case 7: // Do somethingrn case 8:rn {rn menu_position[id] = 9rn menu_two(id)rn }rn case 9: return PLUGIN_HANDLEDrn case 10: // Do somethingrn case 11: // Do somethingrn case 12: // Do somethingrn case 13: // Do somethingrn case 14: // Do somethingrn case 15: // Do somethingrn case 16: // Do somethingrn case 17:rn {rn menu_position[id] = 0rn menu_one(id)rn }rn case 18: return PLUGIN_HANDLEDrn }rn}rnrnpublic menu_one(id)rn{rn new szMenuBody[1024]rn new len = format(szMenuBody, 1023, "yMenu:^n")rn rn Len += format(szMenuBody[Len],511,"
1. woption^n")rn Len += format(szMenuBody[Len],511,"
2. woption^n")rn Len += format(szMenuBody[Len],511,"
3. woption^n")rn Len += format(szMenuBody[Len],511,"
4. woption^n")rn Len += format(szMenuBody[Len],511,"
5. woption^n")rn Len += format(szMenuBody[Len],511,"
6. woption^n")rn Len += format(szMenuBody[Len],511,"
7. woption^n")rn Len += format(szMenuBody[Len],511,"
8. wNext^n")rn Len += format(szMenuBody[Len],511,"
9. wExit")rn rn show_menu(id,1023,szMenuBody)rn} rnrnpublic menu_two(id)rn{rn new szMenuBody[1024]rn new len = format(szMenuBody, 1023, "yMenu:^n")rn rn Len += format(szMenuBody[Len],511,"
1. woption")rn Len += format(szMenuBody[Len],511,"
2. woption")rn Len += format(szMenuBody[Len],511,"
3. woption")rn Len += format(szMenuBody[Len],511,"
4. woption")rn Len += format(szMenuBody[Len],511,"
5. woption")rn Len += format(szMenuBody[Len],511,"
6. woption")rn Len += format(szMenuBody[Len],511,"
7. woption")rn Len += format(szMenuBody[Len],511,"
8. wBack")rn Len += format(szMenuBody[Len],511,"
9. wExit")rn rn show_menu(id,1023,szMenuBody)rn} rnrnNow this is the old way of doing it, there may be a new way that I haven't looked at, so, check it out!rnrnCheers!Threads: 11
Joined: Dec 2007
In handle_menu() you should start from key 0.rnrn
public handle_menu(id,key)rn{rn switch(key+menu_position[id])rn {rn case 0: // Page 1 - Option 1rn case 1: // Page 1 - Option 2rn case 2: // Page 1 - Option 3rn case 3: // Page 1 - Option 4rn case 4: // Page 1 - Option 5rn case 5: // Page 1 - Option 6rn case 6: // Page 1 - Option 7rn case 7: // Page 1 - Option Nextrn {rn menu_position[id] = 9rn menu_two(id)rn }rn case 8: return PLUGIN_HANDLED // Page 1 - Option Exitrn case 9: // Page 2 - Option 1rn case 10: // Page 2 - Option 2 rn case 11: // Page 2 - Option 3 rn case 12: // Page 2 - Option 4 rn case 13: // Page 2 - Option 5 rn case 14: // Page 2 - Option 6rn case 15: // Page 2 - Option 7rn case 16: // Page 2 - Option Backrn {rn menu_position[id] = 0rn menu_one(id)rn }rn case 17: return PLUGIN_HANDLED // Page 2 - Option Exitrn }rn}Threads: 75
Joined: Jun 2006
I was reading a bit about the new menu system and it has changed drastically. So I would suggest that you read that link that diamond put up on your other thread and try it that way!rnrnCheers!
Threads: 59
Joined: Jan 2007
Ok, I've been giving the whole translation thing a go but ended up with a plugin which doesn't work anymore. Hope you wont mind if I double check on getting the method right...not really sure if I understood it properly.rnrn
Len += format(szMenuBody[Len],511,"^n
1. w%L", "MAIN_RULES")rnrnThats how I translated my menu item.rnrnclient_print(id,print_chat,"%L","MAIN_WEBSITE2A")rn client_print(id,print_chat,"%L","MAIN_WEBSITE2B")rn client_print(id,print_chat,"%L","MAIN_WEBSITE2C")rn func_mainmenu(id)rnrnThats how I translated a client_print. I have my doubts with this one as I see some more with ID in the examples but I tried several options and they all failed.rnrnAlso 2 questions on the language textfile, do I do this:rnrn[en]rnDICTIONARY_SENTENCE = testingrnrn[en]rnDICTIONARY_SENTENCEDIF = testingrnrnOr can I just place em like this:rnrn[en]rnDICTIONARY_SENTENCE = testingrnDICTIONARY_SENTENCEDIF = testingrnrnLast thing, can you comment in textfiles using //?Threads: 75
Joined: Jun 2006
You can place the dictionary files like you did for the second one. You only need the seperate tags for different languages. The other part you forgot the ID:rnrn
Your Version: rnLen += format(szMenuBody[Len],511,"^n
1. w%L", "MAIN_RULES")rnrnProper: rnLen += format(szMenuBody[Len],511,"^n
1. w%L", id, "MAIN_RULES") rnrnrnCheers!Threads: 59
Joined: Jan 2007
Thanks a lot, the plugin works perfectly. Now I just hope I can get my members as crazy to translate 70 lines of text :D
Threads: 11
Joined: Dec 2007
I can make the french one if you want.

