Raised This Month: $ Target: $400
 0% 

Menu Handler


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 04-10-2011 , 21:28   Menu Handler
Reply With Quote #1

Code:
public Show_DayMenu()
{
    new menuTitle[256];
    format( menuTitle, charsmax( menuTitle ), "Choose A Day: [%i]", gTimeLeft );
    new menu = menu_create( menuTitle, "DayMenuHandler" );
    
    new holder[6], itemHolder[256];
    for( new i = 0; i < gTotalOptions; i++ )
    {
        num_to_str( i + 1, holder, 5 );
        format( itemHolder, charsmax( itemHolder ), "%s [Votes: %i]", gDaymenuOptions[i], gMainDayVotes[i] );
        menu_additem( menu, itemHolder, holder );
    }
    
    gTimeLeft--;
    
    new players[32], num, player;
    get_players( players, num, "ae", "CT" );
    
    
    if( gTimeLeft >= 0 )
    {
        for( new i = 0; i < num; i++ )
        {
            player = players[i];
            showDayMenu( player, menu );
        }
    }
    
    else
    {
        menu_destroy( menu );
        
        for( new i = 0; i < num; i++ )
        {
            player = players[i];
            
            show_menu( player, 0, "^n", 1 );
        }
    }
    
}

public showDayMenu( id, menu )
{
    menu_display( id, menu, 0 );
    
    menu_destroy( menu );
    
    return PLUGIN_HANDLED;
}

public DayMenuHandler( id, menu, item )
{
    if( cs_get_user_team( id ) != CS_TEAM_CT )
    {
        ColorChat( id, TEAM_COLOR, "^01[Jailbreak] You must be a ^03Counter-Terrorist ^01to vote." );
        
        menu_destroy( menu );
        
        return PLUGIN_HANDLED;
    }
    
    else if( gHasVoted[id] )
    {
        ColorChat( id, TEAM_COLOR, "^01[Jailbreak] You have already voted." );
        menu_destroy( menu );
        return PLUGIN_HANDLED;
    }
    
    else if( !is_user_alive( id ) )
    {
        ColorChat( id, NORMAL, "[Jailbreak] You must be alive to vote." );
        menu_destroy( menu );
        return PLUGIN_HANDLED;
    }
    
    
    new access, callback;
    new data[6], szName[64];
    menu_item_getinfo( menu, item, access, data, 5, szName, 63, callback );
    
    new key = str_to_num( data );
    
    gMainDayVotes[key]++;
    
    gHasVoted[id] = true;
    
    menu_destroy( menu );
    
    showDayMenu( id, menu );
    
    return PLUGIN_HANDLED;
}
It shows "You have already voted" like 100 times for some reason. Any ideas?
__________________
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-10-2011 , 22:19   Re: Menu Handler
Reply With Quote #2

Not quite sure what you are trying to say is actually happening but there are some major logical errors in that code.

What exactly are you trying to do?
__________________
fysiks is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 04-11-2011 , 20:59   Re: Menu Handler
Reply With Quote #3

Sorry, I'm trying to make a votemenu, where there are about 10 different options and then there's a 10 second countdown when the vote ends. Only CT's can choose options, and they can only choose once.
__________________
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-12-2011 , 00:06   Re: Menu Handler
Reply With Quote #4

Replace that whole code block that you posted with this:

PHP Code:
new g_pMenug_iCount

public Show_DayMenu() { start_vote(); }

public 
start_vote() // This function starts the whole process.
{
    
g_iCount 10
    show_vote_menu
()
    
set_task(1.0"taskCount", .flags="a", .repeat=10)
}

end_vote()
{
    if(
g_pMenu)
        
menu_destroy(g_pMenu)
    
    
show_menu(00"^n"1)
    
    
// process votes
}

public 
taskCount()
{
    
g_iCount--
    if(!
g_iCount)
        
end_vote()
}

