/*
*	----------------------------------------
*	-----[ZP] Zombie Class: Bloodsucker-----
*	----------------------------------------
*	---------Author: 4eRT (aka pff)---------
*	----------------------------------------
*		About:
*	I think ghost zombie, speed boost and invisibility are such cheater things that i made this plugin ;)
*	Bloodsucker abilities are copied from STALKER.
*	-----------------------------------
*		Discription:
*	Bloodsucker can be invisible for x seconds  and its speed increase to x u/s , step sounds stop.
*	After Bloodsucker infects smb it recieves 100 HP. Bloodsucker can use ability every 30 seconds.
*	-----------------------------------
*		Credits:
*	Fry! - greate thx for your done speed boost and invisible plugin ^_^
*	fezh - for helping with code
*	hoboman313/Zenix - for status icon tutorial (weapon_icons plugin).
*	-----------------------------------
*		Cvars:
*	zp_bloodsucker_ability_long 10 // how long Bloodsucker can have his ability. def=10sec
*	zp_bloodsucker_increase_speed 300 // increased speed. def=300
*	zp_bloodsucker_gravity 800 // increased gravity. def=800 (no increase)
*	zp_bloodsucker_visible_amount 0 // amount of visibility (0-full invisible, 255-full visible) def=0
*	zp_bloodsucker_infect_hp 100 // additional hp after Bloodsucker infect smb(like leach zombie). def=100
*	zp_bloodsucker_cooldown 30 // time in sec after Bloodsucker can use its ability again.
*	-----------------------------------
*		Modules:
*	fakemeta
*	fun
*	-----------------------------------
*		History:
*	0.1b (05.01.10)
*		First release.
*	0.2b (06.01.10)
*		Fakemeta stocks are rewritten to fun module functions.
*	1.0 (08.01.10)
*		Added autobind menu. Added gravity cvar.
*	1.1 (09.01.10)
*		Fixed some mistakes. Added hudmessages.
*	1.2 (17.01.10)
*		Fixed some bugs. Added hud icon.
*	-----------------------------------
*/

#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <fakemeta>
#include <zombieplague>

#define PLUGIN "[ZP] Class Bloodsucker"
#define VERSION "1.2"
#define AUTHOR "4eRT"

//Some vars
new g_zclass_bloodsucker, g_maxplayers, g_status
new g_sndInv[] = "zombie_plague/bloodsucker_invisible.wav"
new cvar_ability_time, cvar_invamount, cvar_speed, cvar_infect_hp, cvar_cooldown, cvar_gravity, cvar_icon
new Float:g_last[33]
new keys = MENU_KEY_1|MENU_KEY_2|MENU_KEY_3
new g_icon[33][16]
new bool: g_ability[33], bool: g_bind[33] = false, bool: g_use[33]

//Bloodsucker Atributes
new const zclass_name[] = { "Bloodsucker" }
new const zclass_info[] = { "Invisible + speed" }
new const zclass_model[] = { "zombie_source" }
new const zclass_clawmodel[] = { "v_knife_zombie.mdl" }
const zclass_health = 1600
const zclass_speed = 190
const Float:zclass_gravity = 1.0
const Float:zclass_knockback = 1.0

public plugin_init()
{
	cvar_ability_time = register_cvar("zp_bloodsucker_ability_long", "10")
	cvar_invamount = register_cvar("zp_bloodsucker_visible_amount", "0")
	cvar_speed = register_cvar("zp_bloodsucker_max_speed", "300")
	cvar_infect_hp = register_cvar("zp_bloodsucker_infect_hp", "600")
	cvar_cooldown = register_cvar("zp_bloodsucker_cooldown", "30")
	cvar_gravity = register_cvar("zp_bloodsucker_gravity", "800")
	cvar_icon = register_cvar("zp_bloodsucker_icon", "1")
	
	register_clcmd("ability","ability", ADMIN_ALL, "bind ^"key^" ^"ability^"")
	register_forward(FM_PlayerPreThink, "fw_ppt")
	register_event("HLTV", "newround", "a", "1=0", "2=0")
	register_event("DeathMsg", "death", "a")
	register_menucmd(register_menuid("Do you want to bind P ability?"), keys, "bind_p")
	
	g_status = get_user_msgid("StatusIcon")
}

public plugin_precache()
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	g_zclass_bloodsucker = zp_register_zombie_class(zclass_name, zclass_info, zclass_model, zclass_clawmodel, zclass_health, zclass_speed, zclass_gravity, zclass_knockback)
	precache_sound(g_sndInv)
}

public zp_user_infected_post(id, infector)
{
	if (zp_get_user_zombie_class(infector) == g_zclass_bloodsucker)
	{
		set_pev(infector, pev_health, float(pev(infector, pev_health) + get_pcvar_num(cvar_infect_hp)))
		set_hudmessage(255, 0, 0, -1.0, 0.45, 0, 0.0, 3.0, 0.01, 0.01, -1)
		show_hudmessage(infector, "+%i HP!", get_pcvar_num(cvar_infect_hp))
	}
	
	if (zp_get_user_zombie_class(id) == g_zclass_bloodsucker)
	{
		g_ability[id] = false
		set_user_rendering(id, kRenderFxNone, 0, 0, 0, kRenderNormal, 255)
		set_user_maxspeed(id, float(zclass_speed))
		set_user_gravity(id, zclass_gravity)
		
		if (!g_bind[id])
		{
			new menu[192]
			format(menu, 191, "Do you want to bind P ability?^n^n1. Yes^n2. No^n3. Ability on +USE")
			show_menu(id, keys, menu)
		}
	}
}

