#include <amxmodx>								   
#include <amxmisc>									
#include <cstrike>									
#include <hamsandwich>							   
#include <fakemeta>   
#include <fakemeta_util>								
#include <fun>										
#include <dhudmessage>
#include <colorchat>
#include <engine>
#include <xs>

new keys = MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|MENU_KEY_4|MENU_KEY_5|MENU_KEY_6|MENU_KEY_7|MENU_KEY_8|MENU_KEY_9|MENU_KEY_0

new const NADE_TYPE_CAMPO = 6545
new TrailColor[ 3 ] = { 000, 255, 255 }
new Float:Maxs[ 3 ] = { 100.0 , 100.0 , 100.0 }
new Float:Mins[ 3 ] = { -100.0, -100.0, -100.0 }
new g_iCurTeam[33] = { 'U' , ... }
new const model_grenade[] = "models/nova/hero/v_auragren.mdl"
new const model[] = "models/nova/hero/aura8.mdl"
new const w_model[] = "models/nova/hero/w_aura.mdl"
new const sprite_grenade_trail[] = "sprites/laserbeam.spr"
new const entclas[] = "campo_grenade_forze"
new g_trailSpr
new gBomb
const Float:Push = 4.0

#define PLUGIN "Hero_bay_NOVA"
#define VERSION "1.0"
#define AUTHOR "N.O.V.A"
 
new g_HeroID		   //ид героя
new g_HeroName[32]	//имя героя
new g_HeroAktive = 0 //состояние героя
new g_Hero_zag = 0
new g_HeroTeam = 0  //команда героя если 1 то кт, если 2 то тт
new g_hero_sposob = 0
new Float: g_hero_stop


#define PL_TASK_ID			354									  
#define PL_TASK_INFORMER	  355
#define BLAST_TASK_ID		 356
#define PL_TASK_PROVERKA	  357
#define PL_TASK_PRIZ		  358



new g_BESSMERTIE[33]

new Time = 0
new g_iCvar[10]
 
new const sprite_grenade_fire[] = "sprites/flame.spr"
new const sprite_grenade_frost[] = "sprites/csdm_frost_spell.spr"
new g_flameSpr
new g_frostSpr

native get_sentry_ct()
native get_sentry_t()
native get_sentry_team(sentry)

 
new Float:user_tim
 
public plugin_init() 
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	register_event("CurWeapon", "WeaponChange", "be", "1=1")
	register_event("DeathMsg", "onDeath", "a") 
	register_event("TeamInfo", "ev_TeamInfo" , "a" )
	
	register_dictionary("nv_hero.txt");
	
	register_clcmd("hero_play_t","hero_play_t", ADMIN_RCON) //консольная команда для выдачи героя тером
	register_clcmd("hero_play_ct","hero_play_ct", ADMIN_RCON) // выдачи героя контер-тером
	
	register_forward(FM_Touch, "fw_touch")
	register_forward(FM_SetModel, "fw_SetModel")
	
	RegisterHam(Ham_TakeDamage,"func_breakable","fw_TakeDamage2")
	RegisterHam(Ham_Think, "grenade", "fw_ThinkGrenade")
	RegisterHam(Ham_TakeDamage,"player","fw_PlayerTakeDamage")
	RegisterHam(Ham_Item_Deploy, "weapon_smokegrenade", "shield_deploy", 1)
	
	register_logevent("RoundStart", 2, "1=Round_Start")
  
	register_menu("Menu_1", keys, "func_menu") 

	g_iCvar[0] = register_cvar("nv_hero_pereves", "2")
	g_iCvar[2] = register_cvar("nv_hero_hp", "30000")
	g_iCvar[3] = register_cvar("nv_hero_min_p", "1")
	g_iCvar[4] = register_cvar("nv_hero_nag", "30000")
	g_iCvar[5] = register_cvar("nv_hero_inter", "15.0")
	g_iCvar[6] = register_cvar("nv_hero_mode", "1")

	user_tim = get_gametime() + 1.0
	register_clcmd("info_sentry","info_sentry")
}

public plugin_cfg()
{
   new configsdir[128]
   get_localinfo("amxx_configsdir", configsdir, 127)
   server_cmd("exec %s/nova/hero.cfg", configsdir)
}

new cvar_hero_model
new Model_Hero[90]

public plugin_precache() 
{
	cvar_hero_model = 0
	new iFile = fopen("addons/amxmodx/configs/nova/hero.cfg", "rt");
	if(iFile){
		new szLineBuffer[600]
		while(!(feof(iFile))){
			fgets(iFile, szLineBuffer, charsmax(szLineBuffer));
				
			if(!(szLineBuffer[0]) || szLineBuffer[0] == ';' || szLineBuffer[0] == '#') continue;
			
			new Imeil[600]
			new Model[600]
			
			parse(szLineBuffer, Imeil, charsmax(Imeil),Model, charsmax(Model));
			
			if(equal(Imeil, "nv_model_hero")){	
				new ModelPrechare[600]
				cvar_hero_model = 1
				formatex(ModelPrechare, charsmax(ModelPrechare), "models/player/%s/%s.mdl",Model ,Model);
				
				precache_model(ModelPrechare)
				formatex(Model_Hero, charsmax(Model_Hero), "%s", Model);
			}
		}
	}
	fclose(iFile)
	
	if(cvar_hero_model == 0){
		precache_model("models/player/terminator/terminator.mdl")
		formatex(Model_Hero, charsmax(Model_Hero), "terminator");
	}
	
	g_flameSpr = engfunc(EngFunc_PrecacheModel, sprite_grenade_fire)
	g_frostSpr = engfunc(EngFunc_PrecacheModel, sprite_grenade_frost)

	precache_sound( "hero/start_dest.wav" )		//старт
	precache_sound( "hero/end_dest.wav" )		//конец
	precache_sound( "hero/2_target.wav" )		//сообщение разрушителю
	
	g_trailSpr = engfunc(EngFunc_PrecacheModel, sprite_grenade_trail)
	engfunc(EngFunc_PrecacheModel, model_grenade)
	engfunc(EngFunc_PrecacheModel, model)
	engfunc(EngFunc_PrecacheModel, w_model)
}

public info_sentry(id)
{
	ColorChat(0,BLUE,"^3[^4Hero^3] кт: %d, т: %d",get_sentry_ct(), get_sentry_t())
}


public hero_aktiv()
{
	if(g_Hero_zag == 0)
	{
		Time = 5
		set_task ( 1.0, "taimer_minus", _, _, _, "a", 6)
		g_Hero_zag = 1
	}
}

public taimer_minus()
{
	if(Time > 0)
	{
		Time--
		set_dhudmessage(255, 255, 255, -1.0, -1.0, 0, 0.0, 1.0, 0.0, 0.0)
		show_dhudmessage(0, "%L",0 , "NV_HERO_PLAY", Time )
	}else{
		
		if(g_HeroTeam == 2){
			new players[32], num
			get_players(players, num, "ache", "TERRORIST")
			
			if(num){
				hero(players[random(num)])
			}
			
		}
		if(g_HeroTeam == 1){
			new players[32], num
			get_players(players, num, "ache", "CT")
			
			if(!num){
				g_HeroAktive = 0 
				ColorChat(0,BLUE,"%L", 0, "NV_HERO_ERORR1") 
				g_hero_stop = get_gametime() + get_pcvar_float(g_iCvar[5]) 
				return
			}
			
			if(num){
				hero(players[random(num)])
			}
		}
	}		
}
	


public give_grende(id){
	g_BESSMERTIE[id] = 10
	give_shield_grenade(id)
	set_user_godmode(id,1)
	engclient_cmd(id,"weapon_smokegrenade")
	new PID[1]
	PID[0] = id
	set_task (1.0, "gag_mode_minus", (PL_TASK_ID + id), PID, 1)
	
	set_dhudmessage(255, 255, 255, -1.0, 0.2, 0, 0.0, 1.0, 0.0, 0.0)
	show_dhudmessage(id, "%L",id, "NV_HERO_GAD_MODE", g_BESSMERTIE[id] )
}

