// DeathMsg support. To use with StatsMe MetaMod plugin.
// http://www.olo.counter-strike.pl
// http://forums.wwgaming.com/forumdisplay.php?s=&forumid=63

#include <core>
#include <console>
#include <string>
#include <admin>
#include <adminlib>

#define ACCESS_CONSOLE 131072
new STRING_VERSION[MAX_DATA_LENGTH] = "2.1.8";

// Format of msg: "global target" "killer" "victim" "headshot" "weapon"
public event_sm_death(HLCommand,HLData,HLUserName,UserIndex) {
	new eng_msg[MAX_DATA_LENGTH], csrc[4], killer[4], victim[4],hs[4], weapon[32];
	convert_string(HLData,eng_msg,MAX_DATA_LENGTH);	
	strgsplit(eng_msg, " ","^"", csrc, 4, killer, 4, victim, 4,hs, 4, weapon, 32);
	new kIndex= strtonum(killer);
	new vIndex= strtonum(victim);
	// get team info from killer and victim
	// but check first if it's a valid player and not this same (i.e. suicide)
	if (kIndex && vIndex && vIndex != kIndex && streq(weapon,"grenade")) {
		new nKiller[MAX_NAME_LENGTH], nVictim[MAX_NAME_LENGTH];
		playerinfo(kIndex, nKiller, MAX_NAME_LENGTH);
		playerinfo(vIndex, nVictim, MAX_NAME_LENGTH);
		exec("sm_say_hs");
		snprintf( eng_msg, MAX_TEXT_LENGTH, "sm_say ^"%s killed %s\nwith High Explosive Grenade!!!^"", nKiller,nVictim);
		exec(eng_msg);
		snprintf( eng_msg, MAX_TEXT_LENGTH, "sm_clexec * ^"spk de_torn/tornthunderlow^""); // only to killer
		exec(eng_msg);
	}
	return PLUGIN_CONTINUE;
}

public plugin_init() {
	plugin_registerinfo("DeathMsg support","DeathMsg support.",STRING_VERSION);
	plugin_registercmd("event_sm_death","event_sm_death",ACCESS_CONSOLE,"");
	exec("sm_register DeathMsg ^"admin_command event_sm_death^"");
	return PLUGIN_CONTINUE;
}