Raised This Month: $32 Target: $400
 8% 

Solved Need Help with a Vote Menu


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 12-20-2017 , 03:40   Need Help with a Vote Menu
Reply With Quote #1

Hey guys, I need help with inserting these:

PHP Code:
        IntToString(0TVMEntrysizeof(TVMEntry));
        
IntToString(1TVMEntrysizeof(TVMEntry)); 
Into this vote menu:

PHP Code:
        Menu TeleportVoteMenu CreateMenu(TeleportMenuHandler);
        
SetVoteResultCallback(TeleportVoteMenuTeleportVoteResults);
        
Format(VoteOptionssizeof(VoteOptions), "%T""TeleportSpeedrunners"client);
        
TeleportVoteMenu.SetTitle(VoteOptions); 
        
Format(VoteOptionssizeof(VoteOptions), "%T""Yes"client);
        
TeleportVoteMenu.AddItem("Yes"VoteOptions);
        
Format(VoteOptionssizeof(VoteOptions), "%T""No"client);
        
TeleportVoteMenu.AddItem("No"VoteOptions); 
        
SetMenuPagination(TeleportVoteMenuMENU_NO_PAGINATION);
        
TeleportVoteMenu.ExitButton false;
        
VoteMenu(TeleportVoteMenuHumanPlayersTotalHumans30); 
I tried this but it didn't work:

PHP Code:
        Menu TeleportVoteMenu CreateMenu(TeleportMenuHandler);
        
SetVoteResultCallback(TeleportVoteMenuTeleportVoteResults);
        
Format(VoteOptionssizeof(VoteOptions), "%T""TeleportSpeedrunners"client);
        
TeleportVoteMenu.SetTitle(VoteOptions); 
        
Format(VoteOptionssizeof(VoteOptions), "%T""Yes"client);
        
IntToString(0TVMEntrysizeof(TVMEntry));
        
TeleportVoteMenu.AddItem(TVMEntry"Yes"VoteOptions);
        
Format(VoteOptionssizeof(VoteOptions), "%T""No"client);
        
IntToString(1TVMEntrysizeof(TVMEntry));
        
TeleportVoteMenu.AddItem(TVMEntry"No"VoteOptions); 
        
SetMenuPagination(TeleportVoteMenuMENU_NO_PAGINATION);
        
TeleportVoteMenu.ExitButton false;
        
VoteMenu(TeleportVoteMenuHumanPlayersTotalHumans30); 
__________________

Last edited by Psyk0tik; 12-20-2017 at 03:47.
Psyk0tik is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 12-20-2017 , 03:47   Re: Need Help with a Vote Menu
Reply With Quote #2

Never mind. Turns out I didn't need to do anything like this.
__________________
Psyk0tik is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 12-20-2017 , 03:54   Re: Need Help with a Vote Menu
Reply With Quote #3

what exactly are you trying to do?

https://sm.alliedmods.net/new-api/menus/Menu/AddItem

bool AddItem(const char[] info, const char[] display, int style)

PHP Code:
Format(VoteOptionssizeof(VoteOptions), "%T""Yes"client); 
        
IntToString(0TVMEntrysizeof(TVMEntry)); 
        
TeleportVoteMenu.AddItem(TVMEntry"Yes"VoteOptions); 
your using a translation for style?
__________________
8guawong is offline
cravenge
Veteran Member
Join Date: Nov 2015
Location: Chocolate Factory
Old 12-20-2017 , 03:55   Re: Need Help with a Vote Menu
Reply With Quote #4

Here you go, Crasher:
PHP Code:
Menu TeleportVoteMenu = new Menu(TeleportMenuHandler); TeleportVoteMenu.VoteResultCallback TeleportVoteResults;

Format(VoteOptionssizeof(VoteOptions), "%T""TeleportSpeedrunners"client); 
TeleportVoteMenu.SetTitle(VoteOptions);

Format(VoteOptionssizeof(VoteOptions), "%T""Yes"client); 
TeleportVoteMenu.AddItem(""VoteOptions); 
Format(VoteOptionssizeof(VoteOptions), "%T""No"client);  
TeleportVoteMenu.AddItem(""VoteOptions);