public gag_mode_minus(PID[]){
	new id = PID[0]
	if(is_user_connected(id) && g_HeroTeam != fm_cs_get_user_team(id))
	{
		if(g_BESSMERTIE[id] > 0)
		{
			g_BESSMERTIE[id] = g_BESSMERTIE[id] - 1
			set_task (1.0, "gag_mode_minus", (PL_TASK_ID + id), PID, 1)
		
			set_dhudmessage(255, 255, 255, -1.0, 0.2, 0, 0.0, 1.0, 0.0, 0.0)
			show_dhudmessage(id, "%L",id, "NV_HERO_GAD_MODE", g_BESSMERTIE[id] )
		}else{
			set_user_godmode(id,0)
			
			set_dhudmessage(255, 255, 255, -1.0, 0.2, 0, 0.0, 1.0, 0.0, 0.0)
			show_dhudmessage(id, "%L",id, "NV_HERO_GAD_MODE_OFF")
		   
		}
	}
}

public RoundStart()
{
	set_lights("m")
	g_hero_sposob = 0
	g_HeroID = 0	
	g_HeroAktive = 0
	g_Hero_zag = 0
	g_HeroTeam = 0 
	remove_shield_grenade()
	remove_task( PL_TASK_PRIZ );
	remove_task( PL_TASK_PROVERKA );
	set_task ( 5.0, "hero_prowerka", PL_TASK_PROVERKA, _, _, "b")
	
	remove_entity_name(entclas)
	gBomb = 0
}

public hero_prowerka()
{
	new sentry_ct = get_sentry_ct()
	new sentry_t = get_sentry_t()
	
	if(g_HeroAktive == 1) {  

		if(g_HeroTeam == 1){
			if(sentry_ct >= sentry_t){
				set_user_health(g_HeroID,0)
				hero_kill()
			}
		}
	
		if(g_HeroTeam == 2){
			if(sentry_t >= sentry_ct){
				set_user_health(g_HeroID,0)
				hero_kill()
			}
		}
	}else if(g_hero_stop < get_gametime() && get_playersnum() > get_pcvar_num(g_iCvar[3])){
		if(sentry_ct - sentry_t >= get_pcvar_num(g_iCvar[0])){
			g_HeroTeam = 2	//регистрируем что герой дан тером
			hero_aktiv()
		}
		if(sentry_t - sentry_ct >= get_pcvar_num(g_iCvar[0])){
			g_HeroTeam = 1	//регистрируем что герой дан тером
			hero_aktiv()
		}
	}
}

public hero_play_t(id)	//выдача героя терористам
{
	if(g_HeroAktive == 0){
		g_HeroTeam = 2	//регистрируем что герой дан тером
		hero_aktiv()
		
	}
}

public hero_play_ct(id)
{
	if(g_HeroAktive == 0){
		g_HeroTeam = 1	////регистрируем что герой дан контер-тером
		hero_aktiv()
		
	}
}

public WeaponChange(id)
{
	if(id == g_HeroID && g_HeroAktive == 1){
		set_user_maxspeed(id, 400.0)
		set_user_gravity(id,0.5)
	}
}


