AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [INC] Menu stocks (https://forums.alliedmods.net/showthread.php?t=265325)

KissLick 06-26-2015 06:16

[INC] Menu stocks
 
This include allows you to pass a value (cell, float or string) to menu callback.

Just look at the example ;-) Download & GitHub.

PHP Code:

ShowMyMenu(iClientiSecretValue)
{
    new 
Handle:hMenu CreateMenu(MyMenu_Handler);

    
SetMenuTitle(hMenu"Choose your weapon:");
    
AddMenuItem(hMenu"weapon_m4a1""M4A1");
    
AddMenuItem(hMenu"weapon_ak47""AK-47");
    
AddMenuItem(hMenu"weapon_scout""Scout");

    
// here is the magic
    
PushMenuCell(hMenu"-MySecretValue-"iSecretValue);

    
SetMenuExitBackButton(hMenutrue);
    
DisplayMenu(hMenuiClient30);
}

public 
MyMenu_Handler(Handle:hMenuMenuAction:iActioniClientiKey)
{
    switch (
iAction) {
        case 
MenuAction_Select: {
            new 
String:sWeapon[64];
            
GetMenuItem(hMenuiKeysWeaponsizeof(sWeapon));
            
GivePlayerItem(iClientsWeapon);

            
// here is the magic
            
new iSecretValue GetMenuCell(hMenu"-MySecretValue-");       

            
PrintToConsole("Player %N has secret value = %d."iClientiSecretValue);
        }
        case 
MenuAction_End: {
            
CloseHandle(hMenu);
        }
    }


Let's say, you need to pass a value from one menu to another
PHP Code:

public MyMenu_Handler(Handle:hMenuMenuAction:iActioniClientiKey)
{
    switch (
iAction) {
        case 
MenuAction_Select: {
            new 
String:sWeapon[64];
            
GetMenuItem(hMenuiKeysWeaponsizeof(sWeapon));
            
GivePlayerItem(iClientsWeapon);

            new 
Handle:hSubMenu CreateMenu(MySubMenu_Handler);
            
SetMenuTitle(hSubMenu"Choose your HP:");
            
AddMenuItem(hSubMenu"35""35 HP");
            
AddMenuItem(hSubMenu"100""100 HP");
            
AddMenuItem(hSubMenu"300""300 HP");

            
// here is the magic
            
CopyMenuAny(hMenuhSubMenu"-MySecretValue-");

            
SetMenuExitBackButton(hSubMenutrue);
            
DisplayMenu(hSubMenuiClient30);
        }
        case 
MenuAction_End: {
            
CloseHandle(hMenu);
        }
    }


Also notice function AddMenuItemFormat, which allows you to do
PHP Code:

AddMenuItemFormat(hMenu"weapon_ak47"_"AK-47 + %d ammo"90);

// instead of

new String:sDisplay[64];
Format(sDisplaysizeof(sDisplay), "AK-47 + %d ammo"90);
AddMenuItem(hMenu"weapon_ak47"sDisplay); 


TheWho 08-07-2015 11:41

Re: [INC] Menu stocks
 
Pretty smart, thx!

KissLick 12-29-2015 18:29

Re: [INC] Menu stocks
 
Vinnice made a 1.7 syntax version, I am gonna put that in GIT repository as another branch, but till then -> https://github.com/TryHardDood/Menu-stocks

Drixevel 07-27-2016 23:10

Re: [INC] Menu stocks
 
https://github.com/Drixevel/Menu-sto...enu-stocks.inc

Syntax update.

shavit 07-28-2016 11:15

Re: [INC] Menu stocks
 
Quote:

Originally Posted by redwerewolf (Post 2440103)

wrong branch~ https://github.com/Drixevel/Menu-sto...enu-stocks.inc

Drixevel 07-28-2016 13:28

Re: [INC] Menu stocks
 
Quote:

Originally Posted by shavit (Post 2440231)

Fixed, thanks.

xXDeathreusXx 08-02-2016 22:14

Re: [INC] Menu stocks
 
It's not truly 1.7 syntax, as it's still using Handle and AddMenuItem, but I'm just being picky since combining the 2 different syntax' annoys me

Potato Uno 08-03-2016 09:43

Re: [INC] Menu stocks
 
If it compiles with
PHP Code:

#pragma newdecls required 

then it is new syntax compliant.

Farbror Godis 08-03-2016 13:35

Re: [INC] Menu stocks
 
What about something like this? (not tested, but it compiles. Also, not sure what result retagging a typdef yields, but again, it compiles)

Spoiler


EDIT: I went ahead and tested it and it seems to be working perfectly, so i decided to port all of the stocks.

Spoiler


It's used just like the Menu methodmap:
Code:
public void DisplaySuperSecretMenu(int client) {     SmartMenu menu = new SmartMenu(MenuHandler);     menu.SetTitle("Super Secret Menu");     menu.ExitButton = true;     menu.PushCell("super-secret-value", 5);     menu.AddItem("1", "Option 1");     menu.AddItem("2", "Option 2");     menu.Display(client, MENU_TIME_FOREVER); } public int MenuHandler(SmartMenu menu, MenuAction action, int param1, int param2) {     switch(action) {         case(MenuAction_Select): {             int secret_value = menu.GetCell("super-secret-value");             ...         }         case(MenuAction_End): {             delete menu;         }     } }

https://github.com/farbrorgodis/smart-menu

xXDeathreusXx 08-03-2016 21:26

Re: [INC] Menu stocks
 
Quote:

Originally Posted by Potato Uno (Post 2441943)
If it compiles with
PHP Code:

#pragma newdecls required 

then it is new syntax compliant.

Well yeah, it'll compile, but true syntax would be
Code:

    Menu menu = new Menu(hndlr, MENU_ACTIONS_DEFAULT);
And everything would then follow
Code:

    menu.AddItem("item", "item");
    menu.AddItem("item", "item");
    menu.ExitButton = false;
    menu.OptionFlags = MENU_NO_SOUND;
    menu.Display(client, 10);



All times are GMT -4. The time now is 01:30.

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