#include <amxmodx>
#include <fakemeta>
#include <hamsandwich> 
#include <zombieplague>
#include <fun>
#include <engine>
#include <csx>
#include <xs>
#include <cstrike>

#define ENABLE_ZCLASS_GUARD


#if defined ENABLE_ZCLASS_GUARD
	new const zclass_name[] = { "Guardian" }
	new const zclass_info[] = { "Can't be chosen in menu." }
	new const zclass_model[] = { "zombie_guard" }
	new const zclass_clawmodel[] = { "v_knife_zombie_guard.mdl" }
	const zclass_health = 5000
	const zclass_speed = 220
	const Float:zclass_gravity = 1.0
	const Float:zclass_knockback = 1.0

	new g_vclass_guard
#endif


#define fm_create_entity(%1) engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, %1))


new const g_p_c4[] = "models/zombie_plague/p_virus_c4.mdl"
new const g_v_c4[] = "models/zombie_plague/v_virus_c4.mdl"
new const g_w_c4[] = "models/zombie_plague/w_virus_c4.mdl"


new const g_szC4Sounds[][] = {
	
	"weapons/c4_beep1.wav",
	"weapons/c4_beep2.wav",
	"weapons/c4_beep3.wav",
	"weapons/c4_beep4.wav",
	"weapons/c4_beep5.wav"
};

new const sound_armorhit[] = "player/bhit_helmet-1.wav"

new BuyZoneOrigin[33][3]
new DropBombOrigin[3]


new g_TextMsg
new g_EntitySum
new g_msgHostagePos
new g_msgHostageK

new idMaxZombies
new g_player_connected[33]


new bool:g_InPlant[33]
new Float:g_StartPlant[33]
new bool:g_InDefuse[33]
new Float:g_StartDefuse[33]

new bool:g_have_bomb[33] = false

new DropBomb[33][3]
new PlantBomb[33][3]

new g_bomb_pickup, g_bomb_drop, g_bomb_plant
new Defusing
new time_to_expl

//new g_cSprite
new g_eSprite, g_fSprite,  g_isprRing
new g_MaxPlayers
new g_Msg_Sync
new virus_mode = 0

new g_chance_virus
new g_BarTimeMsg
new iconstatus

new virus_chance_mode, virus_gamemode, virus_blocked_item, virus_enable_texthud, virus_enable_c4hud
new virus_min_playrs, virus_bal_human, virus_defuse_human, virus_plant_radius

new ze_knife_radius, ze_knife_painshock, ze_time_painshock
new g_painshok[33]

new time_to_bomb, virus_defuse_time, virus_planting_time, virus_explode_time, virus_explode_damage, virus_explode_radius

#if defined ENABLE_ZCLASS_GUARD
	new current_zclass[33]
	new next_zclass[33]
#endif

new shake_value, g_msgScreenFade

new Float:defuserMaxDistance = 100.0

//new virus_explode_ammo_allz, virus_explode_frag_allz, virus_defuse_ammo_allh, virus_defuse_frag_allh

new virus_explode_ammo_owner, virus_explode_ammo_alivez, virus_explode_frag_owner, virus_explode_frag_alivez, virus_defuse_ammo_owner, virus_defuse_ammo_aliveh, virus_defuse_frag_owner, virus_defuse_frag_aliveh

new prim_knife_dmg_min_armor, prim_knife_dmg_max_armor, sec_knife_dmg_min_armor, sec_knife_dmg_max_armor, prim_knife_dmg_min_head, prim_knife_dmg_max_head, prim_knife_dmg_min_body, prim_knife_dmg_max_body, sec_knife_dmg_min_head, sec_knife_dmg_max_head, sec_knife_dmg_min_body, sec_knife_dmg_max_body

public plugin_init()
{
	RegisterHam(Ham_Think, "info_target", "fw_HamThink", 1)
	RegisterHam(Ham_Killed,"player","fw_PlayerKilled")
	RegisterHam(Ham_TakeDamage, "player", "fw_TakeDamage")
	RegisterHam(Ham_Weapon_PrimaryAttack, "weapon_knife", "fw_primary_attack")
	RegisterHam(Ham_Weapon_SecondaryAttack, "weapon_knife", "fw_secondary_attack")
	register_plugin("[ZP] Virus-bomb mode", "1.1", "Miren")
	register_forward(FM_PlayerPreThink, "fm_PlayerPreThink")
	register_forward(FM_CmdStart, "fw_CmdStart")
	register_clcmd("drop", "clcmd_drop")
	register_event("CurWeapon", "Event_CurWeapon", "be","1=1")
	g_msgHostagePos = get_user_msgid("HostagePos")
	g_msgHostageK = get_user_msgid("HostageK")
	iconstatus = get_user_msgid("StatusIcon")

	shake_value = get_user_msgid ("ScreenShake")
	g_msgScreenFade = get_user_msgid("ScreenFade")

	g_TextMsg = get_user_msgid("TextMsg");
	g_BarTimeMsg = get_user_msgid("BarTime")
	g_MaxPlayers = get_maxplayers()
	g_Msg_Sync = CreateHudSyncObj()

	register_message(g_TextMsg, "message_TextMsg")

//---------------------------------CVARS-----------------------------------------------------------//

	virus_chance_mode = register_cvar("zp_ve_chance_mode", "10")   // chance mode virus explosion in %
	virus_min_playrs = register_cvar("zp_ve_min_playrs", "10")       // min players in game for mode
	virus_gamemode = register_cvar("zp_ve_gamemode", "0")           // 0 - multi & infection, 1 - infection, 2 - multi
	virus_bal_human = register_cvar("zp_ve_bal_human", "3")         // X humans / 1 zombie
	virus_defuse_human = register_cvar("zp_ve_defuse_human", "1")   // 0 zombie live / 1 zombie kill
	virus_blocked_item = register_cvar("zp_ve_blocked_item", "1")   // 0 - unblock extra item / 1 - block extra item
	virus_enable_texthud = register_cvar("zp_ve_enable_texthud", "1")   // 0 - off text hud massage for zombie / 1 - on text hud massage for zombie
	virus_enable_c4hud = register_cvar("zp_ve_enable_c4hud", "1")   // 0 - off c4 planted hud for human / 1 - on c4 planted hud for human

	time_to_bomb = register_cvar("zp_ve_time_to_bomb", "30.0")        // time before respawn bomb
	virus_defuse_time = register_cvar("zp_ve_defuse_time", "9")      // defuse time
	virus_planting_time = register_cvar("zp_ve_planting_time", "3")  // time planting bomb
	virus_explode_time = register_cvar("zp_ve_c4_timer", "45")        // c4 timer
	virus_explode_damage = register_cvar("zp_ve_c4_damage", "5000")  // c4 damage
	virus_explode_radius = register_cvar("zp_ve_c4_radius", "1000")  // c4 damage radius
	virus_plant_radius = register_cvar("zp_ve_plant_radius", "400")  // c4 radius planting from points CT i T respawn

//--------------------------------AWARDS-----------------------------------------------------------//

	virus_explode_ammo_owner = register_cvar("zp_ve_explode_ammo_owner", "4")   // ammo bomb owner for explode
	virus_explode_ammo_alivez = register_cvar("zp_ve_explode_ammo_alivez", "1") // ammo alive zombie for explode
	virus_explode_frag_owner = register_cvar("zp_ve_explode_frag_owner", "3")   // frag bomb owner for explode
	virus_explode_frag_alivez = register_cvar("zp_ve_explode_frag_alivez", "0") // frag alive zombie for explode

	virus_defuse_ammo_owner = register_cvar("zp_ve_defuse_ammo_owner", "4")     // ammo defuser for defuse
	virus_defuse_ammo_aliveh = register_cvar("zp_ve_defuse_ammo_aliveh", "1")   // ammo alive human for defuse
	virus_defuse_frag_owner = register_cvar("zp_ve_defuse_frag_owner", "3")     // frag defuser for defuse
	virus_defuse_frag_aliveh = register_cvar("zp_ve_defuse_frag_aliveh", "0")   // frag alive human for defuse

//-------------------------------------------------------------------------------------------------//	

	ze_knife_radius = register_cvar("zp_zombie_knife_radius", "55")       // knife damage radius
	ze_knife_painshock = register_cvar("zp_zombie_knife_painshock", "1")  // knife damage painshock 0 - off / 1 - on
	ze_time_painshock = register_cvar("zp_zombie_time_painshock", "1.5")  // knife damage time painshock


//------------------------Knife damage from zombie-------------------------------------------------//

	prim_knife_dmg_min_armor = register_cvar("zp_ve_prim_knife_dmg_min_armor", "10")
	prim_knife_dmg_max_armor = register_cvar("zp_ve_prim_knife_dmg_max_armor", "15")
	sec_knife_dmg_min_armor = register_cvar("zp_ve_sec_knife_dmg_min_armor", "20")
	sec_knife_dmg_max_armor = register_cvar("zp_ve_sec_knife_dmg_max_armor", "30")


	prim_knife_dmg_min_head = register_cvar("zp_ve_prim_knife_dmg_min_head", "20")
	prim_knife_dmg_max_head = register_cvar("zp_ve_prim_knife_dmg_max_head", "30")
	prim_knife_dmg_min_body = register_cvar("zp_ve_prim_knife_dmg_min_body", "10")
	prim_knife_dmg_max_body = register_cvar("zp_ve_prim_knife_dmg_max_body", "25")

	sec_knife_dmg_min_head = register_cvar("zp_ve_sec_knife_dmg_min_head", "40")
	sec_knife_dmg_max_head = register_cvar("zp_ve_sec_knife_dmg_max_head", "45")
	sec_knife_dmg_min_body = register_cvar("zp_ve_sec_knife_dmg_min_body", "20")
	sec_knife_dmg_max_body = register_cvar("zp_ve_sec_knife_dmg_max_body", "30")

//-------------------------------------------------------------------------------------------------//

	//virus_explode_ammo_allz = register_cvar("zp_ve_explode_ammo_allz", "0")
	//virus_explode_frag_allz = register_cvar("zp_ve_explode_frag_allz", "0")
	//virus_defuse_ammo_allh = register_cvar("zp_ve_defuse_ammo_allh", "0")
	//virus_defuse_frag_allh = register_cvar("zp_ve_defuse_frag_allh", "0")
}

public plugin_precache()
{
	engfunc(EngFunc_PrecacheSound, sound_armorhit)

	precache_model(g_p_c4)
	precache_model(g_v_c4)
	precache_model(g_w_c4)

	g_eSprite = precache_model("sprites/e_virus_explo.spr")
	g_fSprite = precache_model("sprites/f_virus_explo1.spr")
	g_isprRing = precache_model("sprites/shockwave.spr")

#if defined ENABLE_ZCLASS_GUARD
	g_vclass_guard = zp_register_zombie_class(zclass_name, zclass_info, zclass_model, zclass_clawmodel, zclass_health, zclass_speed, zclass_gravity, zclass_knockback)
#endif
}


public plugin_cfg()
{
	new entity = -1, Float:tmpOrigin[3]

	// func_buyzone
	while ((entity = find_ent_by_class(entity, "func_buyzone")) > 0)
	{
		get_brush_entity_origin(entity, tmpOrigin)
		FVecIVec(tmpOrigin, BuyZoneOrigin[g_EntitySum])

		g_EntitySum++       
	}
}


public Event_CurWeapon(id) 
{
	if ((virus_mode == 1) && zp_get_user_zombie(id))
	{
		new weaponID = read_data(2) 

		if(weaponID == CSW_C4)
		{
			set_pev(id, pev_viewmodel2, g_v_c4)
			set_pev(id, pev_weaponmodel2, g_p_c4)
		}

		return PLUGIN_CONTINUE 
	}
	return PLUGIN_CONTINUE 
}


public zp_round_started(gamemode, id)
{
	static g_inGame
	g_inGame = fn_GetPlaying()

	if (get_pcvar_num(virus_min_playrs) > g_inGame)
	{
		virus_mode = 0
 		return PLUGIN_HANDLED
	}
	else
	{
		if ((gamemode == MODE_INFECTION && (get_pcvar_num(virus_gamemode) == 0)) || (gamemode == MODE_INFECTION && (get_pcvar_num(virus_gamemode) == 1)))
		{
			g_chance_virus = random_num(0,100)
			if (g_chance_virus < get_pcvar_num(virus_chance_mode))
			{
				set_task (1.0, "show_hud_round_start")

				virus_mode = 1

				Defusing = 0
				g_bomb_pickup = 0
				g_bomb_drop = 0
				g_bomb_plant = 0

				g_have_bomb[id] = false

				if (is_user_alive(id))
				{
					set_task (2.0,"pos_ShowOnRadar",id,_,_,"b")
				}

				new idZombies = zp_get_zombie_count()
				idMaxZombies = fn_GetPlaying()/(2*get_pcvar_num(virus_bal_human))

				while (idZombies < idMaxZombies)
				{
					make_zombie()
					idZombies++
				}

				if (is_user_alive(id) && !zp_get_user_zombie(id))
				{
					g_InDefuse[id] = false
				}

				if (zp_get_user_first_zombie(id))
				{
					#if defined ENABLE_ZCLASS_GUARD
						set_task (0.1, "humanize_first_zombie" ,id)
					#endif

					set_task (0.3 + get_pcvar_float(time_to_bomb), "give_bomb" ,id)

					client_print(id,print_chat,"[ZP] You can plant bomb only in buyzone.")
				}
			}
		}
		if ((gamemode == MODE_MULTI && (get_pcvar_num(virus_gamemode) == 0)) || (gamemode == MODE_MULTI && (get_pcvar_num(virus_gamemode) == 2)))
		{
			g_chance_virus = random_num(0,100)
			if (g_chance_virus < get_pcvar_num(virus_chance_mode))
			{
				set_task (1.0, "show_hud_round_start")

				virus_mode = 1
				Defusing = 0
				g_bomb_pickup = 0
				g_bomb_drop = 0
				g_bomb_plant = 0

				g_have_bomb[id] = false

				if (is_user_alive(id))
				{
					set_task (2.0,"pos_ShowOnRadar",id,_,_,"b")
				}

				if (zp_get_user_zombie(id))
				{
					#if defined ENABLE_ZCLASS_GUARD
						set_task (0.1, "humanize_first_zombie" ,id)
					#endif

					new zombie_count = zp_get_zombie_count()
					new z = random_num(1, zombie_count)
					new bomb_owner = GetRandomAliveZombie(z)

					set_task (0.3 + get_pcvar_float(time_to_bomb), "give_bomb" ,bomb_owner)

					client_print(bomb_owner,print_chat,"[ZP] You can plant bomb only in buyzone.")
				}

				new idZombies = zp_get_zombie_count()
				idMaxZombies = fn_GetPlaying()/(2*get_pcvar_num(virus_bal_human))

				while (idZombies < idMaxZombies)
				{
					make_zombie()
					idZombies++
				}

				if (is_user_alive(id) && !zp_get_user_zombie(id))
				{
					g_InDefuse[id] = false
				}
			}
		}
	}
	return PLUGIN_HANDLED
}