public hero(id)		//сам герой
{
	g_HeroAktive = 1

	get_user_name(id, g_HeroName, 31)	//забиваем в массив ник
	g_HeroID = id	//получаем ид героя
	
	cs_set_user_model(id, Model_Hero)
	ColorChat(0,BLUE,"%L",0,"NV_HERO_START" )
	ColorChat(id,BLUE,"^3[^4Hero^3] ^1Вы стали героем^4!" )
	
	switch( fm_cs_get_user_team( id ) ) {
		case CS_TEAM_T: set_user_rendering( id, kRenderFxGlowShell, 255, 247, 8, kRenderNormal, 4 );
		case CS_TEAM_CT: set_user_rendering( id, kRenderFxGlowShell, 8, 247, 255, kRenderNormal, 4 );
	}

	set_task(0.1,"hero_blast", id + BLAST_TASK_ID , _, _,"b"); //Устанавливаем свечение
	set_user_health(id, get_pcvar_num(g_iCvar[2]))
	strip_user_weapons(id)
	client_cmd(id, "give_m1342")
	give_item(id,"weapon_knife")
	set_user_gravity(id,0.5)
	set_user_maxspeed(id, 400.0)
	client_cmd(id,"cl_forwardspeed 400")
	client_cmd(id,"cl_backspeed 400")
	client_cmd(id,"cl_sidespeed 400")
	set_lights("c")
	emit_sound(0,0,"hero/start_dest.wav",1.0, ATTN_NORM, 0, PITCH_NORM )		//старт героя
	informer2()
	set_task ( 1.5, "informer2", PL_TASK_INFORMER, _, _, "b" )
	set_task ( 0.4, "informer_hero", 222344)
	if(get_pcvar_num(g_iCvar[6])){
		priz_Menu(id)
		set_task(0.1,"hero_sposob",PL_TASK_PRIZ,_,_,"b")
	}
	for(new idd = 1; idd <= get_maxplayers(); idd++)	{
		if(is_user_connected(idd))
		{
			message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("ScreenShake"), _, idd)
			write_short(5<<12) // Amplitude
			write_short(5<<12) // Duration
			write_short(5<<12) // Frequency
			message_end()
		
			if(g_HeroTeam == 1){
				if(fm_cs_get_user_team(idd) == 2){
					give_grende(idd)
				}
			}

			if(g_HeroTeam == 2){
				if(fm_cs_get_user_team(idd) == 1){
					give_grende(idd)
				}
			}
		}
	}
}


public priz_Menu(id)
{
	if(g_HeroAktive == 0) return PLUGIN_HANDLED
	static menu[650], iLen
	iLen = 0
	iLen = formatex(menu[iLen],  charsmax(menu) - iLen, "%L", id, "NV_MENU_TOP");
	iLen += formatex(menu[iLen], charsmax(menu) - iLen, "%L", id, "NV_MENU_KEY_1")
	iLen += formatex(menu[iLen], charsmax(menu) - iLen, "%L", id, "NV_MENU_KEY_2")
	show_menu(id, keys, menu, -1, "Menu_1");
	return PLUGIN_HANDLED
}
public func_menu(id, key)
{
	switch(key){
		case 0: {
			if(g_HeroAktive == 0) return
			g_hero_sposob = 1
			ColorChat(0,BLUE,"%L", 0, "NV_HERO_MODE_1") 
		}
		case 1:	{
			if(g_HeroAktive == 0) return
			g_hero_sposob = 2
			ColorChat(0,BLUE,"%L", 0, "NV_HERO_MODE_2") 
		}
	}
}
 
