Skip to content

Commit

Permalink
Release 0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
dronelektron committed Dec 26, 2021
2 parents 1f87f55 + 89dc0d6 commit 43ea2cc
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions scripting/block-spectators.sp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ 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.1",
version = "0.1.2",
url = ""
};

ConVar g_pluginEnabled = null;
ConVar g_blockTimeOffset = null;

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

public void OnPluginStart() {
Expand All @@ -31,6 +32,7 @@ public void OnPluginStart() {

HookEvent("dod_round_start", Event_RoundStart);
HookEvent("dod_round_active", Event_RoundActive);
HookEvent("dod_timer_time_added", Event_TimerTimeAdded);
AddCommandListener(CommandListener_JoinTeam, "jointeam");
LoadTranslations("block-spectators.phrases");
AutoExecConfig(true, "block-spectators");
Expand All @@ -48,9 +50,14 @@ public void Event_RoundActive(Event event, const char[] name, bool dontBroadcast
CreateBlockTimer();
}

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

ExtendBlockTimer(secondsAdded);
}

void UnblockSpectators() {
delete g_blockTimer;
g_isSpectatorsBlocked = false;
}

Expand All @@ -66,13 +73,24 @@ void CreateBlockTimer() {
}

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

if (timerDelay < 0.0) {
timerDelay = 0.0;
}

g_blockTimer = CreateTimer(timerDelay, Timer_BlockSpectators);
g_blockTimerEndTime = GetGameTime() + timerDelay;
}

void DeleteBlockTimer() {
void ExtendBlockTimer(int secondsAdded) {
delete g_blockTimer;

float timerSecondsLeft = g_blockTimerEndTime - GetGameTime();
float timerDelay = timerSecondsLeft + secondsAdded;

g_blockTimer = CreateTimer(timerDelay, Timer_BlockSpectators);
g_blockTimerEndTime = GetGameTime() + timerDelay;
}

public Action Timer_BlockSpectators(Handle timer) {
Expand Down

0 comments on commit 43ea2cc

Please sign in to comment.