Weapon Menu Map Issue

vladyeah

Veteran
Messages
2
Reaction score
1
Points
778
Hey Guys,

I am trying to create a Weapons Menu but I am having a few issues, I'll explain whats happening:

On Shadows of Evil (41 Weapons) Page 1 and Page 2 work but Page 3 doesn't work.

On Revelations (46 Weapons) Page 1 doesn't work but Page 2 does.

On a custom zombies map (64 weapons) all pages work fine.

The reason why I only display 15 weapons + the Page button (16 options total) is due to the limitation, anything above 16 no text will display on the menu.

How can I get around to fix the issue?

Thanks! :grinning:

C++:
    MapWeapons = GetArrayKeys(level.zombie_weapons);

    for(i = 0; i < MapWeapons.size; i++)
    {
        if(i < 16)
        {
            self AddMenuAction("WeaponsMenu", i, MapWeapons[i].name, ::G_GiveWeapon, MapWeapons[i].name);
        }
        else break;
    }
    self AddMenuAction("WeaponsMenu", 16, "^5> ^7Page 2 ", ::SubMenu, "WeaponsMenu2");

    AddMenuTitle( "WeaponsMenu2", "Weapons Menu 2");
    AddBackToMenu("WeaponsMenu2","WeaponsMenu");
    WeaponIndex = 0;
    for(i = 16; i < MapWeapons.size; i++)
    {
        if(i < 32)
        {
            self AddMenuAction("WeaponsMenu2", WeaponIndex, MapWeapons[i].name, ::G_GiveWeapon, MapWeapons[i].name);
            WeaponIndex++;
        }
        else break;
    }
    self AddMenuAction("WeaponsMenu2", 16, "^5> ^7Page 3 ", ::SubMenu, "WeaponsMenu3");

    AddMenuTitle( "WeaponsMenu3", "Weapons Menu 3");
    AddBackToMenu("WeaponsMenu3","WeaponsMenu2");
    WeaponIndex2 = 0;
    for(i = 32; i < MapWeapons.size; i++)
    {
        if(i < 48)
        {
            self AddMenuAction("WeaponsMenu3", WeaponIndex2, MapWeapons[i].name, ::G_GiveWeapon, MapWeapons[i].name);
            WeaponIndex2++;
        }
        else break;
    }
    self AddMenuAction("WeaponsMenu3", 16, "^5> ^7Page 4 ", ::SubMenu, "WeaponsMenu4");

    AddMenuTitle("WeaponsMenu4", "Weapons Menu 4");
    AddBackToMenu("WeaponsMenu4","WeaponsMenu3");
    WeaponIndex3 = 0;
    for(i = 48; i < MapWeapons.size; i++)
    {
        if(i < 64)
        {
            self AddMenuAction("WeaponsMenu4", WeaponIndex3, MapWeapons[i].name, ::G_GiveWeapon, MapWeapons[i].name);
            WeaponIndex3++;
        }
        else break;
    }
 

CabCon

Head Administrator
Staff member
Head Staff Team
Messages
5,022
Reaction score
2,896
Points
1,103
Hey,
what I would do is the following:
  • Dynamic Page Creation: Instead of hardcoding the pages, create a function that dynamically generates pages based on the weapon count.
  • or Scrolling Mechanism: A scroll functionality can be added to cycle through all weapons without having to jump to entirely different pages. But this will force you to modify the menu base.

Since the Dynamic Page Creation is easier I would try something like this (this code is not tested, just want to show you the concept of the idea):
C++:
weapons = GetArrayKeys(level.zombie_weapons);


weaponsPerPage = 15;
totalPages = ceil(weapons.size / weaponsPerPage);

for(page = 0; page =< totalPages; page++)
{
    menuName = "WeaponsMenu" + (page == 0 ? "" : page+1);
    previousMenu = page == 0 ? "" : "WeaponsMenu" + page;
    nextMenu = page+1 == totalPages ? "" : "WeaponsMenu" + (page+2);

    AddMenuTitle(menuName, "Weapons Menu " + (page+1));
    if(previousMenu != "")
        AddBackToMenu(menuName, previousMenu);

    startIndex = page * weaponsPerPage;
    endIndex = min((page+1) * weaponsPerPage, weapons.size);

    for(i = startIndex; i < endIndex; i++)
    {
        self AddMenuAction(menuName, i % weaponsPerPage, weapons[i].name, ::G_GiveWeapon, weapons[i].name);
    }

    if(nextMenu != "")
        self AddMenuAction(menuName, 16, "^5> ^7Page " + (page+2) + " ", ::SubMenu, nextMenu);
}
 

vladyeah

Veteran
Messages
2
Reaction score
1
Points
778
Thank you for your response, I appreciate it.

I managed to edit the code you sent me and it works perfectly.

Thank you again :smile:
 
Top