// Rambo!

/* CVARS - copy and paste to shconfig.cfg

//Rambo
rambo_level 10
rambo_health 125			//Health
rambo_armor 150			//Armor
rambo_m249mult 1.5			//Damage multiplier for PARA M249

*/

#include <amxmod>
#include <superheromod>

// GLOBAL VARIABLES
new gHeroName[]="Rambo"
new gHasRamboPower[SH_MAXSLOTS+1]

#define giveTotal 5
new weapArray[giveTotal][24] = {
	"weapon_hegrenade",
	"weapon_flashbang",
	"weapon_smokegrenade",
	"weapon_glock18",
	"weapon_m249"
}
//----------------------------------------------------------------------------------------------
public plugin_init()
{
	// Plugin Info
	register_plugin("SUPERHERO Rambo","1.1","Glooba")

	// DO NOT EDIT THIS FILE TO CHANGE CVARS, USE THE SHCONFIG.CFG
	register_cvar("rambo_level", "10")
	register_cvar("rambo_health", "125")
	register_cvar("rambo_armor", "150")
	register_cvar("rambo_m249mult", "1.5")

	// FIRE THE EVENT TO CREATE THIS SUPERHERO!
	shCreateHero(gHeroName, "Rambo Style", "Start with a Para and do more Para damage. More HP/AP, free Glock and all 3 Nade types.", false, "rambo_level" )

	// REGISTER EVENTS THIS HERO WILL RESPOND TO! (AND SERVER COMMANDS)
	register_srvcmd("rambo_init", "rambo_init")
	shRegHeroInit(gHeroName, "rambo_init")
	register_event("ResetHUD","newRound","b")

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

	// Let Server know about Rambo Variables
	// It is possible that another hero has more hps, less gravity, or more armor
	// so rather than just setting these - let the superhero module decide each round
	shSetMaxHealth(gHeroName, "rambo_health" )
	shSetMaxArmor(gHeroName, "rambo_armor" )
	shSetShieldRestrict(gHeroName)
}
//----------------------------------------------------------------------------------------------
public rambo_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 Rambo
	read_argv(2,temp,5)
	new hasPowers = str_to_num(temp)
	gHasRamboPower[id] = (hasPowers != 0)

	//Reset thier shield restrict status
	//Shield restrict MUST be before weapons are given out
	shResetShield(id)

	// Got to take away powers from a user that dropped Rambo
	if ( !hasPowers && is_user_connected(id) ) {
		shRemHealthPower(id)
		shRemArmorPower(id)
		rambo_dropweapon(id)
	}
	else {
		rambo_giveweapons(id)
	}
}
//----------------------------------------------------------------------------------------------
public newRound(id)
{
	if ( gHasRamboPower[id] && is_user_alive(id) && shModActive() ) {
		set_task(0.1,"rambo_giveweapons",id)
	}
}
//----------------------------------------------------------------------------------------------
public rambo_giveweapons(id)
{
	if ( !is_user_alive(id) || !gHasRamboPower[id] ) return

	for (new x = 0; x < giveTotal; x++) {
		shGiveWeapon(id, weapArray[x])
	}

	// Give CTs a Defuse Kit
	if ( get_user_team(id) == 2 ) shGiveWeapon(id,"item_thighpack")
}
//----------------------------------------------------------------------------------------------
public rambo_dropweapon(id)
{
	if ( !is_user_alive(id) ) return
	engclient_cmd(id,"drop", "weapon_m249")
}
//----------------------------------------------------------------------------------------------
public rambo_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 ( gHasRamboPower[attacker] && weapon == CSW_M249 && is_user_alive(id) ) {
		// do extra damage
		new extraDamage = floatround(damage * get_cvar_float("rambo_m249mult") - damage)
		if (extraDamage > 0) shExtraDamage( id, attacker, extraDamage, "m249", headshot )
	}
}
//----------------------------------------------------------------------------------------------