/* AMX Mod X Script
*
*	"Killa HP"
*	(c) jas0n, november 2008 
*
*	This file is provided as is (no warranties)	
*
*	Description:
*		plugins shows a chat message "You have been killed by Attacker [78 HP, 100 AP][13 Kills, 2 Deaths]" on death event.
*
*	Request:
*		by ALucard (http://c-s.net.ua/forum/index.php?showtopic=5231)
*
*	Changelog:
*		[12/11/07 13:43] v1.0  - First release.
* 
* 		[12/11/07 19:00] v1.1  - Message bug fix.
*
* 		[14/01/08 14:08] v1.2b - Minor optimization;
* 				       - Now message prints to victim's console too;
* 				       - Support for AmxModX ver. < 1.8.0.
* 
*		[04/04/08 09:29] v1.3 - Some optimizations.
* 				      - Removed dependence of <cstrike> module
* 
*/

#include <amxmodx>

#if AMXX_VERSION_NUM < 180
	#define charsmax(%1)	(sizeof(%1)-1)
#endif

new const PLUGIN[] = "Killa HP"
new const VERSION[] = "1.3"
new const AUTHOR[] = "jas0n"

new const g_msgTemplate[] = "^x04You have been killed by ^x03%s ^x01[^x04%d^x01 HP, ^x04%d^x01 AP][^x04%d ^x01Kills, ^x04%d^x01 Deaths]"
new const g_msgTemplateConsole[] = "You have been killed by %s [%d HP, %d AP][%d Kills, %d Deaths]"

new g_msgSayText

public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	register_event("DeathMsg", "eventDeath", "a", "1>0")
	g_msgSayText = get_user_msgid("SayText")
}

public eventDeath()
{
	static aID, vID
	static aName[32], msgText[255]
	static aHealth, aArmor, aFrags, aDeaths
		
	aID = read_data(1)
	vID = read_data(2)
	
	// OPTIMIZED [by VEN] ->
	if(vID == aID)
	{
		return
	}
	// <- OPTIMIZED [by VEN]
	
	get_user_name(aID, aName, charsmax(aName))
	aHealth = get_user_health(aID)
	aArmor = get_user_armor(aID)
	
	aFrags = get_user_frags(aID)
	aDeaths = get_user_deaths(aID)
	
	formatex(msgText, charsmax(msgText), g_msgTemplate, aName, aHealth, aArmor, aFrags, aDeaths)
	msgText[192] = '^0'
	msgSayText(vID, msgText)

	formatex(msgText, charsmax(msgText), g_msgTemplateConsole, aName, aHealth, aArmor, aFrags, aDeaths)
	client_print(vID, print_console, msgText)
}

msgSayText(id, message[])
{
	message_begin(MSG_ONE, g_msgSayText, _, id)
	write_byte(id)		
	write_string(message)
	message_end()
}