/* Plugin generated by AMXX-Studio */

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

new const nazwa[] = "Demolitions";
new const opis[] = "Ma dynamit, ktory moze podlozyc raz na runde.";
new const bronie = 1<<CSW_AUG | 1<<CSW_HEGRENADE | 1<<CSW_SMOKEGRENADE | 1<<CSW_FLASHBANG;
new const zdrowie = 10;
new const kondycja = 15;
new const inteligencja = 0;
new const wytrzymalosc = 30;


new bool:ma_dynamit[33];

new sprite_blast,
     sprite_white;

public plugin_init() 
{
	register_plugin(nazwa, "1.0", "QTM_Peyote")
	
	cod_register_class(nazwa, opis, bronie, zdrowie, kondycja, inteligencja, wytrzymalosc);
	
	register_event("ResetHUD", "ResetHUD", "abe");
	register_event("HLTV", "NowaRunda", "a", "1=0", "2=0");
}

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

public cod_class_enabled(id)
	ma_dynamit[id] = true;

public cod_class_skill_used(id)
{		
	if(!ma_dynamit[id] || !is_user_alive(id))
		return PLUGIN_CONTINUE;
		
	static dynamit_gracza[33];
	if(is_valid_ent(dynamit_gracza[id]))
	{
		ma_dynamit[id] = false;
		
		new Float:fOrigin[3];
		entity_get_vector(dynamit_gracza[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] + 250 );
		write_coord( iOrigin[2] + 250 );
		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(dynamit_gracza[id], "player", 250.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, 95.0, 0.8, dynamit_gracza[id], (1<<24));
		}
		remove_entity(dynamit_gracza[id]);
		return PLUGIN_CONTINUE;
	}
		
	new Float:origin[3];
	entity_get_vector(id, EV_VEC_origin, origin);
		
	dynamit_gracza[id] = create_entity("info_target");
	entity_set_string(dynamit_gracza[id], EV_SZ_classname, "dynamite");
	entity_set_edict(dynamit_gracza[id], EV_ENT_owner, id);
	entity_set_int(dynamit_gracza[id], EV_INT_movetype, MOVETYPE_TOSS);
	entity_set_origin(dynamit_gracza[id], origin);
	entity_set_int(dynamit_gracza[id], EV_INT_solid, SOLID_BBOX);
	
	entity_set_model(dynamit_gracza[id], "models/QTM_CodMod/dynamite.mdl");
	entity_set_size(dynamit_gracza[id], Float:{-16.0,-16.0,0.0}, Float:{16.0,16.0,2.0});
	
	drop_to_floor(dynamit_gracza[id]);
	
	return PLUGIN_CONTINUE;
}	

public ResetHUD(id)
{
	client_disconnect(id);
	ma_dynamit[id] = true;
}

public client_disconnect(id)
{
	new ent = find_ent_by_class(0, "dynamite");
	while(ent > 0)
	{
		if(entity_get_edict(id, EV_ENT_owner) == id)
			remove_entity(ent);
		ent = find_ent_by_class(ent, "dynamite");
	}
}

public NowaRunda()
{
	new ent = find_ent_by_class(-1, "dynamite");
	while(ent > 0) 
	{
		remove_entity(ent);
		ent = find_ent_by_class(ent, "dynamite");	
	}
}
