[Break] Initial commit.
This commit is contained in:
		
							parent
							
								
									191db90c38
								
							
						
					
					
						commit
						7e45230930
					
				
							
								
								
									
										220
									
								
								Break/scripting/Break.sp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										220
									
								
								Break/scripting/Break.sp
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,220 @@ | |||||||
|  | #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 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; | ||||||
|  | } | ||||||
							
								
								
									
										51
									
								
								Break/scripting/include/Break.inc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								Break/scripting/include/Break.inc
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,51 @@ | |||||||
|  | #if defined _Break_include
 | ||||||
|  |   #endinput
 | ||||||
|  | #endif
 | ||||||
|  | #define _Break_include
 | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Called when a break is started | ||||||
|  |  * | ||||||
|  |  * @return				None | ||||||
|  |  */ | ||||||
|  | forward void Break_OnBreakStarted(); | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Called when a break is finished | ||||||
|  |  * | ||||||
|  |  * @return				None | ||||||
|  |  */ | ||||||
|  | forward void Break_OnBreakFinished(); | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Called when a break is cancelled | ||||||
|  |  * | ||||||
|  |  * @return				None | ||||||
|  |  */ | ||||||
|  | forward void Break_OnBreakCancelled(); | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Returns if a break is active | ||||||
|  |  * | ||||||
|  |  * @return				True when in break, false otherwise | ||||||
|  |  */ | ||||||
|  | native bool Break_IsBreakActive(); | ||||||
|  | 
 | ||||||
|  | public SharedPlugin __pl_Break = | ||||||
|  | { | ||||||
|  | 	name = "Break", | ||||||
|  | 	file = "Break.smx", | ||||||
|  | 
 | ||||||
|  | #if defined REQUIRE_PLUGIN
 | ||||||
|  | 	required = 1 | ||||||
|  | #else
 | ||||||
|  | 	required = 0 | ||||||
|  | #endif
 | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | #if !defined REQUIRE_PLUGIN
 | ||||||
|  | 	public void __pl_Break_SetNTVOptional() | ||||||
|  | 	{ | ||||||
|  | 		MarkNativeAsOptional("Break_IsBreakActive"); | ||||||
|  | 	} | ||||||
|  | #endif
 | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user