Raised This Month: $ Target: $400
 0% 

[WC3FT] Making a second page in a menu


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
bibu
Veteran Member
Join Date: Sep 2010
Old 01-07-2012 , 07:02   [WC3FT] Making a second page in a menu
Reply With Quote #1

I would like to add some races, and I wanted to ask, how I could make a next/back button here:

PHP Code:
// Function will display the changerace menu
public MENU_ChangeRaceidiRaceXP[MAX_RACES] )
{
    
    new 
szRaceName[MAX_RACES+1][64], iposiKeys 0szMenu[512], szXP[16];

    
// Get our race names
    
for ( 0get_pcvar_numCVAR_wc3_races ); i++ )
    {
        
lang_GetRaceName1idszRaceName[i], 63 );
    }

    
pos += formatexszMenu[pos], 512-pos"%L"id"MENU_SELECT_RACE" );

    
// Then add the experience column
    
if ( get_pcvar_numCVAR_wc3_save_xp ) )
    {
        
pos += formatexszMenu[pos], 512-pos"\R%L^n^n"id"MENU_WORD_EXPERIENCE" );
    }
    else
    {
        
pos += formatexszMenu[pos], 512-pos"^n^n" );
    }

    
// Build the changerace menu (for every race)
    
for ( 0get_pcvar_numCVAR_wc3_races ); i++ )
    {
        
num_to_striRaceXP[i], szXP15 );
        
        
// Add the "Select a Hero" message if necessary
        
if ( == )
        {
            
pos += formatszMenu[pos], 512-pos"%L"id"SELECT_HERO" );
        }
        
        
// User's current race
        
if ( == p_data[id][P_RACE] - )
        {
            
pos += formatexszMenu[pos], 512-pos"\d%d. %s\d\R%s^n"1szRaceName[i], ( (get_pcvar_numCVAR_wc3_save_xp )) ? szXP " " ) );

            
iKeys |= (1<<i);
        }

        
// Race the user wants to change to
        
else if ( == p_data[id][P_CHANGERACE] - )
        {
            
pos += formatexszMenu[pos], 512-pos"\r%d. %s\r\R%s^n"1szRaceName[i], ( (get_pcvar_numCVAR_wc3_save_xp )) ? szXP " " ) );

            
iKeys |= (1<<i);
        }

        
// All other cases
        
else
        {
            new 
bool:bAllowRace true;

            
// Check to see if the user can choose this race (are there too many of this race?)
            
if ( bAllowRace )
            {
                
pos += formatexszMenu[pos], 512-pos"\w%d. %s\y\R%s^n"1szRaceName[i], ( (get_pcvar_numCVAR_wc3_save_xp )) ? szXP " " ) );

                
iKeys |= (1<<i);
            }

            
// If not, display the race, but don't give them a key to press
            
else
            {
                
pos += formatexszMenu[pos], 512-pos"\d%d. %s\y\R%s^n"1szRaceName[i], ( (get_pcvar_numCVAR_wc3_save_xp )) ? szXP " " ) );
            }
        }

    }

    
iKeys |= (1<<i);
    
    
// This is needed so we can make the Auto-Select option "0" if the number of races is 9
    
if ( get_pcvar_numCVAR_wc3_races ) == )
    {
        
= -1;
    }

    
pos += formatszMenu[pos], 512-pos"%L"id"SELECT_RACE_FOOTER");
    
    
// Add a cancel button to the bottom
    
if ( get_pcvar_numCVAR_wc3_races ) != )
    {
        
iKeys |= (1<<9);

        
pos += formatszMenu[pos], 512-pos"^n\w0. %L"id"WORD_CANCEL" );
    }
    
    
// Show the menu to the user!
    
show_menuidiKeysszMenu, -);

    return;

Right now, there are races from 1 - 4, and 5 - 8 and the 9th option is the exit button. So I would like to have just 7 races in a menu and then, 8/9 would be next/back buttons, and 0 the exit.
__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.
bibu is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 01-07-2012 , 07:29   Re: [WC3FT] Making a second page in a menu
Reply With Quote #2

You need global variable to store page number. When you show menu, you need to check:
If RACES_PER_PAGE*g_page[id]+1 >= MAX_RACES then g_page[id] = 0
and then display races from RACES_PER_PAGE*g_page[id] to RACES_PER_PAGE*(g_page[id]+1)-1
Next button simply does g_page[id]++ and displays menu again.
With just few pages you don't need "back to previous page" button, or you can use it to replace exit button on pages > 0.

