Raised This Month: $32 Target: $400
 8% 

[INC] Menu stocks


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 


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 07:52.


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