Last active
July 18, 2017 12:11
-
-
Save Hexer10/771ee5c9050a4ea67b09883e30199922 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sourcemod> | |
#include <cstrike> | |
#include <mystocks> | |
#include <warden> | |
#pragma newdecls required | |
#pragma semicolon 1 | |
#define PLUGIN_AUTHOR "Hexah" | |
#define PLUGIN_VERSION "1.00" | |
//Bool | |
bool bFirstWarden = true; | |
bool bStopVote = false; | |
bool bRunningVote = false; | |
//Int | |
int iCanList[MAXPLAYERS + 1] = -1; | |
int iCanCount = 0; | |
//Handle | |
Handle hStopVoteTimer = null; | |
Handle hRunningVoteTimer = null; | |
//ConVar | |
ConVar cv_bChoseType = null; | |
public Plugin myinfo = | |
{ | |
name = "Voteable warden", | |
author = PLUGIN_AUTHOR, | |
description = "", | |
version = PLUGIN_VERSION, | |
url = "" | |
}; | |
public void OnPluginStart() | |
{ | |
cv_bChoseType = CreateConVar("sm_warden_choosetype", "0", "0 - Normal, 1 - By vote", 0, true, 0.0, true, 1.0); | |
//HookEvent | |
HookEvent("round_start", Event_RoundStart); | |
HookEvent("round_end", Event_RoundEnd); | |
HookEvent("player_death", Event_PlayerDeath); | |
HookEvent("round_start", Event_RoundStart); | |
AddCommandListener(Cmd_UnList, "sm_uw"); | |
} | |
public void Event_PlayerDeath(Event event, const char[] name, bool dontBroadcast) | |
{ | |
if (!cv_bChoseType.BoolValue || warden_exist() || !bFirstWarden) | |
{ | |
return; | |
} | |
int client = GetClientOfUserId(event.GetInt("userid")); | |
bool found = false; | |
for (int i = 1; i <= iCanCount; i++) | |
{ | |
if (iCanList[i] == client) | |
{ | |
iCanList[i] = -1; | |
found = true; | |
break; | |
} | |
} | |
if (found) | |
{ | |
ReplyToCommand(client, "[SM] You was successfuly removed from the warden pool!"); | |
} | |
} | |
public Action Cmd_UnList(int client, const char[] name, int argc) | |
{ | |
if (!cv_bChoseType.BoolValue || warden_exist() || !bFirstWarden || GetClientTeam(client) != CS_TEAM_CT) | |
{ | |
return Plugin_Continue; | |
} | |
bool found = false; | |
for (int i = 1; i <= iCanCount; i++) | |
{ | |
if (iCanList[i] == client) | |
{ | |
iCanList[i] = -1; | |
found = true; | |
break; | |
} | |
} | |
if (found) | |
{ | |
ReplyToCommand(client, "[SM] You was successfuly removed from the warden pool!"); | |
} | |
else | |
{ | |
ReplyToCommand(client, "[SM] You aren't in the canditates list!"); | |
} | |
return Plugin_Stop; | |
} | |
public Action warden_OnWardenCreate(int client, int caller) | |
{ | |
if (!cv_bChoseType.BoolValue) | |
{ | |
return Plugin_Continue; | |
} | |
if (bRunningVote) | |
{ | |
ReplyToCommand(client, "[SM] The pool is already started!"); | |
return Plugin_Handled; | |
} | |
if (bFirstWarden && !bStopVote && (client == caller)) | |
{ | |
iCanList[iCanCount] = client; | |
iCanCount++; | |
ReplyToCommand(client, "[SM] You was added to the candidates list!"); | |
return Plugin_Handled; | |
} | |
return Plugin_Continue; | |
} | |
public void Event_RoundStart(Event event, const char[] name, bool dontBroadcast) | |
{ | |
if (!cv_bChoseType.BoolValue) | |
return; | |
hStopVoteTimer = CreateTimer(30.0, Timer_StopVote); | |
bFirstWarden = true; | |
bStopVote = false; | |
bRunningVote = false; | |
for (int i = 0; i <= iCanCount; i++) | |
{ | |
iCanList[i] = -1; | |
} | |
iCanCount = 0; | |
} | |
public Action Event_RoundEnd(Event event, const char[] name, bool dontBroadcast) | |
{ | |
//Check if rounds end early | |
if (hStopVoteTimer != null) | |
KillTimer(hStopVoteTimer); | |
if (hRunningVoteTimer != null) | |
KillTimer(hRunningVoteTimer); | |
} | |
/****************************************************************************************** | |
Timers | |
*******************************************************************************************/ | |
public Action Timer_RunningVote(Handle timer) | |
{ | |
bRunningVote = false; | |
} | |
public Action Timer_StopVote(Handle timer) | |
{ | |
//Check for no candidates | |
if (!iCanCount) | |
{ | |
int warden = GetRandomPlayer(CS_TEAM_CT); | |
warden_set(warden, 0); | |
PrintToChatAll("[SM] %n was randomly chosen because there aren't any candidates"); | |
return Plugin_Continue; | |
} | |
bFirstWarden = false; | |
StartVote(); | |
bStopVote = true; | |
return Plugin_Continue; | |
} | |
/****************************************************************************************** | |
Menu | |
*******************************************************************************************/ | |
void StartVote() | |
{ | |
//Create the menu | |
Menu menu = new Menu(WardenVoteHandler); | |
menu.SetTitle("Choose you favourite warden!"); | |
for (int i = 0; i <= iCanCount; i++) | |
{ | |
if (iCanList[i] == -1) | |
continue; | |
char sPlayerName[32]; | |
char sPlayerIndex[32]; | |
IntToString(iCanList[i], sPlayerIndex, sizeof(sPlayerIndex)); | |
Format(sPlayerName, sizeof(sPlayerName), "%n", iCanList[i]); | |
menu.AddItem(sPlayerName, sPlayerIndex); | |
} | |
//Loop clients for VoteMenu | |
int[] iCTs = new int[GetAlivePlayersCount(CS_TEAM_CT)]; | |
for (int j = 1; 0 <= MaxClients; j++)if (IsClientInGame(j) && IsPlayerAlive(j) && (GetClientTeam(j) == CS_TEAM_CT)) | |
{ | |
for (int k = 0; k <= GetAlivePlayersCount(CS_TEAM_CT); k++) | |
{ | |
iCTs[k] = j; | |
} | |
} | |
VoteMenu(menu, iCTs, GetAlivePlayersCount(CS_TEAM_CT), 15); | |
hRunningVoteTimer = CreateTimer(15.0, Timer_RunningVote); | |
bRunningVote = true; | |
} | |
public int WardenVoteHandler(Menu menu, MenuAction action, int param1, int param2) | |
{ | |
if (action == MenuAction_End) | |
CloseHandle(menu); | |
else if (action == MenuAction_VoteEnd) | |
{ | |
char sPlayerName[32]; | |
char sPlayerIndex[32]; | |
int winCount; | |
int totalCount; | |
menu.GetItem(param1, sPlayerName, sizeof(sPlayerName)); | |
menu.GetItem(param2, sPlayerIndex, sizeof(sPlayerIndex)); | |
GetMenuVoteInfo(param2, winCount, totalCount); | |
int client = StringToInt(sPlayerIndex); | |
PrintToChatAll("[SM] The new warden is: %s - Received %i of %i votes", sPlayerName, winCount, totalCount); | |
warden_set(client, 0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added cmd to remove from the pool & when a client dies.
Added roundstart functions.