public show_hud_round_start()
{
	set_hudmessage(250, 255, 40, -1.0, 0.2, 0, 0.0, 5.0, 1.0, 1.0, -1)
	ShowSyncHudMsg(0, g_Msg_Sync, "Virus explosion round start. Ready for fight.")
}

public show_hud_bomb_plant()
{
	set_hudmessage(40, 200, 0, -1.0, 0.2, 0, 0.0, 5.0, 1.0, 1.0, -1)
	ShowSyncHudMsg(0, g_Msg_Sync, "Virus explosion set. Infection threat.")
}

public show_hud_bomb_defuse()
{
	set_hudmessage(40, 0, 200, -1.0, 0.2, 0, 0.0, 5.0, 1.0, 1.0, -1)
	ShowSyncHudMsg(0, g_Msg_Sync, "Virus explosion neutralised. Threat is neutralised.")
}

public show_hud_bomb_explode()
{
	set_hudmessage(200, 40, 0, -1.0, 0.2, 0, 0.0, 5.0, 1.0, 1.0, -1)
	ShowSyncHudMsg(0, g_Msg_Sync, "Virus explode. Attention a zone biological infection.")
}


public zp_user_infected_post(id, infector)
{
	if (is_user_alive(id) && zp_get_user_zombie(id) && (virus_mode == 1) && (get_pcvar_num(virus_enable_texthud) == 1))
	{
		//time_to_expl = floatround(get_pcvar_float(virus_explode_time))

		set_task(1.0, "BombCondition", id, "", 0, "b")
	}
}


public make_zombie()
{
	new human_count = zp_get_human_count()
	new n = random_num(1, human_count)
	new guard_zombie = GetRandomAliveHuman(n)

#if defined ENABLE_ZCLASS_GUARD
	current_zclass[guard_zombie] = zp_get_user_zombie_class(guard_zombie)
	next_zclass[guard_zombie] = zp_get_user_next_class(guard_zombie)

	zp_set_user_zombie_class(guard_zombie, g_vclass_guard)
#endif

	zp_infect_user(guard_zombie, 0, 1)

#if defined ENABLE_ZCLASS_GUARD
	set_task (0.1, "give_next_class" ,guard_zombie)
#endif
}


#if defined ENABLE_ZCLASS_GUARD
public humanize_first_zombie(id)
{
	zp_disinfect_user(id, 1)
	current_zclass[id] = zp_get_user_zombie_class(id)

	zp_set_user_zombie_class(id, g_vclass_guard)

	set_task (0.1, "infect_user" ,id)
}
#endif


#if defined ENABLE_ZCLASS_GUARD
public infect_user(id)
{
	zp_infect_user(id, 0, 1)
	set_task (0.1, "give_next_class" ,id)
}
#endif

#if defined ENABLE_ZCLASS_GUARD
public give_next_class(id)
{
	if (next_zclass[id] == -1)
	{
		zp_set_user_zombie_class(id, current_zclass[id])
	}
	else
	{
		zp_set_user_zombie_class(id, next_zclass[id])
	}
}
#endif

#if defined ENABLE_ZCLASS_GUARD
public zp_user_infected_pre(id, infector, nemesis)
{
	if ((virus_mode == 0) && (zp_get_user_next_class(id) == g_vclass_guard))
	{
		zp_set_user_zombie_class(id, (g_vclass_guard - 1))
	}

//	if (virus_mode == 1)
//	{
//		if (zp_get_user_next_class(id) != g_vclass_guard)
//		{
//			if (zp_get_user_zombie_class(id)!= g_vclass_guard)
//			{
//				zp_set_user_zombie_class(id, g_vclass_guard)
//			}
//		}
//	}
}
#endif

public give_bomb(id)
{
	g_InPlant[id] = false

	give_item(id, "weapon_c4")

	g_bomb_pickup = 1
	g_bomb_drop = 0
	g_bomb_plant = 0

	g_have_bomb[id] = true
}

public BombCondition(id)
{
	if (is_user_alive(id) && zp_get_user_zombie(id))
	{
		if (g_bomb_pickup == 1)
		{
			if (user_has_weapon(id, CSW_C4))
			{
				set_hudmessage(255, 255, 255, 0.75, 0.90, 0, 1.0, 1.0, _, _, -1)
				show_hudmessage(id, "Bomb found you.")
			}
			else
			{
				//new name[32] 
				//new ent = CSW_C4
				//get_user_name(pev(ent, pev_owner) , name, 31)

				set_hudmessage(255, 255, 255, 0.75, 0.90, 0, 1.0, 1.0, _, _, -1)
				show_hudmessage(id, "Bomb placed at zombie.")
			}
		}
		if (g_bomb_drop == 1)
		{
			set_hudmessage(255, 0, 0, 0.75, 0.90, 0, 1.0, 1.0, _, _, -1)
			show_hudmessage(id, "Bomb thrown.")
		}
		if (g_bomb_plant == 1)
		{
			time_to_expl = time_to_expl - 1

			static did
			for (did = 1; did <= g_MaxPlayers; did++)
			{
				if (g_InDefuse[did])
				{
					set_hudmessage(0, 0, 255, 0.75, 0.90, 0, 1.0, 1.0, _, _, -1)
					show_hudmessage(id, "Attention!!! Human try to clear of bomb.")
				}
				else
				{
					set_hudmessage(0, 255, 0, 0.75, 0.90, 0, 1.0, 1.0, _, _, -1)
					show_hudmessage(id, "Bomb set, waiting explosion.") // %d.", time_to_expl)
				}
			}
		}
//waiting respawn bomb
	}
}

public display_bomb_icon(id)
{
	if (is_user_alive(id) && zp_get_user_zombie(id) && (virus_mode == 1) && user_has_weapon(id, CSW_C4))
	{
		new player_origin_hud[33][3]
		get_user_origin(id, player_origin_hud[id])

		if (is_nearby_other(player_origin_hud[id]))
		{
			set_user_icon(id, 2, 250, 0, 0)
			set_user_icon(id, 2, 250, 250, 0)
		}
		else
		{
			set_user_icon(id, 1, 200, 250, 40)	
		}
	}
	else
	{
		set_user_icon(id , 0, 0, 0, 0)
	}
}