TeleportVoteMenu.MenuPagination MENU_NO_PAGINATION
TeleportVoteMenu.ExitButton false
TeleportVoteMenu.Vote(HumanPlayersTotalHumans30); 
You don't need those to see if they chose yes or no. In the menu handler, just check the param2 because that is the index of the choice.

Example:
cravenge is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 12-20-2017 , 04:02   Re: Need Help with a Vote Menu
Reply With Quote #5

Quote:
Originally Posted by 8guawong View Post
what exactly are you trying to do?

https://sm.alliedmods.net/new-api/menus/Menu/AddItem

bool AddItem(const char[] info, const char[] display, int style)

PHP Code:
Format(VoteOptionssizeof(VoteOptions), "%T""Yes"client); 
        
IntToString(0TVMEntrysizeof(TVMEntry)); 
        
TeleportVoteMenu.AddItem(TVMEntry"Yes"VoteOptions); 
your using a translation for style?
The vote options were messed up, as in, both options were returning the callback function for when the majority vote is "yes". I thought that IntToString was what can solve the problem. However, cravenge pointed it out to me in PM that it was something else, which is pasted in their post above. (The "switch(param2)".)

P.S. Thanks again cravenge!
__________________
Psyk0tik is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 12-20-2017 , 05:03   Re: Need Help with a Vote Menu
Reply With Quote #6

Don't use MenuAction_Select in a vote. You should use one of these instead:
  • Use MenuAction_VoteEnd. param1 will be the winning item and param2 can be passed to GetMenuVoteInfo to get the number of votes the winning item got and how many votes were cast. Edit: I used this in the example down below.
  • Use a VoteResultCallback (aka VoteHandler), which will tell you how many votes each item got at the end of the vote, how many votes were cast, what each client voted for, etc...

Note: If you use a VoteResultCallback, you'll still need a regular MenuHandler to handle things like cleaning up the Menu at the end of the vote or to do proper translations for each client.

Edit: On the subject of translations, the way you have translations set up now, they'll only appear in the language of the person who called the vote. If you want an actual translation for each player, you need to do this:

Code:
// When you create the vote menu
Menu TeleportVoteMenu = new Menu(TeleportMenuHandler,
MENU_ACTIONS_DEFAULT|MenuAction_Display|MenuAction_DisplayItem|MenuAction_VoteEnd);

// and the actual handler
public int TeleportMenuHandler(Menu menu, MenuAction action, int param1, int param2)
{
    switch (action)
    {
        case MenuAction_End:
        {
            delete menu;
        }
        case MenuAction_VoteEnd:
        {
            int winningVotes;
            int totalVotes;
            GetMenuVoteInfo(param2, winningVotes, totalVotes);

            switch (param1)
            {
                case 0:
                {
                    // Yes won, do stuff here
                }
                case 1:
                {
                    // No won, do stuff here
                }
            }
        }
        // translate the menu title
        case MenuAction_Display:
        {
            Panel panel = view_as<Panel>(param2);
            char VoteOptions[64];
            Format(VoteOptions, sizeof(VoteOptions), "%T", "TeleportSpeedrunners", param1);
            panel.SetTitle(VoteOptions);
        }
        // translate the menu options
        case MenuAction_DisplayItem:
        {
            char VoteOptions[64];

            switch (param2)
            {
                case 0:
                {
                    Format(VoteOptions, sizeof(VoteOptions), "%T", "Yes", param1);
                    return RedrawMenuItem(VoteOptions);
                }

                case 1:
                {
                    Format(VoteOptions, sizeof(VoteOptions), "%T", "No", param1);
                    return RedrawMenuItem(VoteOptions);
                }
            }
        }
    }
    return 0;

}
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 12-20-2017 at 05:19.
Powerlord is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 12-20-2017 , 21:51   Re: Need Help with a Vote Menu
Reply With Quote #7

Quote:
Originally Posted by Powerlord View Post
<snipped>
First off, thank you for showing me a more efficient way of creating and handling a vote menu.

Second of all, here's what I have now:

Spoiler


I'm not sure if there's anything that I'm missing or that I did wrong. I used the wiki to help set this up.

EDIT: Tested this out even more and confirmed it to work as intended.
__________________

Last edited by Psyk0tik; 12-23-2017 at 17:51.
Psyk0tik is offline
Reply


Thread Tools
Display Modes

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 12:05.


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