#include <amxmodx>
#define PLUGIN "NightMode"
#define VERSION "0.1 BETA"
#define AUTHOR "amxmodx"
/* ########## -> Укажите время, для начала режима <- ########## */
#define PB_MODE_START "16:00"
/* ########## -> Укажите карту для начала режима (Требуется для загрузки кваров) <- ########## */
#define PB_MAPNAME_START "de_dust2"
/* ########## -> Укажите время, для конца режима <- ########## */
#define PB_MODE_END "22:00"
/* ########## -> Укажите карту для конца режима (Требуется для загрузки кваров) <- ########## */
#define PB_MAPNAME_END "de_dust2"
new g_ExecStartCmds[][] =
{
"amxx unpause mapchooser.amxx",
"exec server.cfg"
}
new g_ExecPauseCmds[][] =
{
"amxx pause mapchooser.amxx",
"mp_timelimit 0"
}
#define MODE_DAY 0
#define MODE_NIGHT 1
#define TIME_UNIT_LENGTH 2
#define TIMESTRING_LENGTH TIME_UNIT_LENGTH * 2 + 1
enum _:IntervalTypes
{
NIGHT_START,
NIGHT_END
}
enum _:TimeUnits
{
TIME_HOUR,
TIME_MINUTE
}
#define MINUTES_IN_DAY 1440
new giNightModeBorder[IntervalTypes], giMode, giNextChangeDelay, iLastProcessingTime
new const giTimeLimit[TimeUnits] =
{
24,
60
}
public plugin_init()
{
register_plugin( PLUGIN, VERSION, AUTHOR )
#define TIME_UNIT_DELIMITER ':'
new szNightModeIntervals[IntervalTypes][TimeUnits][TIME_UNIT_LENGTH + 1]
strtok(PB_MODE_START, szNightModeIntervals[NIGHT_START][TIME_HOUR], TIME_UNIT_LENGTH,
szNightModeIntervals[NIGHT_START][TIME_MINUTE], TIME_UNIT_LENGTH, TIME_UNIT_DELIMITER)
strtok(PB_MODE_END, szNightModeIntervals[NIGHT_END][TIME_HOUR], TIME_UNIT_LENGTH,
szNightModeIntervals[NIGHT_END][TIME_MINUTE], TIME_UNIT_LENGTH, TIME_UNIT_DELIMITER)
for( new i = 0; i < IntervalTypes; i++ )
{
giNightModeBorder = ( str_to_num( szNightModeIntervals[TIME_HOUR] ) % giTimeLimit[TIME_HOUR] )
* giTimeLimit[TIME_MINUTE] + str_to_num( szNightModeIntervals[TIME_MINUTE] ) % giTimeLimit[TIME_MINUTE]
}
new iHours, iMinutes
time( iHours, iMinutes )
iLastProcessingTime = iHours * giTimeLimit[TIME_MINUTE] + iMinutes
new iDelay[IntervalTypes]
iDelay[NIGHT_START] = GetModeChangeDelay(iLastProcessingTime, giNightModeBorder[NIGHT_START])
iDelay[NIGHT_END] = GetModeChangeDelay(iLastProcessingTime, giNightModeBorder[NIGHT_END])
if( iDelay[NIGHT_START] < iDelay[NIGHT_END] )
{
giMode = MODE_DAY
}
else giMode = MODE_NIGHT
giNextChangeDelay = iDelay[giMode]
ProcessCurrentMode()
}
GetModeChangeDelay( currenttime, nexttime )
{
giNextChangeDelay = nexttime - currenttime
if( giNextChangeDelay < 0 )
{
giNextChangeDelay += MINUTES_IN_DAY
}
return giNextChangeDelay
}
ProcessCurrentMode()
{
switch( giMode )
{
case MODE_DAY :
{
for(new i; i < sizeof g_ExecStartCmds; i++)
{
server_cmd("%s", g_ExecStartCmds);
server_cmd("changelevel %s", PB_MAPNAME_START);
}
}
case MODE_NIGHT :
{
for(new i; i < sizeof g_ExecPauseCmds; i++)
{
server_cmd("%s", g_ExecPauseCmds);
server_cmd("changelevel %s", PB_MAPNAME_END);
}
}
}
}