This is how I coded menu with multiple pages in my rpg_mod:
PHP Code:
public menu_buy_upg(idpage){
    static 
ikeysposupgpricemaxcache[1024]
    
pos 0
    keys 
0
    
if(page*8>=g_enabled_upgs)
        
page 0
    g_p_menu_page
[id] = page

    max 
= (g_enabled_upgs-1)/8+1
    
if(max<1)
        
max=1
    pos 
+= format(cache[pos], 1023-pos"\yRPG mod \d[#.1]\wBuy menu^n\d[%d/%d]\w[Credits: \y%d\w]^n\wn. \d[ \wlvl\d ][\wprice\d]\wupgrade^n^n"page+1maxg_p_credits[id])
    
max g_enabled_upgs page*8
    
if(max>8)
        
max=8
    
for(i=0i<8i++){
        if(
i>=max){
            
pos += formatex(cache[pos], 1023-pos"\d%d.^n"i+1)
            continue
        }
        
upg g_enabled_list[i+page*8]
        
price g_upg_sp[upg] + g_upg_ip[upg]*g_p_upg[id][upg]
        if(
g_p_upg[id][upg] >= g_upg_maxlvl[upg]){
            
pos += formatex(cache[pos], 1023-pos"\d%d. [\rmax\d][-----]%L^n"i+1idg_upg_name[upg])
        }else if(
price g_p_credits[id]){
            
pos += formatex(cache[pos], 1023-pos"\d%d. [%4d ][\r%5d \d]%L^n"i+1g_p_upg[id][upg]+1priceidg_upg_name[upg])
        }else{
            
pos += formatex(cache[pos], 1023-pos"\w%d. \d[\w%4d \d][\y%5d \d]\w%L^n"i+1g_p_upg[id][upg]+1priceidg_upg_name[upg])
            
keys keys|(1<<i)
        }
    }

    
pos += formatex(cache[pos], 1023-pos"^n%s9. More...^n"g_enabled_upgs>"\w" "\d")
    
keys keys|(1<<8)|(1<<9)
    
pos += formatex(cache[pos], 1023-pos"\w0. Back^n")
    
show_menuidkeyscache, -1)
    return 
PLUGIN_HANDLED
}


