2019-06-02 23:31:34 +02:00
# pragma semicolon 1
# include <sourcemod>
# include <cstrike>
# include <multicolors>
bool g_bHappyHour ;
bool g_bHappyHourAdmin ;
int g_iMorningStart ;
int g_iMorningEnd ;
int g_iNightStart ;
int g_iNightEnd ;
2019-06-04 23:08:10 +02:00
float g_fMessageTimer ;
2019-06-02 23:31:34 +02:00
ConVar g_cvMorningStart ;
ConVar g_cvMorningEnd ;
ConVar g_cvNightStart ;
ConVar g_cvNightEnd ;
2019-06-04 23:08:10 +02:00
ConVar g_cvMessageTimer ;
Handle g_h_MessageTimer ;
2019-06-02 23:31:34 +02:00
public Plugin myinfo =
{
name = " Happy Hour " ,
author = " Dogan + Neon " ,
description = " Create an happy hour with more rank points " ,
2019-06-03 00:27:41 +02:00
version = " 1.1.0 " ,
2019-06-02 23:31:34 +02:00
url = " "
} ;
public APLRes AskPluginLoad2 ( Handle myself , bool late , char [ ] error , int err_max )
{
CreateNative ( " HH_IsItHappyHour " , Native_IsItHappyHour ) ;
RegPluginLibrary ( " HappyHour " ) ;
return APLRes_Success ;
}
public void OnPluginStart ( )
{
g_bHappyHour = false ;
g_bHappyHourAdmin = false ;
CreateTimer ( 15.0 , Timer_CheckTime , _ , TIMER_REPEAT ) ;
2019-06-03 23:25:03 +02:00
g_cvMorningStart = CreateConVar ( " sm_happyhour_morning_start " , " 1000 " , " starttime of happy hour in the morning (timezone UTC+1 in summer, UTC+2 in winter) " ) ;
g_cvMorningEnd = CreateConVar ( " sm_happyhour_morning_end " , " 1400 " , " endtime of happy hour in the morning/afternoon (timezone UTC+1 in summer, UTC+2 in winter) " ) ;
g_cvNightStart = CreateConVar ( " sm_happyhour_night_start " , " 2300 " , " starttime of happy hour in the night (timezone UTC+1 in summer, UTC+2 in winter) " ) ;
g_cvNightEnd = CreateConVar ( " sm_happyhour_night_end " , " 0300 " , " endtime of happy hour in the night (timezone UTC+1 in summer, UTC+2 in winter) " ) ;
2019-06-04 23:08:10 +02:00
g_cvMessageTimer = CreateConVar ( " sm_happyhour_message_interval " , " 60.0 " , " interval for repetetive message of happy hour in chat " ) ;
2019-06-02 23:31:34 +02:00
RegConsoleCmd ( " sm_hh " , Command_DisplayHappyHour , " Shows if happy hour is currently enabled or not " ) ;
RegAdminCmd ( " sm_forcehh " , AdminCommand_HappyHour , ADMFLAG_GENERIC , " Toggle to enable/disable Happy Hour. Resets after Mapswitch. " ) ;
AutoExecConfig ( true , " plugin.HappyHour " ) ;
GetConVars ( ) ;
}
public void GetConVars ( )
{
g_iMorningStart = g_cvMorningStart . IntValue ;
g_iMorningEnd = g_cvMorningEnd . IntValue ;
g_iNightStart = g_cvNightStart . IntValue ;
g_iNightEnd = g_cvNightEnd . IntValue ;
2019-06-04 23:08:10 +02:00
g_fMessageTimer = g_cvMessageTimer . FloatValue ;
2019-06-02 23:31:34 +02:00
}
public void ConVarChange ( ConVar convar , char [ ] oldValue , char [ ] newValue )
{
GetConVars ( ) ;
2019-06-04 23:18:21 +02:00
if ( g_h_MessageTimer ! = INVALID_HANDLE & & CloseHandle ( g_h_MessageTimer ) )
g_h_MessageTimer = INVALID_HANDLE ;
2019-06-04 23:08:10 +02:00
g_h_MessageTimer = CreateTimer ( g_fMessageTimer , MessageHappyHour , _ , TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE ) ;
2019-06-02 23:31:34 +02:00
}
public Action Timer_CheckTime ( Handle timer )
{
2019-06-03 00:27:41 +02:00
if ( g_bHappyHourAdmin )
return Plugin_Continue ;
2019-06-02 23:31:34 +02:00
2019-06-03 23:25:03 +02:00
if ( ( InsideTimeFrame ( g_iMorningStart , g_iMorningEnd ) ) | | ( InsideTimeFrame ( g_iNightStart , g_iNightEnd ) ) )
{
g_bHappyHour = true ;
}
2019-06-03 00:27:41 +02:00
else
2019-06-03 23:25:03 +02:00
{
g_bHappyHour = false ;
}
2019-06-02 23:31:34 +02:00
2019-06-03 00:27:41 +02:00
return Plugin_Continue ;
}
2019-06-02 23:31:34 +02:00
2019-06-03 00:27:41 +02:00
public bool InsideTimeFrame ( int MinTime , int MaxTime )
{
char sTime [ 8 ] ;
FormatTime ( sTime , sizeof ( sTime ) , " %H%M " ) ;
2019-06-02 23:31:34 +02:00
2019-06-03 00:27:41 +02:00
int CurTime = StringToInt ( sTime ) ;
//Wrap around.
CurTime = ( CurTime < = MinTime ) ? CurTime + 2400 : CurTime ;
MaxTime = ( MaxTime < = MinTime ) ? MaxTime + 2400 : MaxTime ;
if ( MinTime < = CurTime < = MaxTime )
return true ;
2019-06-02 23:31:34 +02:00
2019-06-03 00:27:41 +02:00
return false ;
2019-06-02 23:31:34 +02:00
}
public void OnMapStart ( )
{
if ( g_bHappyHourAdmin )
{
g_bHappyHourAdmin = false ;
}
2019-06-04 23:08:10 +02:00
g_h_MessageTimer = CreateTimer ( g_fMessageTimer , MessageHappyHour , _ , TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE ) ;
2019-06-02 23:31:34 +02:00
}
public Action Command_DisplayHappyHour ( int client , int args )
{
if ( g_bHappyHour )
{
ReplyToCommand ( client , " [SM] Happy Hour is currently active. " ) ;
}
else
{
ReplyToCommand ( client , " [SM] Happy Hour is currently not active. " ) ;
}
return Plugin_Handled ;
}
public Action AdminCommand_HappyHour ( int client , int args )
{
ToggleHappyHour ( client ) ;
return Plugin_Handled ;
}
public void ToggleHappyHour ( int client )
{
g_bHappyHourAdmin = ! g_bHappyHourAdmin ;
if ( g_bHappyHour )
{
g_bHappyHour = false ;
ReplyToCommand ( client , " [SM] Deactivated Happy Hour. " ) ;
CPrintToChatAll ( " [SM] %N deactivated Happy Hour! " , client ) ;
LogAction ( client , - 1 , " \" %L \" deactivated Happy Hour. " , client ) ;
}
else
{
g_bHappyHour = true ;
ReplyToCommand ( client , " [SM] Activated Happy Hour. " ) ;
CPrintToChatAll ( " [SM] %N activated Happy Hour! " , client ) ;
LogAction ( client , - 1 , " \" %L \" activated Happy Hour. " , client ) ;
}
}
public Action MessageHappyHour ( Handle timer )
{
if ( g_bHappyHour )
2019-06-03 23:25:03 +02:00
CPrintToChatAll ( " {cyan}[UNLOZE] {red}Happy Hour {cyan}is currently active! Everyone gets 50%% Bonus on most rank points! " ) ;
2019-06-02 23:31:34 +02:00
return Plugin_Continue ;
}
public int Native_IsItHappyHour ( Handle hPlugin , int numParams )
{
if ( g_bHappyHour )
return true ;
return false ;
}