sm-plugins/Break/scripting/Break.sp
2023-01-14 16:39:42 +01:00

228 lines
6.7 KiB
SourcePawn

#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <cstrike>
#include <zombiereloaded>
/* INTS */
int g_iBreak = 0;
/* BOOLS */
bool g_bBreak = false;
/* HANDLES */
Handle g_hBreak = null;
/* FORWARDS */
GlobalForward g_hFwd_OnBreakStarted = null;
GlobalForward g_hFwd_OnBreakFinished = null;
GlobalForward g_hFwd_OnBreakCancelled = null;
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Plugin myinfo =
{
name = "Break",
author = "zaCade",
description = "Allows for making breaks during events ect.",
version = "1.0.0"
};
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public APLRes AskPluginLoad2(Handle hMyself, bool bLate, char[] sError, int iErrorSize)
{
CreateNative("Break_IsBreakActive", Native_IsBreakActive);
RegPluginLibrary("Break");
return APLRes_Success;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnPluginStart()
{
g_hFwd_OnBreakStarted = new GlobalForward("Break_OnBreakStarted", ET_Ignore);
g_hFwd_OnBreakFinished = new GlobalForward("Break_OnBreakFinished", ET_Ignore);
g_hFwd_OnBreakCancelled = new GlobalForward("Break_OnBreakCancelled", ET_Ignore);
RegAdminCmd("sm_break", Command_InitiateBreak, ADMFLAG_BAN);
RegAdminCmd("sm_cancelbreak", Command_CancelBreak, ADMFLAG_BAN);
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnMapEnd()
{
ResetVariables();
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action Command_InitiateBreak(int iClient, int iArgs)
{
if (iArgs < 1)
{
ReplyToCommand(iClient, "[SM] Usage: sm_break <time>");
return Plugin_Handled;
}
if (g_bBreak)
{
ReplyToCommand(iClient, "[SM] Break already in progress.");
return Plugin_Handled;
}
char sArgs[16];
GetCmdArg(1, sArgs, sizeof(sArgs));
int iDuration;
if (!StringToIntEx(sArgs, iDuration) || iDuration <= 0)
{
ReplyToCommand(iClient, "[SM] Invalid duration specified.");
return Plugin_Handled;
}
InitiateBreak(iDuration);
LogAction(iClient, -1, "\"%L\" initiated a \"%d\" minutes break.", iClient, iDuration);
PrintToChatAll("[SM] %N: Initiated a %d minutes break.", iClient, iDuration);
return Plugin_Handled;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action Command_CancelBreak(int iClient, int iArgs)
{
if (!g_bBreak)
{
ReplyToCommand(iClient, "[SM] No break in progress.");
return Plugin_Handled;
}
CancelBreak();
LogAction(iClient, -1, "\"%L\" cancelled the break.", iClient);
PrintToChatAll("[SM] %N: Cancelled the break.", iClient);
return Plugin_Handled;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
stock void ResetVariables()
{
g_iBreak = 0;
g_bBreak = false;
if (g_hBreak != null)
{
KillTimer(g_hBreak);
g_hBreak = null;
}
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
stock void InitiateBreak(int iLength = 0)
{
ResetVariables();
g_bBreak = true;
g_hBreak = CreateTimer(1.0, OnBreakTimer, iLength * 60, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
Call_StartForward(g_hFwd_OnBreakStarted);
Call_Finish();
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
stock void CancelBreak()
{
ResetVariables();
Call_StartForward(g_hFwd_OnBreakCancelled);
Call_Finish();
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action OnBreakTimer(Handle hTimer, int iLength)
{
if (g_iBreak >= iLength)
{
ResetVariables();
Call_StartForward(g_hFwd_OnBreakFinished);
Call_Finish();
CS_TerminateRound(1.0, CSRoundEnd_GameStart, false);
return Plugin_Stop;
}
else
{
g_iBreak++;
float flTimeLeft = float(iLength - g_iBreak);
if (flTimeLeft > 60)
PrintCenterTextAll("Break ends in %d minutes.", RoundToCeil(flTimeLeft / 60));
else
PrintCenterTextAll("Break ends in %d seconds.", RoundToCeil(flTimeLeft));
return Plugin_Continue;
}
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action CS_OnTerminateRound(float &flDelay, CSRoundEndReason &iRoundEndReason)
{
if(g_bBreak)
return Plugin_Handled;
return Plugin_Continue;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action ZR_OnInfectCountdown()
{
if(g_bBreak)
return Plugin_Handled;
return Plugin_Continue;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action ZR_OnClientInfect(int &iClient, int &iAttacker, bool &bMotherInfect, bool &bRespawnOverride, bool &bRespawn)
{
if(g_bBreak)
return Plugin_Handled;
return Plugin_Continue;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public int Native_IsBreakActive(Handle hPlugin, int iNumParams)
{
return g_bBreak;
}