/*================================================================================
* ======== ОПИСАНИЕ ========
*
*			[SM]
*		  SurvivorMod
* Выживающий Режим для Deathrun мода
*
* == КОМАНДЫ ДЛЯ АДМИНА ==
*
*	- Запустить Режим в чате /survmod
*	- Запустить Режим в консоле deathrun_survivor
*
* ===== ПЕРЕМЕННЫЕ ======
*
*
* sm_mod <0/1> [По умолчанию: 1]
* 	- Выживающий Мод
*	- 0 Выключен
*	- 1 Включен
*
* sm_zombhp <хп> [По умолчанию: 10000]
*	- Кол. Здоровья у выживающего
*	- 0 Стандарт 100 хп
*
* sm_zombhp <хп> [По умолчанию: 1500]
*	- Кол. Здоровья у зомби
*	- 0 Стандарт 100 хп
*
* sm_nvgsize <%> [По умолчанию: 80]
*	- Дальность Ночного Видения
*	- 0 Выключена
*
* sm_nvgcolor_R <%> [По умолчанию: 255]
*	- Настройка Красных каналов в RGB
*	- 0 Выключена
*
* sm_nvgcolor_G <%> [По умолчанию: 255]
*	- Настройка Зеленых каналов в RGB
*	- 0 Выключена
*
* sm_nvgcolor_B <%> [По умолчанию: 255]
*	- Настройка Синих каналов в RGB
*	- 0 Выключена
*
* sm_nvg_zombie <0/1> [По умолчанию: 1]
* 	- Управление ночного видения [Цветами | Радиусами]
*	- 0 Выключен
*	- 1 Включен
*
* sm_pistols <0/1> [По умолчанию: 1]
*	- Давать ли пистолеты Выжившему
*	- 0 Выключен
*	- 1 Включен
*
* sm_knock_power <power> [По умолчанию: 5]
*	- Сила Отталкивание у Выживающего [knife]
*	- 0 Выключен
*
* sm_knockback <0/1> [По умолчанию: 1]
*	- Отталкивание у Выживающего [knife]
*	- 0 Выключен
*	- 1 Включен
*
* sm_music <0/1> [По умолчанию: 1]
*	- Музыка во время режима
*	- 0 Выключен
*	- 1 Включен
*
* sm_effects <1/2/3/4/5/6/7> [По умолчанию: 7]
* 	- Эффекты при Возрождении
*	- 1 Только Мясо
*	- 2 Только Тряска Экрана
*	- 3 Только Затемнение
*	- 4 Только Мясо и Тряска Экрана
*	- 5 Только Мясо и Затемнение
*	- 6 Только Тряска Экрана и Затемнение
*	- 7 Все - Тряска Экрана, Затемнение и Мясо
*
* sm_modwait <секунды> [По умолчанию: 10 ] 	=	 мин>1 секунда | макс> 20 секунд
* 	- Ожидание перед запуском режима
*
* sm_ctmin <кол.> [По умолчанию: 4]
*	- Сколько должно быть СТ игроков, чтобы начать режим		= набирается 4 КТ Игрока и тогда режим можно запустить.
*	- 0 Выключен
*
* sm_tmin <кол.> [По умолчанию: 0]
*	- Сколько должно быть Т игроков, чтобы начать режим			= если стоит значение 0, то набирается 1 Т и можно запускать.
*	- 0 Выключен
*
* === ИСТОРИЯ ИЗМЕНЕНИЙ ===
*
* 1.8:
*	- Фиксы ошибок
*	- Добавлено ограничение игроков
*	- Добавлен Отсчет Таймер
*	- Добавлен Выбор Оружий у Выжившего
*	- Упрощен Код
*
* 1.7:
*	- Фиксы ошибок
*	- Поправлены некоторые баги
*	- Добавлен KnockBack
*	- Добавлен Победные Звуки
*	- Добавлен сообщение при старте
*	- Добавлен сообщение о победе
*
* 1.6:
*	- Поправлены некоторые баги
*
* 1.5:
*	- Поправлены некоторые баги
*	- Добавлен Hud ХП Зомби
*	- Оптимизация кода
*
* 1.4:
*	- Добавлен Hud ХП Выживающего
*	- Фиксы ошибок
*	- Упрощен Код
*
* 1.3:
*	- Фиксы ошибок
*	- Добавлены Модели Claw
*	- Добавлено Функциональность Ночного Видения
*
* 1.2:
*	- Фиксы ошибок
*	- Добавлены эффекты
*	- Исправлен HUD отображение с HP
* 1.1:
*	- Фиксы ошибок
*	- Добавлен Cfg файл
*	- Добавлен Ограничение в раундах
*
* 1.0:
*	- Первый частный релиз для [Sib-City] 94.180.116.148:27027
*
* =================================================================================*/
/*================================================================================
	Подключенные Инклюды
=================================================================================*/
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <fakemeta>
#include <hamsandwich>
#include <fakemeta_util>
#include <fun>
#include <engine>

/*================================================================================
	Данные о плагине !
=================================================================================*/
#define	PLUGIN		"[Deathrun] Survivor Mod"
#define	VERSION		"1.8"
#define	AUTHOR		"s1lent"
#define	PREFIX		"!g[Sib-City]!y"

/*================================================================================
	Допуск к запуску режима по флагам:
=================================================================================*/
#define	CMD_ACCESS	ADMIN_KICK

/*================================================================================
	Различные данные !
=================================================================================*/
#define	TIMERSTOP 100504
#define	SCOUNT 20

#define	OFFSET_CLIPAMMO	51
#define	OFFSET_LINUX_WEAPONS	4
#define	fm_cs_set_weapon_ammo(%1,%2)	set_pdata_int(%1, OFFSET_CLIPAMMO, %2, OFFSET_LINUX_WEAPONS)
#define	m_pActiveItem	373
#define	ZMCOUNT		5

#define	TASK_NVISION 100 
#define	ID_NVISION (taskid - TASK_NVISION) 

/*================================================================================
	Константы !
=================================================================================*/
const NOCLIP_WPN_BS	=	( ( 1<<CSW_HEGRENADE ) | ( 1<<CSW_SMOKEGRENADE ) | ( 1<<CSW_FLASHBANG ) | ( 1<<CSW_KNIFE ) | ( 1<<CSW_C4 ) )
const UNIT_SECOND = (1<<12)
const FFADE_IN = 0x0000

