/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <engine>
#include <codmod>

new const nazwa[] = "Autodestrukcja";
new const opis[] = "Natychmiastowa smierc twoja i wrogow w twoim otoczeniu";

new sprite_blast,
     sprite_white;

public plugin_init()
 {
	register_plugin(nazwa, "1.0", "QTM_Peyote");
	
	cod_register_perk(nazwa, opis);
}

public plugin_precache()
{
	sprite_white = precache_model("sprites/white.spr");
	sprite_blast = precache_model("sprites/dexplo.spr");
}

public cod_perk_used(id)
{
	if(!is_user_alive(id))
		return PLUGIN_CONTINUE;
		
	new Float:fOrigin[3];
	entity_get_vector(id, EV_VEC_origin, fOrigin);
	
	new iOrigin[3];
	for(new i=0;i<3;i++)
		iOrigin[i] = floatround(fOrigin[i]);
	
	message_begin(MSG_BROADCAST,SVC_TEMPENTITY, iOrigin);
	write_byte(TE_EXPLOSION);
	write_coord(iOrigin[0]);
	write_coord(iOrigin[1]);
	write_coord(iOrigin[2]);
	write_short(sprite_blast);
	write_byte(32); 
	write_byte(20); 
	write_byte(0);
	message_end();
		
	message_begin( MSG_BROADCAST, SVC_TEMPENTITY, iOrigin );
	write_byte( TE_BEAMCYLINDER );
	write_coord( iOrigin[0] );
	write_coord( iOrigin[1] );
	write_coord( iOrigin[2] );
	write_coord( iOrigin[0] );
	write_coord( iOrigin[1] + 200 );
	write_coord( iOrigin[2] + 200 );
	write_short( sprite_white );
	write_byte( 0 ); 
	write_byte( 0 ); 
	write_byte( 10 ); 
	write_byte( 10 ); 
	write_byte( 255 ); 
	write_byte( 255 ); 
	write_byte( 100 );
	write_byte( 100 ); 
	write_byte( 128 ); 
	write_byte( 0 ); 
	message_end();
	
	new entlist[33];
	new numfound = find_sphere_class(id, "player", 200.0 , entlist, 32);
		
	for (new i=0; i < numfound; i++)
	{		
		new pid = entlist[i];
	
		if (is_user_alive(pid) && get_user_team(id) != get_user_team(pid))
			cod_inflict_damage(id, pid, float(get_user_health(pid)), 0.0);
	}
	user_silentkill(id);
		
	return PLUGIN_CONTINUE;
}

