/*	Credite
		YONTU => Un mic/mare tutorial =)
		CS-Devil.Ru => translated into Rus-lang =)
	
	Change Log
		0.1 - Lansarea
		0.2 - Fixare buguri*/

#include <amxmodx>
#include <amxmisc>
#include <colorchat>
#include <message_const>

#define have_acces(%1)	(get_user_flags(%1) & ADMIN_SLAY)

new const
	PLUGIN_NAME[] = "Amx_Explode",
	AUTHOR_NAME[] = "GhosT ***";

static VERSION[] = "0.2";

new PLUGIN_ON;

new explode_sprite;

public plugin_init()
{
	register_concmd("amx_explode", "explode_command", ADMIN_SLAY, "<target> - Explode target");
	
	PLUGIN_ON = register_cvar("explode_on", "1"); // Cvar : ON(<=1) || OFF(==0)
}

public plugin_precache()
{
	register_plugin(PLUGIN_NAME, VERSION, AUTHOR_NAME); // register plug'in
	
	explode_sprite = precache_model("sprites/csdevilru/explode.spr"); // sprite explode
}
public explode_command(index)
{
	if(get_pcvar_num(PLUGIN_ON) >= 1)
	{
		if(have_acces(index))
		{
			new szArgv[32];
			read_argv(1, szArgv, sizeof(szArgv) - 1);
			
			if(equal(szArgv, ""))
			{
				console_print(index, "amx_explode <target>");
				return true;
			}
			
			new iTarget = cmd_target(index, szArgv);
			if(!iTarget)
				return true;
			
			new Admin_Name[32];
			get_user_name(index, Admin_Name, sizeof(Admin_Name) - 1);
			
			new Target_Name[32];
			get_user_name(iTarget, Target_Name, sizeof(Target_Name) - 1);
			
			new all = 0;
			
			if(is_user_alive(iTarget))
			{
				user_kill(iTarget);
				explode_effects(iTarget);
				console_print(all, "ADMIN: %s a folosit comanda amx_explode pe %s !", Admin_Name, Target_Name);
			
				ColorChat(all, RED, "^x04[ADMIN]^x03 %s^x01 уничтожил взрывом^x03 %s", Admin_Name, Target_Name);
				
				set_hudmessage(200, 25, 123, -1.0, -1.0);
				show_hudmessage(all, "", Target_Name);
			}
			else
			{
				console_print(index, "Игрок %s мертв!", Target_Name);
				return true;
			}
			
			return false;
		}
		else
		{
			console_print(index, "У вас недостаточно прав!");
			return true;
		}
	}
	else
	{
		console_print(index, "Pluginul este dezactivat !");
		return true;
	}
	
	return false;
}
stock explode_effects(iTarget)
{
	new orginn[3];
	get_user_origin(iTarget, orginn);
	
	message_begin(MSG_ALL, SVC_TEMPENTITY);
	write_byte(TE_EXPLOSION);
	write_coord(orginn[0]);
	write_coord(orginn[1]);
	write_coord(orginn[2]);
	write_short(explode_sprite);
	write_byte(30);
	write_byte(10);
	write_byte(2);
	write_byte(50);
	write_byte(10);
	message_end( );
}