PHP Code:
#include <sourcemod>
#include <nativevotes>
public Plugin myinfo =
{
name = "[NativeVotes] KickSpec",
author = "Keith Warren (Sky Guardian), edited by Malifox",
description = "Vote to kick all spectators from the server.",
url = "http://www.sourcemod.com/"
}
public OnPluginStart()
{
RegConsoleCmd("sm_kickspec", OnCallVote, "Vote to kick all spectators from the server.");
RegConsoleCmd("sm_kickspecs", OnCallVote, "Vote to kick all spectators from the server.");
}
public Action OnCallVote(int client, int args)
{
if ((GetClientTeam(client) == 1) && (!IsGenericAdmin(client))){
PrintToChat(client, "\x04[SM] Spectators may not use this command.");
return Plugin_Handled;
}
if (NativeVotes_IsVoteInProgress())
{
PrintToChat(client, "\x04[SM] You cannot start a vote while one is currently going.");
return Plugin_Handled;
}
//NativeVote vote = NativeVotes_Create(MenuHandler_VoteCallback, NativeVotesType_Custom_YesNo);
NativeVote vote = new NativeVote(MenuHandler_VoteCallback, NativeVotesType_Custom_YesNo, NATIVEVOTES_ACTIONS_DEFAULT | MenuAction_Display);
/*NativeVotes_SetInitiator(vote, client);
char sDetails[256];
FormatEx(sDetails, sizeof(sDetails), "Kick spectators from the server?");
NativeVotes_SetDetails(vote, sDetails);
NativeVotes_SetResultCallback(vote, VoteResultHandler);
NativeVotes_DisplayToAllNonSpectators(vote, 20);*/
vote.Initiator = client;
vote.SetDetails("Kick spectators from the server?");
vote.DisplayVoteToAll(20);
return Plugin_Handled;
}
/*public int MenuHandler_VoteCallback(NativeVote menu, MenuAction action, int param1, int param2)
{
switch (action)
{
case MenuAction_VoteCancel:
{
if (param1 == VoteCancel_NoVotes)
{
NativeVotes_DisplayFail(menu, NativeVotesFail_NotEnoughVotes);
}
else
{
NativeVotes_DisplayFail(menu, NativeVotesFail_Generic);
}
}
case MenuAction_End:
{
NativeVotes_Close(menu);
}
}
}*/
public int MenuHandler_VoteCallback(NativeVote vote, MenuAction action, int param1, int param2)
{
switch (action)
{
case MenuAction_End:
{
vote.Close();
}
case MenuAction_Display:
{
char display[64];
Format(display, sizeof(display), "Kick spectators from the server?");
PrintToChat(param1, "Vote: %s", display);
NativeVotes_RedrawVoteTitle(display);
return view_as<int>(Plugin_Changed);
}
case MenuAction_VoteCancel:
{
if (param1 == VoteCancel_NoVotes)
{
vote.DisplayFail(NativeVotesFail_NotEnoughVotes);
}
else
{
vote.DisplayFail(NativeVotesFail_Generic);
}
}
case MenuAction_VoteEnd:
{
if (param1 == NATIVEVOTES_VOTE_NO)
{
vote.DisplayFail(NativeVotesFail_Loses);
}
else
{
vote.DisplayPass("Vote Passed!");
for (int i = 1; i <= MaxClients; i++) {
if (IsClientInGame(i) && !IsFakeClient(i) && GetClientTeam(i) == 1 && !CheckCommandAccess(i, "kickspec_immune", ADMFLAG_RESERVATION, true))
{
KickClient(i, "You have been votekicked.");
}
}
}
}
}
return 0;
}
/*public int VoteResultHandler(Handle vote, int num_votes, int num_clients, const int[] client_indexes, const int[] client_votes, int num_items, const int[] item_indexes, const int[] item_votes)
{
for (int i = 0; i < num_items; i++)
{
if (item_indexes[i] == NATIVEVOTES_VOTE_YES && item_votes[i] > (num_clients / 2))
{
char sDetails[256];
FormatEx(sDetails, sizeof(sDetails), "Kicking non-admin spectators from the server...");
NativeVotes_DisplayPass(vote, sDetails);
for (int x = 1; x <= MaxClients; x++)
{
if (IsClientInGame(x) && GetClientTeam(x) == 1 && !CheckCommandAccess(x, "kickspec_immune", ADMFLAG_RESERVATION, true))
{
KickClient(x, "You have been kicked for being a spectator.");
}
}
return;
}
}
NativeVotes_DisplayFail(vote, NativeVotesFail_Loses);
}*/
static bool:IsGenericAdmin(client) {
return CheckCommandAccess(client, "generic_admin", ADMFLAG_GENERIC, false);
}