// SNAKE! - I'm assuming this is meant to be Solid Snake from the MGS games.

/*

//Snake
snake_level 0
snake_health 125		//Default 125
snake_armor 125		//Default 125
snake_uspmult 2.0		//Multiplier for usp damage
snake_healpoints 75		//Amount of health given by health ration
snake_cooldown 20		//Cooldown between uses of health ration

*/


/*
* v1.2 - vittu - 6/22/05
*      - Minor code clean up.
*
* v1.1 - vittu - 4/14/05
*      - Cleaned up and optimized code.
*      - Fixed Rations to get max health from Snake's health cvar.
*
*   hero created by Taker, "My First".
*/

#include <amxmod>
#include <superheromod>

// GLOBAL VARIABLES
new gHeroName[] = "Snake"
new bool:gHasSnakePower[SH_MAXSLOTS+1]
new gHealPoints, gMaxHealth
//----------------------------------------------------------------------------------------------
public plugin_init()
{
	// Plugin Info
	register_plugin("SUPERHERO Snake", "1.2", "Taker")

	// DO NOT EDIT THIS FILE TO CHANGE CVARS, USE THE SHCONFIG.CFG
	register_cvar("snake_level", "0")
	register_cvar("snake_health", "125")
	register_cvar("snake_armor", "125")
	register_cvar("snake_uspmult", "2.0")
	register_cvar("snake_healpoints", "75")
	register_cvar("snake_cooldown", "20")

	// FIRE THE EVENT TO CREATE THIS SUPERHERO!
	shCreateHero(gHeroName, "Health Rations & USP", "More Health, Free Armor, Free Powerful USP, and Health Rations on power key use.", true, "snake_level")

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

	// KEYDOWN
	register_srvcmd("snake_kd", "snake_kd")
	shRegKeyDown(gHeroName, "snake_kd")

	// NEW ROUND
	register_event("ResetHUD", "newSpawn", "b")

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

	// Let Server know about Snakes Variable
	shSetMaxHealth(gHeroName, "snake_health")
	shSetMaxArmor(gHeroName, "snake_armor")

	gHealPoints = get_cvar_num("snake_healpoints")
	gMaxHealth = get_cvar_num("snake_health")
}
//----------------------------------------------------------------------------------------------
public snake_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 ) {
			snake_weapons(id)
		}
		// This gets run if they had the power but don't anymore
		else if ( !hasPowers && gHasSnakePower[id] ) {
			if ( get_user_team(id) == 1 ) {
				engclient_cmd(id, "drop", "weapon_usp")
			}
			shRemHealthPower(id)
			shRemArmorPower(id)
		}
	}

	// Sets this variable to the current status
	gHasSnakePower[id] = (hasPowers != 0)
}
//----------------------------------------------------------------------------------------------
public newSpawn(id)
{
	if ( shModActive() && gHasSnakePower[id] && is_user_alive(id) ) {
		set_task(0.1, "snake_weapons", id)

		gPlayerUltimateUsed[id] = false
	}
}
//----------------------------------------------------------------------------------------------
public snake_weapons(id)
{
	// No need to give a USP to a CT
	if ( is_user_alive(id) && get_user_team(id) == 1) {
		shGiveWeapon(id,"weapon_usp")
	}
}
//----------------------------------------------------------------------------------------------
public snake_kd()
{
	// First Argument is an id
	new temp[6]
	read_argv(1,temp,5)
	new id = str_to_num(temp)

	if ( !is_user_alive(id) || !gHasSnakePower[id] ) return

	if ( gPlayerUltimateUsed[id] ) {
		playSoundDenySelect(id)
		return
	}

	shAddHPs(id, gHealPoints, gMaxHealth)

	if ( get_cvar_float("snake_cooldown") > 0.0 ) ultimateTimer(id, get_cvar_float("snake_cooldown"))

	// Snake Messsage
	new message[128]
	format(message, 127, "Snake - Ration Used")
	set_hudmessage(255, 0, 0, -1.0, 0.3, 0, 0.25, 1.0, 0.0, 0.0, 26)
	show_hudmessage(id, message)
}
//----------------------------------------------------------------------------------------------
public snake_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 ( gHasSnakePower[attacker] && weapon == CSW_USP && is_user_alive(id) ) {
		new extraDamage = floatround(damage * get_cvar_float("snake_uspmult") - damage)
		if (extraDamage > 0) shExtraDamage(id, attacker, extraDamage, "usp", headshot)
	}
}
//----------------------------------------------------------------------------------------------