Raised This Month: $ Target: $400
 0% 

[Help] Menu Problems


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kDiosn
Member
Join Date: Sep 2010
Old 05-07-2011 , 05:36   [Help] Menu Problems
Reply With Quote #1

hello modders!
i'm not know how to explain what i'm trying to do, but i will do my best.

OT: i want it so when i open the menu (weaponmenu) i will show
1. awp
2. deagle
3. fiveseven
4. he grenade
5. smokegrenade
6. heatseeking he

when i press 1/2/3 it will open the submenus for awp,deagle and fiveseven. and when i press 4/5/6 i will buy a lvl. (he,smoke, heatseek)
but now to my problem, the menu is showed like it is suppossed to do, but when i press 1 i buy first lvl of hegrenade, and when i press 2 i buy first lvl of smokegrenade :S i hope you understood what i meant.

Regards, kDiosn
Code:
enum _:g_iGrenCount
{
    HE_GRENADE,
    SMOKEGRENADE,
    Heatseek_HE,
}
public WeaponMenu(iPlayer, menu, item)
{
         //Menu Title
    new title[170]; formatex(title, sizeof(title) - 1, "\w- \y[MoneyMod] \wWeapon Shop -^n^n    \wYou Got: \y%i Euro's", g_iMoney[iPlayer]);
    //Create the menu
    new menu = menu_create(title, "WeaponMenu_Handle");
    new iNumber[5], iCost, szOption[80], Amount, Level, Level2;
    
    
    menu_additem(menu, "\wAwp Menu", "1", 0);
        menu_additem(menu, "\wDeagle Menu", "2", 0);
        menu_additem(menu, "\wFiveseven Menu", "3", 0);
    
    //Browse through all menu items
    for( new iGren = 0; iGren < g_iGrenCount; iGren++ )
    {
        //Bunch of variables
        num_to_str(iGren, iNumber, 4);
        Level = g_iGrenLevel[iPlayer][iGren];
        Level2 = g_iGrenLevel[iPlayer][iGren] + 1;
        iCost = g_iFirstGCost[iGren] * (1 << (Level2 - 1));
        Amount = g_iGrenMaxVal[iGren] * g_iGrenLevel[iPlayer][iGren] / g_iGrenMaxLevel[iGren];
        
        //If the player already have maxlevel
        if( g_iGrenLevel[iPlayer][iGren] >= g_iGrenMaxLevel[iGren] )
        {
            if( g_iGrenClass[iGren] == 2 )
            {
                formatex(szOption, 79, "");
            }
            else
            {
                formatex(szOption, 79, "\y%s: \wLevel %i \r(\d%i%s\r)", g_iGren[iGren], Level, Amount, g_iGrenShort[iGren]);
            }
        }
        //If the player cant afford the item
        else if( g_iMoney[iPlayer] < iCost )
        {
            if( g_iGrenClass[iGren] == 2 )
            {
                formatex(szOption, 79, "");
            }
            else
            {
                formatex(szOption, 79, "\d%s: \wLevel %i \r(\d%i%s\r) \y%i$", g_iGren[iGren], Level, Amount, g_iGrenShort[iGren], iCost);
            }
        }
        //If the player has not maxed out the item
        else if( g_iGrenLevel[iPlayer][iGren] < g_iGrenMaxLevel[iGren] )
        {
            if( g_iGrenClass[iGren] == 2 )
            {
                formatex(szOption, 79, "");
            }
            else
            {
                formatex(szOption, 79, "\r%s: \wLevel %i \r(\d%i%s\r) \y%i$", g_iGren[iGren], Level, Amount, g_iGrenShort[iGren], iCost);
            }
        }
        
        //Add all the menu items
        if( g_iGrenClass[iGren] == 2 )
        {
            menu_addblank(menu, 0);
        }
        else
        {
            menu_additem(menu, szOption, iNumber);
        }
        
    
        
    }
    
    //Display the menu
    menu_display(iPlayer, menu, 0);
}

