Skip to content

Instantly share code, notes, and snippets.

@Hexer10
Created November 23, 2017 19:26
Show Gist options
  • Save Hexer10/6a8383d40a39ffc74c99691133e8abf4 to your computer and use it in GitHub Desktop.
Save Hexer10/6a8383d40a39ffc74c99691133e8abf4 to your computer and use it in GitHub Desktop.
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <cstrike>
#include <mystocks>
#include <warden>
#include <myjbwarden>
#define PLUGIN_AUTHOR "Hexah"
#define PLUGIN_VERSION "1.0"
#pragma semicolon 1
#pragma newdecls required
Handle hTimerPool;
ConVar cv_bVoteType;
ConVar cv_iCandidateTime;
ConVar cv_bVoteOverride;
ConVar cv_iVoteTime;
ArrayList CandidatesArray;
bool bFirstWarden = true;
public Plugin myinfo =
{
name = "VoteWarden",
author = PLUGIN_AUTHOR,
description = "",
version = PLUGIN_VERSION,
url = "shanapu.de/MyJailBreak"
};
public void OnPluginStart()
{
//Register Cvars
AutoExecConfig(true, "warden", "MyJailBreak");
cv_bVoteType = CreateConVar("sm_warden_type", "1", "0 - Let MyJB handle the warden. 1 - The Warden is votated.", _, true, 0.0, true, 1.0);
cv_iCandidateTime = CreateConVar("sm_wardem_candidate_time", "30", "Time to candidate after the round start.", _, true, 1.0);
cv_iVoteTime = CreateConVar("sm_warden_vote_time", "10", "Time to vote after the candidate time ends.", _, true, 1.0);
cv_bVoteOverride = CreateConVar("sm_warden_vote_override", "1", "0 - If there's already a running vote choose the warden randomly. 1 - If running stop the current vote.", _, true, 0.0, true, 1.0);
//HookEvents
HookEvent("round_start", Event_RoundStart);
}
public Action warden_OnWardenCreate(int client, int caller)
{
if (!cv_bVoteType.BoolValue)
return Plugin_Continue;
if (!bFirstWarden)
return Plugin_Continue;
if (client != caller)
{
if (hTimerPool != null)
{
hTimerPool.Close();
hTimerPool = null;
}
bFirstWarden = false;
return Plugin_Continue;
}
bFirstWarden = false;
CandidatesArray.Push(GetClientUserId(client));
return Plugin_Handled;
}
public void Event_RoundStart(Event event, const char[] name, bool dontBroadcast)
{
if (!cv_bVoteType.BoolValue)
return;
CandidatesArray.Clear();
bFirstWarden = true;
hTimerPool = CreateTimer(cv_iCandidateTime.FloatValue, Timer_StartPool, _, TIMER_FLAG_NO_MAPCHANGE);
}
public Action Timer_StartPool(Handle timer)
{
hTimerPool = null;
if (!CandidatesArray.Length)
{
SetRandomWarden("There are no candidatates!");
return;
}
else if (cv_bVoteOverride.BoolValue && IsVoteInProgress())
{
CancelVote();
return;
}
else if (IsVoteInProgress())
{
SetRandomWarden("The pool couldn't be started");
return;
}
Menu menu = new Menu(Handler_VoteMenu);
menu.SetTitle("Vote for your warden!");
for (int i = 0; i < CandidatesArray.Length; i++)
{
int client = GetClientOfUserId(CandidatesArray.Get(i));
if (!client)
return;
char sDisplay[64];
char sInfo[8];
Format(sDisplay, sizeof(sDisplay), "%N", client);
IntToString(CandidatesArray.Get(i), sInfo, sizeof(sInfo));
menu.AddItem(sInfo, sDisplay);
}
int[] iClients = new int[GetAlivePlayersCount(CS_TEAM_CT)];
for (int i = 0; i <= MaxClients; i++)if (IsClientInGame(i) && (GetClientTeam(i) == CS_TEAM_CT))
{
for (int j = 0; j <= GetAlivePlayersCount(CS_TEAM_CT); j++)iClients[j] = i;
}
menu.DisplayVote(iClients, GetAlivePlayersCount(CS_TEAM_CT), cv_iVoteTime.IntValue);
}
public int Handler_VoteMenu(Menu menu, MenuAction action, int param1, int param2)
{
if (action == MenuAction_End)
{
delete menu;
}
else if (action == MenuAction_VoteEnd)
{
char sInfo[8];
menu.GetItem(param1, sInfo, sizeof(sInfo));
int client = GetClientOfUserId(StringToInt(sInfo));
if (!client)
{
SetRandomWarden("The winner isn't valid anymore");
}
warden_set(client, 0);
PrintToChatAll("[SM] %N was voted as the new warden!", client);
bFirstWarden = true;
}
}
void SetRandomWarden(const char[] sReason)
{
int warden = GetRandomPlayer(CS_TEAM_CT);
warden_set(warden, 0);
PrintToChatAll("[SM] %N was randomly selected as warden because: %s", sReason);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment