OnPlayerSelectedMenuRow not being called
#1

Hello fellow scripters. I have a problem with menus. In the past i have only used dialogs, but i like the look of standard menu's. I'm writing a shop script for the server i script for and have hit a snag. I'm hoping someone can shed light on the matter. Here's the code please tell me if i'm doing something wrong.

pawn Код:
#define AMMO_MENU                           (0)

enum E_SHOP_DATA
{
    Menu:e_mShopMainMenu,
    Menu:e_mShopAmmoMenu,
}

new gShopData[E_SHOP_DATA];

ISHOP::CreateShopMenu()//is called in OnGameModeInit
{
    //main menu
    gShopData[e_mShopMainMenu] = CreateMenu("Shop", 1, 200.0, 100.0, 150.0, 150.0);
   
    AddMenuItem(gShopData[e_mShopMainMenu], 0, "Ammo");
   
   
    //Ammo Menu
   
    gShopData[e_mShopAmmoMenu] = CreateMenu("Ammo", 2, 100.0, 250, 150.0, 150.0);
   
    AddMenuItem(gShopData[e_mShopAmmoMenu], 0, "Armour Piercing");
    AddMenuItem(gShopData[e_mShopAmmoMenu], 1, "$50000");
   
    AddMenuItem(gShopData[e_mShopAmmoMenu], 0, "Hollow Point");
    AddMenuItem(gShopData[e_mShopAmmoMenu], 1, "$50000");
}

public OnPlayerSelectedMenuRow(playerid, row)//never gets executed
{
    new Menu:mPlayerMenu = GetPlayerMenu(playerid);
    printf("ROW: %d", row);//never prints
   
    if(mPlayerMenu == gShopData[e_mShopMainMenu])
    {
        switch(row)
        {
            case AMMO_MENU:
            {
                ShowMenuForPlayer(gShopData[e_mShopAmmoMenu], playerid);
                return 1;
            }
        }
    }
   
    return 1;
}

COMMAND:shop(playerid, params[])
{
    ShowMenuForPlayer(gShopData[e_mShopMainMenu], playerid);
    return 1;
}
Like the title suggests the callback is never called, any idea's why?

2x rep points for the person who helps.

Thanks in advance!
Reply
#2

Doesn't this get declared at the top of the script?
pawn Код:
new Menu:mPlayerMenu
Reply
#3

Tried removing brackets around the 0 where you defined AMMO_MENU?
Try to print it inside of switch(row)

edit: suhrab,no it doesn't

edit2: if you are showing us only half of the selectedmenurow i'm afraid we can't help. I had some problems of not executing and all fault was on other menu somehow.
Reply
#4

Quote:
Originally Posted by suhrab_mujeeb
Посмотреть сообщение
Doesn't this get declared at the top of the script?
pawn Код:
new Menu:mPlayerMenu
No. It's declared locally. It has to be global? (and used when i show the menu?)

Quote:
Originally Posted by wildcookie007
Посмотреть сообщение
Tried removing brackets around the 0 where you defined AMMO_MENU?
Try to print it inside of switch(row)
The brackets are ignored by the compiler. Also if the print won't work inside the callback (at the top) it definatly wont work in the switch statement. Also that is the full code ATM its an include.
Reply
#5

It doesn't have to be global, check my edit in posts.
Reply
#6

Quote:
Originally Posted by wildcookie007
Посмотреть сообщение
Tried removing brackets around the 0 where you defined AMMO_MENU?
Try to print it inside of switch(row)

edit: suhrab,no it doesn't

edit2: if you are showing us only half of the selectedmenurow i'm afraid we can't help. I had some problems of not executing and all fault was on other menu somehow.
According to https://sampwiki.blast.hk/wiki/CreateMenu it does.
Reply
#7

Quote:
Originally Posted by suhrab_mujeeb
Посмотреть сообщение
I don't see it say it must be global anywhere on that page. Look here https://sampwiki.blast.hk/wiki/OnPlayerSelectedMenuRow

Thanks for trying to help though.

EDIT: The thing is, it IS showing the menu (/shop command), but when i select an item the callback is not called (so it never shows the next menu). The "printf" is never printed, as far as im aware that callback is called when a player selects an item from a menu. So even if the variables are mixed up (which they are not) the callback should be called if a menu item is selected regardless.
Reply
#8

try doing a different menu, create basic menu without any enums and a simple item in it which gives you a message, I'm not 100% sure but it COULD be cause of your defines or you're not showing us the whole code.

Quote:
Originally Posted by suhrab_mujeeb
Посмотреть сообщение
what you show me here is CREATING A MENU. But you showed a GETPLAYERMENU define code.
Reply
#9

Ok now iv changed the code here is the entire code now, every single reference to this code is here. And still the callback isn't called. Again it shows the menu, i select "testmenu" the menu closes without calling the callback.

pawn Код:
#define _ishop_included

new Menu:TestMenu;

public OnGameModeInit()//inside the GM
{
    TestMenu = CreateMenu("Test Menu", 1, 200.0, 100.0, 150.0, 150.0);
    AddMenuItem(TestMenu, 0, "TestMenu");
    return 1;
}

public OnPlayerSelectedMenuRow(playerid, row)//never gets executed
{
    SendClientMessage(playerid, -1, "OnPlayerSelectedMenuRow called");
    new Menu:mPlayerMenu = GetPlayerMenu(playerid);
   
    if(mPlayerMenu == TestMenu)
    {
        switch(row)
        {
            case 0:
            {
                SendClientMessage(playerid, -1, "OnPlayerSelectedMenuRow Item 0");
                return 1;
            }
        }
    }
   
    return 1;
}

COMMAND:test(playerid, params[])
{
    ShowMenuForPlayer(TestMenu, playerid);
    return 1;
}
Reply
#10

Weird, this can't be right.. I have no idea what could be wrong.. Did you define all your includes ?

Edit: How are you pressing to choose in the menu?
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)