I got cancer from trying to work it out without being brain raped by another menu...
PHP Code:
#include <sourcemod>
public Plugin:myinfo =
{
name = "Admin Vote Map",
author = "Eyal282 ( FuckTheSchool )",
description = "Allows admins to let players decide a map to change to.",
version = "1.1",
url = "<- URL ->"
}
enum enMaps
{
String:CampaignName[50],
String:CampaignSerialName[50]
}
new const MapList[][enMaps] =
{
{ "Dead Center", "c1m1_hotel" },
{ "Dark Carnival", "c2m1_highway" },
{ "Swamp Fever", "c3m1_plankcountry" },
{ "Hard Rain", "c4m1_milltown_a" },
{ "The Parish", "c5m1_waterfront" },
{ "The Sacrifice", "c7m1_docks" },
{ "No Mercy", "c8m1_apartment" },
{ "Crash Course", "c9m1_alleys" },
{ "Death Toll", "c10m1_caves" },
{ "Dead Air", "c11m1_greenhouse" },
{ "Blood Harvest", "c12m1_hilltop" },
{ "Cold Stream", "c13m1_alpinecreek" }
};
new bool:isVoteRunning;
new TimeLeft;
new bCanVote[MAXPLAYERS];
new bNextMenu[MAXPLAYERS];
new Votes[sizeof(MapList)];
new Handle:hVoteTimer = INVALID_HANDLE;
public OnPluginStart()
{
RegAdminCmd("sm_startvotemap", Command_StartVoteMap, ADMFLAG_VOTE);
RegAdminCmd("sm_stopvotemap", Command_StopVoteMap, ADMFLAG_VOTE);
}
public OnMapStart()
{
hVoteTimer = INVALID_HANDLE;
}
public Action:Command_StopVoteMap(client, args)
{
if(!isVoteRunning)
{
ReplyToCommand(client, "[SM] Error: No map vote is running.");
return Plugin_Handled;
}
FinishVote();
PrintToChatAll("\x03%N\x01 has stopped the\x04 map vote!", client);
return Plugin_Handled;
}
public Action:Command_StartVoteMap(client, args)
{
if(isVoteRunning)
{
ReplyToCommand(client, "[SM] Error: Map vote is already running.");
return Plugin_Handled;
}
TimeLeft = 15;
isVoteRunning = true;
for(new i=0;i < sizeof(MapList);i++)
{
Votes[i] = 0;
}
new String:TempFormat[100];
for(new i=1;i <= MaxClients;i++)
{
if(!IsClientInGame(i))
continue;
else if(IsFakeClient(i))
continue;
bCanVote[i] = true;
bNextMenu[i] = false;
/*
new Handle:hMenu = CreateMenu(Vote_MenuHandler);
for(new ii=0;ii < sizeof(MapList);ii++)
{
Format(TempFormat, sizeof(TempFormat), "%s [ %i Votes ]", MapList[ii][CampaignName], Votes[ii]);
AddMenuItem(hMenu, "", TempFormat);
}
SetMenuTitle(hMenu, "Choose your map:");
DisplayMenu(hMenu, i, 1);
*/
}
TriggerTimer(hVoteTimer = CreateTimer(1.0, CountDown, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE), true);
PrintToChatAll("\x03%N\x01 has started a\x04 map vote!", client);
PrintToChat(client, "You can use !stopvotemap only before the timer hits 0.");
return Plugin_Handled;
}
public Vote_MenuHandler(Handle:hMenu, MenuAction:action, client, item)
{
if(action == MenuAction_End)
delete hMenu;
if(action == MenuAction_Select)
{
PrintToChatAll("%N %i", client, item);
if(item == 7)
bNextMenu[client] = false;
else if(item == 8)
{
PrintToChat(client, "Testdve");
bNextMenu[client] = true;
}
else if(item == 9)
return;
else if(bCanVote[client])
{
new ActualItem = item > 9 ? item + 3 : item;
Votes[ActualItem]++;
bCanVote[client] = false;
}
}
}
public Action:CountDown(Handle:hTimer)
{
if(TimeLeft == 0)
{
new TotalVotes = 0;
new WinnerID = 0;
for(new i=0;i < sizeof(MapList);i++)
{
TotalVotes += Votes[i];
if(Votes[i] > Votes[WinnerID] || ( Votes[i] == Votes[WinnerID] && GetRandomInt(0, 1) == 1) ) // Make the map the winner if it has more votes or if votes are equal and luck helped the map.
WinnerID = i;
}
FinishVote();
ServerCommand("changelevel %s", MapList[WinnerID][CampaignSerialName]);
return Plugin_Stop;
}
PrintHintTextToAll("Vote map is running!\nTime Left: %i", TimeLeft);
new String:TempFormat[50];
for(new i=1;i <= MaxClients;i++)
{
if(!IsClientInGame(i))
continue;
else if(IsFakeClient(i))
continue;
new Handle:hMenu = CreateMenu(Vote_MenuHandler);
new Button = 0;
for(new ii=0;ii < sizeof(MapList);ii++)
{
Button++;
if(Button == 8)
{
AddMenuItem(hMenu, "", "Previous");
AddMenuItem(hMenu, "", "Next");
AddMenuItem(hMenu, "", "Exit");
Button = 1;
}
Format(TempFormat, sizeof(TempFormat), "%s [ %i Votes ]", MapList[ii][CampaignName], Votes[ii]);
AddMenuItem(hMenu, "", TempFormat);
}
//while(Button < 7)
//{
//AddMenuItem(hMenu, "", "", ITEMDRAW_NOTEXT);
//Button++;
//}
AddMenuItem(hMenu, "", "Previous");
AddMenuItem(hMenu, "", "Next");
AddMenuItem(hMenu, "", "Exit");
SetMenuTitle(hMenu, "Choose your map:");
SetMenuPagination(hMenu, MENU_NO_PAGINATION);
DisplayMenuAtItem(hMenu, i, bNextMenu[i] ? 10 : 0, 1);
}
TimeLeft--;
return Plugin_Continue;
}
public FinishVote()
{
isVoteRunning = false;
TimeLeft = 0;
if(hVoteTimer != INVALID_HANDLE)
{
CloseHandle(hVoteTimer);
hVoteTimer = INVALID_HANDLE
}
}