// STICK! - Daredevil's Mentor/Sensei, guided Daredevil in mastering his "radar sense," which resembled Stick's own "proximity sense".

/* CVARS - copy and paste to shconfig.cfg

//Stick
stick_level 0
stick_speed 560		//How fast Stick runs (def 560)
stick_radius 1024		//Radius of the rings (def 1024)
stick_bright 192		//How bright to make the rings (def 192)
stick_teamcolored 0		//0=default color 1=team colored rings
stick_enemyonly 0		//0=rings on all players 1=rings on enemy only

*/

/*
* v1.4 - vittu - 7/3/05
*      - Fixed crash to AMX caused by the previous update, since
*          AMX can't register a MSG_ONE_UNRELIABLE message.
*
* v1.3 - vittu - 6/22/05
*      - Minor code clean up.
*
* v1.2 - vittu - 4/2/05
*      - Fixed rings to be displayed off players instead of 1024 above them.
*      - Renamed Hero to Stick, can not find any info on who/what Ithius is.
*      - Lowered rings a bit from Daredevil height.
*      - Added cvars: radius, team colored option, enemy only option.
*
*    Hero orginally named Ithius Created by a|eX, from orginal script: "Thanks alot to Necro for helping me".
*    Hero was Ripped from Daredevil, was orginally same as daredevil only with a larger radius.
*/

#include <amxmod>
#include <superheromod>

// GLOBAL VARIABLES
new gHeroName[]="Stick"
new bool:gHasStickPower[SH_MAXSLOTS+1]
new gSpriteWhite, gRadius, gBright
//----------------------------------------------------------------------------------------------
public plugin_init()
{
	// Plugin Info
	register_plugin("SUPERHERO Stick", "1.4", "a|eX / vittu")

	// DO NOT EDIT THIS FILE TO CHANGE CVARS, USE THE SHCONFIG.CFG
	register_cvar("stick_level", "0")
	register_cvar("stick_speed", "560")
	register_cvar("stick_radius", "1024")
	register_cvar("stick_bright", "192")
	register_cvar("stick_teamcolored", "0")
	register_cvar("stick_enemyonly", "0")

	// FIRE THE EVENT TO CREATE THIS SUPERHERO!
	shCreateHero(gHeroName, "Proximity Sense", "Longer ESP Rings show you when other players are approaching, also run faster.", false, "stick_level")

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

	//ESP Rings Task
	set_task(2.0, "stick_senseloop", 0, "", 0, "b")

	// Let Server know about Stick's varibles
	shSetMaxSpeed(gHeroName, "stick_speed", "[0]")
}
//----------------------------------------------------------------------------------------------
public plugin_precache()
{
	gSpriteWhite = precache_model("sprites/white.spr")
}
//----------------------------------------------------------------------------------------------
public stick_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)

	// This gets run if they had the power but don't anymore
	if ( !hasPowers && gHasStickPower[id]  && is_user_alive(id) ) {
		shRemSpeedPower(id)
	}

	// Sets this variable to the current status
	gHasStickPower[id] = (hasPowers!=0)
}
//----------------------------------------------------------------------------------------------
public stick_senseloop()
{
	if ( !shModActive() ) return

	new players[SH_MAXSLOTS], pnum
	new idring, id, vec1[3], rgb[3]

	gRadius = get_cvar_num("stick_radius")
	gBright = get_cvar_num("stick_bright")

	get_players(players, pnum, "a")

	for (new i = 0; i < pnum; i++) {
		id = players[i]
		if ( !gHasStickPower[id] || !is_user_alive(id) ) continue

		for(new r = 0; r < pnum; r++) {
			idring = players[r]
			if ( !is_user_alive(idring) || idring == id ) continue

			if ( get_cvar_num("stick_enemyonly") ) {
				if ( get_user_team(id) == get_user_team(idring) ) continue
			}

			if ( !get_user_origin(idring, vec1) ) continue

			// Set ring color
			if ( !get_cvar_num("stick_teamcolored") ) {
				rgb = {100, 100, 255} //default same color as daredevil
			}
			// Terrorist
			else if ( get_user_team(idring) == 1 ) {
				rgb = {255, 35, 35}
			}
			// Counter-Terrorist
			else {
				rgb = {35, 35, 255}
			}

			//TE_BEAMCYLINDER
			message_begin(MSG_ONE, SVC_TEMPENTITY, vec1, id)
			write_byte(21)
			write_coord(vec1[0])		// center position
			write_coord(vec1[1])
			write_coord(vec1[2] + 13)
			write_coord(vec1[0])		// axis and radius
			write_coord(vec1[1])
			write_coord(vec1[2] + gRadius)
			write_short(gSpriteWhite)	// sprite index
			write_byte(0)		// startframe
			write_byte(1)		// frame rate in 0.1's
			write_byte(6)		// life in 0.1's
			write_byte(8)		// line width in 0.1's
			write_byte(1)		// noise amplitude in 0.01's
			write_byte(rgb[0])	// r
			write_byte(rgb[1])	// g
			write_byte(rgb[2])	// b
			write_byte(gBright)	// brightness
			write_byte(0)		// scroll speed in 0.1's
			message_end()
		}
	}
}
//----------------------------------------------------------------------------------------------
public client_connect(id)
{
	gHasStickPower[id] = false
}
//----------------------------------------------------------------------------------------------