Skip to content

Commit

Permalink
Release 0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dronelektron committed Dec 29, 2021
2 parents 23547b7 + 982238f commit 85fcc47
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,21 @@ 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_notifications_mode - None - 0, Join attempt - 1, Round end - 2, Early - 4 [default: "7"]
* sm_blockspectators_time_offset - Time offset (in seconds) until the end of the round [default: "0"]

### Notification flags

Use a sum of flags to manage notifications.

For example:

* Mode 7 includes: Join attempt (1) + Round end (2) + Early (4)
* Mode 5 includes: Join attempt (1) + Early (4)

Flags description:

* None (0) - notifications disabled
* Join attempt (1) - when the player tries to join the spectators team
* Round end (2) - at the end of the round
* Early (4) - when the block timer was triggered
32 changes: 20 additions & 12 deletions scripting/block-spectators.sp
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,20 @@
#define TEAM_SPECTATOR 1
#define ROUND_TIMER_EXISTS_DEFAULT_VALUE true

#define NOTIFICATIONS_JOIN_ATTEMPT (1 << 0)
#define NOTIFICATIONS_ROUND_END (1 << 1)
#define NOTIFICATIONS_EARLY (1 << 2)

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.2.0",
version = "0.3.0",
url = ""
};

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

Handle g_blockTimer = null;
Expand All @@ -31,7 +35,7 @@ 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_notificationsMode = CreateConVar("sm_blockspectators_notifications_mode", "7", "None (0), Join attempt (1), Round end (2), Early (4)");
g_blockTimeOffset = CreateConVar("sm_blockspectators_time_offset", "0", "Time offset (in seconds) until the end of the round");

HookEvent("dod_round_start", Event_RoundStart);
Expand Down Expand Up @@ -61,7 +65,7 @@ public void Event_RoundActive(Event event, const char[] name, bool dontBroadcast

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

Expand All @@ -71,9 +75,9 @@ public void Event_TimerTimeAdded(Event event, const char[] name, bool dontBroadc
ExtendBlockTimer(secondsAdded);
}

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

void UnblockSpectators() {
Expand Down Expand Up @@ -117,7 +121,7 @@ void ExtendBlockTimer(int secondsAdded) {

public Action Timer_BlockSpectators(Handle timer) {
g_blockTimer = null;
BlockSpectators();
BlockSpectators(NOTIFICATIONS_EARLY);

return Plugin_Continue;
}
Expand All @@ -138,14 +142,18 @@ public Action CommandListener_JoinTeam(int client, const char[] command, int arg
return Plugin_Continue;
}

void NotifySpectatorsWasBlocked() {
if (IsNotificationsEnabled()) {
void NotifySpectatorsWasBlocked(int notificationFlag) {
bool isNotificationEnalbed = IsNotificationFlagEnabled(notificationFlag);

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

void NotifySpectatorsIsBlocked(int client) {
if (IsNotificationsEnabled()) {
bool isNotificationEnalbed = IsNotificationFlagEnabled(NOTIFICATIONS_JOIN_ATTEMPT);

if (isNotificationEnalbed) {
CPrintToChat(client, "%s%t", PREFIX_COLORED, "Spectators team is blocked");
}
}
Expand All @@ -154,8 +162,8 @@ bool IsPluginEnabled() {
return g_pluginEnabled.IntValue == 1;
}

bool IsNotificationsEnabled() {
return g_notificationsEnabled.IntValue == 1;
bool IsNotificationFlagEnabled(int flag) {
return (g_notificationsMode.IntValue & flag) == flag;
}

float GetBlockTimeOffset() {
Expand Down

0 comments on commit 85fcc47

Please sign in to comment.