/*===============================================================================
/
/
/				[ZP] Class : Ghost Zombie
/				   ( Another Zombie )
/				      by The_Thing 
/
/
/	Description :
/			
/			This is another zombie class only this zombie will be invisble like ghost.
/			Zombie can be noticed with his blue glow, of course You can change glow to lower color.
/
/	
/
/	Cvars :
/
/			zp_ghost_glow_red  	"0"	- This is red color.
/			zp_ghost_glow_green 	"0"	- This is green color.
/			zp_ghost_glow_blue 	"255" 	- This is blue color, you can set it lower.
/
/
/
/	Changelog :
/
/			10/11/2008 - v1.0 - First test
/			11/11/2008 - v1.1 - added zombie can't be visible if it will be frozen.
/			23/12/2008 - v1.2.2 - added 2 more cvars for red and green color, changed zombie stats was so weak, now ghost zombie will be fall restist.
/
/
*/

#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#include <hlsdk_const>
#include <zombieplague>

#define PLUGIN "[ZP] Class : Ghost Zombie"
#define VERSION "1.2.2"
#define AUTHOR "The_Thing aka Fry"

new g_zclass11_ghost, g_glow_red, g_glow_green, g_glow_blue
new bool:g_AreGhost[33], bool:g_Frozen[33]

new const zclass11_name[] = { "Ghost Zombie" }
new const zclass11_info[] = { "HP+++ Speed- Knockback+ Fall RESIST" }
new const zclass11_model[] = { "zombie_source" }
new const zclass11_clawmodel[] = { "v_knife_zombie.mdl" }
const zclass11_health = 2450
const zclass11_speed = 190
const Float:zclass11_gravity = 1.0
const Float:zclass11_knockback = 1.35


public plugin_init()
{
	register_cvar("zp_zclass_ghost_zombie",VERSION,FCVAR_SERVER|FCVAR_EXTDLL|FCVAR_UNLOGGED|FCVAR_SPONLY)
	
	g_glow_red = register_cvar("zp_ghost_glow_red", "0")
	g_glow_green = register_cvar("zp_ghost_glow_green", "0")
	g_glow_blue  = register_cvar("zp_ghost_glow_blue",  "255")
	
	RegisterHam(Ham_TakeDamage, "player", "fw_TakeDamage")
}

public plugin_precache()
{
	g_zclass11_ghost = zp_register_zombie_class(zclass11_name, zclass11_info, zclass11_model, zclass11_clawmodel, zclass11_health, zclass11_speed, zclass11_gravity, zclass11_knockback)
}

public client_putinserver(id)
{
	g_AreGhost[id] = false
	g_Frozen[id] = false
	fm_set_rendering(id, kRenderFxGlowShell, 0, 0, 0, kRenderNormal, 255)	
}

public client_disconnect(id)
{
	g_AreGhost[id] = false
	g_Frozen[id] = false
}

public ghost_zombie(player)
{
	if (!get_pcvar_num(g_glow_blue) || !is_user_alive(player) || !zp_get_user_zombie(player))
	{
		fm_set_rendering(player, kRenderFxGlowShell, 0, 0, 0, kRenderNormal, 255)
		g_AreGhost[player] = false
		return FMRES_IGNORED
	}
		
	if (zp_get_user_zombie_class(player) != g_zclass11_ghost)
	{
		g_AreGhost[player] = true
		return PLUGIN_CONTINUE
	}
	
	if (get_pcvar_num(g_glow_blue) && g_Frozen[player])
	{
		fm_set_rendering(player, kRenderFxGlowShell, get_pcvar_num(g_glow_red), get_pcvar_num(g_glow_green), get_pcvar_num(g_glow_blue), kRenderTransAlpha, 5)
	}
	return PLUGIN_CONTINUE
}

public frozen_zombie(player)
{
	if (!get_pcvar_num(g_glow_blue) || !is_user_alive(player) || !zp_get_user_zombie(player) || g_Frozen[player])
		return FMRES_IGNORED
	
	if (get_pcvar_num(g_glow_blue) && zp_get_user_zombie(player) && g_Frozen[player])
	{
		g_Frozen[player] = true
		fm_set_rendering(player, kRenderFxGlowShell, get_pcvar_num(g_glow_red), get_pcvar_num(g_glow_green), get_pcvar_num(g_glow_blue), kRenderTransAlpha, 5)
	}
	return PLUGIN_CONTINUE
}

public zp_user_infected_post(player, infector)
{
	if (zp_get_user_zombie_class(player) == g_zclass11_ghost)
	{
		fm_set_rendering(player, kRenderFxGlowShell, get_pcvar_num(g_glow_red), get_pcvar_num(g_glow_green), get_pcvar_num(g_glow_blue), kRenderTransAlpha, 5)
	}
}

public fw_TakeDamage(victim, inflictor, attacker, Float:damage, damage_type)
{
	// Victim is not taking damage from a fall
	if (!(damage_type & DMG_FALL))
		return HAM_IGNORED;

	if (!zp_get_user_zombie(victim) || zp_get_user_zombie_class(victim) != g_zclass11_ghost)
		return HAM_IGNORED;
	
	return HAM_SUPERCEDE;
}

stock fm_set_rendering(entity, fx = kRenderFxNone, r = 255, g = 255, b = 255, render = kRenderNormal, amount = 16) 
{
	new Float:RenderColor[3];
	RenderColor[0] = float(r);
	RenderColor[1] = float(g);
	RenderColor[2] = float(b);

	set_pev(entity, pev_renderfx, fx);
	set_pev(entity, pev_rendercolor, RenderColor);
	set_pev(entity, pev_rendermode, render);
	set_pev(entity, pev_renderamt, float(amount));

	return 1;
}
