/*
*   _______     _      _  __          __
*  | _____/    | |    | | \ \   __   / /
*  | |         | |    | |  | | /  \ | |
*  | |         | |____| |  | |/ __ \| |
*  | |   ___   | ______ |  |   /  \   |
*  | |  |_  |  | |    | |  |  /    \  |
*  | |    | |  | |    | |  | |      | |
*  | |____| |  | |    | |  | |      | |
*  |_______/   |_|    |_|  \_/      \_/
*
*
*
*  Last Edited: 08-04-08
*
*  ============
*   Changelog:
*  ============
*
*  v2.1
*    -money_after_death CVAR added
*    -Minus Money for Team Attack
*
*  v2.0
*    -Optimized Code
*
*  v1.0
*    -Initial Release
*
*/

#define VERSION	"2.1"

#include <amxmodx>
#include <amxmisc>
#include <cstrike>

new mpd, mkb, mhb, mad
new maxplayers

new g_money[33][33]

public plugin_init()
{
	register_plugin("Damage Money",VERSION,"GHW_Chronic")
	mpd = register_cvar("money_per_damage","3")
	mkb = register_cvar("money_kill_bonus","100")
	mhb = register_cvar("money_hs_bonus","50")
	mad = register_cvar("money_after_death","1")

	register_event("Damage","Damage","b")
	register_event("DeathMsg","death_msg","a")

	maxplayers = get_maxplayers()
}

public client_disconnect(id)
{
	for(new i=1;i<=maxplayers;i++)
	{
		g_money[i][id] = 0
	}
}

public Damage(id)
{
	new weapon, hitpoint, attacker = get_user_attacker(id,weapon,hitpoint)
	if(attacker<=maxplayers && is_user_alive(attacker) && attacker!=id)
	{
		new money = read_data(2) * get_pcvar_num(mpd)
		if(hitpoint==1) money += get_pcvar_num(mhb)
		if(get_user_team(attacker)==get_user_team(id)) money *= -1
		cs_set_user_money2(attacker,id,cs_get_user_money(attacker) + money)
	}
}

public death_msg()
{
	new victim = read_data(2)
	if(is_user_connected(victim))
	{
		new attacker = read_data(1)
		if(
		attacker &&
		attacker<=maxplayers &&
		is_user_connected(attacker) &&
		attacker!=victim
		)
			cs_set_user_money2(read_data(1),read_data(2),cs_get_user_money(read_data(1)) + get_pcvar_num(mkb) - 300)


		give_ad_money(victim)
	}
}

public cs_set_user_money2(attacker,victim,money)
{
	if(get_pcvar_num(mad)) g_money[victim][attacker] += money
	else cs_set_user_money(attacker,money)
}

public give_ad_money(victim)
{
	for(new i=1;i<=maxplayers;i++)
	{
		if(g_money[victim][i] && is_user_connected(i)) cs_set_user_money(i,g_money[victim][i] + cs_get_user_money(i))
	}
}