public WeaponMenu_Handle(iPlayer, menu, item)
{
    //Get the menu data
    if( item == MENU_EXIT )
    {
        menu_destroy(menu);
        WeaponMenu(iPlayer, menu, item);
        return PLUGIN_HANDLED;
    }

    //Bunc of variables
    new data[6], iName[64];
    new num[6];
    new access, callback;
    menu_item_getinfo(menu, item, access, data,5, iName, 63, callback);
    
    new key = str_to_num(num);
    switch(key)
    {
        
        case 1:
        {
            AwpMenu(iPlayer);
        }
        case 2:
        {
            DglMenu(iPlayer);
        }
        case 3:
        {
            FsMenu(iPlayer);
        }
    }
    
    new iGren = str_to_num( data ), iCost, Level;
    Level = g_iGrenLevel[iPlayer][iGren] + 1;
    iCost = g_iFirstGCost[iGren] * (1 << (Level - 1));
    
    //If player has maxed out the item
    if( g_iGrenLevel[iPlayer][iGren] == g_iGrenMaxLevel[iGren] )
    {
        Print(iPlayer, "^x03You have the max level of %s!", g_iGren[iGren]);
    }
    //If the player cant afford the item
    else if( g_iMoney[iPlayer] < iCost )
    {
        Print(iPlayer, "^x03You dont have enough Money to buy %s Level: %i", g_iGren[iGren], Level);
    }
    //Take money, Print and give level
    else
    {
        //Take money
        g_iMoney[iPlayer] -= iCost;
        
        //Give a level
        g_iGrenLevel[iPlayer][iGren] += 1;
        
        //Print out to the player that he/she bought an item with corresponding level
        Print(iPlayer, "^x03You bought %s Level: %i", g_iGren[iGren], Level);
    }
    
    
    menu_display(iPlayer, menu, 0);
    return PLUGIN_HANDLED;
}
kDiosn is offline
SonicSonedit
Veteran Member
Join Date: Nov 2008
Location: Silent Hill
Old 05-07-2011 , 11:15   Re: [Help] Menu Problems
Reply With Quote #2

PHP Code:
num_to_str(iGreniNumber4); 

