HTML Code:
new bool:is_vote[MAXPLAYERS];
new max_votes;
new vote_counts;
new Handle:h_cvar_players;
public OnPluginStart()
{
RegConsoleCmd("sm_rtv", ChangeMap_Func, "Used console command changelevel_next");
RegConsoleCmd("say .rtv", ChangeMap_Func, "Used console command changelevel_next");
LoadTranslations("mapchange_ini.phrases");
h_cvar_players = CreateConVar("sm_initial_players", "1", "How many minimum players need on this Server, what Turn On Vote", FCVAR_NOTIFY, true, 0.0, true, 64.0);
CreateConVar("sm_mapchange_ini", "1.0", "Version of Plugin", FCVAR_NOTIFY | FCVAR_NONE);
}
public Action:ChangeMap_Func(client, args)
{
if (!args)
{
if (max_votes >= GetConVarInt(h_cvar_players))
{
if (is_vote[client] == false)
{
is_vote[client] = true;
new vote_count_half = max_votes / 2;
if (vote_count_half == vote_counts++)
{
ServerCommand("changelevel_next");
}
else
{
decl String:map_name[32];
decl String:level_name[32];
GetCurrentMap(map_name, sizeof(map_name));
new Handle:map_file = OpenFile("cfg/mapcycle.txt", "r");
new bool:test_end_file = false;
while (!IsEndOfFile(map_file))
{
ReadFileLine(map_file, level_name, sizeof(level_name));
TrimString(level_name);
if (StrEqual(map_name, level_name, false))
{
if (!IsEndOfFile(map_file))
{
ReadFileLine(map_file, level_name, sizeof(level_name));
TrimString(level_name);
break;
}
else
{
test_end_file = true;
}
}
}
if (test_end_file)
{
CloseHandle(map_file);
map_file = OpenFile("cfg/mapcycle.txt", "r");
ReadFileLine(map_file, level_name, sizeof(level_name));
TrimString(level_name);
}
CloseHandle(map_file);
for (new i_client = 1; i_client <= MaxClients; i_client++)
{
if (!IsClientInGame(i_client) || IsFakeClient(i_client))
{
continue;
}
decl String:name_include[MAX_NAME_LENGTH];
decl String:map_include[32];
decl String:vote_string[16];
FormatEx(name_include, sizeof(name_include), "\x04%N\x01", client);
FormatEx(map_include, sizeof(map_include), "\x04%s\x01", level_name);
FormatEx(vote_string, sizeof(vote_string), "[\x04%i\x01/\x04%i\x01]", vote_counts, vote_count_half);
PrintToChat(i_client, "\x03[SM]\x01 %t", "Vote Apply", name_include, map_include, vote_string);
}
}
}
else
{
PrintToChat(client, "\x03[SM]\x01 %t", "Vote Already");
}
}
else
{
PrintToChat(client, "\x03[SM]\x01 %t", "More Players");
}
}
return Plugin_Handled;
}
public OnClientDisconnect(client)
{
if (!IsFakeClient(client) && IsClientInGame(client))
{
max_votes--;
if (is_vote[client] == true)
{
is_vote[client] = false;
vote_counts--;
}
}
}
public OnClientPutInServer(client)
{
if (!IsFakeClient(client))
{
max_votes++;
}
}