/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <codmod>
#include <hamsandwich>
#include <engine>
 
#define DMG_BULLET (1<<1)

new const nazwa[] = "Tropiciel";
new const opis[] = "1/2 z scouta, Radar";
new const bronie = 1<<CSW_SCOUT
new const zdrowie = 15;
new const kondycja = 15;
new const inteligencja = -10;
new const wytrzymalosc = -15;

new bool: ma_klase[33];
new g_msgHostageAdd, g_msgHostageDel;

public plugin_init() 
{
	register_plugin(nazwa, "1.0", "Play");
	
	g_msgHostageAdd = get_user_msgid("HostagePos");
	g_msgHostageDel = get_user_msgid("HostageK");
	
	cod_register_class(nazwa, opis, bronie, zdrowie, kondycja, inteligencja, wytrzymalosc);
	
	set_task (2.0,"radar_scan",_,_,_,"b");
	RegisterHam(Ham_TakeDamage, "player", "TakeDamage");
}
public cod_class_enabled(id)
{
	ma_klase[id] = true;
	
}
	  
public cod_class_disabled(id)
{
	ma_klase[id] = false;
}

public TakeDamage(this, idinflictor, idattacker, Float:damage, damagebits)
{
	if(!is_user_connected(idattacker))
		return HAM_IGNORED; 
	
	if(!ma_klase[idattacker])
		return HAM_IGNORED;
	
	if(damagebits & DMG_BULLET)
	{
		new weapon = get_user_weapon(idattacker);
		
		if(weapon == CSW_SCOUT && random_num(1,2) == 1) 
			cod_inflict_damage(idattacker, this, float(get_user_health(this))-damage+1.0, 0.0, idinflictor, damagebits);
			
	}
	
	return HAM_IGNORED;
}
public radar_scan(id)
{
	new PlayerCoords[3];
                
	for (new id=1; id<=32; id++)
	{
		if((!is_user_alive(id))||(!ma_klase[id])) continue;
                        
		for (new i=1;i<=32;i++)
		{       
			if(!is_user_alive(i) || get_user_team(i) == get_user_team(id)) continue;
			
			get_user_origin(i, PlayerCoords)
                                
			message_begin(MSG_ONE_UNRELIABLE, g_msgHostageAdd, {0,0,0}, id)
			write_byte(id)
			write_byte(i)           
			write_coord(PlayerCoords[0])
			write_coord(PlayerCoords[1])
			write_coord(PlayerCoords[2])
			message_end()
                                
			message_begin(MSG_ONE_UNRELIABLE, g_msgHostageDel, {0,0,0}, id)
			write_byte(i)
			message_end()
		}
	}
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1045\\ f0\\ fs16 \n\\ par }
*/