AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   How can i make vote (https://forums.alliedmods.net/showthread.php?t=324783)

pr0mers 05-27-2020 03:48

How can i make vote
 
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

SpirT 05-27-2020 06:00

Re: How can i make vote
 
Quote:

Originally Posted by pr0mers (Post 2702542)
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.


All times are GMT -4. The time now is 16:29.

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