public zp_user_humanized_post(id)
	if(zp_get_user_zombie_class(id) == g_zclass_bloodsucker)
		ability_end(id)

public bind_p(id, keys)
{
	g_bind[id] = true
	switch(keys)
	{
		case 0:
			client_cmd(id, "bind p ability")
		
		case 1:
			client_print(id, print_chat, "[ZP] To be invisible and increase your speed type in console: bind ^'^'key^'^' ^'^'ability^'^'. And than press it!")
		
		case 2:
			g_use[id] = true
		
		default:
			g_bind[id] = false
	}
	
	return PLUGIN_HANDLED
}

public ability(id)
{
	if (zp_get_user_zombie(id) && (zp_get_user_zombie_class(id) == g_zclass_bloodsucker))
	{
		if(g_ability[id])
		{
			client_print(id, print_chat, "[ZP] You are already invisible and have maximum speed.")
			return PLUGIN_HANDLED
		}
		
		if(!is_user_alive(id))
		{
			client_print(id, print_chat, "[ZP] You are dead now. Dead people can't use abilities.")
			return PLUGIN_HANDLED
		}
		
		static Float: i
		i = get_pcvar_float(cvar_cooldown)
		
		if (get_gametime() - g_last[id] < i) {
			client_print(id, print_chat, "[ZP] Wait %.f0 sec. to use your ability!", get_pcvar_float(cvar_cooldown) - (get_gametime() - g_last[id]))
			return PLUGIN_HANDLED
		} else {
			set_user_rendering(id, kRenderFxGlowShell, 0, 0, 0, kRenderTransAlpha, get_pcvar_num(cvar_invamount))
			set_user_maxspeed(id, get_pcvar_float(cvar_speed))
			set_user_gravity(id, get_pcvar_float(cvar_gravity) / 800)
			emit_sound(id, CHAN_BODY, g_sndInv, 1.0, ATTN_NORM, 0, PITCH_HIGH)
			set_hudmessage(200, 100, 0, -1.0, 0.85, 0, 0.0, 3.0, 0.01, 0.01, -1)
			show_hudmessage(id, "You are now invisible. Time to hunt!")
			set_task(get_pcvar_float(cvar_ability_time), "ability_end", id)
			if(get_pcvar_num(cvar_icon) == 1)
				set_icon(id)
			g_ability[id] = true
		}
	}
	return PLUGIN_CONTINUE
}

public ability_end(id)
{
	set_user_rendering(id, kRenderFxNone, 0, 0, 0, kRenderNormal, 255)
	set_user_maxspeed(id, float(zclass_speed))
	set_user_gravity(id, zclass_gravity)
	
	if (get_pcvar_num(cvar_cooldown) > 0)
		client_print(id, print_chat, "[ZP] Wait %i sec to use your ability again.", get_pcvar_num(cvar_cooldown))
	
	if(get_pcvar_num(cvar_icon) == 1)
		delete_icon(id)
	
	g_last[id] = get_gametime()
	g_ability[id] = false
}

public fw_ppt(id)
{
	if (!is_user_alive(id) || !zp_get_user_zombie(id))
		return FMRES_IGNORED
	
	if (g_use[id])
	{
		static button, oldbutton
		button = get_user_button(id)
		oldbutton = get_user_oldbutton(id)
		
		if (!(button & IN_USE) && (oldbutton & IN_USE))      
			ability(id)
	}
	
	if (g_ability[id] && (zp_get_user_zombie_class(id) == g_zclass_bloodsucker) && zp_get_user_zombie(id))
	{
		set_user_rendering(id, kRenderFxGlowShell, 0, 0, 0, kRenderTransAlpha, get_pcvar_num(cvar_invamount))
		set_user_maxspeed(id, get_pcvar_float(cvar_speed))
		set_pev(id, pev_flTimeStepSound, 999)
		set_user_gravity(id, get_pcvar_float(cvar_gravity) / 800)
	}
	
	return PLUGIN_CONTINUE
}

public newround()
{
	g_maxplayers = get_maxplayers()
	
	for (new id = 1; id <= g_maxplayers; id++)
	{
		g_last[id] = get_gametime()
		g_ability[id] = false
	}
}

public death()
{
	new id = read_data(2)
	ability_end(id)
	return PLUGIN_HANDLED
}

public set_icon(id)
{
	static color[3], sprite[16]
	color = {250, 250, 250}
	sprite = "dmg_gas"
	g_icon[id] = sprite
	
	message_begin(MSG_ONE, g_status, {0, 0, 0}, id)
	write_byte(1)
	write_string(g_icon[id])
	write_byte(color[0])
	write_byte(color[1])
	write_byte(color[2])
	message_end()
}

public delete_icon(id) 
{
	message_begin(MSG_ONE, g_status, {0, 0, 0}, id)
	write_byte(0)
	write_string(g_icon[id])
	message_end()
}

stock get_user_button(id)
	return pev(id, pev_button)

stock get_user_oldbutton(id)
	return pev(id, pev_oldbuttons)
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1049\\ f0\\ fs16 \n\\ par }
*/
