//GRIM REAPER! Yea that guy with a Scythe that comes for you when you die.

/* CVARS - copy and paste to shconfig.cfg

//Grim Reaper
grimreaper_level 0
grimreaper_knifemult 10.0	//Multiplier for knife damage	(Default 10.0)
grimreaper_alpha 60			//Grim Reaper's invisibility (Default 60)
grimreaper_gravity 0.25		//Precent of normal gravity (Default 0.25)

*/

/*
* v1.1 - vittu - 12/10/05
*      - Code cleaned up. Cvars renamed.
*      - Set invisible on spawn, like Raiden (avoiding over use of render).
*      - Changed gravity cvar from 0 to .25, because 0 is normal gravity
*          not 0 gravity.
*
*  Same as Raiden (MGS2) by N4m3LesS`Jay, one is a rip of the other not sure which (both are rips of windwalker)
*   only difference is this has extaknife damage and instead of hp/ap this has low gravity.
*/

#include <amxmod>
#include <superheromod>

#if defined AMX_NEW
	#include <Vexd_Utilities>
#endif

#if defined AMX98
	#include <xtrafun>
#endif

// GLOBAL VARIBLES
new gHeroName[]="Grim Reaper"
new bool:ghasGrimPower[SH_MAXSLOTS+1]
//---------------------------------------------------------------------------------------------------------------------
public plugin_init()
{
	// Plugin Info
	register_plugin("SUPERHERO Grim Reaper", "1.1", "SniperX")

	// DO NOT EDIT THIS FILE TO CHANGE CVARS, USE THE SHCONFIG.CFG
	register_cvar("grimreaper_level", "0")
	register_cvar("grimreaper_alpha", "60")
	register_cvar("grimreaper_knifemult", "10.0")
	register_cvar("grimreaper_gravity", "0.25")

	// FIRE THE EVENT TO CREATE THIS SUPERHERO!
	shCreateHero(gHeroName, "Invisibility/Scythe/Float/Silent", "Invisibility/Knife=1 Hit KO/Low Gravity/Silent Walking", false, "grimreaper_level")

	// REGISTER EVENTS THIS HERO WILL RESPOND TO! (AND SERVER COMMANDS)
	// INIT
	register_srvcmd("grimreaper_init", "grimreaper_init")
	shRegHeroInit(gHeroName, "grimreaper_init")

	// EXTRA KNIFE DAMAGE
	register_event("Damage", "scythe_damage", "b", "2!0")

	// EVENTS
	register_event("ResetHUD", "newSpawn", "b")

	// Let Server know about Grim Reaper's Variables
	shSetMinGravity(gHeroName, "grimreaper_gravity")
}
//---------------------------------------------------------------------------------------------------------------------
public grimreaper_init()
{
	// First Argument is an id
	new temp[6]
	read_argv(1,temp,5)
	new id = str_to_num(temp)

	// 2nd Argument is 0 or 1 depending on whether the id has the hero
	read_argv(2,temp,5)
	new hasPowers = str_to_num(temp)

	if ( is_user_alive(id) ) {
		if ( hasPowers ) {
			invisible(id)
		}
		else if ( !hasPowers && ghasGrimPower[id] ) {
			shRemGravityPower(id)
			visible(id)
		}
	}

#if defined AMX_NEW

	ghasGrimPower[id] = (hasPowers != 0)
}
//----------------------------------------------------------------------------------------------
public client_prethink(id)
{
	if( ghasGrimPower[id] ) {
		Entvars_Set_Int(id, EV_INT_flTimeStepSound, 999)
	}
}

#else

	if ( hasPowers && is_user_connected(id) ) {
		set_user_footsteps(id, 1)
	}
	else if ( !hasPowers && ghasGrimPower[id] && is_user_connected(id) ) {
		set_user_footsteps(id, 0)
	}

	ghasGrimPower[id] = (hasPowers != 0)
}
#endif
//----------------------------------------------------------------------------------------------
public newSpawn(id)
{
	if ( ghasGrimPower[id] && is_user_connected(id) ) {
		set_task(1.0, "invisible", id)
		#if !defined AMX_NEW
			set_user_footsteps(id, 1)
		#endif
	}
}
//----------------------------------------------------------------------------------------------
public invisible(id)
{
	if ( !is_user_alive(id) ) return

	set_user_rendering(id, kRenderFxGlowShell, 8, 8, 8, kRenderTransAlpha, get_cvar_num("grimreaper_alpha"))
}
//----------------------------------------------------------------------------------------------
public visible(id)
{
	if ( !is_user_alive(id) ) return

	set_user_rendering(id)
}
//----------------------------------------------------------------------------------------------
public scythe_damage(id)
{
	if ( !shModActive() || !is_user_alive(id) ) return

	new damage = read_data(2)
	new weapon, bodypart, attacker = get_user_attacker(id, weapon, bodypart)
	new headshot = (bodypart == 1) ? 1 : 0

	if ( attacker <= 0 || attacker > SH_MAXSLOTS ) return

	if ( ghasGrimPower[attacker] && weapon == CSW_KNIFE && is_user_alive(id) ) {
		// do extra damage
		new extraDamage = floatround(damage * get_cvar_float("grimreaper_knifemult") - damage)
		if (extraDamage > 0) shExtraDamage( id, attacker, extraDamage, "knife", headshot)
	}
}
//---------------------------------------------------------------------------------------------------------------------