show_vote_menu()
{
    if(
g_pMenu)
        
menu_destroy(g_pMenu)
    
    if( !(
g_iCount 0) )
        return
    
    new 
szBuffer[32]
    
formatex(szBuffercharsmax(szBuffer), "Choose A Day: [%i]"g_iCount)
    
g_pMenu menu_create(szBuffer"menuHandler")

    
// Build Menu
    
new szNum[3]
    for( new 
0gTotalOptionsi++ )
    {
        
num_to_str(iszNumcharsmax(szNum))
        
formatszBuffercharsmax(szBuffer), "%s [Votes: %i]"gDaymenuOptions[i], gMainDayVotes[i])
        
menu_additemg_pMenuszBufferszNum)
    }

    
// Show Menu
    
new iPlayers[32], iPlayersNum
    get_players
(iPlayersiPlayersNum)
    for( new 
0iPlayersNumi++ )
    {
        
menu_display(iPlayers[i], g_pMenu)
    }
}

public 
menuHandler(idmenuitem)
{
    if( !
gHasVoted[id] )
    {
        new 
_accesscallback;
        new 
data[6];
        
menu_item_getinfomenuitem_accessdata5""0callback )
        
gMainDayVotes[str_to_numdata )]++
        
        
gHasVoted[id] = true
    
}
    else
    {
        
client_print(idprint_chat"You already voted")
    }
    
    
show_vote_menu()

Tell me if the main functionality works (ignore that it doesn't check if they are alive or if they are on the correct team).
__________________
fysiks is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 04-12-2011 , 17:44   Re: Menu Handler
Reply With Quote #5

The voting works fine, but the counting down doesn't work correctly. It updates the time remaining only after you choose after the menu options, so it would stay on 5 or 6 until you press a menu option and it updates.
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please

Last edited by nikhilgupta345; 04-12-2011 at 18:05.
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-12-2011 , 18:50   Re: Menu Handler
Reply With Quote #6

Quote:
Originally Posted by nikhilgupta345 View Post
The voting works fine, but the counting down doesn't work correctly. It updates the time remaining only after you choose after the menu options, so it would stay on 5 or 6 until you press a menu option and it updates.
Oh, yeah. I have it update when the votes change.

You should be able to do this:

PHP Code:
public taskCount() 

    
g_iCount-- 
    if(
g_iCount 0)
    {
        
show_vote_menu()
    }
    else
    {
        
end_vote()
    }

With this you may be able to remove the show_vote_menu() in the menu handler (try it with and without; without will be more efficient).
__________________
fysiks is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 04-12-2011 , 20:16   Re: Menu Handler
Reply With Quote #7

K, so now the countdown and vote works fine, but after I have voted, and whenever the countdown goes down by 1, it says "You have already voted.". So basically if I vote when the countdown is at 7, it shows "You have already voted" 6 times. (7 - 1)

I'm pretty sure it's calling the menuhandler function whenever the countdown goes down, but I'm not sure how to fix that :/
__________________
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-12-2011 , 20:39   Re: Menu Handler
Reply With Quote #8

Quote:
Originally Posted by nikhilgupta345 View Post
K, so now the countdown and vote works fine, but after I have voted, and whenever the countdown goes down by 1, it says "You have already voted.". So basically if I vote when the countdown is at 7, it shows "You have already voted" 6 times. (7 - 1)

I'm pretty sure it's calling the menuhandler function whenever the countdown goes down, but I'm not sure how to fix that :/
Oh! You have to add the

PHP Code:
    if( item == MENU_EXIT )
    {
        
menu_destroy(menu);
        return 
PLUGIN_HANDLED;
    } 
in the handler. When you destroy the menu it cancels the menu. When you cancel the menu it forces people to effectively select the "Exit" key regardless of it existing or not.

i think
__________________
fysiks is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 04-12-2011 , 21:52   Re: Menu Handler
Reply With Quote #9

Thanks, works perfect now.

<3 (NO HOMO)
__________________
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 , 00:38   Re: Menu Handler
Reply With Quote #10

Quote:
Originally Posted by fysiks View Post
When you destroy the menu it cancels the menu. When you cancel the menu it forces people to effectively select the "Exit" key regardless of it existing or not.

i think
Yup.
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 20:11.


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