public display_bomb_icon_human(id)
{
	if (is_user_alive(id) && !zp_get_user_zombie(id) && (virus_mode == 1))
	{
		if (g_bomb_plant == 1)
		{
			set_user_icon(id, 2, 250, 0, 0)
			set_user_icon(id, 2, 250, 250, 0)
		}
		else
		{
			set_user_icon(id , 0, 0, 0, 0)
		}
	}
}


stock set_user_icon(id , mode , red , green , blue)
{
	message_begin(MSG_ONE,iconstatus,{0,0,0},id);
	write_byte(mode);
	write_string("c4");
	write_byte(red);
	write_byte(green);
	write_byte(blue);
	message_end();
}

public fw_CmdStart(id, uc_handle, uc_seed)
{
	if (!is_user_alive(id) || (virus_mode == 0))
	{
		return FMRES_IGNORED
	}

	set_task(0.5, "display_bomb_icon", id)

	if (get_pcvar_num(virus_enable_c4hud) == 1)
	{
		set_task(0.5, "display_bomb_icon_human", id)
	}

	static iButton, iOldButton
	iButton = get_uc(uc_handle, UC_Buttons)
	iOldButton = pev(id, pev_oldbuttons)

	static iWpn
	iWpn = get_user_weapon(id)
	
	if(!pev_valid(iWpn))
	{
		return HAM_IGNORED
	}

	if (is_user_alive(id) && !zp_get_user_zombie(id))
	{
		new bEnt
		while ((bEnt = engfunc(EngFunc_FindEntityByString, bEnt, "classname", "c4_bomb")) > 0)
		if(!bEnt)
		{
			return HAM_IGNORED
		}
		else
		{
			if ((iButton & IN_USE) && (iOldButton & IN_USE))
			{
				static Float:start[3], Float:view_ofs[3], Float:origin[3], Float:dest[3]
				
				pev(id, pev_origin, start);
				pev(id, pev_view_ofs, view_ofs);
				xs_vec_add(start, view_ofs, start);

				pev(id, pev_v_angle, dest);
				engfunc(EngFunc_MakeVectors, dest);
				global_get(glb_v_forward, dest);
				xs_vec_mul_scalar(dest, defuserMaxDistance, dest);
				xs_vec_add(start, dest, dest);

				engfunc(EngFunc_TraceLine, start, dest, 0, id, 0);
				get_tr2(0, TR_vecEndPos, origin);
							
				if(is_valid_ent(bEnt))
				{
					engfunc ( EngFunc_TraceModel, start, dest, HULL_POINT, bEnt ,0)
					
					new hit = get_tr2(0, TR_pHit);
					
					if(hit == bEnt)
					{
						if (!g_InDefuse[id])
						{
							g_InDefuse[id] = true
							g_StartDefuse[id] = get_gametime()
							msg_bar_time(id, get_pcvar_num(virus_defuse_time))
						}
						else if (g_InDefuse[id])
						{
							if(get_gametime() >= g_StartDefuse[id] + float(get_pcvar_num(virus_defuse_time)))
							{
								g_InDefuse[id] = false
								msg_bar_time(id, 0)

								//y6patb 6om6y u 6ydywuu B3pbiB
								engfunc(EngFunc_RemoveEntity, bEnt)

								new sEnt;
								while((sEnt= engfunc(EngFunc_FindEntityByString, sEnt, "classname", "c4_sprite")))
								{
									if(pev_valid(sEnt))
									engfunc(EngFunc_RemoveEntity, sEnt);
								}

								Defusing = 1

								set_task (0.0, "show_hud_bomb_defuse")
								static zid
								for (zid = 1; zid <= g_MaxPlayers; zid++)
								{
									if (is_user_alive(zid) && zp_get_user_zombie(zid))
									{
										remove_task(zid)
										if (get_pcvar_num(virus_defuse_human) == 1)
										{
											//zombie kill
											set_user_rendering(zid, kRenderFxGlowShell, 0, 255, 0, kRenderNormal, 10)
											message_begin(MSG_BROADCAST, g_msgScreenFade, _, zid)
											write_short(3)	// Duration
											write_short(3)	// Hold time
											write_short(0x0001)	// Fade type
											write_byte (0)	// Red
											write_byte (255)	// Green
											write_byte (40)	// Blue
											write_byte (100)	// Alpha
											message_end()

											set_task(3.0, "remove_glow", zid)
										}
									}

									if (is_user_alive(zid) && !zp_get_user_zombie(zid))
									{
										new ammo = zp_get_user_ammo_packs(zid) + get_pcvar_num(virus_defuse_ammo_aliveh)
										zp_set_user_ammo_packs(zid, ammo)

										new frags = get_user_frags(zid) + get_pcvar_num(virus_defuse_frag_aliveh)
										set_user_frags(zid, frags)
									}

									//if (!is_user_alive(zid) && !zp_get_user_zombie(zid))
									//{
										//new ammo = zp_get_user_ammo_packs(zid) + get_pcvar_num(virus_defuse_ammo_allh)
										//zp_set_user_ammo_packs(zid, ammo)

										//new frags = get_user_frags(zid) + get_pcvar_num(virus_defuse_frag_allh)
										//set_user_frags(zid, frags)
									//}

								}

								new ammo = zp_get_user_ammo_packs(id) + get_pcvar_num(virus_defuse_ammo_owner)
								zp_set_user_ammo_packs(id, ammo)

								new frags = get_user_frags(id) + get_pcvar_num(virus_defuse_frag_owner)
								set_user_frags(id, frags)

								g_bomb_pickup = 0
								g_bomb_drop = 0
								g_bomb_plant = 0

							}
						}
					}
					else
					{
						g_InDefuse[id] = false
						msg_bar_time(id, 0)
						return HAM_IGNORED
					}
				}
			}
			else if (!(iButton & IN_USE) && g_InDefuse[id])
			{
				g_InDefuse[id] = false
				msg_bar_time(id, 0)
			}
		}
		return HAM_IGNORED
	}

	if (!user_has_weapon(id, CSW_C4) && zp_get_user_zombie(id))
	{
		new bomb = engfunc(EngFunc_FindEntityByString, bomb, "classname", "dropped_c4_bomb")
		if (bomb)
		{
			new Float:dBomb_origin[3]
			pev(bomb, pev_origin, dBomb_origin)
			FVecIVec(dBomb_origin, DropBombOrigin)

			new zomb_origin[33][3]
			get_user_origin(id, zomb_origin[id])

			if (is_zone_bomb(zomb_origin[id]))
			{
				engfunc(EngFunc_RemoveEntity, bomb)
				message_begin(MSG_ALL, get_user_msgid("BombPickup"), {0,0,0}, id)
				message_end()
				give_item(id, "weapon_c4")

				g_have_bomb[id] = true

				g_bomb_pickup = 1
				g_bomb_drop = 0
				g_bomb_plant = 0
			}
			else
			{
				return HAM_IGNORED
			}
		}
		else
		{
			return HAM_IGNORED
		}
	}

	if (get_user_weapon(id) == CSW_C4 && zp_get_user_zombie(id))
	{
		if((iButton & IN_ATTACK) && (iOldButton & IN_ATTACK) && !g_InPlant[id])
		{
			new player_origin[33][3]
			get_user_origin(id, player_origin[id])

			if (is_nearby_other(player_origin[id]))
			{
				fm_set_animation(id, 3)
				g_InPlant[id] = true
				g_StartPlant[id] = get_gametime()
			
				msg_bar_time(id, get_pcvar_num(virus_planting_time))
			}
			else
			{
				return HAM_IGNORED
			}
		}
		else if((iButton & IN_ATTACK) && (iOldButton & IN_ATTACK) && g_InPlant[id])
		{
			if(get_gametime() >= g_StartPlant[id] + float(get_pcvar_num(virus_planting_time)))
			{
				g_InPlant[id] = false
				msg_bar_time(id, 0)
				
				ham_strip_weapon(id, "weapon_c4")
				
				new Float:vOrigin[3], Float:vEnd[3]
				pev(id, pev_origin, vOrigin)
				
				vEnd[0] = vOrigin[0];
				vEnd[1] = vOrigin[1];
				vEnd[2] = -1337.0;

				FVecIVec(vEnd, PlantBomb[id])
				
				engfunc(EngFunc_TraceLine, vOrigin, vEnd, 0, id, 0)
				get_tr2(0, TR_vecEndPos, vEnd)
				
				new iEnt = fm_create_entity("info_target")
				set_pev(iEnt, pev_classname, "c4_bomb")
				engfunc(EngFunc_SetOrigin, iEnt, vEnd)
				engfunc(EngFunc_SetModel, iEnt, g_w_c4)
				set_pev(iEnt, pev_solid, SOLID_BBOX)
				set_pev(iEnt, pev_owner, id)
				set_pev(iEnt, pev_fuser1, get_pcvar_float(virus_explode_time))
				
				set_pev(iEnt, pev_nextthink, get_gametime())

				g_have_bomb[id] = false

				set_task (0.0, "show_hud_bomb_plant")

				g_bomb_pickup = 0
				g_bomb_drop = 0
				g_bomb_plant = 1
			}
		}
		else if(!(iButton & IN_ATTACK) && g_InPlant[id])
		{
			fm_set_animation(id, 0)
			g_InPlant[id] = false			
			msg_bar_time(id, 0)
		}
	}
	else if((get_user_weapon(id) != CSW_C4) && g_InPlant[id])
	{
		msg_bar_time(id, 0)
		g_InPlant[id] = false
	}
	return FMRES_IGNORED
}

