Raised This Month: $12 Target: $400
 3% 

How can i make vote


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
pr0mers
Junior Member
Join Date: May 2020
Old 05-27-2020 , 03:48   How can i make vote
Reply With Quote #1

I want to make something like sm_vote but if like this:


Do this?
Yes
No

and if yes i s more than 50% do ...
else ...

how can i do it
pr0mers is offline
SpirT
Senior Member
Join Date: Sep 2018
Location: Portugal
Old 05-27-2020 , 06:00   Re: How can i make vote
Reply With Quote #2

Quote:
Originally Posted by pr0mers View Post
I want to make something like sm_vote but if like this:


Do this?
Yes
No

and if yes i s more than 50% do ...
else ...

how can i do it
Hey there! You can take a look to MenuAPI of sourcemod! Anyways I am going to leave here that example:

Simple Vote:
PHP Code:
//OnPluginStart
RegConsoleCmd("sm_command"Command_Command);

public 
Action Command_Command(int clientint args)
{
    
char currentMap[64];
    
GetCurrentMap(currentMapsizeof(currentMap));
    
DoVoteMenu(currentMap);
    return 
Plugin_Handled;
}

public 
int Handle_VoteMenu(Menu menuMenuAction actionint param1int param2)
{
    if (
action == MenuAction_End)
    {
        
/* This is called after VoteEnd */
        
delete menu;
    }
    else if (
action == MenuAction_VoteEnd)
    {
        
/* 0=yes, 1=no */
        
if (param1 == 0)
        {
            
char map[64];
            
menu.GetItem(param1mapsizeof(map));
            
ServerCommand("changelevel %s"map);
        }
    }
}
 
void DoVoteMenu(const char[] map)
{
    if (
IsVoteInProgress())
    {
        return;
    }
 
    
Menu menu = new Menu(Handle_VoteMenu);
    
menu.SetTitle("Change map to: %s?"map);
    
menu.AddItem(map"Yes");
    
menu.AddItem("no""No");
    
menu.ExitButton false;
    
menu.DisplayVoteToAll(20);

Advanced Vote:
PHP Code:
//OnPluginStart
RegConsoleCmd("sm_command"Command_Command);

public 
Action Command_Command(int clientint args)
{
    
char currentMap[64];
    
GetCurrentMap(currentMapsizeof(currentMap));
    
DoVoteMenu(currentMap);
    return 
Plugin_Handled;
}

public 
int Handle_VoteMenu(Menu menuMenuAction actionint param1int param2)
{
    if (
action == MenuAction_End)
    {
        
/* This is called after VoteEnd */
        
delete menu;
    }
}
 
public 
void Handle_VoteResults(Menu menu
        
int num_votes
        
int num_clients
        const 
int[][] client_info
        
int num_items
        const 
int[][] item_info)
{
    
/* See if there were multiple winners */
    
int winner 0;
    if (
num_items 1
    
&& (item_info[0][VOTEINFO_ITEM_VOTES] == item_info[1][VOTEINFO_ITEM_VOTES]))
    {
        
winner GetRandomInt(01);
    }
 
    
char map[64];
    
menu.GetItem(item_info[winner][VOTEINFO_ITEM_INDEX], mapsizeof(map));
    
ServerCommand("changelevel %s"map);
}
 
void DoVoteMenu(const char[] map)
{
    if (
IsVoteInProgress())
    {
        return;
    }
 
    
Menu menu = new Menu(Handle_VoteMenu);
    
menu.VoteResultCallback Handle_VoteResults;
    
menu.SetTitle("Change map to: %s?"map);
    
menu.AddItem(map"Yes");
    
menu.AddItem("no""No");
    
menu.ExitButton false;
    
menu.DisplayVoteToAll(20);

If you don't understand something click on the banner of my description and add me on steam or Discord -> SpirT#1309

Best Regards,

SpirT.
__________________
SpirT 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 09:23.


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