AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   New Menus and Old Menus (https://forums.alliedmods.net/showthread.php?t=120916)

Dizzy 03-09-2010 12:39

New Menus and Old Menus
 
Hey guys, I've been constantly looking though various codes here and there and have always seen different types of menus, and when running code can really see differences..

Some menus allow for a user to declare when it is white text or dark text (as if it were a disabled option) and some codes don't allow this. I have a code that I'm working on that I want to have the feature functionality and I've seen people throw around the "new menu system"

However, I've seen three menu systems throughout the code I've seen.. Is there a thread on this forum that actually shows the new menu system and how to use it? I've looked through scripting help and code snippet's stickies and have not really seen anything..

Means a lot guys, thanks!

fR4gn0tiX! 03-09-2010 12:41

Re: New Menus and Old Menus
 
http://forums.alliedmods.net/showthread.php?t=46364

Dizzy 03-09-2010 12:57

Re: New Menus and Old Menus
 
Thanks a lot fR4gn0tiX! :)

Dizzy 03-09-2010 13:10

Re: New Menus and Old Menus
 
Hmmm, very useful tutorial! Just one question that I didn't directly see addressed there.. I noticed that at the new menu item you can use \r before what you say, I am assuming that this is the color red to the text.

How can you perform a check on CVARs to choose the color?

Like, if (!get_cvar_num(CVAR))

Then \d

else

\w

I noticed you could do this with format, but is this the way to do it in this menu system?

Emp` 03-09-2010 14:27

Re: New Menus and Old Menus
 
You could do something like:
Code:

if( blah )
  menu_additem(menu, "\dI'm Selection #1", "1", 0);
else
  menu_additem(menu, "\wI'm Selection #1", "", 0);

But using format is not a bad option.

edit: You should have posted this in Scripting Help btw.

Exolent[jNr] 03-09-2010 14:29

Re: New Menus and Old Menus
 
Use callbacks in new menus to choose the color.

Also, why did you post this in Off-Topic?
You are obviously talking about scripting.

Dizzy 03-09-2010 15:16

Re: New Menus and Old Menus
 
Well it originally was just a post to find the thread, but then it started becoming scripting help.. My bad =/

Dizzy 03-09-2010 16:21

Re: New Menus and Old Menus
 
How exactly do Callbacks work? I didn't really understand it via the New Menu tutorial..

Also, could I have this moved to Scripting help rather than creating a new topic.. Don't wanna make a load of threads for one big question :)

Exolent[jNr] 03-09-2010 21:25

Re: New Menus and Old Menus
 
Code:
#include < amxmodx > #define MAX_PLAYERS 32 new bool:g_bToggle[ MAX_PLAYERS + 1 ]; new g_hMenu; public plugin_init( ) {     register_plugin( "Callback Test", "0.0.1", "Exolent" );         register_clcmd( "say /toggle", "CmdToggle" );         new hCallback = menu_makecallback( "CallbackToggle" );     g_hMenu = menu_create( "Toggle Menu", "MenuToggle" );         menu_additem( g_hMenu, "On", "1", _, hCallback );     menu_additem( g_hMenu, "Off", "0", _, hCallback ); } public client_disconnect( iPlayer ) {     g_bToggle[ iPlayer ] = false; } public CmdToggle( iPlayer ) {     menu_display( iPlayer, g_hMenu ); } public CallbackToggle( iPlayer, hMenu, iItem ) {     new iAccess, szInfo[ 2 ], hCallback;     menu_item_getinfo( hMenu, iItem, iAccess, szInfo, charsmax( szInfo ), _, _, hCallback );         switch( szInfo[ 0 ] )     {         case '1':         {             if( g_bToggle[ iPlayer ] )             {                 // toggle is already on, so disable the "On" item                 return ITEM_DISABLED;             }         }         case '0':         {             if( !g_bToggle[ iPlayer ] )             {                 // toggle is already off, so disable the "Off" item                 return ITEM_DISABLED;             }         }     }         // enable the items if they are allowed     return ITEM_ENABLED; } public MenuToggle( iPlayer, hMenu, iItem ) {     if( iItem == MENU_EXIT )     {         return;     }         new iAccess, szInfo[ 2 ], hCallback;     menu_item_getinfo( hMenu, iItem, iAccess, szInfo, charsmax( szInfo ), _, _, hCallback );         switch( szInfo[ 0 ] )     {         case '1':         {             // this will only be called if callback returns ITEM_ENABLED             g_bToggle[ iPlayer ] = true;         }         case '0':         {             // this will only be called if callback returns ITEM_ENABLED             g_bToggle[ iPlayer ] = false;         }     }         menu_display( iPlayer, g_hMenu ); }

If the callback returns ITEM_DISABLED, the item and number will be grayed out and nothing will happen if the key is pressed.

Of course, this could be reduced to smaller code, but it was just an example.


All times are GMT -4. The time now is 08:40.

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