#include <amxmodx>
#include <fakemeta>

#define PLUGIN "Effect Sprites"
#define VERSION "1.0"
#define AUTHOR "Play"

//Engine
native register_think(const classname[],const func[])

new const sprite_score[]="sprites/combo/combo.spr"
new const sprite_bonus[]="sprites/combo/efkill.spr"
new const sprite_classname[]="ef_combo"

new info_target
new sprindex_combo[33],sprindex_head[33],sprindex_knife[33],spriteindex_grenade[33],Float:LastKill[33],kill_count[33],Float:GrenadeTime[33][33]
const Float:ComboTime=5.0

enum
{
	Combo=0,
	Head,
	Knife,
	Grenade
}

public plugin_precache()precache_model(sprite_score),precache_model(sprite_bonus)
public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	register_event("DeathMsg", "Event_Death", "a", "1>0")
	register_message(get_user_msgid("DeathMsg"), "message_DeathMsg")
	
	register_think(sprite_classname,"delete")	
	
	info_target=engfunc(EngFunc_AllocString, "info_target")
	// Add your code here...
}
public message_DeathMsg(msg_id, msg_dest, id)
{
	static Weapon_Msg[16], attacker, victim
	get_msg_arg_string(4, Weapon_Msg, charsmax(Weapon_Msg))
	
	attacker = get_msg_arg_int(1)
	victim = get_msg_arg_int(2)
	if (contain(Weapon_Msg,"grenade")!=-1)GrenadeTime[attacker][victim]=get_gametime()+0.1
}

public Event_Death()
{
	static id,victim,head,Float:gametime,Float:Origin[3]
	id=read_data(1);victim=read_data(2);head=read_data(3)
	gametime=get_gametime()
	
	if(!is_user_connected(id))return
	
	static ent
	if(GrenadeTime[id][victim]<gametime)
	{
		ent=sprindex_combo[id];if(ef_valid(ent,id))engfunc(EngFunc_RemoveEntity, ent)
		ent=spriteindex_grenade[id];if(ef_valid(ent,id))engfunc(EngFunc_RemoveEntity, ent)
	}
	ent=sprindex_head[id];if(ef_valid(ent,id))engfunc(EngFunc_RemoveEntity, ent)
	ent=sprindex_knife[id];if(ef_valid(ent,id))engfunc(EngFunc_RemoveEntity, ent)
	
	if(LastKill[id]-gametime>0.0)kill_count[id]++;else kill_count[id]=1
	LastKill[id]=gametime+ComboTime
	
	pev(victim,pev_origin,Origin);Origin[2]=Origin[2]+90.0	
	
	static Float:RGB[3]
	RGB[0]=random_float(0.0,255.0)
	RGB[1]=random_float(0.0,255.0)
	RGB[2]=random_float(0.0,255.0)
	
	if(RGB[0]<200.0&&RGB[1]<200.0&&RGB[2]<200.0)
	switch(random_num(1,3))
	{
		case 1:RGB[0]=255.0
		case 2:RGB[1]=255.0
		case 3:RGB[2]=255.0
	}
	sprindex_combo[id]=ef_spr(Combo,Origin,kill_count[id]<20?(kill_count[id]-1.0):(19.0),RGB,id)
	
	RGB[0]=255.0;RGB[1]=0.0;RGB[2]=0.0
	if(GrenadeTime[id][victim]>gametime)
	{
		Origin[2]=Origin[2]-30.0
		spriteindex_grenade[id]=ef_spr(Grenade,Origin,2.0,RGB,id)
		return
	}
	if(head)
	{
		Origin[2]=Origin[2]-30.0
		sprindex_head[id]=ef_spr(Head,Origin,0.0,RGB,id)			
	}
	if(get_user_weapon(id)==CSW_KNIFE)
	{
		Origin[2]=Origin[2]-30.0
		sprindex_knife[id]=ef_spr(Knife,Origin,1.0,RGB,id)
	}
}
stock ef_spr(type,Float:Origin[3],Float:frame,Float:Color[3],id)
{
	new ient = 
	engfunc(EngFunc_CreateNamedEntity, info_target)
	switch(type)
	{
		case Combo:engfunc(EngFunc_SetModel,ient, sprite_score)
		case Head:engfunc(EngFunc_SetModel,ient, sprite_bonus)
		case Knife:engfunc(EngFunc_SetModel,ient, sprite_bonus)
		case Grenade:engfunc(EngFunc_SetModel,ient, sprite_bonus)
	}
	set_pev(ient, pev_classname, sprite_classname)
	set_pev(ient, pev_movetype, MOVETYPE_NOCLIP)
	set_pev(ient,pev_gravity,0.0001)
	set_pev(ient,pev_solid,SOLID_TRIGGER)
	set_pev(ient, pev_rendermode, kRenderTransAdd)
	set_pev(ient, pev_renderamt, 250.0)
	set_pev(ient, pev_nextthink,get_gametime()+ComboTime)
	set_pev(ient,pev_origin,Origin)
	set_pev(ient,pev_iuser1,id)
	set_pev(ient,pev_rendercolor,Color)
	set_pev(ient, pev_scale, 0.4)
	set_pev(ient, pev_framerate, 0.0)
	set_pev(ient, pev_frame,frame)	
	return ient
}
stock bool: ef_valid(ent,id)
{
	if(!ent||!id)return false
	if(!pev_valid(ent))return false
	if(pev(ent,pev_iuser1)!=id)return false
	
	static ClassName[30]
	pev(ent, pev_classname, ClassName, charsmax(ClassName))
	if (contain(ClassName, sprite_classname ) != -1)return true
	return false
}
public delete(ent)if(pev_valid(ent))engfunc(EngFunc_RemoveEntity, ent)
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang11274\\ f0\\ fs16 \n\\ par }
*/