public hero_sposob()
{
	if(g_HeroAktive == 0) return
	if(g_hero_sposob == 0){
		if(user_tim < get_gametime())
		{
			user_tim = get_gametime() + 1.0
			priz_Menu(g_HeroID)
		}
	}
	
	if(g_hero_sposob == 1){
		new ent
		while((ent = find_ent_by_class(ent,"sentry")) != 0){
			if(get_sentry_team(ent) != fm_cs_get_user_team( g_HeroID )){
				new Float:entorigin[3],origin[3]
				pev( ent, pev_origin, entorigin )
				pev( g_HeroID, pev_origin, origin )
				
				if(UTIL_IsVisible( ent, g_HeroID ) && get_distance_f(origin , entorigin )  <=  500.0)
				{
					set_anim(ent, 0)
					set_pev(ent, pev_euser3, 1)
					new Float:fAngle[3]
					entity_get_vector ( ent, EV_VEC_angles, fAngle )
					fAngle[0] = 200 * (180.0 / 3.141592654)
					entity_set_vector ( ent, EV_VEC_angles, fAngle )
					
					new Float:fOriginSentry[3]
					entity_get_vector ( ent, EV_VEC_origin, fOriginSentry )
					new start_[3]
					FVecIVec(fOriginSentry, start_)
					message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
					write_byte(TE_SPRITE)//говорим что хотим создать, в данном случае спрайт
					write_coord(start_[0])//х - координата
					write_coord(start_[1])//у - координата
					write_coord(start_[2] + 20)//z - координата
					write_short(g_frostSpr)// id спрайта
					write_byte(5) //масштаб
					write_byte(500)//яркость
					message_end()
				}else{
					set_pev(ent, pev_euser3, 0)
				}	
			}
		}
	}
	
	if(g_hero_sposob == 2)
	{
		new ent
		while((ent = find_ent_by_class(ent,"sentry")) != 0)
		{
			if(get_sentry_team(ent) != fm_cs_get_user_team( g_HeroID ))
			{
				new Float:entorigin[3],origin[3]
				pev( ent, pev_origin, entorigin )
				pev( g_HeroID, pev_origin, origin )
				
				if(UTIL_IsVisible( ent, g_HeroID ) && get_distance_f(origin , entorigin )  <=  500.0 )
				{
					ExecuteHamB(Ham_TakeDamage, ent, g_HeroID, g_HeroID, 2.0, DMG_BLAST)

					message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
					write_byte(TE_SPRITE)//говорим что хотим создать, в данном случае спрайт
					engfunc(EngFunc_WriteCoord, entorigin[0]+random_float(-5.0, 5.0)) // x
					engfunc(EngFunc_WriteCoord, entorigin[1]+random_float(-5.0, 5.0)) // y
					engfunc(EngFunc_WriteCoord, entorigin[2]+random_float(-10.0, 10.0)) // z
					write_short(g_flameSpr) // sprite
					write_byte(random_num(5, 10)) // scale
					write_byte(200) // brightness
					message_end()
				}
			}
		}
	}
}

public informer_hero()
{
	client_cmd( g_HeroID, "speak ^"hero/2_target.wav^"" );
}

public informer2()
{
	if(g_HeroAktive == 1){	
	
		if(get_user_health(g_HeroID) > 3000){
			set_dhudmessage(0, 212, 255, -1.0, 0.2, 0, 0.0, 1.5, 0.0, 0.0)
			show_dhudmessage(0, "%L", 0, "NV_HERO_INFO", g_HeroName, get_user_health(g_HeroID))		
		}else{
			set_dhudmessage(255, 212, 0, -1.0, 0.3, 0, 0.0, 1.5, 0.0, 0.0)
			show_dhudmessage(0, "%L", 0, "NV_HERO_INFO", g_HeroName, get_user_health(g_HeroID))	
		}
	}
}

public client_disconnect( id ) 
{
	gBomb &= ~( 1 << ( id % 32 ) )

	if(g_HeroAktive == 1)
	{
		if(id == g_HeroID)
		{
			ColorChat(0,BLUE,"%L", 0, "NV_HERO_OFF")
			hero_kill()
		}
	}
}

public onDeath(id)
{ 
	new iKiller = read_data(1) 
	new iVictim = read_data(2) 
	
	if(g_HeroAktive == 1)
	{
		if(iVictim == g_HeroID)
		{
			hero_kill()
			new AttackerName[32]
			get_user_name(iKiller,AttackerName,31)
			
			if(iKiller == g_HeroID)
			{
				ColorChat(0,BLUE,"%L", 0, "NV_HERO_KILLER") 
			}else{
				ColorChat(0,BLUE,"%L", 0, "NV_HERO_KILLER_ID", AttackerName, get_pcvar_num(g_iCvar[4]))
				cs_set_user_money( iKiller, cs_get_user_money( iKiller ) + get_pcvar_num(g_iCvar[4]) ); 
			}
		}
	}
  
	return PLUGIN_CONTINUE 
} 

public fw_TakeDamage2 ( ent, idinflictor, idattacker, Float:damage, damagebits)
{
	if (pev_valid(ent))
	{
		new sClassname[11]
		pev ( ent, pev_classname, sClassname, charsmax ( sClassname ) )
	
		if(g_HeroAktive == 1 && idattacker == g_HeroID){	
			if ( equal ( sClassname, "sentry" )){
				
				if(get_user_health(g_HeroID) < get_pcvar_num(g_iCvar[2])){
					set_user_health(g_HeroID,get_user_health(g_HeroID) + floatround(damage))
				}else{
					set_user_health(g_HeroID,get_pcvar_num(g_iCvar[2]))
				}
			}
		}	
	}
	return HAM_IGNORED	
}

public hero_kill()
{
	g_Hero_zag = 0
	g_hero_stop = get_gametime() + get_pcvar_float(g_iCvar[5]) 
	g_hero_sposob = 0
	g_HeroAktive = 0
	set_lights("m")
	cs_reset_user_model(g_HeroID)
	remove_shield_grenade()
	remove_task( PL_TASK_INFORMER );
	remove_task( g_HeroID + BLAST_TASK_ID );
	if(get_pcvar_num(g_iCvar[6])){
		remove_task( PL_TASK_PRIZ );
	}
	emit_sound(0,0,"hero/end_dest.wav",1.0, ATTN_NORM, 0, PITCH_NORM )	//конец
	remove_task( PL_TASK_PROVERKA );
	set_task ( 5.0, "hero_prowerka", PL_TASK_PROVERKA, _, _, "b")
	remove_entity_name(entclas)
	gBomb = 0
	new ent
	while((ent = find_ent_by_class(ent,"sentry")) != 0){
		set_pev(ent, pev_euser3, 0)
	}
}

public hero_blast(TaskID)
{  
	if (g_HeroAktive == 0 ){
		if(task_exists(TaskID))
			remove_task(TaskID)
		return;
	}
	
	new Float:fOriginHero[3];
	entity_get_vector ( g_HeroID , EV_VEC_origin, fOriginHero )
	new origin[3]
	FVecIVec(fOriginHero,origin)
	
	message_begin(MSG_BROADCAST,SVC_TEMPENTITY)
	write_byte(TE_DLIGHT)
	write_coord(origin[0])
	write_coord(origin[1])
	write_coord(origin[2])
	write_byte(floatround(130.0/7.0))
	if(g_HeroTeam == 1){
		write_byte(8)
		write_byte(247)	
		write_byte(255)
	}else if(g_HeroTeam == 2){
		write_byte(255)
		write_byte(247)	
		write_byte(8)
	}
	write_byte(1)
	write_byte(1)
	message_end()
}

stock fm_cs_get_user_team(id)
{
	if(pev_valid(id) != 2) return 0
	
	return get_pdata_int(id, 114, 5)
}

stock bool:UTIL_IsVisible( index, entity, ignoremonsters = 0 )
{
	new Float:flStart[ 3 ], Float:flDest[ 3 ];
	pev( index, pev_origin, flStart );
	pev( index, pev_view_ofs, flDest );
	xs_vec_add( flStart, flDest, flStart );
	pev( entity, pev_origin, flDest );
	engfunc( EngFunc_TraceLine, flStart, flDest, ignoremonsters, index, 0 );
	new Float:flFraction;
	get_tr2( 0, TR_flFraction, flFraction );
	
	if( flFraction == 1.0 || get_tr2( 0, TR_pHit) == entity ) return true;
	
	return false;
}

stock set_anim(ent, sequence) 
{
	set_pev(ent, pev_sequence, sequence)
	set_pev(ent, pev_animtime, halflife_time())
	set_pev(ent, pev_framerate, 3.5)
}

//щит
/*---------------------*/

public give_shield_grenade ( id )
{
	if ( !is_user_connected ( id ) || !is_user_alive ( id ) )
		return false

	if( gBomb & ( 1 << ( id % 32 ) ) )
		return false

	gBomb |= ( 1 << ( id % 32 ) )
		
	if( !user_has_weapon( id, CSW_SMOKEGRENADE ) )
		give_item(id,"weapon_smokegrenade")

	return true
}

public remove_shield_grenade()
{
	remove_entity_name(entclas)
	gBomb = 0
	return true
}

public fw_PlayerTakeDamage ( victim, inflictor, attacker, Float:damage, damagebits )
{
	return ( victim != attacker && IsInSphere ( victim ) ) ? HAM_SUPERCEDE : HAM_IGNORED
}

bool:IsInSphere ( id )
{
	if ( !is_user_alive ( id ) )
		return false

	new ent = -1 
	while ( ( ent = engfunc ( EngFunc_FindEntityByString, ent, "classname", entclas ) ) > 0 )
	{
		new iOwner = pev ( ent, pev_owner )

		if ( cs_get_user_team ( id ) != cs_get_user_team ( iOwner ) )
			continue

		new Float:fOrigin[3]
		pev ( ent, pev_origin, fOrigin )
		new iPlayer = -1
		while ( ( iPlayer = engfunc ( EngFunc_FindEntityInSphere, iPlayer, fOrigin, 68.0 ) ) != 0 )
		{
			if ( iPlayer == id )
				return true
		}
	}
	return false
}

public remowe_ent()
{
	remove_entity_name(entclas)
	gBomb = 0
}

public ev_TeamInfo ()
{
	static id; id = read_data ( 1 )
	static sTeam[2]; read_data(2, sTeam, 1 )
	
	if ( g_iCurTeam[id] != sTeam[0] )
	{
		g_iCurTeam[id] = sTeam[0]
		gBomb &= ~( 1 << ( id % 32 ) )

		new ent = -1
		while ( ( ent = engfunc ( EngFunc_FindEntityByString, ent, "classname", entclas ) ) > 0 )
			if ( pev ( ent, pev_owner ) == id )
				engfunc ( EngFunc_RemoveEntity, ent )
	}
}

public fw_ThinkGrenade(entity) {   
	
	if(!pev_valid(entity)) return HAM_IGNORED
	
	static Float:dmgtime   
	pev(entity, pev_dmgtime, dmgtime)

	new Float:current_time = get_gametime()
	
	if (dmgtime > current_time)
		return HAM_IGNORED   
	
	if(pev(entity, pev_flTimeStepSound) == NADE_TYPE_CAMPO)
	{
		if ((pev(entity, pev_flags) & FL_ONGROUND) && fm_get_speed(entity) < 10)
		{
			set_pev(entity, pev_dmgtime, current_time + 0.1)
			crear_ent(entity)
			return HAM_SUPERCEDE
		}
		else
			set_pev(entity, pev_dmgtime, current_time + 0.5)
	}
	
	return HAM_IGNORED
}

public fw_SetModel(entity, const model[]) {	
	
	static Float:dmgtime
	
	if(!pev_valid(entity)) 
		return FMRES_IGNORED;
	
	pev(entity, pev_dmgtime, dmgtime)
	
	if (dmgtime == 0.0)
		return FMRES_IGNORED;
	
	if (equal(model[7], "w_sm", 4))
	{		
		new owner = pev(entity, pev_owner)		
		
		if( is_user_alive(owner) && ( gBomb & ( 1 << ( owner % 32 ) ) ) ) 
		{	
			fm_set_rendering(entity, kRenderFxGlowShell, 000, 255, 255, kRenderNormal, 16)
			
			message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
			write_byte(TE_BEAMFOLLOW) // TE id
			write_short(entity) // entity
			write_short(g_trailSpr) // sprite
			write_byte(10) // life
			write_byte(10) // width
			write_byte(TrailColor[ 0 ]) // r
			write_byte(TrailColor[ 1 ]) // g
			write_byte(TrailColor[ 2 ]) // b
			write_byte(500) // brightness
			message_end()
			
			set_pev(entity, pev_flTimeStepSound, NADE_TYPE_CAMPO)

			gBomb &= ~( 1 << ( owner % 32 ) )
			entity_set_model(entity, w_model)
			return FMRES_SUPERCEDE
		}
	}
	return FMRES_IGNORED
}

public crear_ent(id) {	
	// Create entitity
	new iEntity = create_entity("info_target")
	
	if(!is_valid_ent(iEntity))
		return PLUGIN_HANDLED
	
	new Float: Origin[3] 
	entity_get_vector(id, EV_VEC_origin, Origin) 
	
	entity_set_string(iEntity, EV_SZ_classname, entclas)
	
	entity_set_vector(iEntity,EV_VEC_origin, Origin)
	entity_set_model(iEntity,model)
	entity_set_int(iEntity, EV_INT_solid, SOLID_TRIGGER)
	entity_set_size(iEntity, Mins, Maxs )
	entity_set_int(iEntity, EV_INT_renderfx, kRenderFxGlowShell)
	entity_set_int(iEntity, EV_INT_rendermode, kRenderTransAlpha)
	entity_set_float(iEntity, EV_FL_renderamt, 50.0)
	entity_set_edict ( iEntity, EV_ENT_owner, pev ( id, pev_owner ) )	
	
	
	if(is_valid_ent(iEntity))
	{
		new Float:vColor[3]
		
		for(new i; i < 3; i++)
			vColor[i] = random_float(0.0, 255.0)
		
		entity_set_vector(iEntity, EV_VEC_rendercolor, vColor)
	}
	
	DeleteEntity(id)

	return PLUGIN_CONTINUE;
}

new Float:user_timer[33]

public fw_touch(ent, touched)
{
	if ( !pev_valid(ent) ) return FMRES_IGNORED;
	static entclass[32];
	pev(ent, pev_model, entclass, 31);
	
	if ( strcmp( entclass, model ) == 0 )
	{	
		new iOwner = pev ( ent, pev_owner )

		if ( !is_user_connected ( iOwner ) || !is_user_alive ( touched ) )
			return FMRES_IGNORED
		
		if(user_timer[touched] < get_gametime())
		{
			user_timer[touched] = get_gametime() + 1.0
			if ( cs_get_user_team ( touched ) != cs_get_user_team ( iOwner ) || g_HeroID == touched)
			{
				static Float:pos_ptr[3], Float:pos_ptd[3]
				
				pev(ent, pev_origin, pos_ptr)
				pev(touched, pev_origin, pos_ptd)
				
				for(new i = 0; i < 3; i++)
				{
					pos_ptd[i] -= pos_ptr[i]
					pos_ptd[i] *= Push
					
					new Float:fOrigin[3]
					pev ( ent, pev_origin, fOrigin )
					new iPlayer = -1
					while ( ( iPlayer = engfunc ( EngFunc_FindEntityInSphere, iPlayer, fOrigin, 68.0 ) ) != 0 )
					{
						if ( iPlayer == i )
						pos_ptd[i] *= 4
					}
				}
				set_pev(touched, pev_velocity, pos_ptd)
				set_pev(touched, pev_impulse, pos_ptd)
			}
		}
	}
	return FMRES_HANDLED
}

public DeleteEntity( entity )  // Thanks xPaw For The Code =D
	if( is_valid_ent( entity ) ) 
		remove_entity( entity );
		
public shield_deploy( shield_ent )
{
	if( pev_valid( shield_ent ) != 2 )
		return HAM_IGNORED;
	
	static const mPlayer = 41
	
	new id = get_pdata_cbase( shield_ent, mPlayer, 4 );
	
	if( ( gBomb & ( 1 << ( id % 32 ) ) ) )
		set_pev( id, pev_viewmodel2, model_grenade );
	
	return HAM_IGNORED;
}