// CAPTAIN AMERICA!

/* CVARS - copy and paste to shconfig.cfg

//Captain America
captaina_level 0
captaina_pctperlev 0.02		//Percentage that factors into godmode randomness
captaina_godsecs 1			//# of seconds of god mode

*/

#include <amxmod>
#include <superheromod>

// GLOBAL VARIABLES
new gHeroName[]="Captain America"
new bool:gHasCaptainAPowers[SH_MAXSLOTS+1]
new gPlayerLevels[SH_MAXSLOTS+1]
//----------------------------------------------------------------------------------------------
public plugin_init()
{
	// Plugin Info
	register_plugin("SUPERHERO Captain America","1.18","{HOJ} Batman/JTP10181")

	// DO NOT EDIT THIS FILE TO CHANGE CVARS, USE THE SHCONFIG.CFG
	register_cvar("captaina_level", "0" )
	register_cvar("captaina_pctperlev", "0.02" )
	register_cvar("captaina_godsecs", "1" )

	// FIRE THE EVENT TO CREATE THIS SUPERHERO!
	shCreateHero(gHeroName, "Super Shield", "Random Invincibility", false, "captaina_level" )

	// REGISTER EVENTS THIS HERO WILL RESPOND TO! (AND SERVER COMMANDS)

	// INIT
	register_srvcmd("captaina_init", "captaina_init")
	shRegHeroInit(gHeroName, "captaina_init")

	// OK Random Generator
	set_task(1.0,"captaina_loop",0,"",0,"b" )

	// LEVELS
	register_srvcmd("captaina_levels", "captaina_levels")
	shRegLevels(gHeroName,"captaina_levels")

}
//----------------------------------------------------------------------------------------------
public captaina_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 wolverine skills
	read_argv(2,temp,5)
	new hasPowers=str_to_num(temp)

	gHasCaptainAPowers[id] = (hasPowers!=0)
}
//----------------------------------------------------------------------------------------------
public captaina_levels()
{
	new id[5]
	new lev[5]

	read_argv(1,id,4)
	read_argv(2,lev,4)

	gPlayerLevels[str_to_num(id)] = str_to_num(lev)
}
//----------------------------------------------------------------------------------------------
public captaina_loop()
{
	new players[32], count, id
	get_players(players,count,"ac")

	for ( new x = 0; x < count; x++ ) {
		id = players[x]
		if ( gHasCaptainAPowers[id] && is_user_alive(id) ) {
			new randNum = random_num(0, 100 )
			new heroLevel = floatround(gPlayerLevels[id] * get_cvar_float("captaina_pctperlev") * 100)
			//server_print("setting god mode: heroLevel=%d, randNum=%d", heroLevel, randNum)
			if ( heroLevel >= randNum && !get_user_godmode(id) ) {
				shSetGodMode(id,get_cvar_num("captaina_godsecs"))
				setScreenFlash(id, 0, 0, 255, 10, 50 )  //Quick Blue Screen Flash Letting You know about god mode
			}
		}
	}
}
//----------------------------------------------------------------------------------------------
public client_connect(id)
{
	gHasCaptainAPowers[id] = false
}
//----------------------------------------------------------------------------------------------