PHP Code:
num_to_str(iGreniNumber+44); 
also
PHP Code:
switch(key)    
{                  
   case 
1:
      
AwpMenu(iPlayer)

   case 
2:
      
DglMenu(iPlayer)

   case 
3:
      
FsMenu(iPlayer)

   case 
4:
      
4. he grenade

   
case 5:
      
5. smokegrenade

   
case 6:
      
6. heatseeking

__________________


Last edited by SonicSonedit; 05-07-2011 at 11:20.
SonicSonedit is offline
kDiosn
Member
Join Date: Sep 2010
Old 05-07-2011 , 14:43   Re: [Help] Menu Problems
Reply With Quote #3

Welcome to the AMX Mod X 1.8.1-300 Compiler.
Copyright (c) 1997-2006 ITB CompuPhase, AMX Mod X Team

Error: Array must be indexed (variable "iNumber") on line 1023
Warning: Expression has no effect on line 1116
Warning: Expression has no effect on line 1120
Warning: Expression has no effect on line 1124

1 Error.

Last edited by kDiosn; 05-07-2011 at 15:13.
kDiosn is offline
SonicSonedit
Veteran Member
Join Date: Nov 2008
Location: Silent Hill
Old 05-07-2011 , 15:04   Re: [Help] Menu Problems
Reply With Quote #4

err...mistyped.
PHP Code:
num_to_str(iGren+4iNumber4
__________________

SonicSonedit is offline
kDiosn
Member
Join Date: Sep 2010
Old 05-07-2011 , 15:23   Re: [Help] Menu Problems
Reply With Quote #5

still same problem ^.^
kDiosn is offline
SonicSonedit
Veteran Member
Join Date: Nov 2008
Location: Silent Hill
Old 05-07-2011 , 16:24   Re: [Help] Menu Problems
Reply With Quote #6

Did you moved everything after switches into switch case 4/5/6 ?
__________________

SonicSonedit is offline
kDiosn
Member
Join Date: Sep 2010
Old 05-07-2011 , 16:29   Re: [Help] Menu Problems
Reply With Quote #7

ye, i moved them to the spot there they was suppossed to be

i guess it's not suppossed to be case 4: he_grenade, case 5: smokegrenade and so on. = Warning: Expression has no effect :S

Code:
Welcome to the AMX Mod X 1.8.1-300 Compiler.
Copyright (c) 1997-2006 ITB CompuPhase, AMX Mod X Team

Warning: Expression has no effect on line 1116
Warning: Expression has no effect on line 1120
Warning: Expression has no effect on line 1124
Header size:           3744 bytes
Code size:            62044 bytes
Data size:            56028 bytes
Stack/heap size:      16384 bytes; estimated max. usage=785 cells (3140 bytes)
Total requirements:  138200 bytes

3 Warnings.
Done.


Code:
switch(key)    
    {                  
        case 1:
        {
            AwpMenu(iPlayer)
        }
        case 2:
        {
            DglMenu(iPlayer)
        }
        case 3:
        {
            FsMenu(iPlayer)
        }
        case 4:
        {
            HE_GRENADE
        }
        case 5:
        {
            SMOKEGRENADE
        }
        case 6:
        {
            Heatseek_HE
        }
    }
kDiosn is offline
SonicSonedit
Veteran Member
Join Date: Nov 2008
Location: Silent Hill
Old 05-07-2011 , 16:53   Re: [Help] Menu Problems
Reply With Quote #8

kDiosn
Do you actually understand what you are doing?
Try this, maybe it will be more clearly for you:
PHP Code:
switch(key)    
    {                  
        case 
1:
        {
            
client_print(idprint_chat"SELECTED AWP MENU")
            
AwpMenu(iPlayer)
        }
        case 
2:
        {
            
client_print(idprint_chat"SELECTED DEAGLE MENU")
            
DglMenu(iPlayer)
        }
        case 
3:
        {
            
client_print(idprint_chat"SELECTED 5-7 MENU")
            
FsMenu(iPlayer)
        }
        case 
4:
        {
            
client_print(idprint_chat"SELECTED HE_GRENADE MENU")
            
HE_GRENADE
            
// place your HE_GRENADE-related code here
        
}
        case 
5:
        {
            
client_print(idprint_chat"SELECTED SMOKEGRENADE MENU")
            
SMOKEGRENADE
            
// place your SMOKEGRENADE-related code here
        
}
        case 
6:
        {
            
client_print(idprint_chat"SELECTED Heatseek_HE MENU")
            
Heatseek_HE
            
// place your Heatseek_HE-related code here
        
}
    } 
__________________

SonicSonedit is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 05-08-2011 , 00:38   Re: [Help] Menu Problems
Reply With Quote #9

@SonicSonedit: If you looked at his WeaponMenu_Handle function, you'd see that he wants to use the following code for the grenade parts of the menu.
Code:
    new iGren = str_to_num( data ), iCost, Level;
    Level = g_iGrenLevel[iPlayer][iGren] + 1;
    iCost = g_iFirstGCost[iGren] * (1 << (Level - 1));
    
    //If player has maxed out the item
    if( g_iGrenLevel[iPlayer][iGren] == g_iGrenMaxLevel[iGren] )
    {
        Print(iPlayer, "^x03You have the max level of %s!", g_iGren[iGren]);
    }
    //If the player cant afford the item
    else if( g_iMoney[iPlayer] < iCost )
    {
        Print(iPlayer, "^x03You dont have enough Money to buy %s Level: %i", g_iGren[iGren], Level);
    }
    //Take money, Print and give level
    else
    {
        //Take money
        g_iMoney[iPlayer] -= iCost;
        
        //Give a level
        g_iGrenLevel[iPlayer][iGren] += 1;
        
        //Print out to the player that he/she bought an item with corresponding level
        Print(iPlayer, "^x03You bought %s Level: %i", g_iGren[iGren], Level);
    }
You could do this several different ways, but here is a simple way.

Just move the above code into a default case for the switch statement.

Look here at the switch example if you are confused.

Last edited by Emp`; 05-08-2011 at 00:40.
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
kDiosn
Member
Join Date: Sep 2010
Old 05-08-2011 , 06:51   Re: [Help] Menu Problems
Reply With Quote #10

thanks for the reply emp. can u look what i have done wrong, it is still the same problem.

Code:
public WeaponMenu_Handle(iPlayer, menu, item)
{
    //Get the menu data
    if( item == MENU_EXIT )
    {
        menu_destroy(menu);
        WeaponMenu(iPlayer, menu, item);
        return PLUGIN_HANDLED;
    }

    //Bunc of variables
    new data[6], iName[64];
    new num[6];
    new access, callback;
    menu_item_getinfo(menu, item, access, data,5, iName, 63, callback);
    
    new key = str_to_num(num);
    switch(key)    
    {                  
        case 1:
        {
            AwpMenu(iPlayer)
        }
        case 2:
        {
            DglMenu(iPlayer)
        }
        case 3:
        {
            FsMenu(iPlayer)
        }
        default:
        {
            new iGren = str_to_num( data ), iCost, Level;
            Level = g_iGrenLevel[iPlayer][iGren] + 1;
            iCost = g_iFirstGCost[iGren] * (1 << (Level - 1));
    
            //If player has maxed out the item
            if( g_iGrenLevel[iPlayer][iGren] == g_iGrenMaxLevel[iGren] )
            {
                Print(iPlayer, "^x03You have the max level of %s!", g_iGren[iGren]);
            }
            //If the player cant afford the item
            else if( g_iMoney[iPlayer] < iCost )
            {
                Print(iPlayer, "^x03You dont have enough Money to buy %s Level: %i", g_iGren[iGren], Level);
            }
            //Take money, Print and give level
            else
            {
                //Take money
                g_iMoney[iPlayer] -= iCost;
            
                //Give a level
                g_iGrenLevel[iPlayer][iGren] += 1;
        
                //Print out to the player that he/she bought an item with corresponding level
                Print(iPlayer, "^x03You bought %s Level: %i", g_iGren[iGren], Level);
            }
        }

    }  
    menu_display(iPlayer, menu, 0);
    return PLUGIN_HANDLED;
}
kDiosn is offline
Reply



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 04:24.


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