Skip to content

Commit

Permalink
Release 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dronelektron committed Dec 27, 2021
2 parents 43ea2cc + 53560ae commit 23547b7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ Allows you to block the spectators team at the end of the round or earlier
### Console Variables

* sm_blockspectators - Enable (1) or disable (0) spectators team blocking [default: "1"]
* sm_blockspectators_notifications - Enable (1) or disable (0) notifications [default: "1"]
* sm_blockspectators_time_offset - Time offset (in seconds) until the end of the round [default: "0"]
46 changes: 41 additions & 5 deletions scripting/block-spectators.sp
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,43 @@
#define ENTITY_NOT_FOUND -1
#define TEAM_ARG_MAX_SIZE 2
#define TEAM_SPECTATOR 1
#define ROUND_TIMER_EXISTS_DEFAULT_VALUE true

public Plugin myinfo = {
name = "Block spectators",
author = "Dron-elektron",
description = "Allows you to block the spectators team at the end of the round or earlier",
version = "0.1.2",
version = "0.2.0",
url = ""
};

ConVar g_pluginEnabled = null;
ConVar g_notificationsEnabled = null;
ConVar g_blockTimeOffset = null;

Handle g_blockTimer = null;
float g_blockTimerEndTime = 0.0;
bool g_isSpectatorsBlocked = false;
bool g_isRoundTimerExists = ROUND_TIMER_EXISTS_DEFAULT_VALUE;

public void OnPluginStart() {
g_pluginEnabled = CreateConVar("sm_blockspectators", "1", "Enable (1) or disable (0) spectators team blocking");
g_notificationsEnabled = CreateConVar("sm_blockspectators_notifications", "1", "Enable (1) or disable (0) notifications");
g_blockTimeOffset = CreateConVar("sm_blockspectators_time_offset", "0", "Time offset (in seconds) until the end of the round");

HookEvent("dod_round_start", Event_RoundStart);
HookEvent("dod_round_active", Event_RoundActive);
HookEvent("dod_round_win", Event_RoundWin);
HookEvent("dod_timer_time_added", Event_TimerTimeAdded);
AddCommandListener(CommandListener_JoinTeam, "jointeam");
LoadTranslations("block-spectators.phrases");
AutoExecConfig(true, "block-spectators");
}

public void OnMapStart() {
g_isRoundTimerExists = ROUND_TIMER_EXISTS_DEFAULT_VALUE;
}

public void OnMapEnd() {
UnblockSpectators();
}
Expand All @@ -50,12 +59,23 @@ public void Event_RoundActive(Event event, const char[] name, bool dontBroadcast
CreateBlockTimer();
}

public void Event_RoundWin(Event event, const char[] name, bool dontBroadcast) {
if (!g_isRoundTimerExists) {
BlockSpectators();
}
}

public void Event_TimerTimeAdded(Event event, const char[] name, bool dontBroadcast) {
int secondsAdded = event.GetInt("seconds_added");

ExtendBlockTimer(secondsAdded);
}

void BlockSpectators() {
g_isSpectatorsBlocked = true;
NotifySpectatorsWasBlocked();
}

void UnblockSpectators() {
delete g_blockTimer;
g_isSpectatorsBlocked = false;
Expand All @@ -69,6 +89,8 @@ void CreateBlockTimer() {
int timerEntity = FindEntityByClassname(ENTITY_NOT_FOUND, "dod_round_timer");

if (timerEntity == ENTITY_NOT_FOUND) {
g_isRoundTimerExists = false;

return;
}

Expand All @@ -95,9 +117,7 @@ void ExtendBlockTimer(int secondsAdded) {

public Action Timer_BlockSpectators(Handle timer) {
g_blockTimer = null;
g_isSpectatorsBlocked = true;

CPrintToChatAll("%s%t", PREFIX_COLORED, "Spectators team was blocked");
BlockSpectators();

return Plugin_Continue;
}
Expand All @@ -110,18 +130,34 @@ public Action CommandListener_JoinTeam(int client, const char[] command, int arg
int team = StringToInt(teamStr);

if (g_isSpectatorsBlocked && team == TEAM_SPECTATOR) {
CPrintToChat(client, "%s%t", PREFIX_COLORED, "Spectators team is blocked");
NotifySpectatorsIsBlocked(client);

return Plugin_Stop;
}

return Plugin_Continue;
}

void NotifySpectatorsWasBlocked() {
if (IsNotificationsEnabled()) {
CPrintToChatAll("%s%t", PREFIX_COLORED, "Spectators team was blocked");
}
}

void NotifySpectatorsIsBlocked(int client) {
if (IsNotificationsEnabled()) {
CPrintToChat(client, "%s%t", PREFIX_COLORED, "Spectators team is blocked");
}
}

bool IsPluginEnabled() {
return g_pluginEnabled.IntValue == 1;
}

bool IsNotificationsEnabled() {
return g_notificationsEnabled.IntValue == 1;
}

float GetBlockTimeOffset() {
return g_blockTimeOffset.FloatValue;
}

0 comments on commit 23547b7

Please sign in to comment.