public 
hnd_menu_buy_upg(id,key){
    static 
upg

    
if(key<8){
        
upg g_enabled_list[g_p_menu_page[id]*8+key]
        
g_p_credits[id] -= g_upg_sp[upg] + g_upg_ip[upg]*g_p_upg[id][upg]
        
g_p_upg[id][upg]++
        
upgrade_change(idupg)
        
menu_buy_upg(idg_p_menu_page[id])
    }else if(
key==8){
        
menu_buy_upg(idg_p_menu_page[id]+1)
    }else{
        
menu_main(id)
    }

    return 
PLUGIN_HANDLED

__________________
Impossible is Nothing

Last edited by Sylwester; 01-07-2012 at 07:30.
Sylwester is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 01-07-2012 , 11:05   Re: [WC3FT] Making a second page in a menu
Reply With Quote #3

This is looks really hard for me. Could you get me this to working please? I mean how should I make all races with a single line and give them the korrect keys to press.
__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.
bibu is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-07-2012 , 15:26   Re: [WC3FT] Making a second page in a menu
Reply With Quote #4

Your description sounds exactly like "New Menus".
__________________
fysiks is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 01-07-2012 , 15:41   Re: [WC3FT] Making a second page in a menu
Reply With Quote #5

Quote:
Originally Posted by fysiks View Post
Your description sounds exactly like "New Menus".
I only know new menus, so I really have no idea on how to convert this to new style then. Anyway, Sylwester's way is also the old menu system.
__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.
bibu is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 01-14-2012 , 14:43   Re: [WC3FT] Making a second page in a menu
Reply With Quote #6

Either learn the way that Sylwester showed (there are more examples of it in plmenu.sma)

Or convert it to the new menu system like fysiks suggested.

Here is how I changed it at one point. Note that there are probably more changes in the code than you need.

Code:
// Function will display the changerace menu
public MENU_ChangeRace( id, iRaceXP[MAX_RACES], page )
{
	if ( XP_FreeXP( id, false ) )
	{
		MENU_FreeRaceXP( id, page )
		return;
	}

	new szRaceName[64], i, pos, iKeys = 0, szMenu[512], szXP[16];

	new iTotalRaces = get_pcvar_num( CVAR_wc3_races );

	pos += formatex( szMenu[pos], 512-pos, "%L", id, ( page == 2 ) ? "MENU_SELECT_LOCKED" : "MENU_SELECT_RACE" );

	// Then add the experience column
	if ( get_pcvar_num( CVAR_wc3_save_xp ) )
	{
		pos += formatex( szMenu[pos], 512-pos, "\R%L^n^n", id, "MENU_WORD_EXPERIENCE" );
	}
	else
	{
		pos += formatex( szMenu[pos], 512-pos, "^n^n" );
	}

	new iSaveXP = get_pcvar_num( CVAR_wc3_save_xp );

	new iRace;

	// Build the changerace menu (for every race)
	for ( i = 0; i < 8; i++ )
	{
		iRace = MENU_Race( page, i + 1, iTotalRaces );

		if( iRace > iTotalRaces )
			break;

		if( iRace == RACE_NONE )
			continue;

		if ( iSaveXP )
			num_to_str( iRaceXP[iRace - 1], szXP, 15 );
		else
			copy( szXP, charsmax(szXP), "" );
		
/*
		// Add the "Select a Hero" message if necessary
		if ( iRace == 4 )
		{
			pos += format( szMenu[pos], 512-pos, "%L", id, "SELECT_HERO" );
		}
*/
		switch( iRace )
		{
			case RACE_BLOOD,RACE_SEAWITCH: pos += format( szMenu[pos], 512-pos, "%L", id, "SELECT_HERO" );
		}
		
		// User's current race
		if ( iRace == p_data[id][P_RACE] )
		{
			lang_GetRaceName( iRace, id, szRaceName, charsmax(szRaceName) );
			pos += formatex( szMenu[pos], 512-pos, "\d%d. %s\d\R%s^n", i + 1, szRaceName, szXP );

			iKeys |= (1<<i);
		}

		// Race the user wants to change to
		else if ( iRace == p_data[id][P_CHANGERACE] )
		{
			lang_GetRaceName( iRace, id, szRaceName, charsmax(szRaceName) );
			pos += formatex( szMenu[pos], 512-pos, "\r%d. %s\r\R%s^n", i + 1, szRaceName, szXP );

			iKeys |= (1<<i);
		}

		// All other cases
		else
		{
			/*
			new iRaceLimit = get_pcvar_num( CVAR_wc3_race_limit );
			new bool:bAllowRace = true;

			if ( iRaceLimit > 0 )
			{
				new iTotal[MAX_RACES];

				// Get how many people are using each race
				new iPlayers[32], iNumPlayers, i, iTarget;
				get_players( iPlayers, iNumPlayers );

				for ( i = 0; i < iNumPlayers; i++ )
				{
					iTarget = iPlayers[i];

					if ( iTarget != id && p_data[iTarget][P_RACE] > 0 && p_data[iTarget][P_RACE] <= iTotalRaces )
					{
						iTotal[p_data[iTarget][P_RACE]]++;
					}
				}
				
				// Now if we have more races selected than iRaceLimit provides us with, then we need to increase iRaceLimit
				while ( HLPR_TotalUsingRaces( iTotal ) > iRaceLimit * get_playersnum() )
				{
					iRaceLimit++;
				}

				// Check to see if there was an increase that was necessary
				if ( iRaceLimit > get_pcvar_num( CVAR_wc3_race_limit ) )
				{
					WC3_Log( true, "Error, increase wc3_race_limit to at least %d", iRaceLimit );
				}

				if ( iTotal[i+1] >= iRaceLimit )
				{
					bAllowRace = false;

				}
			}*/

			// Check to see if the user can choose this race (are there too many of this race?)
			if ( MENU_AddRace( szMenu, pos, i, id, iRace, szXP ) )
			{
				iKeys |= (1<<i);
			}
		}

	}

	// Add a cancel button to the bottom
	if ( iTotalRaces > 8 )
	{
		iKeys |= (1<<8);

		pos += format( szMenu[pos], 512-pos, "^n\w9. \y%L", id, "WORD_NEXT" );
	}

	iKeys |= (1<<9);
	pos += format( szMenu[pos], 512-pos, "^n\w0. %L", id, "WORD_CANCEL" );
	
	// Show the menu to the user!
	show_menu( id, iKeys, szMenu, -1 );

	return;
}

public _MENU_ChangeRace( id, key )
{

	if ( !WC3_Check() )
	{
		return PLUGIN_HANDLED;
	}

	new page = g_menuPosition[id];
	new iTotalRaces = clamp( get_pcvar_num( CVAR_wc3_races ), 1, MAX_RACES );

	if( key == KEY_0 )
	{
		return PLUGIN_HANDLED;
	}
	else if( key == KEY_9 )
	{
		new iMaxPages = MENU_RacePages( iTotalRaces );

		page = ( page + 1 ) % iMaxPages;
		WC3_ChangeRaceStart( id, ( g_menuPosition[id] = page ) )
		return PLUGIN_HANDLED;
	}

	new iRace = MENU_Race( page, key + 1, iTotalRaces );

	// Save the current race data before we change
	DB_SaveXP( id, false );

	// User currently has a race
	if ( p_data[id][P_RACE] != 0 )
	{

		// Change the user's race at the start of next round
		if ( iRace != p_data[id][P_RACE] )
		{
			
			// Special message for csdm
			if ( CVAR_csdm_active > 0 && get_pcvar_num( CVAR_csdm_active ) == 1 )
			{
				client_print( id, print_center, "Your race will be changed when you respawn" );
			}	
			else
			{
				client_print( id, print_center, "%L", id, "CENTER_CHANGED_NEXT" );
			}

			p_data[id][P_CHANGERACE] = iRace;
		}

		// Do nothing
		else
		{
			p_data[id][P_CHANGERACE] = 0;
		}
	}

	// User doesn't have a race so give it to him!!!
	else
	{
		WC3_SetRace( id, iRace );
	}

	return PLUGIN_HANDLED;
}
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`
bibu
Veteran Member
Join Date: Sep 2010
Old 01-14-2012 , 15:18   Re: [WC3FT] Making a second page in a menu
Reply With Quote #7

Can you also show me some other code, I get several errors:

Quote:
undefined symbol "MENU_Race"
undefined symbol "MENU_AddRace"
undefined symbol "MENU_RacePages"
__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.
bibu is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 01-14-2012 , 16:49   Re: [WC3FT] Making a second page in a menu
Reply With Quote #8

Code:
MENU_Race( page, num, iTotalRaces )
{
	switch( page )
	{
		case 0:
		{
			switch( num )
			{
				case 1: return RACE_UNDEAD;
				case 2: return RACE_HUMAN;
				case 3: return RACE_ORC;
				case 4: return RACE_ELF;
				case 5: return RACE_BLOOD;
				case 6: return RACE_SHADOW;
				case 7: return RACE_WARDEN;
				case 8: return RACE_CRYPT;
			}
		}
		case 1:
		{
			if ( iTotalRaces == 9 )
				return ( num == 1 ) ? RACE_CHAMELEON : RACE_NONE;
			switch( num )
			{
				case 1: return RACE_CHAMELEON;
				case 2: return RACE_NONE;
				case 3: return RACE_NONE;
				case 4: return RACE_NONE;
				case 5: return RACE_NONE;
				case 6: return RACE_NONE;
				case 7: return RACE_NONE;
				case 8: return RACE_NONE;
			}
		}
	}
	return RACE_NONE;
}

MENU_AddRace( szMenu[512], &pos, i, iPlayer, iRace, szXP[], iChar = 'w' )
{
	new szRace[64];
	lang_GetRaceName( iRace, iPlayer, szRace, charsmax(szRace) );

	pos += formatex( szMenu[pos], charsmax(szMenu)-pos, "\%c%d. %s\y\R%s^n", iChar, i + 1, szRace, szXP );
	return true;
}

MENU_RacePages( iRaces )
{
	switch( iRaces )
	{
		case 0..8: return 1;
		case 9: return 2;
		case 10..13: return 3;
		case 14..16: return 4;
	}
	return 1;
}
Note that you will need to modify them to suit your needs.
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`
bibu
Veteran Member
Join Date: Sep 2010
Old 01-14-2012 , 17:18   Re: [WC3FT] Making a second page in a menu
Reply With Quote #9

Right, throws me still an error on this Can you show me also WC3_ChangeRaceStart ?

Quote:
error 088: number of arguments does not match definition
PHP Code:
WC3_ChangeRaceStartid, ( g_menuPosition[id] = page ) ) 
__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.
bibu is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 01-14-2012 , 17:50   Re: [WC3FT] Making a second page in a menu
Reply With Quote #10

Code:
// Function will grab XP for the user
WC3_ChangeRaceStart( id, start_page = 0 )
{
	
	// Make sure the user is on a team!
	if ( SHARED_IsOnTeam( id ) )
	{
		// Get the XP if we're saving XP
		if ( get_pcvar_num( CVAR_wc3_save_xp ) )
		{
			// This function will also display the changerace menu
			DB_GetAllXP( id, start_page );
		}
		
		// We're not saving XP, so lets just change the user's race
		else
		{
			WC3_ChangeRaceShowMenu( id, _, start_page );
		}
	}

	else
	{
		client_print( id, print_center, "Please join a team before selecting a race!" );
	}
}

// Function will show the "select a race" menu to the user
WC3_ChangeRaceShowMenu( id, iRaceXP[MAX_RACES] = {0}, start_page = 0 )
{

	// We don't want to replace the player's current XP with whats in the database now do we ?
	if ( p_data[id][P_RACE] )
	{
		iRaceXP[p_data[id][P_RACE]-1] = p_data[id][P_XP];
	}

	// Need to call this here
	MENU_ChangeRace( id, iRaceXP, ( g_menuPosition[id] = start_page ) );
}
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`
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 13:35.


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