Quote:
Originally Posted by pr0mers
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 client, int args)
{
char currentMap[64];
GetCurrentMap(currentMap, sizeof(currentMap));
DoVoteMenu(currentMap);
return Plugin_Handled;
}
public int Handle_VoteMenu(Menu menu, MenuAction action, int param1, int 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(param1, map, sizeof(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 client, int args)
{
char currentMap[64];
GetCurrentMap(currentMap, sizeof(currentMap));
DoVoteMenu(currentMap);
return Plugin_Handled;
}
public int Handle_VoteMenu(Menu menu, MenuAction action, int param1, int 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(0, 1);
}
char map[64];
menu.GetItem(item_info[winner][VOTEINFO_ITEM_INDEX], map, sizeof(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.
__________________