Raised This Month: $ Target: $400
 0% 

Menu Handler


Post New Thread Reply   
 
Thread Tools Display Modes
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 04-13-2011 , 20:28   Re: Menu Handler
Reply With Quote #11

Everything works perfect, except for the thing where if I go to the second page of the menu, then it goes back to the first page whenever the thing resets.

I tried saving their current page whenever the menu exits, whenever they press "Next" or whenever they press "Back", and displaying that page whenever the menu opens, but it just keeps going back to the first page.

Here's my code:

PHP Code:
public StartDayVote() // This function starts the whole process.
{
    
gTimeLeft gVoteTime;
    
ShowDayMenu();
    
set_task1.0"MainDayCountdown", .flags="a", .repeat=10 );
}

public 
MainDayCountdown()
{
    
gTimeLeft--;
    
    if( 
gTimeLeft )
    {
        
ShowDayMenu();
    }
    
    else
    {
        
DayVoteEnded();
    }
}

public 
ShowDayMenu()
{
    if( 
gMainMenu )
        
menu_destroygMainMenu );
    
    if( !( 
gTimeLeft 0) )
        return;
    
    new 
szBuffer[32];
    
formatexszBuffercharsmaxszBuffer ), "Choose A Day: [%i]"gTimeLeft );
    
gMainMenu menu_createszBuffer"menuHandler" );
    
    
// Build Menu
    
new szNum[3];
    for( new 
0gTotalOptionsi++ )
    {
        
num_to_striszNumcharsmaxszNum ) );
        
formatszBuffercharsmaxszBuffer ), "%s [Votes: %i]"gDaymenuOptions[i], gMainDayVotes[i] );
        
menu_additemgMainMenuszBufferszNum);
    }
    
    
// Show Menu
    
new players[32], numplayer;
    
get_playersplayersnum );
    for( new 
0numi++ )
    {
        
player players[i];
        
menu_displayplayergMainMenugCurrentPage[player] );
    }
}

public 
menuHandleridmenuitem )
{
    if( 
item == MENU_EXIT )
    {
        
menu_destroymenu );
        return 
PLUGIN_HANDLED;
    }
    
    else if( 
item == MENU_MORE )
    {
        
gCurrentPage[id] = 1;
        
menu_destroymenu );
        return 
PLUGIN_HANDLED;
    }
    
    else if( 
item == MENU_BACK )
    {
        
gCurrentPage[id] = 0;
        
menu_destroymenu );
        return 
PLUGIN_HANDLED;
    }
    
    else if( 
gHasVoted[id] )
    {
        
client_printidprint_chat"[Jailbreak] You have already voted." );
        return 
PLUGIN_HANDLED;
    }
    
    else if( 
cs_get_user_teamid ) != CS_TEAM_CT )
    {
        
ColorChatidNORMAL"[Jailbreak] You must be a ^03Counter-Terrorist ^01to vote." );
        return 
PLUGIN_HANDLED;
    }
    
    new 
_accesscallback;
    new 
data[6];
    
menu_item_getinfomenuitem_accessdata5""0callback );
    
gMainDayVotes[str_to_numdata )]++;
    
    
gHasVoted[id] = true;
    
    return 
PLUGIN_HANDLED;
}  

public 
DayVoteEnded()
{
    if( 
gMainMenu )
        
menu_destroygMainMenu );
    
    
show_menu00"^n");
    
    
TallyDayVotes();
    

__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 04-13-2011 , 21:46   Re: Menu Handler
Reply With Quote #12

Check if MENU_MORE and MENU_BACK are sent to the handler function, IIRC they aren't.

Another method you could use is:
Code:
iPage = item / items_per_page
Obviously items_per_page is by default 7, but in case you were to change it.
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`
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 04-13-2011 , 22:10   Re: Menu Handler
Reply With Quote #13

Yea, I don't think they are either, but I have no idea how to do it.

Also, the second idea won't always work because the menu counts down even if they dont choose anything, forcing them to choose menu_exit, which is available on both pages, so you would be unable to tell which page they are exiting from :/

Any other way to get their current page
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 04-13-2011 , 23:48   Re: Menu Handler
Reply With Quote #14

I did this recently for someone else but was a little bit of a different situation but try it, I think it might work:

PHP Code:
    static oldmenunewmenu
    player_menu_info
(idoldmenunewmenugCurrentPage[id])
    if( 
item == MENU_EXIT )
    { 
__________________

Last edited by fysiks; 04-13-2011 at 23:52.
fysiks is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 04-16-2011 , 11:55   Re: Menu Handler
Reply With Quote #15

New problem: When somebody pressed MENU_EXIT, the vote just stops and I get errors in console. The menu freezes at a number, and then when you press a button on it the menu disappears.

Errors:

Code:
L 04/16/2011 - 11:52:15: Invalid menu id 1(2)
L 04/16/2011 - 11:52:15: [AMXX] Displaying debug trace (plugin "jb_daymenu.amxx")
L 04/16/2011 - 11:52:15: [AMXX] Run time error 10: native error (native "menu_destroy")
L 04/16/2011 - 11:52:15: [AMXX]    [0] jb_daymenu.sma::DayVoteEnded (line 487)
L 04/16/2011 - 11:52:15: [AMXX]    [1] jb_daymenu.sma::MainDayCountdown (line 412)

Line 486-487:
PHP Code:
if( gMainMenu )
        
menu_destroygMainMenu ); //487 
Line 405-413:
PHP Code:
if( gTimeLeft )
    {
        
ShowDayMenu();
    }
    
    else
    {
        
DayVoteEnded(); //Line 412
    

__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 04-16-2011 , 13:30   Re: Menu Handler
Reply With Quote #16

Last time I checked, if the menu was already destroyed the pointer had a value of 0 but it seems like that's not the case here. The "NewMenus" doesn't not give me the option of checking if the menu exists first so I don't see an easy solution other than not using the "NewMenu" style (which, granted, probably isn't easy).
__________________
fysiks is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 04-16-2011 , 13:37   Re: Menu Handler
Reply With Quote #17

Uhh, i hate the old menu style :/
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 04-16-2011 , 14:06   Re: Menu Handler
Reply With Quote #18

Found out the solution,

menu_setprop( gMainMenu, MPROP_EXIT, MEXIT_NEVER );
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
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 20:11.


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