new const gPknifeDefault[] 	= 	"models/p_knife.mdl"
new const gVknifeDefault[] 	= 	"models/v_knife.mdl"
new const gClawZombie[ ]	=	"models/SM/v_zombclaw.mdl"
new const gSurvModel[ ]	=	"models/player/sas/sas.mdl"
new const gZombieModel[ ]	=	"models/player/zombie_source/zombie_source.mdl"

new i
new sm
new Count
new Timer
new TalkChat
new Auralight
new Maxplayers
new CountRound

new SmsgScreenShake
new SmsgScreenFade
new SmsgNVGToggle

new Players[ 32 ]
new g_iMaxPlayers;
new g_NvgEnabled[33] 

new ChannelHud_1
new ChannelHud_2
new ChannelHud_3
new ChannelHud_4

new Pcvar_Mod
new Pcvar_Nvg
new Pcvar_Wait
new Pcvar_MinT
new Pcvar_Music
new Pcvar_MinCT
new Pcvar_Effects
new Pcvar_HpZomb
new Pcvar_MaxRound
new Pcvar_KnockBack
new Pcvar_GivePistols
new Pcvar_Power_Knock
new Pcvar_HpSurvivor
new Pcvar_ZombNvgColor[3]
new Pcvar_SizeNVG

new bool:Sm_Mod
new bool:Sm_NotDrop
new bool:Sm_ZombieHp
new bool:Sm_Knockback
new bool:Sm_SurvivorHp
new bool:Sm_UseButtons
new bool:Sm_TouchWeapon
new bool:Sm_ClipAmmoSurvivor

new Sound[SCOUNT][] =
{
	"vox/one",
	"vox/two",
	"vox/three",
	"vox/four",
	"vox/five",
	"vox/six",
	"vox/seven",
	"vox/eight",
	"vox/nine",
	"vox/ten",
	"vox/eleven",
	"vox/twelve",
	"vox/thirteen",
	"vox/fourteen",
	"vox/fifteen",
	"vox/sixteen",
	"vox/seventeen",
	"vox/eighteen",
	"vox/nineteen",
	"vox/twenty"
}
new Sm_Music[ZMCOUNT][] = 
{
	"media/Half-Life04.mp3",
	"media/Half-Life07.mp3",
	"media/Half-Life10.mp3",
	"media/Half-Life16.mp3",
	"media/Half-Life14.mp3"
}

