/* Plugin generated by AMXX-Studio */

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

#define FALA_SMIERCI 7845

#define OBRAZENIA 5 //tu mozesz zmienic wartosc zadawanych obrazen na sec
#define CZAS_OBRAZEN 8 //tu mozesz zmienic czas efektu (w sec.)

new sprite_white

new const perk_name[] = "Fala smierci";
new const perk_desc[] = "Po uzyciu na przeciwnikach, zadajesz im 5 obrazen co sec przez 8 sec.";
new ilosc_fal[33] = 0
new czas_obrazen[33]
new ma_perk[33]

public plugin_init() 
{
	register_plugin("codperk_falasmierci", "1.0", "MarWit")
	cod_register_perk(perk_name, perk_desc);
	register_event("ResetHUD", "ResetHUD", "abe");
}

public plugin_precache()
	sprite_white = precache_model("sprites/white.spr");
	
public cod_perk_enabled(id)
{
	ma_perk[id] = true
	ilosc_fal[id] = 5 //tu wpisz ilosc fal na runde
}

public cod_perk_disabled(id)
{
	ma_perk[id] = false
	ilosc_fal[id]=0
}

public cod_perk_used(id)
{
	if(ilosc_fal[id] == 0 || !is_user_alive(id) || !ma_perk[id])
		return PLUGIN_CONTINUE
		
	ilosc_fal[id]--;
	
	new iOrigin[3];
	get_user_origin(id, iOrigin);
	
	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] + 300 );
	write_coord( iOrigin[2] + 300 );
	write_short( sprite_white );
	write_byte( 0 ); 
	write_byte( 0 ); 
	write_byte( 10 ); 
	write_byte( 120 ); 
	write_byte( 255 ); 
	write_byte( 0 ); 
	write_byte( 0 );
	write_byte( 255 ); 
	write_byte( 100 ); 
	write_byte( 4 ); 
	message_end();
	
	new entlist[33];
	new numfound = find_sphere_class(id, "player", 300.0, entlist, 32);
		
	for (new i=0; i < numfound; i++)
	{		
		new vic = entlist[i];
	
		if (is_user_alive(vic) && get_user_team(id) != get_user_team(vic)){
			czas_obrazen[vic] = CZAS_OBRAZEN
			set_task(1.0, "FalaSmierci_task", vic+FALA_SMIERCI, _, _, "b")
		}
	}
	
	return PLUGIN_CONTINUE;
}

public FalaSmierci_task(id)
{
	id -= FALA_SMIERCI
	czas_obrazen[id]--
	set_user_health(id, (get_user_health(id)-OBRAZENIA))
	if(!(is_user_alive(id)) || !(is_user_connected(id)) || czas_obrazen[id] <= 0){
		if(task_exists(id+FALA_SMIERCI)) remove_task(id+FALA_SMIERCI)
		
		return PLUGIN_HANDLED
	}
	return PLUGIN_CONTINUE
}

public ResetHUD(id)
	ilosc_fal[id] = 5