public remove_glow(id)
{
	set_user_rendering(id, kRenderFxGlowShell, 0, 0, 0, kRenderNormal,10)
	user_kill(id, 1)
}

public fm_PlayerPreThink(id)
{
	if (is_user_alive(id) && zp_get_user_zombie(id) && (virus_mode == 1))
	{
		if (g_InPlant[id])
		{
			set_pev(id, pev_maxspeed, 1.0)
		}
	}

	if (is_user_alive(id) && !zp_get_user_zombie(id) && (virus_mode == 1))
	{
		if (g_InDefuse[id] || g_painshok[id])
		{
			set_pev(id, pev_maxspeed, 1.0)
		}
	}
}

public clcmd_drop(id)
{
	if (zp_get_user_zombie(id) && (virus_mode == 1))
		return PLUGIN_HANDLED;
	
	return PLUGIN_CONTINUE;
}

public fw_TakeDamage(victim, inflictor, attacker, Float:damage, damage_type)
{
	if (zp_get_user_zombie(attacker) && (virus_mode == 1))
	{
		if (zp_get_user_last_human(victim))
		{
			static Float:larmor
			pev(victim, pev_armorvalue, larmor)
			if (larmor > 0.0)
			{
				set_pev(victim, pev_armorvalue, floatmax(0.0, larmor - damage))
				return HAM_SUPERCEDE
			}
			else
			{
				return HAM_IGNORED
			}
		}
	}
	return HAM_IGNORED
}

public fw_primary_attack(ent)
{
	if (virus_mode == 0) 
	{
		return HAM_IGNORED
	}

	if (virus_mode == 1) 
	{
		new id = pev(ent,pev_owner)
		new shoottarget, body
		get_user_aiming(id, shoottarget, body, get_pcvar_num(ze_knife_radius))
		if (zp_get_user_zombie(id))
		{
			if (!is_user_alive(shoottarget))
			{
				return HAM_IGNORED
			}

			if (!zp_get_user_zombie(shoottarget) && !zp_get_user_last_human(shoottarget))
			{
				new health = get_user_health(shoottarget)
				new damage

				static Float:armor
				pev(shoottarget, pev_armorvalue, armor)
				if (armor > 0.0)
				{
					new armdamage = random_num(get_pcvar_num(prim_knife_dmg_min_armor), get_pcvar_num(prim_knife_dmg_max_armor))
					emit_sound(shoottarget, CHAN_BODY, sound_armorhit, 1.0, ATTN_NORM, 0, PITCH_NORM)
					set_pev(shoottarget, pev_armorvalue, floatmax(0.0, armor - armdamage))
				}
				else
				{				
					if (body == HIT_HEAD)
					{
						damage = random_num(get_pcvar_num(prim_knife_dmg_min_head), get_pcvar_num(prim_knife_dmg_max_head))
					}

					if (body != HIT_HEAD)
					{
						damage = random_num(get_pcvar_num(prim_knife_dmg_min_body), get_pcvar_num(prim_knife_dmg_max_body))
					}

					if (health > damage)
					{
						new health = get_user_health(shoottarget)
						set_user_health(shoottarget, health - damage)

						if ((get_pcvar_num(ze_knife_painshock) == 1) && (pev(shoottarget, pev_flags) & FL_ONGROUND))
						{
							pain_shock(shoottarget)
						}
					}
					else
					{
						ExecuteHamB(Ham_Killed, shoottarget, id, 1)
	
						new ammo = zp_get_user_ammo_packs(id) + 1
						zp_set_user_ammo_packs(id, ammo)

						//new frags = get_user_frags(id) + get_pcvar_num(hum_frag_kill)
						//set_user_frags(id, frags)	
					}
				}
			}

		}
		return HAM_IGNORED
	}
	return HAM_IGNORED
}

public fw_secondary_attack(ent)
{
	if (virus_mode == 0) 
	{
		return HAM_IGNORED
	}

	if (virus_mode == 1) 
	{
		new id = pev(ent,pev_owner)
		new shoottarget, body
		get_user_aiming(id, shoottarget, body, get_pcvar_num(ze_knife_radius))
		if (zp_get_user_zombie(id))
		{
			if (!is_user_alive(shoottarget))
			{
				return HAM_IGNORED
			}

			if (!zp_get_user_zombie(shoottarget) && !zp_get_user_last_human(shoottarget))
			{
				new health = get_user_health(shoottarget)
				new damage

				static Float:armor
				pev(shoottarget, pev_armorvalue, armor)
				if (armor > 0.0)
				{
					new armdamage = random_num(get_pcvar_num(sec_knife_dmg_min_armor), get_pcvar_num(sec_knife_dmg_max_armor))

					emit_sound(shoottarget, CHAN_BODY, sound_armorhit, 1.0, ATTN_NORM, 0, PITCH_NORM)
					set_pev(shoottarget, pev_armorvalue, floatmax(0.0, armor - armdamage))
				}
				else
				{
					if (body == HIT_HEAD)
					{
						damage = random_num(get_pcvar_num(sec_knife_dmg_min_head), get_pcvar_num(sec_knife_dmg_max_head))
					}

					if (body != HIT_HEAD)
					{
						damage = random_num(get_pcvar_num(sec_knife_dmg_min_body), get_pcvar_num(sec_knife_dmg_max_body))
					}

					if (health > damage)
					{
						new health = get_user_health(shoottarget)
						set_user_health(shoottarget, health - damage)

						if ((get_pcvar_num(ze_knife_painshock) == 1) && (pev(shoottarget, pev_flags) & FL_ONGROUND))
						{
							pain_shock(shoottarget)
						}
					}
					else
					{
						ExecuteHamB(Ham_Killed, shoottarget, id, 1)
	
						new ammo = zp_get_user_ammo_packs(id) + 1
						zp_set_user_ammo_packs(id, ammo)

						//new frags = get_user_frags(id) + get_pcvar_num(hum_frag_kill)
						//set_user_frags(id, frags)	
					}
				}
			}
		}
		return HAM_IGNORED
	}
	return HAM_IGNORED
}


public pain_shock(id)
{
	g_painshok[id] = true
	
	set_task(get_pcvar_float(ze_time_painshock), "pain_shock_off", id)
}

public pain_shock_off(id)
{
	g_painshok[id] = false
}


public fw_PlayerKilled(victim,attacker,corpse)
{
	if (zp_get_user_zombie(victim) && (virus_mode == 1) && user_has_weapon(victim, CSW_C4))
	{
		new lost = zp_get_zombie_count()
		if (lost > 0)
		{
			new Float:v_Origin[3], Float:v_End[3]
			pev(victim, pev_origin, v_Origin)
				
			v_End[0] = v_Origin[0];
			v_End[1] = v_Origin[1];
			v_End[2] = -1337.0;
				
			engfunc(EngFunc_TraceLine, v_Origin, v_End, 0, victim, 0)
			get_tr2(0, TR_vecEndPos, v_End)
		
			new iBomb = fm_create_entity("info_target")
			set_pev(iBomb, pev_classname, "dropped_c4_bomb")
			engfunc(EngFunc_SetOrigin, iBomb, v_End)
			engfunc(EngFunc_SetModel, iBomb, g_w_c4)
			set_pev(iBomb, pev_solid, SOLID_BBOX)

			FVecIVec(v_End, DropBomb[victim])

			g_have_bomb[victim] = false

			g_bomb_pickup = 0
			g_bomb_drop = 1
			g_bomb_plant = 0
		}
	}
}

public fw_HamThink(ent)
{
	if(!pev_valid(ent) || (virus_mode == 0))
	{
		return HAM_IGNORED
	}
	
	static szClassname[32]
	pev(ent, pev_classname, szClassname, sizeof szClassname - 1)
	
	if(szClassname[0] == 'c' && szClassname[1] == '4' && szClassname[3] == 's')
	{
		switch(pev(ent, pev_iuser1))
		{
			case 3: { set_pev(ent, pev_renderamt, 100.0); }
			case 2: { set_pev(ent, pev_renderamt, 50.0); }
			case 1: { set_pev(ent, pev_renderamt, 10.0); }
			case 0:
			{
				engfunc(EngFunc_RemoveEntity, ent)
				return HAM_IGNORED
			}
		}
		set_pev(ent, pev_iuser1, pev(ent, pev_iuser1) - 1)
		set_pev(ent, pev_nextthink, get_gametime() + 0.1)
	}
	else if(szClassname[0] == 'c' && szClassname[1] == '4' && szClassname[3] == 'b')
	{
		static Float:vOrigin[3]
		pev(ent, pev_origin, vOrigin)
		
		vOrigin[2] += 7.0
		
		new iSprite = fm_create_entity("info_target")
		set_pev(iSprite, pev_classname, "c4_sprite")
		engfunc(EngFunc_SetOrigin, iSprite, vOrigin)
		set_pev(iSprite, pev_rendermode, 5)
		set_pev(iSprite, pev_renderamt, 200.0)
		set_pev(iSprite, pev_scale, 0.3)
		engfunc(EngFunc_SetModel, iSprite, "sprites/ledglow.spr")
		set_pev(iSprite, pev_iuser1, 3)
		set_pev(iSprite, pev_nextthink, get_gametime() + 0.1)
		
		new Float:fTime
		pev(ent, pev_fuser1, fTime)
		new Float:fExplodeTime = get_pcvar_float(virus_explode_time)
		
		if(!fTime || fTime < 0.0)
		{
			set_task (0.0, "show_hud_bomb_explode")


			// A ring effect
			engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, vOrigin, 0)
			write_byte(TE_BEAMCYLINDER) // TE id
			engfunc(EngFunc_WriteCoord, vOrigin[0]) // x
			engfunc(EngFunc_WriteCoord, vOrigin[1]) // y
			engfunc(EngFunc_WriteCoord, vOrigin[2]) // z
			engfunc(EngFunc_WriteCoord, vOrigin[0]) // x axis
			engfunc(EngFunc_WriteCoord, vOrigin[1]) // y axis
			engfunc(EngFunc_WriteCoord, vOrigin[2] + 500.0) // z axis
			write_short(g_isprRing) // sprite
			write_byte(0) // startframe
			write_byte(0) // framerate
			write_byte(10) // life
			write_byte(25) // width
			write_byte(0) // noise
			write_byte(0) // red
			write_byte(150) // green
			write_byte(255) // blue
			write_byte(200) // brightness
			write_byte(0) // speed
			message_end()

			static zid
			for (zid = 1; zid <= g_MaxPlayers; zid++)
			{
				if (is_user_alive(zid) && zp_get_user_zombie(zid))
				{
					remove_task(zid)
				}

				if (is_user_alive(zid) && zp_get_user_zombie(zid))
				{
					new ammo = zp_get_user_ammo_packs(zid) + get_pcvar_num(virus_explode_ammo_alivez)
					zp_set_user_ammo_packs(zid, ammo)

					new frags = get_user_frags(zid) + get_pcvar_num(virus_explode_frag_alivez)
					set_user_frags(zid, frags)
				}

				//if (!is_user_alive(zid) && zp_get_user_zombie(zid))
				//{
				//	new ammo = zp_get_user_ammo_packs(zid) + get_pcvar_num(virus_explode_ammo_allz)
				//	zp_set_user_ammo_packs(zid, ammo)

				//	new frags = get_user_frags(zid) + get_pcvar_num(virus_explode_frag_allz)
				//	set_user_frags(zid, frags)
				//}

			}
			
			new saper = pev(ent, pev_owner)
			ham_fakedamage_r(vOrigin, pev(ent, pev_owner), get_pcvar_float(virus_explode_damage), get_pcvar_float(virus_explode_radius))	
		

			if(pev_valid(ent))
			{
				engfunc(EngFunc_RemoveEntity, ent)
			}

			new ammo = zp_get_user_ammo_packs(saper) + get_pcvar_num(virus_explode_ammo_owner)
			zp_set_user_ammo_packs(saper, ammo)

			new frags = get_user_frags(saper) + get_pcvar_num(virus_explode_frag_owner)
			set_user_frags(saper, frags)


			static id
			for (id = 1; id <= g_MaxPlayers; id++)
			{
				if (is_user_alive(id) && !zp_get_user_zombie(id))
				{
					if (zp_get_user_last_human(id) || zp_get_user_survivor(id))
					{
						user_kill(id, 1)
					}
					else
					{
						zp_infect_user(id)
					}
				}
				if (is_user_alive(id) && zp_get_user_zombie(id))
				{
					fov_shake(id)
				}
			}
			
			return HAM_IGNORED
		}
		
		if(0 <= fTime <= fExplodeTime / 5)
			emit_sound(ent, CHAN_AUTO, g_szC4Sounds[4], VOL_NORM, ATTN_STATIC, 0, PITCH_NORM);
		else if(fExplodeTime / 5 < fTime <= fExplodeTime / 4)
			emit_sound(ent, CHAN_AUTO, g_szC4Sounds[3], VOL_NORM, ATTN_STATIC, 0, PITCH_NORM);
		else if(fExplodeTime / 4 < fTime <= fExplodeTime / 3)
			emit_sound(ent, CHAN_AUTO, g_szC4Sounds[2], VOL_NORM, ATTN_STATIC, 0, PITCH_NORM);
		else if(fExplodeTime / 3 < fTime <= fExplodeTime / 2)
			emit_sound(ent, CHAN_AUTO, g_szC4Sounds[1], VOL_NORM, ATTN_STATIC, 0, PITCH_NORM);
		else if(fExplodeTime / 2 < fTime <= fExplodeTime)
			emit_sound(ent, CHAN_AUTO, g_szC4Sounds[0], VOL_NORM, ATTN_STATIC, 0, PITCH_NORM);
		
		set_pev(ent, pev_fuser1, fTime - 1.5)
		set_pev(ent, pev_nextthink, get_gametime() + 1.5)
	}
	return HAM_IGNORED;
}


public fov_shake(id)
{
	message_begin( MSG_ONE, shake_value, { 0, 0, 0 }, id)
	write_short(1<<14)
	write_short(1<<12)
	write_short(1<<14)
	message_end()
}


public zp_round_ended(winteam)
{
	if (virus_mode == 1)
	{
		new iEnt;
		while((iEnt = engfunc(EngFunc_FindEntityByString, iEnt, "classname", "c4_bomb")))
		{
			if(pev_valid(iEnt))
				engfunc(EngFunc_RemoveEntity, iEnt);
		}

		new bEnt;
		while((bEnt= engfunc(EngFunc_FindEntityByString, bEnt, "classname", "dropped_c4_bomb")))
		{
			if(pev_valid(bEnt))
				engfunc(EngFunc_RemoveEntity, bEnt);
		}

		new sEnt;
		while((sEnt= engfunc(EngFunc_FindEntityByString, sEnt, "classname", "c4_sprite")))
		{
			if(pev_valid(sEnt))
				engfunc(EngFunc_RemoveEntity, sEnt);
		}

		virus_mode = 0

		static zid
		for (zid = 1; zid <= g_MaxPlayers; zid++)
		{
			if (is_user_alive(zid) && zp_get_user_zombie(zid))
			{
				remove_task(zid)
			}
		}
	}
}



public zp_user_infect_attempt(id, infector, nemesis)
{	
	if(infector && (virus_mode == 1))
	{
		return ZP_PLUGIN_HANDLED
	}
	return PLUGIN_CONTINUE
}


public zp_user_humanize_attempt(id, survivor)
{
	if(zp_get_user_zombie(id) && is_user_alive(id) && (virus_mode == 1))
	{
		return ZP_PLUGIN_HANDLED
	}
	return PLUGIN_CONTINUE
}

public zp_extra_item_selected(id, itemid)
{	
	if(zp_get_user_zombie(id) && is_user_alive(id) && (get_pcvar_num(virus_blocked_item) == 1) && (virus_mode == 1))
	{
		client_print(id,print_chat,"[ZP] You can't buy extra items.")
		return ZP_PLUGIN_HANDLED
	}
	return PLUGIN_CONTINUE
}


fn_GetPlaying()
{
	static iPlaying, id, team
	iPlaying = 0
	
	for (id = 1; id <= g_MaxPlayers; id++)
	{
		if (g_player_connected[id])
		{
			team = get_user_team(id)
			
			if (team != 3 && team != 0)
				iPlaying++
		}
	}
	
	return iPlaying;
}

GetRandomAliveHuman(n)
{
	static idAlive, id
	idAlive = 0
	
	for (id = 1; id <= g_MaxPlayers; id++)
	{
		if (is_user_alive(id) && !zp_get_user_zombie(id))
			idAlive++
		
		if (idAlive == n)
			return id;
	}
	
	return -1;
}

GetRandomAliveZombie(n)
{
	static idAlive, id
	idAlive = 0
	
	for (id = 1; id <= g_MaxPlayers; id++)
	{
		if (is_user_alive(id) && zp_get_user_zombie(id))
			idAlive++
		
		if (idAlive == n)
			return id;
	}
	
	return -1;
}


public client_disconnect(id)
{
	g_player_connected[id] = false

	if (zp_get_user_zombie(id) && (virus_mode == 1) && user_has_weapon(id, CSW_C4))
	{
		new lost = zp_get_zombie_count()
		if (lost > 0)
		{
			new Float:v_Origin[3], Float:v_End[3]
			pev(id, pev_origin, v_Origin)
				
			v_End[0] = v_Origin[0];
			v_End[1] = v_Origin[1];
			v_End[2] = -1337.0;
				
			engfunc(EngFunc_TraceLine, v_Origin, v_End, 0, id, 0)
			get_tr2(0, TR_vecEndPos, v_End)
		
			new iBomb = fm_create_entity("info_target")
			set_pev(iBomb, pev_classname, "dropped_c4_bomb")
			engfunc(EngFunc_SetOrigin, iBomb, v_End)
			engfunc(EngFunc_SetModel, iBomb, g_w_c4)
			set_pev(iBomb, pev_solid, SOLID_BBOX)

			FVecIVec(v_End, DropBomb[id])

			g_have_bomb[id] = false

			g_bomb_pickup = 0
			g_bomb_drop = 1
			g_bomb_plant = 0
		}
	}
}

public client_putinserver(id)
{
	g_player_connected[id] = true
}



stock ham_strip_weapon(id,weapon[])
{
	if(!equal(weapon,"weapon_",7)) return 0;
	
	new wId = get_weaponid(weapon);
	if(!wId) return 0;
	
	new wEnt;
	while((wEnt = engfunc(EngFunc_FindEntityByString, wEnt, "classname", weapon)) && pev(wEnt, pev_owner) != id) {}
	if(!wEnt) return 0;
	
	new iTmp;
	if(get_user_weapon(id, iTmp, iTmp) == wId) ExecuteHamB(Ham_Weapon_RetireWeapon, wEnt);
	
	if(!ExecuteHamB(Ham_RemovePlayerItem, id, any:wEnt)) return 0;
	
	ExecuteHamB(Ham_Item_Kill, wEnt);
	set_pev(id, pev_weapons, pev(id, pev_weapons) & ~(1<<wId));
	
	return 1;
}

stock ham_fakedamage_r(Float:origin[3], inflictor, Float:damage, Float:range)
{
	message_begin(MSG_BROADCAST, SVC_TEMPENTITY); 
	write_byte(TE_EXPLOSION);
	write_coord(floatround(origin[0])); 
	write_coord(floatround(origin[1]));      
	write_coord(floatround(origin[2]));
	write_short(g_eSprite);
	write_byte(40);
	write_byte(0); 
	write_byte(0); 
	message_end();

	message_begin(MSG_BROADCAST, SVC_TEMPENTITY); 
	write_byte(TE_EXPLOSION);
	write_coord(floatround(origin[0])); 
	write_coord(floatround(origin[1]));      
	write_coord(floatround(origin[2]));
	write_short(g_fSprite);
	write_byte(30);
	write_byte(0); 
	write_byte(0); 
	message_end();
	
	static Float:vOrigin[3], Float:fDistance, Float:fTmpDmg;
	
	for(new i = 1 ; i <= g_MaxPlayers ; i++)
	{
		client_print(i, print_center, "Explosion virus bomb !")

		if(!is_user_alive(i))
			continue;
				
		if (zp_get_user_zombie(i))
			continue;

		pev(i, pev_origin, vOrigin);
		fDistance = vector_distance(origin, vOrigin);
		
		if(fDistance <= range)
		{
			fTmpDmg = damage - (damage / range) * fDistance;
			ExecuteHamB(Ham_TakeDamage, i, any:inflictor, any:inflictor, any:fTmpDmg, any:DMG_BLAST);
		}
	}
}

stock fm_set_animation(id, animation)
{
	set_pev(id, pev_weaponanim, animation);
	
	message_begin(MSG_ONE, SVC_WEAPONANIM, {0, 0, 0}, id);
	write_byte(animation);
	write_byte(pev(id, pev_body));
	message_end();
}

stock msg_bar_time(id, scale)
{
	message_begin(MSG_ONE, g_BarTimeMsg, _, id);
	write_short(scale);
	message_end();
}

public message_TextMsg(msg_id, msg_dest, msg_entity)
{
	static szMessage[64];
	get_msg_arg_string(2, szMessage, sizeof szMessage - 1);
	
	if(equal(szMessage, "#C4_Plant_At_Bomb_Spot") && g_have_bomb[msg_entity])
		return 1;
	
	return 0;
}


public pos_ShowOnRadar(id) 
{
	if (!zp_get_user_zombie(id) && (virus_mode == 1))
	{
		if (Defusing == 0)
		{
			for (new i = 0; i < g_EntitySum; i++)
			{  
				message_begin(MSG_ONE_UNRELIABLE, g_msgHostagePos, {0,0,0}, id)
				write_byte(id)
				write_byte(i+22)
				write_coord(BuyZoneOrigin[i][0])
				write_coord(BuyZoneOrigin[i][1])
				write_coord(BuyZoneOrigin[i][2])
				message_end()

				message_begin(MSG_ONE_UNRELIABLE, g_msgHostageK, {0,0,0}, id)
				write_byte(i+22)
				message_end()
			}
		}
		if ((Defusing == 1) && (get_pcvar_num(virus_defuse_human) == 0))
		{
			for (new zi = 1; zi <= g_MaxPlayers; zi++)
			{  
				if (zp_get_user_zombie(zi) && is_user_alive(zi))
				{
					new ZombieOrigin[33][3]
					get_user_origin(zi, ZombieOrigin[zi])

					message_begin(MSG_ONE_UNRELIABLE, g_msgHostagePos, {0,0,0}, id)
					write_byte(id)
					write_byte(zi)
					write_coord(ZombieOrigin[zi][0])
					write_coord(ZombieOrigin[zi][1])
					write_coord(ZombieOrigin[zi][2])
					message_end()

					message_begin(MSG_ONE_UNRELIABLE, g_msgHostageK, {0,0,0}, id)
					write_byte(zi)
					message_end()
				}
			}
		}
	}

	if (zp_get_user_zombie(id) && (virus_mode == 1))
	{
		if (g_bomb_pickup == 1)
		{
			for (new ie = 0; ie < g_EntitySum; ie++)
			{  
				message_begin(MSG_ONE_UNRELIABLE, g_msgHostagePos, {0,0,0}, id)
				write_byte(id)
				write_byte(ie+21)
				write_coord(BuyZoneOrigin[ie][0])
				write_coord(BuyZoneOrigin[ie][1])
				write_coord(BuyZoneOrigin[ie][2])
				message_end()

				message_begin(MSG_ONE_UNRELIABLE, g_msgHostageK, {0,0,0}, id)
				write_byte(ie+21)
				message_end()
			}

			for (new zb = 1; zb <= g_MaxPlayers; zb++)
			{  
				if (zp_get_user_zombie(zb) && is_user_alive(zb) && user_has_weapon(zb, CSW_C4))
				{
					new ZombieBombOrigin[33][3]
					get_user_origin(zb, ZombieBombOrigin[zb])

					message_begin(MSG_ONE_UNRELIABLE, g_msgHostagePos, {0,0,0}, id)
					write_byte(id)
					write_byte(zb)
					write_coord(ZombieBombOrigin[zb][0])
					write_coord(ZombieBombOrigin[zb][1])
					write_coord(ZombieBombOrigin[zb][2])
					message_end()

					message_begin(MSG_ONE_UNRELIABLE, g_msgHostageK, {0,0,0}, id)
					write_byte(zb)
					message_end()
				}
			}
		}
		if (g_bomb_drop == 1)
		{
			for (new bd = 1; bd <= g_MaxPlayers; bd++)
			{  
				message_begin(MSG_ONE_UNRELIABLE, g_msgHostagePos, {0,0,0}, id)
				write_byte(id)
				write_byte(bd)
				write_coord(DropBomb[bd][0])
				write_coord(DropBomb[bd][1])
				write_coord(DropBomb[bd][2])
				message_end()

				message_begin(MSG_ONE_UNRELIABLE, g_msgHostageK, {0,0,0}, id)
				write_byte(bd)
				message_end()
			}
		}
		if (g_bomb_plant == 1)
		{
			for (new bp = 1; bp <= g_MaxPlayers; bp++)
			{  
				message_begin(MSG_ONE_UNRELIABLE, g_msgHostagePos, {0,0,0}, id)
				write_byte(id)
				write_byte(bp)
				write_coord(PlantBomb[bp][0])
				write_coord(PlantBomb[bp][1])
				write_coord(PlantBomb[bp][2])
				message_end()

				message_begin(MSG_ONE_UNRELIABLE, g_msgHostageK, {0,0,0}, id)
				write_byte(bp)
				message_end()
			}
		}
	}
}


bool:is_nearby_other(newOrigin[3])
{
   if (g_EntitySum)
   {
      for (new i=0;i<g_EntitySum;i++)
      {
         if (get_distance(BuyZoneOrigin[i],newOrigin)<get_pcvar_num(virus_plant_radius)
             && abs(BuyZoneOrigin[i][2]-newOrigin[2])<100)
            return true
      }
   }

   return false
}


bool:is_zone_bomb(new_Origin[3])
{
	if (get_distance(DropBombOrigin,new_Origin)<5 && abs(DropBombOrigin[2]-new_Origin[2])<100)
	{
		return true
	}

	return false
}