AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Menu thing (https://forums.alliedmods.net/showthread.php?t=9736)

Smokey485 01-29-2005 02:04

Menu thing
 
give me a full code of making a menu with 9 options.. and on all of em theres client_cmds(just show me where to put the client command code u dont have to put em there)

XxAvalanchexX 01-29-2005 03:07

Re: Menu thing
 
http://djeyl.net/forum/index.php?showtopic=27288

Peli 01-29-2005 14:38

Here is the code from the link Avalanche gave , it is Xeroblood's tutorial to make menus , works for AMX Mod and AMX Mod X. All you have to do is change #include <amxmod> to #include <amxmodx> but I did that for you , I added comments where you put the client commands , and where you put the messages you want when that client uses that command. :
Code:
#include <amxmodx> public plugin_init() {     register_clcmd( "say /menu","ShowMenu", -1, "Shows The menu" )     register_menucmd(register_menuid("\yFirst Menu:"), 1023, "MenuCommand" )     return PLUGIN_CONTINUE } public ShowMenu( id ) {     new szMenuBody[256]     new keys     format( szMenuBody, 255, "\yFirst Menu:^n" )     add( szMenuBody, 255, "^n\w1. First Option Name" )     add( szMenuBody, 255, "^n\w2. Second Option Name" )     add( szMenuBody, 255, "^n\w3. Third Option Name" )     add( szMenuBody, 255, "^n\w4. Fourth Option Name" )     add( szMenuBody, 255, "^n\w5. Fifth Option Name" )     add( szMenuBody, 255, "^n\w6. Sixth Option Name" )     add( szMenuBody, 255, "^n\w7. Seventh Option Name" )     add( szMenuBody, 255, "^n\w8. Eighth Option Name" )     add( szMenuBody, 255, "^n\w9. Ninth Option Name" )     add( szMenuBody, 255, "^n^n\w0. Exit Option Name" )     keys = (1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<6|1<<7|1<<8|1<<9)         show_menu( id, keys, szMenuBody, -1 )     return PLUGIN_CONTINUE } public MenuCommand( id, key ) {     client_print( id, print_console, "[AMX] Key=%d", key )     client_print( id, print_chat, "[AMX] Key=%d", key )     switch( key )     {         case 0:            // Put your client message hereclient_print( id, print_chat, "Text")            // Put your client command here         case 1:            // Put your client message hereclient_print( id, print_chat, "Text")            // Put your client command here         case 2:            // Put your client message hereclient_print( id, print_chat, "Text")            // Put your client command here         case 3:            // Put your client message hereclient_print( id, print_chat, "Text")            // Put your client command here         case 4:            // Put your client message hereclient_print( id, print_chat, "Text")            // Put your client command here         case 5:            // Put your client message hereclient_print( id, print_chat, "Text")            // Put your client command here         case 6:            // Put your client message hereclient_print( id, print_chat, "Text")            // Put your client command here         case 7:            // Put your client message hereclient_print( id, print_chat, "Text")            // Put your client command here         case 8:            // Put your client message hereclient_print( id, print_chat, "Text")            // Put your client command here         case 9:            // Put your client message hereclient_print( id, print_chat, "Text")            // Put your client command here     }     return PLUGIN_HANDLED }

MistaGee 03-03-2005 09:18

btw: the author of the linked tutorial didn't tell us why you can also use
Code:

new keys = 1023
instead of
Code:

new keys=(1<<0|1<<1|1<<2|1<<3|..|1<<9)
Well this is quite easy:

With the above code you set bits. Written side by side, this looks as following:
Code:

Keys: 9 8 7 6 5 4 3 2 1 0
Bits: 1 1 1 1 1 1 1 1 1 1

This way makes clear that these bits represent a binary number, which, "translated" into the decimal system, is equal to 1023.

Let's see what happens if u only need keys 0-4:
Code:

Keys: 9 8 7 6 5 4 3 2 1 0
Bits: 0 0 0 0 0 1 1 1 1 1

The corresponding decimal value for this would be 31.

I think it's a lot easier using the bitwise notation cuz u won't lose the overview there, just wanted to give a hint...

v3x 03-04-2005 19:12

Coo, thanks.

xeroblood 03-05-2005 09:27

@MistaGee:

I understand BitWise operations fully, the question I had (way back then) was not "Why is the number 1023", but more like "Why do we even need keys there, when the show_menu() function ultimately ignores them and uses its own keys anyway"...
(Nice explanaition tho! But you didn't explain the math to them! ;))


Also, please don't use that code bit containing the add() functions.. use this instead:
Code:
public ShowMenu( id ) {     new szMenuBody[256]     new keys     new len = format( szMenuBody, 255, "\yFirst Menu:^n" )     len += format( szMenuBody[len], 255-len, "^n\w1. First Option Name" )     len += format( szMenuBody[len], 255-len, "^n\w2. Second Option Name" )     len += format( szMenuBody[len], 255-len, "^n\w3. Third Option Name" )     len += format( szMenuBody[len], 255-len, "^n\w4. Fourth Option Name" )     len += format( szMenuBody[len], 255-len, "^n\w5. Fifth Option Name" )     len += format( szMenuBody[len], 255-len, "^n\w6. Sixth Option Name" )     len += format( szMenuBody[len], 255-len, "^n\w7. Seventh Option Name" )     len += format( szMenuBody[len], 255-len, "^n\w8. Eighth Option Name" )     len += format( szMenuBody[len], 255-len, "^n\w9. Ninth Option Name" )     len += format( szMenuBody[len], 255-len, "^n^n\w0. Exit Option Name" )     keys = (1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<6|1<<7|1<<8|1<<9)         show_menu( id, keys, szMenuBody, -1 )     return PLUGIN_CONTINUE }

Just replace the same function from above with this one..

MistaGee 03-05-2005 10:06

Quote:

Originally Posted by xeroblood
@MistaGee:

I understand BitWise operations fully

sorry bout that d00d :D

Quote:

Originally Posted by xeroblood
the question I had (way back then) was not "Why is the number 1023", but more like "Why do we even need keys there, when the show_menu() function ultimately ignores them and uses its own keys anyway"...

isn't life one big question? :]

Quote:

Originally Posted by xeroblood
(Nice explanaition tho! But you didn't explain the math to them! ;))

Here it comes:
To get a decimal number out of a binary do the following:
for example: 1101010
decimal = 1*2^7 + 1*2^6 + 0*2^5 + 1*2^4 + 1*2^3 + 0*2^2 + 1*2^1 + 0*2^0 = 26

or just ask your calc.exe in scientific mode (can be switched via menu "View") :D

xeroblood 03-05-2005 10:43

(..double-post..)

xeroblood 03-05-2005 10:44

Quote:

Originally Posted by MistaGee
decimal = 1*2^7 + 1*2^6 + 0*2^5 + 1*2^4 + 1*2^3 + 0*2^2 + 1*2^1 + 0*2^0 = 26

:D GJ!!! That was almost *10100111001* !!!!

v3x 03-05-2005 12:09

Noooo, not math!!

xero, read your gmail =].


All times are GMT -4. The time now is 19:16.

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