Skip to content

Commit

Permalink
Release 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dronelektron committed Dec 24, 2021
2 parents 9290159 + f8c895f commit ec6639d
Show file tree
Hide file tree
Showing 6 changed files with 804 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ Allows you to block the spectators team at the end of the round or earlier

* Download latest [release](https://github.com/dronelektron/block-spectators/releases) (compiled for SourceMod 1.10)
* Extract "plugins" folder to "addons/sourcemod" folder of your server

### Console Variables

* sm_blockspectators - Enable (1) or disable (0) spectators team blocking [default: "1"]
* sm_blockspectators_time_offset - Time offset (in seconds) until the end of the round [default: "0"]
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
PLUGIN_NAME="block-spectators"

cd scripting
spcomp $PLUGIN_NAME.sp -o ../plugins/$PLUGIN_NAME.smx
spcomp $PLUGIN_NAME.sp -i include -o ../plugins/$PLUGIN_NAME.smx
100 changes: 100 additions & 0 deletions scripting/block-spectators.sp
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
#include <sourcemod>
#include <sdktools>

#include "morecolors"

#pragma semicolon 1
#pragma newdecls required

#define PREFIX_COLORED "{green}[Block spectators] "
#define ENTITY_NOT_FOUND -1
#define TEAM_ARG_MAX_SIZE 2
#define TEAM_SPECTATOR 1

public Plugin myinfo = {
name = "Block spectators",
Expand All @@ -7,3 +18,92 @@ public Plugin myinfo = {
version = "0.1.0",
url = ""
};

ConVar g_pluginEnabled = null;
ConVar g_blockTimeOffset = null;

Handle g_blockTimer = null;
bool g_isSpectatorsBlocked = false;

public void OnPluginStart() {
g_pluginEnabled = CreateConVar("sm_blockspectators", "1", "Enable (1) or disable (0) spectators team blocking");
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);
AddCommandListener(CommandListener_JoinTeam, "jointeam");
LoadTranslations("block-spectators.phrases");
AutoExecConfig(true, "block-spectators");
}

public void OnMapEnd() {
UnblockSpectators();
}

public void Event_RoundStart(Event event, const char[] name, bool dontBroadcast) {
UnblockSpectators();
}

public void Event_RoundActive(Event event, const char[] name, bool dontBroadcast) {
CreateBlockTimer();
}

void UnblockSpectators() {
DeleteBlockTimer();

g_isSpectatorsBlocked = false;
}

void CreateBlockTimer() {
if (!IsPluginEnabled()) {
return;
}

int timerEntity = FindEntityByClassname(ENTITY_NOT_FOUND, "dod_round_timer");

if (timerEntity == ENTITY_NOT_FOUND) {
return;
}

float timeRemanining = GetEntPropFloat(timerEntity, Prop_Send, "m_flTimeRemaining");
float timerDelay = timeRemanining - GetBlockTimeOffset();

g_blockTimer = CreateTimer(timerDelay, Timer_BlockSpectators);
}

void DeleteBlockTimer() {
delete g_blockTimer;
}

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

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

return Plugin_Continue;
}

public Action CommandListener_JoinTeam(int client, const char[] command, int argc) {
char teamStr[TEAM_ARG_MAX_SIZE];

GetCmdArg(1, teamStr, sizeof(teamStr));

int team = StringToInt(teamStr);

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

return Plugin_Stop;
}

return Plugin_Continue;
}

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

float GetBlockTimeOffset() {
return g_blockTimeOffset.FloatValue;
}
Loading

0 comments on commit ec6639d

Please sign in to comment.