/*============================================================================================
------------------------------------------
-*- [Immersive] Concentrate on votemap -*-
------------------------------------------
Суть плагина - убрать всё лишнее во время выбора карт. Не важно - HUD это, или
какой-то плагинишко, нужно заткнуть их всех.
==============================================================================================
================================= Конфигурация плагина =====================================*/
#define DEBUG false // Включить отладку
#define IGNORE_MASK true // Переключить режим паузы (true - поставятся все, кроме тех, что в перечне и наоборот)
// Если IGNORE_MASK == true, то это плагины, которые будут проигнорированы при установке паузы
// Если IGNORE_MASK == false, то только эти плагины будут поставлены на паузу
new const SEARCH_MASK[][64] =
{
"map_manager_"
};
// Какие элементы HUD будем прярятать
// (см. https://wiki.alliedmods.net/Half-Life_1_Game_Events#HideWeapon)
new g_iHudFlags = (1<<0) | (1<<1) | (1<<3) | (1<<4) | (1<<5) | (1<<6);
/*==========================================================================================*/
#include <amxmodx>
#include <cellarray>
#include <map_manager_consts>
#define PLUG_OBJNAME "FocusOnVotemap"
#define PLUG_VERSION "1.2.1"
#define PLUG_CREATOR "Boec[SpecOPs]"
/*=================================== Блок переменных ======================================*/
new g_iPluginId;
new Array:g_aAlredyPaused;
new g_msgHideWeapon;
new g_bBlockHud;
/*================== первичная инициализация и завершение работы плагина ===================*/
public plugin_init()
{
g_iPluginId = register_plugin(PLUG_OBJNAME, PLUG_VERSION, PLUG_CREATOR);
g_msgHideWeapon = get_user_msgid("HideWeapon");
register_event("ResetHUD", "onResetHUD", "ab");
register_message(g_msgHideWeapon, "msgHideWeapon");
#if DEBUG
register_clcmd("say /focus_test", "clcmd_focus_test");
#endif
}
/*================================== События плагина =======================================*/
#if DEBUG
public clcmd_focus_test(id)
{
static switcher = false;
(!switcher) ? mapm_prepare_votelist(0) : mapm_vote_finished("", 0, 0);
switcher = !switcher;
}
#endif
public onResetHUD(id)
{
if(!g_bBlockHud) {
return;
}
switch_hud(id, false);
}
public msgHideWeapon()
{
if(!g_bBlockHud) {
return;
}
if(g_iHudFlags)
set_msg_arg_int(1, ARG_BYTE, get_msg_arg_int(1) | g_iHudFlags);
}
// Начало голосования
public mapm_prepare_votelist(type)
{
if(type == VOTE_BY_SCHEDULER_SECOND) return;
g_bBlockHud = true;
FREEZE_ALL();
switch_hud(0, false);
clear_screen();
}
// Окончание голосования
public mapm_vote_finished(const map[], type, total_votes)
{
g_bBlockHud = false;
UNFREEZE_ALL();
switch_hud(0, true);
clear_screen();
}
/*================================== Функции очистки =======================================*/
clear_screen()
{
for (new iDHUD = 0; iDHUD < 8; iDHUD++) {
send_dhudmessage(0);
}
for (new iHUD = 0; iHUD < 4; iHUD++) {
set_hudmessage(0, 0, 0, -1.0, -1.0, 0, 0.0, 0.0, 0.0, 0.0, iHUD);
show_hudmessage(0 , "");
}
for(new i = 1; i < 7; i++) {
client_print(0, print_chat, " ");
}
client_print(0, print_center, " ");
show_menu(0, 0, "^n", 1);
}
FREEZE_ALL()
{
new plugins = get_pluginsnum();
g_aAlredyPaused = ArrayCreate(plugins);
for(new i=0, fname[256], status[10]; i < plugins; i++) {
if(i == g_iPluginId) {
continue;
}
get_plugin(i, .filename=fname, .len1=charsmax(fname), .status=status, .len5=charsmax(status));
if(find_by_mask(fname)) {
continue;
}
if(contain(status, "paused") != -1) {
ArrayPushCell(g_aAlredyPaused, i);
continue;
}
pause_plugin(fname);
}
}
UNFREEZE_ALL()
{
new plugins = get_pluginsnum();
for(new i=0, fname[256], status[10]; i < plugins; i++) {
if(i == g_iPluginId) {
continue;
}
get_plugin(i, .filename=fname, .len1=charsmax(fname), .status=status, .len5=charsmax(status));
if(find_by_mask(fname)) {
continue;
}
if(ArrayFindValue(g_aAlredyPaused, i) != -1) {
continue;
}
pause_plugin(fname, false);
}
ArrayDestroy(g_aAlredyPaused);
}
public switch_hud(id, enable)
{
message_begin((id) ? MSG_ONE : MSG_ALL, g_msgHideWeapon, _, id);
write_byte((enable) ? 0 : g_iHudFlags);
message_end();
}
/*============================= Вспомогательные функции ====================================*/
stock find_by_mask(const fname[])
{
for(new j=0, found; j<sizeof(SEARCH_MASK); j++) {
found = (contain(fname, SEARCH_MASK[j]) == 0);
if(found) {
return IGNORE_MASK;
}
}
return !IGNORE_MASK;
}
stock pause_plugin(const name[], _pause=true)
{
if(_pause) {
pause("ac", name);
} else {
unpause("ac", name);
}
}
stock send_dhudmessage( const index )
{
message_begin( ( index ? MSG_ONE_UNRELIABLE : MSG_BROADCAST ), SVC_DIRECTOR, _, index );
{
write_byte( 31 );
write_byte( DRC_CMD_MESSAGE );
write_byte( 1 );
write_long( 0 );
write_long( -1 );
write_long( -1 );
write_long( 0 );
write_long( 0 );
write_long( 0 );
write_long( 0 );
write_string( "" );
}
message_end();
}
#if AMXX_VERSION_NUM < 183
ArrayFindValue(Array:which, item)
{
new size=ArraySize(which);
for(new i=0; i<size; i++) {
if(item == ArrayGetCell(which, i)) {
return i;
}
}
return -1;
}
#endif