Skip to content

Instantly share code, notes, and snippets.

@roflmuffin
Last active September 12, 2016 20:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roflmuffin/bed001ee2d12cb49deff to your computer and use it in GitHub Desktop.
Save roflmuffin/bed001ee2d12cb49deff to your computer and use it in GitHub Desktop.
Block command if time left in round is less than 5 seconds. (Sourcemod, CSGO)
#include <sdktools>
#pragma newdecls required
#pragma semicolon 1
#include <sourcemod>
int g_roundStartedTime = -1;
public void OnPluginStart()
{
RegConsoleCmd("test_command", Command_Test);
HookEvent("round_start", Event_RoundStart);
}
public Action Event_RoundStart(Handle event, const char[] name, bool dontBroadcast) {
g_roundStartedTime = GetTime();
}
public int GetTotalRoundTime() {
return GameRules_GetProp("m_iRoundTime");
}
public int GetCurrentRoundTime() {
Handle h_freezeTime = FindConVar("mp_freezetime"); // Freezetime Handle
int freezeTime = GetConVarInt(h_freezeTime); // Freezetime in seconds (5 by default)
return (GetTime() - g_roundStartedTime) - freezeTime;
}
public Action Command_Test(int client, int args) {
if (GetTotalRoundTime() - GetCurrentRoundTime() <= 5) {
ReplyToCommand(client, "Its too late to use this command..");
return Plugin_Handled;
} else {
// Do command stuff.
return Plugin_Handled;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment