Raised This Month: $7 Target: $400
 1% 

[INC] Menu stocks


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 06-26-2015 , 06:16   [INC] Menu stocks
Reply With Quote #1

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); 

Last edited by KissLick; 06-26-2015 at 06:19.
KissLick is offline
TheWho
AlliedModders Donor
Join Date: Jul 2012
Old 08-07-2015 , 11:41   Re: [INC] Menu stocks
Reply With Quote #2

Pretty smart, thx!
TheWho is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 12-29-2015 , 18:29   Re: [INC] Menu stocks
Reply With Quote #3

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
__________________
Plugins: TeamGames
Includes: Menu stocks, ColorVariables, DownloadTableConfig

> No help through PM, make a topic.
KissLick is offline
Drixevel
AlliedModders Donor
Join Date: Sep 2009
Location: Somewhere headbangin'
Old 07-27-2016 , 23:10   Re: [INC] Menu stocks
Reply With Quote #4

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

Syntax update.

Last edited by Drixevel; 07-28-2016 at 13:28.
Drixevel is offline
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 07-28-2016 , 11:15   Re: [INC] Menu stocks
Reply With Quote #5

Quote:
Originally Posted by redwerewolf View Post
wrong branch~ https://github.com/Drixevel/Menu-sto...enu-stocks.inc
__________________
retired
shavit is offline
Drixevel
AlliedModders Donor
Join Date: Sep 2009
Location: Somewhere headbangin'
Old 07-28-2016 , 13:28   Re: [INC] Menu stocks
Reply With Quote #6

Quote:
Originally Posted by shavit View Post
Fixed, thanks.
Drixevel is offline
xXDeathreusXx
Veteran Member
Join Date: Mar 2013
Location: pPlayer->GetOrigin();
Old 08-02-2016 , 22:14   Re: [INC] Menu stocks
Reply With Quote #7

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
__________________
Plugins|Profile
Requests closed

I'm a smartass by nature, get used to it
xXDeathreusXx is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 08-03-2016 , 09:43   Re: [INC] Menu stocks
Reply With Quote #8

If it compiles with
PHP Code:
#pragma newdecls required 
then it is new syntax compliant.
Potato Uno is offline
Farbror Godis
AlliedModders Donor
Join Date: Feb 2016
Old 08-03-2016 , 13:35   Re: [INC] Menu stocks
Reply With Quote #9

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
__________________

Last edited by Farbror Godis; 08-04-2016 at 09:34.
Farbror Godis is offline
xXDeathreusXx
Veteran Member
Join Date: Mar 2013
Location: pPlayer->GetOrigin();
Old 08-03-2016 , 21:26   Re: [INC] Menu stocks
Reply With Quote #10

Quote:
Originally Posted by Potato Uno View Post
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);
__________________
Plugins|Profile
Requests closed

I'm a smartass by nature, get used to it
xXDeathreusXx is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 22:34.


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