/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <codmod>
#include <hamsandwich>
#include <fakemeta>
#include <cstrike>
#include <fun>

new bool:g_NitrogenGalil[33]
new NitrogenGalilSpr

new const perk_name[] = "NitrogenGalil";
new const perk_desc[] = "Posiadasz nitrogen gail, który zamraza wrogow";

new bool:ma_perk[33];

public plugin_init() 
{
	register_plugin(perk_name, "1.1", "QTM_Peyote");
	
	cod_register_perk(perk_name, perk_desc);
	RegisterHam(Ham_TakeDamage, "player", "fw_TakeDamage")
}

public cod_perk_enabled(id)
{
	cod_give_weapon(id, CSW_GALIL);
	ma_perk[id] = true;
}

public cod_perk_disabled(id)
{
	cod_take_weapon(id, CSW_GALIL);
	ma_perk[id] = false;
}
	
public fw_TakeDamage(victim, inflictor, attacker, Float:damage, damage_type)
{
	if(!is_user_connected(attacker) || !is_user_connected(victim) || attacker == victim || !attacker)
	return HAM_IGNORED
	
	if(!ma_perk[attacker])
		return HAM_IGNORED;
	
	static Float:originF[3]
	pev(victim, pev_origin, originF)
		
	if (g_NitrogenGalil[attacker] && get_user_weapon(attacker) == CSW_GALIL)
	{	
		if(cs_get_user_team(attacker) == cs_get_user_team(victim))
		return HAM_IGNORED
		
		set_pev(victim, pev_velocity, Float:{0.0,0.0,0.0}) // stop motion
		set_pev(victim, pev_maxspeed, 5.0) // prevent from moving
		
		Effects(originF)
		
		emit_sound(0, CHAN_STATIC, "warcraft3/impalehit.wav", 1.0, ATTN_NORM, 0, PITCH_NORM) 
	}
	return HAM_IGNORED;
}

//___________/ Effects \___________________________________________________________________________________________
//**************************************************************************************************************************/
Effects(const Float:originF3[3])
{
	// Largest ring
	engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, originF3, 0)
	write_byte(TE_BEAMCYLINDER) // TE id
	engfunc(EngFunc_WriteCoord, originF3[0]) // x
	engfunc(EngFunc_WriteCoord, originF3[1]) // y
	engfunc(EngFunc_WriteCoord, originF3[2]) // z
	engfunc(EngFunc_WriteCoord, originF3[0]) // x axis
	engfunc(EngFunc_WriteCoord, originF3[1]) // y axis
	engfunc(EngFunc_WriteCoord, originF3[2]+100.0) // z axis
	write_short(NitrogenGalilSpr) // sprite
	write_byte(0) // startframe
	write_byte(0) // framerate
	write_byte(4) // life
	write_byte(60) // width
	write_byte(0) // noise
	write_byte(41) // red
	write_byte(138) // green
	write_byte(255) // blue
	write_byte(200) // brightness
	write_byte(0) // speed
	message_end()
}
