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
2019-06-04 23:08:10 +02:00
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-06 00:46:21 +02:00
version = " 1.2.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
2019-06-06 00:46:21 +02:00
ConVar cvar ;
HookConVarChange ( ( cvar = CreateConVar ( " sm_happyhour_morning_start " , " 1000 " , " starttime of happy hour in the morning (timezone UTC+1 in summer, UTC+2 in winter) " ) ) , g_cvMorningStart ) ;
2019-06-06 01:05:55 +02:00
g_iMorningStart = cvar . IntValue ;
2019-06-06 00:46:21 +02:00
HookConVarChange ( ( cvar = CreateConVar ( " sm_happyhour_morning_end " , " 1400 " , " endtime of happy hour in the morning/afternoon (timezone UTC+1 in summer, UTC+2 in winter) " ) ) , g_cvMorningEnd ) ;
2019-06-06 01:05:55 +02:00
g_iMorningEnd = cvar . IntValue ;
2019-06-06 00:46:21 +02:00
HookConVarChange ( ( cvar = CreateConVar ( " sm_happyhour_night_start " , " 2300 " , " starttime of happy hour in the night (timezone UTC+1 in summer, UTC+2 in winter) " ) ) , g_cvNightStart ) ;
2019-06-06 01:05:55 +02:00
g_iNightStart = cvar . IntValue ;
2019-06-06 00:46:21 +02:00
HookConVarChange ( ( cvar = CreateConVar ( " sm_happyhour_night_end " , " 0300 " , " endtime of happy hour in the night (timezone UTC+1 in summer, UTC+2 in winter) " ) ) , g_cvNightEnd ) ;
2019-06-06 01:05:55 +02:00
g_iNightEnd = cvar . IntValue ;
2019-06-06 00:46:21 +02:00
HookConVarChange ( ( cvar = CreateConVar ( " sm_happyhour_message_interval " , " 60.0 " , " interval for repetetive message of happy hour in chat " ) ) , g_cvMessageTimer ) ;
2019-06-06 01:05:55 +02:00
g_fMessageTimer = cvar . FloatValue ;
2019-06-06 00:46:21 +02:00
CloseHandle ( cvar ) ;
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 " ) ;
}
2019-06-06 00:46:21 +02:00
public void g_cvMorningStart ( ConVar convar , const char [ ] oldValue , const char [ ] newValue )
{
2019-06-06 01:05:55 +02:00
g_iMorningStart = convar . IntValue ;
2019-06-06 00:46:21 +02:00
}
public void g_cvMorningEnd ( ConVar convar , const char [ ] oldValue , const char [ ] newValue )
2019-06-02 23:31:34 +02:00
{
2019-06-06 01:05:55 +02:00
g_iMorningEnd = convar . IntValue ;
2019-06-06 00:46:21 +02:00
}
2019-06-04 23:08:10 +02:00
2019-06-06 00:46:21 +02:00
public void g_cvNightStart ( ConVar convar , const char [ ] oldValue , const char [ ] newValue )
{
2019-06-06 01:05:55 +02:00
g_iNightStart = convar . IntValue ;
2019-06-06 00:46:21 +02:00
}
public void g_cvNightEnd ( ConVar convar , const char [ ] oldValue , const char [ ] newValue )
{
2019-06-06 01:05:55 +02:00
g_iNightEnd = convar . IntValue ;
2019-06-02 23:31:34 +02:00
}
2019-06-06 00:46:21 +02:00
public void g_cvMessageTimer ( ConVar convar , const char [ ] oldValue , const char [ ] newValue )
2019-06-02 23:31:34 +02:00
{
2019-06-06 01:05:55 +02:00
g_fMessageTimer = convar . FloatValue ;
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 ;
}