AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   More help learning (https://forums.alliedmods.net/showthread.php?t=361)

xeroblood 03-30-2004 09:06

Quote:

Originally Posted by Peli
Okay , I will work on a plugin , I got a good idea it is probably made already but who cares I'm practicing. How would I make a menu with options? Someone please help , that's all I don't know , the rest I will look at your plugin and get some info.

I once wrote a tut for Menu systems in AMX, it should suffice since making menus in AMXX hasn't changed!!

Also, I wrote the tutorial a long time ago, and I explained using the add() function for combining strings, but you should use format().. anyway, not a big deal there..

You could find it here!

(Maybe Bailopan has written a better one since tho, be sure to check for his in the AMXX Docs!!)

Hope it helps!!

Peli 03-30-2004 15:22

Xeroblood , I looked in the Amx scripting section I saw your stickie a long time ago , I just thought of it right now , thanks it really helps :) One question though , I know how to set the menu up , but how do you set actions up for each option?

Gor.d 03-30-2004 16:17

I hate to jack someone else's help thread, but what is the significance of i++?

Peli 03-30-2004 18:05

No problem man. This is for all to get help :) I am a noob but I think that would mean , i could be more? Just a guess.

xeroblood 03-31-2004 09:00

@Peli:

first, of course, you display the menu (I know you got that), but that will only show it on screen..
when you register the Menu with AMX/X, it will call any function you specify when a user chooses one of the options.. register it like:
Code:
register_menucmd(register_menuid("\yYour Menu:"), (1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<6|1<<7|1<<8|1<<9|1<<0), "MenuCommand" )

where "\yYour Menu:" is whatever you named your menu when displaying it (the very first part of the string)

If I did the above in code I am telling AMX/X that my menu uses all 10 options: (1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<6|1<<7|1<<8 |1<<9|1<<0)
1<<0 = KeyPad Key 1
1<<1 = KeyPad Key 2
1<<2 = KeyPad Key 3
...
...
1<<8 = KeyPad Key 9
1<<9 = KeyPad Key 0

and when any one of those keys is pressed by the user, AMX/X will hide the on-screen menu and call the "MenuCommand" function..

now in your MenuCommand function (you can name it anything) you would 'catch' the key pressed by the user (sent from AMX/X) in a parameter (ussually called 'key') so that your code knows what option was chosen:

id = the user who seen then menu and chose option,
key = the option they chose (as a bit, so if they Press 1 on keypad, you get 0 in code, just like above)
Code:
public MenuCommand( id, key ) {     switch( key )     {         case 0: client_print( id, print_chat, "Menu Option #1" )         case 1: client_print( id, print_chat, "Menu Option #2" )                 case 2: client_print( id, print_chat, "Menu Option #3" )         case 3: client_print( id, print_chat, "Menu Option #4" )         case 4: client_print( id, print_chat, "Menu Option #5" )         case 5: client_print( id, print_chat, "Menu Option #6" )         case 6: client_print( id, print_chat, "Menu Option #7" )         case 7: client_print( id, print_chat, "Menu Option #8" )         case 8: client_print( id, print_chat, "Menu Option #9" )         case 9: client_print( id, print_chat, "Menu Option #0" )     }     return PLUGIN_HANDLED }

Hope that helps!!

@Gor.d:

i++ is a postfix 'increment' operation..

i++ is simply i = i + 1 after the current usage of i (postfix)
++i is simply i = i + 1 before the current usage of i (prefix)

so if i = 5
and I did: call_some_ex_func( i++ )

then the function "call_some_ex_func" would recieve a value of '5'
then, the i gets incremented by one..
however, if I did: call_some_ex_func( ++i )
then i gets incremented first to '6' then the function gets called, passing the new value of 6!!

Hope that didn't confuze you..

Gor.d 03-31-2004 09:10

No, it actually helped alot. Thanks Xeroblood.

Peli 03-31-2004 14:28

Nevermind :)


All times are GMT -4. The time now is 10:44.

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