new const Sm_ClipAmmo[ ] = 
{
	0, 
	13, 
	0, 
	10, 
	0, 
	7, 
	0, 
	30, 
	30, 
	0, 
	15, 
	20, 
	25, 
	30, 
	35, 
	25, 
	12, 
	20, 
	10, 
	30, 
	100, 
	8, 
	30, 
	30, 
	20, 
	0, 
	7, 
	30, 
	30, 
	0, 
	50
}
/*================================================================================
	База данных Плагина
=================================================================================*/
public plugin_init( )
{
		RegisterHam(Ham_Touch, "weaponbox", "NotTouch")
		RegisterHam(Ham_Touch, "armoury_entity", "NotTouch")
		RegisterHam(Ham_Touch, "weapon_shield", "NotTouch")
		RegisterHam(Ham_Spawn, "player", "FwdHamPlayerSpawn", 1)

		register_clcmd("drop", "clcmd_drop")

		RegisterHam(Ham_Use, "func_button", "key");


		register_plugin(PLUGIN, VERSION, AUTHOR)
		register_clcmd( "say /survmod", "IdentityLogin", CMD_ACCESS );
		register_concmd( "deathrun_survivor", "IdentityLogin", CMD_ACCESS );
		register_clcmd("nightvision", "NvgToogle") 

		register_logevent( "RoundEnd", 2, "1=Round_End" )
		register_event( "HLTV", "RoundStart", "a", "1=0", "2=0" )


		register_event( "Damage" , "DamageEvent" , "b" , "2>0" );
		register_event( "CurWeapon", "HookCurWeapon", "be", "1=1" )

		register_event( "SendAudio", "Sound_SurvWin", "a", "2&%!MRAD_terwin" )
		register_event( "SendAudio", "Sound_ZombWin", "a", "2&%!MRAD_ctwin" )  

		register_message(SmsgScreenFade, "message_screenfade")
		register_message(get_user_msgid("Health"), "message_health")

		TalkChat					=	get_user_msgid("SayText")
		SmsgNVGToggle			= 	get_user_msgid("NVGToggle") 
		SmsgScreenFade			= 	get_user_msgid("ScreenFade")
    		SmsgScreenShake			= 	get_user_msgid("ScreenShake");

		ChannelHud_1 			= 	CreateHudSyncObj( )
		ChannelHud_2 			= 	CreateHudSyncObj( )
		ChannelHud_3 			= 	CreateHudSyncObj( )
		ChannelHud_4 			= 	CreateHudSyncObj( )

		Pcvar_KnockBack 			= 	register_cvar( "sm_knockback" , "1" );
		Pcvar_Power_Knock 		= 	register_cvar( "sm_knock_power" , "5" );

		Pcvar_Mod				=	register_cvar("sm_mod", "1")
		Pcvar_Wait 				= 	register_cvar("sm_modwait", "10")
		Pcvar_Nvg 				= 	register_cvar("sm_nvg_zombie", "1")
		Pcvar_MinT 				= 	register_cvar("sm_tmin", "0")
		Pcvar_MinCT 				= 	register_cvar("sm_ctmin", "4")
		Pcvar_Music				=	register_cvar("sm_music", "1")
		Pcvar_Effects 			= 	register_cvar("sm_effects", "7")
		Pcvar_HpZomb			=	register_cvar("sm_zombhp", "1500")
		Pcvar_SizeNVG 			= 	register_cvar("sm_nvgsize", "80")
		Pcvar_MaxRound			=	register_cvar( "sm_maxround" , "5" );
		Pcvar_GivePistols			=	register_cvar("sm_pistols", "1")
		Pcvar_HpSurvivor			=	register_cvar("sm_survhp", "10000")
		Pcvar_ZombNvgColor[0] 	= 	register_cvar("sm_nvgcolor_R", "255")
		Pcvar_ZombNvgColor[1] 	= 	register_cvar("sm_nvgcolor_G", "255")
		Pcvar_ZombNvgColor[2] 	= 	register_cvar("sm_nvgcolor_B", "255")

		Maxplayers = get_maxplayers( )
		g_iMaxPlayers = get_maxplayers( );

		set_task( 1.0, "ShowHpSurv", 0, _, _, "b" )
		set_task( 0.5, "ShowHpZomb", 0, _, _, "b" )

		register_dictionary("deathrun_survivor.txt")
}
/*================================================================================
	Закачиваем файлы [ Модели | Звуки ]
=================================================================================*/
public plugin_precache( )
{
	precache_sound("SM/sm_survround.wav")
	precache_sound("SM/sm_survround_2.wav")

	precache_sound("SM/sm_survwin.wav")
	precache_sound("SM/sm_survwin_2.wav")

	precache_sound("SM/sm_zombiewin.wav")
	precache_sound("SM/sm_zombiewin_2.wav")

	precache_model(gZombieModel)
	precache_model(gSurvModel)
	precache_model(gClawZombie)
}
/*================================================================================
	Создаем и проверяем конфиг !
=================================================================================*/
public plugin_cfg()
{
	new CfgDir[ 32 ], Data[ 192 ];

	get_configsdir( CfgDir, charsmax( CfgDir ) );
	formatex( Data, charsmax( Data ), "%s/SM_Deathrun.cfg", CfgDir );

	if( !file_exists( Data ) )
	{
		server_print( "Конфиг %s не существует !", Data );
		write_file( Data, " ", -1 );
	}
		else
	{		
		server_print( "Конфиг %s успешно загружен !", Data );
		server_cmd( "exec %s", Data );
	}
}
/*================================================================================
	Проверка индетификация [ Допуск к активации Режима ]
=================================================================================*/
public IdentityLogin( id, level, cid )
{
	if(get_pcvar_num( Pcvar_Mod ))
	{
		if(Sm_Mod )
		{
			MsgColor(id, "%s %L", PREFIX, LANG_PLAYER, "SM_START_MOD")
			return PLUGIN_HANDLED
		}
		if(!cmd_access( id, level, cid, 1 ))
		{
		return PLUGIN_HANDLED
		}
		else
		{
			CheckPlayers( id ) 
		}
	}
	return PLUGIN_HANDLED
}
/*===============================================================================================
	Проверка игроков в команде ! 
=================================================================================================*/
public CheckPlayers(id)
{
	new iPlayers[ 32 ], Count;
	get_players( iPlayers, Count, "ahc" );

	if( Count <= 1 )
	{
		MsgColor(id, "%s %L", PREFIX, LANG_PLAYER, "SM_NO_PLAYERS")
		return PLUGIN_CONTINUE;
	}
	if (  get_ctsnum() < get_pcvar_num( Pcvar_MinCT )  || get_tsnum() < get_pcvar_num( Pcvar_MinT ) )
        {
		MsgColor(id, "%s %L", PREFIX, LANG_PLAYER, "SM_NOT_ENOUGH", get_pcvar_num( Pcvar_MinCT ), get_pcvar_num( Pcvar_MinT ))
                return PLUGIN_HANDLED;
        }
		if(CountRound >= get_pcvar_num(Pcvar_MaxRound))
		{
			Timer = get_pcvar_num(Pcvar_Wait)
			set_task(0.0, "ModWait", TIMERSTOP)
			CountRound = 0
		}
			else
		{
			MsgColor(id, "%s %L", PREFIX, LANG_PLAYER, "SM_MAX_ROUND", get_pcvar_num(Pcvar_MaxRound)-CountRound)
		}
		return PLUGIN_CONTINUE
}
/*================================================================================
	Запуск Таймера !
=================================================================================*/
public ModWait()
{
	set_hudmessage(204, 0, 0, -1.0, 0.25, 0, 1.0, 1.0, _, _, 1)
	ShowSyncHudMsg( 0, ChannelHud_1, "%L", LANG_PLAYER, "SM_HTIMER", Timer )

	Timer--
	client_cmd(0, "spk %s", Sound[Timer])
	if(Timer <= 0)
	{
		set_task(1.0, "ModStart")
	}
	else
	{
		set_task(1.0, "ModWait", TIMERSTOP)
	}
	return PLUGIN_CONTINUE
}
/*================================================================================
	Запуск Режима !
=================================================================================*/
public ModStart( id )
{
		new rand = random_num( 0, 1 )
		client_cmd( 0,"stopsound" )
		switch( rand )
		{
		case 0: client_cmd( 0,"spk SM/sm_survround.wav" )
		case 1: client_cmd( 0,"spk SM/sm_survround_2.wav" )
		}
		get_players( Players, Count, "ahc" )
		for( i = 0; i < Count; i++ )
		{
			sm = Players[i]
			if( is_user_connected( sm ) && is_user_alive(sm) && get_user_team( sm ) == 1 )
			{
			if(get_pcvar_num(Pcvar_Music))
			{
			new musicnum = random_num( 0, ZMCOUNT-1 )
			client_cmd(0, "mp3volume 0.5")
			client_cmd( 0, "mp3 play %s", Sm_Music[musicnum] )
			}
			set_lights( "a" )
			Sm_Mod = true
			Sm_ZombieHp = true
			Sm_SurvivorHp = true
			Sm_UseButtons = true
			Sm_TouchWeapon = true
			Sm_ClipAmmoSurvivor = true
			Sm_NotDrop = false
			Sm_Knockback = false
			LigthAura( sm )
			SetModelsSurv( sm )
			strip_user_weapons( sm )
			set_user_health( sm, get_pcvar_num(Pcvar_HpSurvivor) )
			give_item( sm, "weapon_knife" )
			server_cmd( "deathrun_lifesystem 0" )
			server_cmd( "deathrun_mode INFECTION" )
			set_user_rendering( sm, kRenderFxGlowShell, 0, 0, 255, kRenderNormal, 20 )
			set_task( 0.2, "SurvStart", sm )
			set_task( 0.2, "ChooseWeaponMenu", sm )
			}
			else
			{
			EffectStart()
			strip_user_weapons( sm )
			client_cmd(sm, "nightvision")
			cs_set_user_nvg(sm, true)
			give_item( sm, "weapon_knife" )
			SetModelsZomb( sm )
			set_pev( sm, pev_viewmodel2, gClawZombie )
			set_pev( sm, pev_weaponmodel2, "" )
			set_user_health( sm, get_pcvar_num(Pcvar_HpZomb) )
			set_user_gravity( sm, 0.6 )
			set_user_footsteps( sm, 1);
			set_user_maxspeed( sm, 350.0 )
			MsgColor( sm, "%s %L", PREFIX, LANG_PLAYER, "SPAWN_NVG_INFO" )
			}
		}
		return PLUGIN_CONTINUE
}
/*================================================================================
	Блокировка выброса оружия для обоих команд !
=================================================================================*/
public clcmd_drop(id)
{
	if (is_user_alive(id) && Sm_NotDrop)
	{
		return PLUGIN_CONTINUE 
	}
	return PLUGIN_HANDLED     
}
/*================================================================================
	Блокировка поднятие для обоих команд !
=================================================================================*/
public NotTouch( weapon, id )
{
	if ( is_user_alive( id ) && Sm_TouchWeapon )
	{
		return HAM_SUPERCEDE       
	}     
	return HAM_IGNORED     
}
/*================================================================================
	Блокировка кнопки у Выжившего !
=================================================================================*/
public key( ent, idcaller, idactivator, use_type, Float:value )
{
	if ( is_user_alive( idactivator ) && Sm_UseButtons &&  get_user_team( idactivator ) == 1 )
	{
		return HAM_SUPERCEDE       
	}     
	return HAM_IGNORED
}
/*================================================================================
	Отлов смены оружия ! [ Возращаем модель ножа Выжившему и Бесконечные патроны ]
=================================================================================*/
public HookCurWeapon( id )
{
	new iWeapon = read_data( 2 )
	if( !( NOCLIP_WPN_BS & ( 1<<iWeapon ) ) && Sm_ClipAmmoSurvivor && get_user_team( id ) == 1 )
	{
	fm_cs_set_weapon_ammo( get_pdata_cbase( id, m_pActiveItem ) , Sm_ClipAmmo[ iWeapon ] )
	}
	return PLUGIN_CONTINUE;
}
/*================================================================================
	Показываем Жизни Выжившего !
=================================================================================*/
public ShowHpSurv( )
{
	for(new i=1; i<33; i++ )
	{
		if(is_user_alive(i) && Sm_SurvivorHp && get_user_team(i) == 1)
		{
		set_hudmessage( 255, 230, 0, -1.0, 0.2, 0, 1.0, 3.0, 0.5, 0.5, 1 )
		ShowSyncHudMsg( 0, ChannelHud_1, "%L", LANG_PLAYER, "SM_HHP_SURV", get_user_health( i ) )
		}
	}
}
/*================================================================================
	Показываем себе жизни [ Зомби ] !
=================================================================================*/
public ShowHpZomb( )
{
	for(new i = 1 ; i <= Maxplayers ; i++)
	{
		if(is_user_connected( i ) && is_user_alive( i ) && Sm_ZombieHp && get_user_team( i ) == 2 )
		{
		set_hudmessage( 255, 230, 0, 0.01, 0.91, 0, 1.0, 2.0, 0.5, 0.5, 2 )
		ShowSyncHudMsg( i, ChannelHud_2, "%L", LANG_PLAYER, "SM_HHP_ZOMB", get_user_health( i ) )
		}
	}
}
/*================================================================================
	Дает Ауру Освещения !
=================================================================================*/
public LigthAura( id )
{
	Auralight = entity_get_int( id,EV_INT_effects )
	entity_set_int( id,EV_INT_effects,EF_BRIGHTLIGHT )
	return PLUGIN_HANDLED
}
/*================================================================================
	Забираем Ауру Освещения !
=================================================================================*/
public LigthAuraClear( id )
{ 
	entity_set_int( id,EV_INT_effects, Auralight )
	return PLUGIN_HANDLED
}
/*================================================================================
	Устанавливаем модель зомбям !
=================================================================================*/
public SetModelsZomb(id)
{
	new CsTeams:team
	team = cs_get_user_team(id)
	if(team == CS_TEAM_CT)
	{
	cs_set_user_model (id, "sm_zombie")
	}
	return PLUGIN_HANDLED
}
/*================================================================================
	Устанавливаем модель выживающему !
=================================================================================*/
public SetModelsSurv(id)
{
	new CsTeams:team
	team = cs_get_user_team(id)
	if(team == CS_TEAM_T)
	{
	cs_set_user_model (id,  "sas")
	}
	return PLUGIN_HANDLED
}
/*================================================================================
	Начало раунда
=================================================================================*/
public RoundStart( )
{
	if(get_pcvar_num(Pcvar_Music))
	{
		client_cmd(0, "cd fadeout")
	}
	Sm_Mod = false
	Sm_ZombieHp = false
	Sm_UseButtons = false
	Sm_SurvivorHp = false
	Sm_TouchWeapon = false
	Sm_ClipAmmoSurvivor = false
	Sm_NotDrop = true
	Sm_Knockback = true


	for(new i=1; i<33; i++ )
	{
		if( is_user_alive( i ) && get_user_team( i ) == 2 )
		{
			set_pev( i, pev_viewmodel2, gVknifeDefault )
			set_pev( sm, pev_weaponmodel2, gPknifeDefault )
		}
	}
	server_cmd( "deathrun_lifesystem 2" )
	client_cmd( 0, "cd fadeout" )

	set_lights("#OFF")

	for( new i = 1; i <= get_maxplayers(); i++ )
	{
	if(!is_user_connected( i ))
		continue;
	cs_set_user_nvg(i, false)
	set_user_footsteps( i, 0 )
	set_user_rendering( i )
	LigthAuraClear(i)
	cs_reset_user_model( i )
	}

	CountRound++
	remove_task(TIMERSTOP)
	return PLUGIN_CONTINUE
}
/*================================================================================
	Конец раунда
=================================================================================*/
public RoundEnd( )
{
	if(get_pcvar_num(Pcvar_Music))
	{
		client_cmd(0, "cd fadeout")
	}
	client_cmd( 0, "nightvision")
	Sm_ClipAmmoSurvivor = false
	Sm_Mod = false
	Sm_SurvivorHp = false
	Sm_ZombieHp = false
	Sm_Knockback = true
	remove_task(TIMERSTOP)
	return PLUGIN_CONTINUE
}
/*================================================================================
	Игрок покинул игру !
=================================================================================*/
public client_disconnect(id)
{
	LigthAuraClear( id )
	set_user_footsteps( id )
	set_user_rendering( id )
	cs_reset_user_model( id )
	if(task_exists( id ) )
	{
		remove_task(TIMERSTOP)
		remove_task(id)
	}
	return PLUGIN_CONTINUE
}
/*================================================================================
	Игрок Возродился !
=================================================================================*/
public FwdHamPlayerSpawn( id )
{
	if(is_user_connected( id ) && is_user_alive(id) && Sm_Mod && get_user_team(id) == 2 )
	{
		set_task( 1.2, "SpawnGiveZomb", id )
	}
	return PLUGIN_CONTINUE;
}
/*================================================================================
	Игрок Возродился - Надеваем шмотки и Способности
=================================================================================*/
public SpawnGiveZomb( id )
{
		EffectStartOne(id)
		strip_user_weapons( id )
		cs_set_user_nvg(id, true)
		SetModelsZomb( id )
		give_item( id, "weapon_knife" )
		set_pev( id, pev_viewmodel2, gClawZombie )
		set_pev( id, pev_weaponmodel2, "" )
		set_user_footsteps(id, 1);
		set_user_health( id, get_pcvar_num(Pcvar_HpZomb) )
		set_user_gravity( id, 0.6 )
		set_user_maxspeed( id, 350.0 )
		MsgColor(id, "%s %L", PREFIX, LANG_PLAYER, "SPAWN_NVG_INFO")
}
/*================================================================================
	Воспроизводим эффекты  = > [ Покраснение экрана, Тряска экрана и Разлетающие куски мяса ]
	Для 1 ИГРОКА!	
=================================================================================*/
public EffectStartOne(id)
{
	static origin[ 3 ]
	get_user_origin( id, origin )
	switch(get_pcvar_num(Pcvar_Effects))
	{
		case 1:
		{
			message_begin(MSG_PVS, SVC_TEMPENTITY, origin )
			write_byte( TE_PARTICLEBURST )
			write_coord( origin[ 0 ] )
			write_coord( origin[ 1 ] )
			write_coord( origin[ 2 ] )
			write_short( 50 )
			write_byte( 70 )
			write_byte( 3 )
			message_end( )
		}
		case 2:
		{
			message_begin( MSG_ONE_UNRELIABLE, SmsgScreenShake, _, id)
			write_short( UNIT_SECOND*4 )
			write_short( UNIT_SECOND*2 )
			write_short( UNIT_SECOND*10 )
			message_end( )
		}
		case 3:
		{
			message_begin( MSG_ONE_UNRELIABLE, SmsgScreenFade, _, id )
			write_short( UNIT_SECOND )
			write_short( 0 )
			write_short( FFADE_IN )
			write_byte( 189 )
			write_byte( 15 )
			write_byte( 15 )
			write_byte ( 120 )
			message_end( )
		}
		case 4:
		{

			message_begin(MSG_PVS, SVC_TEMPENTITY, origin )
			write_byte( TE_PARTICLEBURST )
			write_coord( origin[ 0 ] )
			write_coord( origin[ 1 ] )
			write_coord( origin[ 2 ] )
			write_short( 50 )
			write_byte( 70 )
			write_byte( 3 )
			message_end( )

			message_begin( MSG_ONE_UNRELIABLE, SmsgScreenShake, _, id)
			write_short( UNIT_SECOND*4 )
			write_short( UNIT_SECOND*2 )
			write_short( UNIT_SECOND*10 )
			message_end( )
		}
		case 5:
		{
			message_begin(MSG_PVS, SVC_TEMPENTITY, origin )
			write_byte( TE_PARTICLEBURST )
			write_coord( origin[ 0 ] )
			write_coord( origin[ 1 ] )
			write_coord( origin[ 2 ] )
			write_short( 50 )
			write_byte( 70 )
			write_byte( 3 )
			message_end( )

			message_begin( MSG_ONE_UNRELIABLE, SmsgScreenFade, _, id )
			write_short( UNIT_SECOND )
			write_short( 0 )
			write_short( FFADE_IN )
			write_byte( 189 )
			write_byte( 15 )
			write_byte( 15 )
			write_byte ( 120 )
			message_end( )
		}
		case 6:
		{
			message_begin( MSG_ONE_UNRELIABLE, SmsgScreenFade, _, id )
			write_short( UNIT_SECOND )
			write_short( 0 )
			write_short( FFADE_IN )
			write_byte( 189 )
			write_byte( 15 )
			write_byte( 15 )
			write_byte ( 120 )
			message_end( )

			message_begin( MSG_ONE_UNRELIABLE, SmsgScreenShake, _, id)
			write_short( UNIT_SECOND*4 )
			write_short( UNIT_SECOND*2 )
			write_short( UNIT_SECOND*10 )
			message_end( )
		}
		case 7:
		{
			message_begin(MSG_PVS, SVC_TEMPENTITY, origin )
			write_byte( TE_PARTICLEBURST )
			write_coord( origin[ 0 ] )
			write_coord( origin[ 1 ] )
			write_coord( origin[ 2 ] )
			write_short( 50 )
			write_byte( 70 )
			write_byte( 3 )
			message_end( )

			message_begin( MSG_ONE_UNRELIABLE, SmsgScreenFade, _, id )
			write_short( UNIT_SECOND )
			write_short( 0 )
			write_short( FFADE_IN )
			write_byte( 189 )
			write_byte( 15 )
			write_byte( 15 )
			write_byte ( 120 )
			message_end( )

			message_begin( MSG_ONE_UNRELIABLE, SmsgScreenShake, _, id)
			write_short( UNIT_SECOND*4 )
			write_short( UNIT_SECOND*2 )
			write_short( UNIT_SECOND*10 )
			message_end( )
		}
	}
	return PLUGIN_CONTINUE
}
/*================================================================================
	Показываем меню выжившему Список Оружий !
=================================================================================*/
public ChooseWeaponMenu( id )
{
	for(new i=1; i<33; i++ )
	{
		if( is_user_alive( i ) && get_user_team( i ) == 1 && Sm_Mod )
		{
			new WeaponMenu = menu_create( "\r[Sib-City] \yВыберите Оружие!",  "WeaponMenuCase" )
			menu_additem( WeaponMenu, "\wM249", "1" )
			menu_additem( WeaponMenu, "\wM4a1", "2" )
			menu_additem( WeaponMenu, "\wAK47", "3" )
			menu_additem( WeaponMenu, "\wMP5", "4" )
			menu_setprop( WeaponMenu, MPROP_EXIT,MEXIT_NEVER )
			menu_display( id, WeaponMenu, 0 )
		}
	}
}
/*================================================================================
	Кейсы #1 к оружию
=================================================================================*/
public WeaponMenuCase( id, menu, item )
{
	new s_Data[ 6 ], s_Name[ 64 ], i_Access, i_Callback
	menu_item_getinfo( menu, item, i_Access, s_Data, charsmax( s_Data ), s_Name, charsmax( s_Name ), i_Callback )
	new Num_Key = str_to_num( s_Data )
	switch( Num_Key )
	{
		case 1:
		{
		give_item( id, "weapon_m249" )
		ChooseGunMenu( id )
		}
		case 2:
		{
		give_item( id, "weapon_m4a1" )
		ChooseGunMenu( id )
		}
		case 3:
		{
		give_item( id, "weapon_ak47" )
		ChooseGunMenu( id )
		}
		case 4:
		{
		give_item( id, "weapon_mp5navy" )
		ChooseGunMenu( id )
		}
	}
	menu_destroy( menu )
	return PLUGIN_HANDLED
}
/*================================================================================
	Показываем меню выжившему Список Пистолетов !
=================================================================================*/
public ChooseGunMenu( id )
{
	for(new i=1; i<33; i++ )
	{
		if( is_user_alive( i ) && get_user_team( i ) == 1 && Sm_Mod && get_pcvar_num( Pcvar_GivePistols ))
		{
			new GunMenu = menu_create( "\r[Sib-City] \yВыберите Пистолеты!",  "GunMenuCase" )
			menu_additem( GunMenu, "\wDeagle", "1" )
			menu_additem( GunMenu, "\wUSP", "2" )
			menu_additem( GunMenu, "\wDual Elites", "3" )
			menu_additem( GunMenu, "\wFiveseven", "4" )
			menu_setprop( GunMenu, MPROP_EXIT,MEXIT_NEVER )
			menu_display( id, GunMenu, 0 )
		}
	}
}
/*================================================================================
	Кейсы #2 к пистолетам
=================================================================================*/
public GunMenuCase( id, menu, item )
{
	new s_Data[ 6 ], s_Name[ 64 ], i_Access, i_Callback
	menu_item_getinfo( menu, item, i_Access, s_Data, charsmax( s_Data ), s_Name, charsmax( s_Name ), i_Callback )
	new Num_Key = str_to_num( s_Data )
	switch( Num_Key )
	{
		case 1:
		{
		give_item( id, "weapon_deagle" )
		}
		case 2:
		{
		give_item( id, "weapon_usp" )
		}
		case 3:
		{
		give_item( id, "weapon_elite" )
		}
		case 4:
		{
		give_item( id, "weapon_fiveseven" )
		}
	}
	menu_destroy( menu )
	return PLUGIN_HANDLED
}
/*================================================================================
	Исправляем HUD отображение с HP, когда HP выше 255 !
=================================================================================*/
public message_health( msg_id, msg_dest, msg_entity )
{
	static health
	health = get_msg_arg_int( 1 )
	if( health < 256 ) return
	if( health % 256 == 0 )
	fm_set_user_health( msg_entity, pev( msg_entity, pev_health ) + 1 )
	set_msg_arg_int( 1, get_msg_argtype( 1 ), 255 )
}
/*================================================================================
	Отлов удар ножом у Выжившего !
=================================================================================*/
public DamageEvent( id )
{
	if( !get_pcvar_num( Pcvar_KnockBack ) || Sm_Knockback )
		return PLUGIN_CONTINUE;

	if( !is_user_alive( id ) || get_user_team( id ) == 1 )
		return PLUGIN_CONTINUE;

	new weapon, attacker = get_user_attacker( id , weapon );

	if( !is_user_alive( attacker ) )
		return PLUGIN_CONTINUE;

	if( weapon == CSW_KNIFE )
	{
		new Float:vec[ 3 ];
		new Float:oldvelo[ 3 ];
		get_user_velocity( id, oldvelo );
		create_velocity_vector( id, attacker, vec );
		vec[ 0 ] += oldvelo[ 0 ];
		vec[ 1 ] += oldvelo[ 1 ];
		set_user_velocity( id, vec );
	}
	return PLUGIN_CONTINUE;
}
/*================================================================================
	Воспроизводим музыку победы Выжившего, если Sm_Mod активирован !
=================================================================================*/
public Sound_SurvWin( )
{
	if( Sm_Mod )
	{
		new Snd_SurvWin = random_num( 0,1 )
		client_cmd( 0, "stopsound" )
		set_task( 0.7, "SurvWin", sm )
		switch( Snd_SurvWin )
		{
		case 0: client_cmd( 0,"spk SM/sm_survwin.wav" )
		case 1: client_cmd( 0,"spk SM/sm_survwin_2.wav" )
		}
	}
	return PLUGIN_CONTINUE
}
/*================================================================================
	Воспроизводим музыку победы Зомби, если Sm_Mod активирован !
=================================================================================*/
public Sound_ZombWin( )
{
	if( Sm_Mod )
	{
		new Snd_ZombWin = random_num( 0, 1 )
		client_cmd( 0, "stopsound" )
		set_task( 0.6, "ZombieWin", sm )
		switch( Snd_ZombWin )
		{
		case 0: client_cmd( 0, "spk SM/sm_zombiewin.wav" )
		case 1: client_cmd( 0, "spk SM/sm_zombiewin_2.wav" )
		}
	}
	return PLUGIN_CONTINUE
}
/*================================================================================
	Воспроизводим HUD сообщение победы Зомби, если Sound_ZombWin активирован !
=================================================================================*/
public ZombieWin( id )
{
	set_hudmessage( 189, 0, 0, 0.02, -1.0, 0, 1.0, 3.0, 0.5, 0.5, 4 )
	new Msg_ZombWin = random_num( 0, 1 )
	switch( Msg_ZombWin )
	{
	case 0: ShowSyncHudMsg( 0, ChannelHud_4, "%L", LANG_PLAYER, "SM_HWIN_ZOMB" )
	case 1: ShowSyncHudMsg( 0, ChannelHud_4, "%L", LANG_PLAYER, "SM_HWIN_ZOMB2" )
	}
}
/*================================================================================
	Воспроизводим HUD сообщение победы Выжившего, если Sound_SurvWin активирован !
=================================================================================*/
public SurvWin( id )
{
	set_hudmessage( 0, 189, 255, 0.02, -1.0, 0, 1.0, 3.0, 0.5, 0.5, 4 )
	new Msg_SurvWin = random_num( 0, 1 )
	switch( Msg_SurvWin )
	{
	case 0: ShowSyncHudMsg( 0, ChannelHud_4, "%L", LANG_PLAYER, "SM_HWIN_SURV" )
	case 1: ShowSyncHudMsg( 0, ChannelHud_4, "%L", LANG_PLAYER, "SM_HWIN_SURV2" )
	}
}
/*================================================================================
	Воспроизводим HUD сообщение появления Выжившего !
=================================================================================*/
public SurvStart( id )
{
	new name[32]
	for(new i=1; i<33; i++ )
	{
		if(is_user_alive( i ) && Sm_Mod && get_user_team( i ) == 1 )
		{
			get_user_name( i, name, 31 )
			set_hudmessage( 0, 189, 255, 0.02, -1.0, 0, 1.0, 3.0, 0.5, 0.5, 3 )
			new Msg_SurvStart = random_num( 0, 1 )
			switch( Msg_SurvStart)
			{
				case 0: ShowSyncHudMsg( 0, ChannelHud_3, "%L", LANG_PLAYER, "SM_HSTART_MOD" )
				case 1: ShowSyncHudMsg( 0, ChannelHud_3, "%L", LANG_PLAYER, "SM_HSTART_MOD2", name )
			}
		}
	}
	return PLUGIN_CONTINUE
}
/*================================================================================
	Воспроизводим эффекты  = > [ Покраснение экрана, Тряска экрана и Разлетающие куски мяса ]
=================================================================================*/
public EffectStart()
{
	for( new i = 1; i <= get_maxplayers(); i++ )
	{
		if( is_user_connected( i ) && is_user_alive( i ) && cs_get_user_team( i ) == CS_TEAM_CT )
		{
			static origin[ 3 ]
			get_user_origin( i, origin )
			switch(get_pcvar_num(Pcvar_Effects))
			{
				case 1:
				{
					message_begin(MSG_PVS, SVC_TEMPENTITY, origin )
					write_byte( TE_PARTICLEBURST )
					write_coord( origin[ 0 ] )
					write_coord( origin[ 1 ] )
					write_coord( origin[ 2 ] )
					write_short( 50 )
					write_byte( 70 )
					write_byte( 3 )
					message_end( )
				}
				case 2:
				{
					message_begin( MSG_ONE_UNRELIABLE, SmsgScreenShake, _, i )
					write_short( UNIT_SECOND*4 )
					write_short( UNIT_SECOND*2 )
					write_short( UNIT_SECOND*10 )
					message_end( )
				}
				case 3:
				{
					message_begin( MSG_ONE_UNRELIABLE, SmsgScreenFade, _, i )
					write_short( UNIT_SECOND )
					write_short( 0 )
					write_short( FFADE_IN )
					write_byte( 189 )
					write_byte( 15 )
					write_byte( 15 )
					write_byte ( 120 )
					message_end( )
				}
				case 4:
				{
					message_begin(MSG_PVS, SVC_TEMPENTITY, origin )
					write_byte( TE_PARTICLEBURST )
					write_coord( origin[ 0 ] )
					write_coord( origin[ 1 ] )
					write_coord( origin[ 2 ] )
					write_short( 50 )
					write_byte( 70 )
					write_byte( 3 )
					message_end( )

					message_begin( MSG_ONE_UNRELIABLE, SmsgScreenShake, _, i )
					write_short( UNIT_SECOND*4 )
					write_short( UNIT_SECOND*2 )
					write_short( UNIT_SECOND*10 )
					message_end( )
				}
				case 5:
				{
					message_begin(MSG_PVS, SVC_TEMPENTITY, origin )
					write_byte( TE_PARTICLEBURST )
					write_coord( origin[ 0 ] )
					write_coord( origin[ 1 ] )
					write_coord( origin[ 2 ] )
					write_short( 50 )
					write_byte( 70 )
					write_byte( 3 )
					message_end( )

					message_begin( MSG_ONE_UNRELIABLE, SmsgScreenFade, _, i )
					write_short( UNIT_SECOND )
					write_short( 0 )
					write_short( FFADE_IN )
					write_byte( 189 )
					write_byte( 15 )
					write_byte( 15 )
					write_byte ( 120 )
					message_end( )
				}
				case 6:
				{
					message_begin( MSG_ONE_UNRELIABLE, SmsgScreenFade, _, i )
					write_short( UNIT_SECOND )
					write_short( 0 )
					write_short( FFADE_IN )
					write_byte( 189 )
					write_byte( 15 )
					write_byte( 15 )
					write_byte ( 120 )
					message_end( )

					message_begin( MSG_ONE_UNRELIABLE, SmsgScreenShake, _, i )
					write_short( UNIT_SECOND*4 )
					write_short( UNIT_SECOND*2 )
					write_short( UNIT_SECOND*10 )
					message_end( )
				}
				case 7:
				{
					message_begin(MSG_PVS, SVC_TEMPENTITY, origin )
					write_byte( TE_PARTICLEBURST )
					write_coord( origin[ 0 ] )
					write_coord( origin[ 1 ] )
					write_coord( origin[ 2 ] )
					write_short( 50 )
					write_byte( 70 )
					write_byte( 3 )
					message_end( )

					message_begin( MSG_ONE_UNRELIABLE, SmsgScreenFade, _, i )
					write_short( UNIT_SECOND )
					write_short( 0 )
					write_short( FFADE_IN )
					write_byte( 189 )
					write_byte( 15 )
					write_byte( 15 )
					write_byte ( 120 )
					message_end( )

					message_begin( MSG_ONE_UNRELIABLE, SmsgScreenShake, _, i )
					write_short( UNIT_SECOND*4 )
					write_short( UNIT_SECOND*2 )
					write_short( UNIT_SECOND*10 )
					message_end( )
				}
			}
		}
	}
	return PLUGIN_CONTINUE
}
/*================================================================================
	Устанавливаем и удаляем Ночное Видение !
=================================================================================*/
public NvgToogle(id) 
{ 
	if (cs_get_user_nvg(id)) 
	{ 
		// Enable-disable 
		g_NvgEnabled[id] = !(g_NvgEnabled[id]) 
		
		// Custom nvg? 
		if (get_pcvar_num( Pcvar_Nvg )) 
		{ 
			remove_task(id+TASK_NVISION) 
			set_task(0.1, "set_user_nvision", id+TASK_NVISION, _, _, "b") 
		} 
		else 
			set_user_gnvision(id, g_NvgEnabled[id]) 
	} 
	
	return PLUGIN_HANDLED 
} 
/*================================================================================
	Устанавливаем цвета, радиус, Ночного Видения у Зомби !
=================================================================================*/
public set_user_nvision( taskid ) 
{
	if( !is_user_connected( ID_NVISION ) )
	{
		remove_task( taskid )
		return
	}
	if ( !cs_get_user_nvg( ID_NVISION ) || !g_NvgEnabled[ ID_NVISION ] ) 
	{ 
		remove_task( taskid ) 
		return; 
	} 
	static Float:originF[ 3 ]//, alive 
	pev( ID_NVISION, pev_origin, originF ) 
	//    alive = is_user_alive( ID_NVISION ) 

	message_begin( MSG_ONE_UNRELIABLE, SVC_TEMPENTITY, _, ID_NVISION ) 
	write_byte( TE_DLIGHT )
	engfunc( EngFunc_WriteCoord, originF[ 0 ] )
	engfunc( EngFunc_WriteCoord, originF[ 1 ] )
	engfunc( EngFunc_WriteCoord, originF[ 2 ] ) 
	write_byte( get_pcvar_num( Pcvar_SizeNVG ) )
	
	write_byte( get_pcvar_num( Pcvar_ZombNvgColor[ 0 ] ) ) 
	write_byte( get_pcvar_num( Pcvar_ZombNvgColor[ 1 ] ) ) 
	write_byte( get_pcvar_num( Pcvar_ZombNvgColor[ 2 ] ) )
	
	write_byte( 2 )
	write_byte( 0 )
	message_end( ) 
} 
/*================================================================================
	Проверка включения и выключения Ночного Видения !
=================================================================================*/
set_user_gnvision( id, toggle ) 
{ 
	message_begin( MSG_ONE, SmsgNVGToggle, _, id ) 
	write_byte( toggle )
	message_end( ) 
}
/*================================================================================
	Стоки...
	Создания вектора, после удара ножом Выжившего на зомби !
=================================================================================*/
stock create_velocity_vector( victim,attacker,Float:velocity[ 3 ] )
{
	if( get_user_team( victim ) == 1 || !is_user_alive( attacker ) )
		return 0;

	new Float:vicorigin[ 3 ];
	new Float:attorigin[ 3 ];
	entity_get_vector( victim, EV_VEC_origin, vicorigin );
	entity_get_vector( attacker, EV_VEC_origin, attorigin );

	new Float:origin2[ 3 ]
	origin2[ 0 ] = vicorigin[ 0 ] - attorigin[ 0 ];
	origin2[ 1 ] = vicorigin[ 1 ] - attorigin[ 1 ];

	new Float:largestnum = 0.0;

	if( floatabs( origin2[ 0 ] )>largestnum ) largestnum = floatabs( origin2[ 0 ] );
	if( floatabs( origin2[ 1 ] )>largestnum ) largestnum = floatabs( origin2[ 1 ] );

	origin2[ 0 ] /= largestnum;
	origin2[ 1 ] /= largestnum;

	velocity[ 0 ] = ( origin2[ 0 ] * ( get_pcvar_float( Pcvar_Power_Knock ) * 3000 ) ) / get_entity_distance( victim , attacker );
	velocity[ 1 ] = ( origin2[ 1 ] * ( get_pcvar_float( Pcvar_Power_Knock ) * 3000 ) ) / get_entity_distance( victim , attacker );
	if(velocity[ 0 ] <= 20.0 || velocity[ 1 ] <= 20.0 )
		velocity[ 2 ] = random_float( 200.0, 275.0 );

	return 1;
}
/*================================================================================
	Стоки...
	Кол. Спецназа
=================================================================================*/
stock get_ctsnum()
{
        new iCount;
        
        for( new i = 1; i <= g_iMaxPlayers; i++ )
        {
                if( !is_user_connected( i ) )
                        continue;
                        
                if( cs_get_user_team( i ) != CS_TEAM_CT )
                        continue;
                        
                iCount++
        }
        return iCount;
}
/*================================================================================
	Стоки...
	Кол. Террористов
=================================================================================*/
stock get_tsnum()
{
        new iCount;
        
        for( new i = 1; i <= g_iMaxPlayers; i++ )
        {
                if( !is_user_connected( i ) )
                        continue;
                        
                if( cs_get_user_team( i ) != CS_TEAM_T )
                        continue;
                        
                iCount++
        }
        return iCount;
}
/*================================================================================
	Стоки...
	Цветной чат
=================================================================================*/
stock MsgColor(const id, const input[], any:...)
{
	new count = 1, players[32]
	static msg[191]
	vformat(msg, 190, input, 3)
	replace_all(msg, 190, "!g", "^4")
	replace_all(msg, 190, "!y", "^1")
	replace_all(msg, 190, "!t", "^3")
	if (id) players[0] = id
	else get_players(players, count, "ch")
	for (new i = 0; i < count; i++)
	{
		if (is_user_connected(players[i]))
		{
			message_begin(MSG_ONE_UNRELIABLE, TalkChat, _, players[i])
			write_byte(players[i])
			write_string(msg)
			message_end()
		}
	}
	return PLUGIN_CONTINUE
}
/*================================================================================
	Copyright 2011 (c) s1lent. Special for http://noob-teams.clan.su and s1lent.
=================================================================================*/