#include <amxmodx>
#tryinclude <reapi>
#if !defined MAX_CLIENTS
const MAX_CLIENTS = 32
#endif
#if !defined MAX_NAME_LENGTH
const MAX_NAME_LENGTH = 32
#endif
#if !defined MAX_USER_INFO_LENGTH
const MAX_USER_INFO_LENGTH = 256
#endif
#if AMXX_VERSION_NUM < 183
new MaxClients
#include <colorchat>
#define engine_changelevel(%0) server_cmd("changelevel %s", %0)
#endif
#define START 21 /* Начало ночного режима. */
#define END 06 /* Конец ночного режима. */
#define AUTORR 10 /* Авто-рестарт карты (sv_restart 1) каждые n раундов. Установите 0 для отключения. */
#define AUTO_SWAP_TEAMS /* Автоматическая смена сторон. (Только если AUTORR > 0) */
//#define STEAM_VIP /* Выдавать флаги только стим игрокам. */
new const FLAGS[2][] =
{
"t", "fj" /* 1) Выдаваемые флаги. 2) Какие флаги забираем на время ночного режима. */
}
new const SET_MAP[2][] =
{
"de_dust2", "de_inferno" /* 1) Карта ночного режима. 2) Карта которая будет после ночного режима. */
}
#define BLOCK_COMMANDS /* Блок команд чата или консоли в ночном режиме. */
#if defined BLOCK_COMMANDS
new const block_commands[][] =
{
"say rtv", "say_team rtv",
"say /rtv", "say_team rtv", "amx_rtv"
}
#endif
//#define STOP_PLUGS /* Ставим плагины на паузу во время ночного режима. */
#if defined STOP_PLUGS
new g_arPlugins[][] =
{
"aknife.amxx"
}
#endif
#define NIGHT_MODE_INFORMER /* Информер ночного режима. */
#if defined NIGHT_MODE_INFORMER
new const HUD_COLOR[3] = {0, 100, 0} /* Цвет сообщения в формате R, G, B */
new const Float:HUD_POSITION[2] = {-1.0, 0.0} /* Позиция сообщения по оси X, Y */
#endif
#if !defined _reapi_included
#if defined AUTO_SWAP_TEAMS
#include <fakemeta>
const PDATA_SAFE = 2
const OFFSET_LINUX = 5
#if cellbits == 32
const OFFSET_TEAMS = 114
#else
const OFFSET_TEAMS = 139
#endif
#endif
#endif
#if AUTORR > 0
new g_iRound
#endif
new FW_START, FW_END, FW_Result, szCurMap[MAX_NAME_LENGTH],
CurHour, bool:g_bNight, g_pTimeLimit, g_iOldTime, Float:g_flResetTime
public plugin_init()
{
#if AMXX_VERSION_NUM < 183
MaxClients = get_maxplayers()
#endif
#if defined BLOCK_COMMANDS
for (new i = 0; i < sizeof(block_commands); i ++)
register_clcmd(block_commands[i], "BlockHook")
#endif
#if defined NIGHT_MODE_INFORMER
set_task(1.0, "night_informer", _, _, _, "b")
#endif
g_pTimeLimit = get_cvar_pointer("mp_timelimit")
register_event("HLTV", "EventStartRound", "a", "1=0", "2=0")
register_event("TextMsg", "EventRestartRound", "a", "2=#Game_Commencing", "2=#Game_will_restart_in")
FW_START = CreateMultiForward("night_mode_start_event", ET_CONTINUE)
FW_END = CreateMultiForward("night_mode_end_event", ET_CONTINUE)
register_plugin("Lite Night Mode", "1.0", "neugomon ?")
}
public client_putinserver(id)
{
if (!g_bNight)
return PLUGIN_CONTINUE
if ((get_user_flags(id) & read_flags(FLAGS[0])) == read_flags(FLAGS[0]))
return PLUGIN_CONTINUE
remove_user_flags(id, read_flags(FLAGS[1]))
#if defined STEAM_VIP
if (!is_user_steam(id))
return PLUGIN_CONTINUE
#endif
set_user_flags(id, read_flags(FLAGS[0]))
return PLUGIN_CONTINUE
}
public plugin_end()
{
if (g_iOldTime)
set_pcvar_num(g_pTimeLimit, g_iOldTime)
}
public EventStartRound()
{
time(CurHour)
#if START > END
if (CurHour >= START || CurHour < END)
#else
if (START <= CurHour < END)
#endif
{
if (!szCurMap[0])
get_mapname(szCurMap, charsmax(szCurMap))
if (!equal(szCurMap, SET_MAP[0]))
engine_changelevel(SET_MAP[0])
else if (!g_bNight)
{
g_bNight = true
ExecuteForward(FW_START, FW_Result)
#if defined STOP_PLUGS
PluginController(1)
#endif
RemovePlayersFlags()
g_iOldTime = get_pcvar_num(g_pTimeLimit)
set_pcvar_num(g_pTimeLimit, 0)
}
#if AUTORR > 0
static iRound
iRound = AUTORR - ++ g_iRound + 1
if (iRound > 0)
client_print_color(0, print_team_default, "^1[^4Night Mode^1] Через ^3%d раундов ^1авто-рестарт карты. ^1[^4Тек. раунд: ^3%d^1|^4Всего: ^3%d^1]", iRound, g_iRound, AUTORR)
else
{
#if defined AUTO_SWAP_TEAMS
#if !defined _reapi_included
SwapTeams()
#else
rg_swap_all_players()
#endif
#endif
server_cmd("sv_restart 1")
}
#endif
}
else if (g_bNight)
{
set_pcvar_num(g_pTimeLimit, floatround(get_gametime() - g_flResetTime) / 60 +5)
g_bNight = false
ExecuteForward(FW_END, FW_Result)
#if defined STOP_PLUGS
PluginController(0)
#endif
engine_changelevel(SET_MAP[1])
}
}
public EventRestartRound()
{
#if AUTORR > 0
g_iRound = 0
#endif
g_flResetTime = get_gametime()
}
RemovePlayersFlags()
{
static players[MAX_CLIENTS], pcount
get_players(players, pcount, "ch")
for (new i; i < pcount; i ++)
{
client_putinserver(players[i])
remove_user_flags(players[i], read_flags(FLAGS[1]))
}
}
#if defined STOP_PLUGS
PluginController(stop)
{
for (new i; i < sizeof g_arPlugins; i ++)
{
if (stop) pause ("ac", g_arPlugins[i])
else unpause ("ac", g_arPlugins[i])
}
}
#endif
#if defined BLOCK_COMMANDS
public BlockHook(id)
{
if (!g_bNight) return PLUGIN_CONTINUE
client_print_color(id, print_team_default, "^1[^4Night Mode^1] данная ^4команда отключена ^1в ночном режиме.")
return PLUGIN_HANDLED
}
#endif
#if defined NIGHT_MODE_INFORMER
public night_informer()
{
if (!g_bNight)
return PLUGIN_CONTINUE
static id, SyncHudMsg
static buffer[192], len
if (!SyncHudMsg)
SyncHudMsg = CreateHudSyncObj()
trim(buffer)
for (id = 1; id <= MaxClients; id ++)
{
if (!is_user_connected(id))
return PLUGIN_CONTINUE
ClearSyncHud(id, SyncHudMsg)
len += format(buffer, charsmax(buffer), "[Ночной режим]^n[с %d часов до %d часов утра]^n", START, END)
set_hudmessage(HUD_COLOR[0], HUD_COLOR[1], HUD_COLOR[2], HUD_POSITION[0], HUD_POSITION[1], 0, 0.0, 1.0, _, _, -1)
ShowSyncHudMsg(id, SyncHudMsg, "%s", buffer)
}
return PLUGIN_HANDLED
}
#endif
#if !defined _reapi_included
#if defined AUTO_SWAP_TEAMS
public SwapTeams()
{
new players[MAX_CLIENTS], pnum
get_players(players, pnum, "h")
for (new i; i < pnum; i ++)
{
if (is_user_connected(players[i]))
{
switch(fm_get_user_team(players[i]))
{
case 1: fm_set_user_team(players[i], 2)
case 2: fm_set_user_team(players[i], 1)
}
}
}
}
stock fm_get_user_team(index)
return get_pdata_int(index, OFFSET_TEAMS, OFFSET_LINUX)
stock fm_set_user_team(index, team)
{
if (!(1 <= index <= MaxClients) || pev_valid(index) != PDATA_SAFE)
return 0
if (fm_get_user_team(index) != team)
{
set_pdata_int(index, OFFSET_TEAMS, team, OFFSET_LINUX)
dllfunc(DLLFunc_ClientUserInfoChanged, index, engfunc(EngFunc_GetInfoKeyBuffer, index))
}
return 1
}
#endif
#if defined STEAM_VIP
stock bool:is_user_steam(id)
{
server_cmd("dp_clientinfo %d", id); server_exec()
return get_pcvar_num(get_cvar_pointer("dp_r_id_provider")) == 2 ? true : false
}
#endif
#endif