/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <hamsandwich>
#include <codmod>
#include <colorchat>

#define PLUGIN "Exp by Maps Objectives"
#define VERSION "1.0"
#define AUTHOR "Hleb"

#define HOST_TOUCH 
#define HOST_KILL 
#define HOST_RESCUE 
#define HOST_ALL_RESCUE
#define BOMB_DEFUSE 
#define BOMB_PLANT 
#define BOMB_EXPLODE 
#define TARGET_SAVE 
#define HOST_NOT_RESCUE



new cvar_exp_za_dotyk_hosta
new cvar_exp_za_bombe
new cvar_exp_za_bombe_team
new cvar_exp_za_wybuch
new cvar_exp_za_hosta
new cvar_exp_za_hosty_team
new cvar_exp_za_hosty
new cvar_exp_za_cele_mapy

new g_TouchXp
new g_HostXp
new g_TeamHostages
new g_AllHostages
new g_ExplodeXp
new g_BombTeamXp
new g_BombPlantXp
new g_BombDefuseXp
new g_TargetXp

new ostatni_odprowadzacz = 0;
new wszystkich_hostow = 0;
new hosty_gracza[33] = 0;
new podkladajacy;
new rozbrajajacy;

public plugin_init() 
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	register_logevent("Host_Rescued", 3, "1=triggered", "2=Rescued_A_Hostage");
	register_logevent("All_Hostages_Rescued", 6, "2=triggered", "3=All_Hostages_Rescued");
	register_logevent("Host_Killed", 3, "1=triggered", "2=Killed_A_Hostage");
	register_logevent("Host_Touched", 3, "2=Touched_A_Hostage")
	register_logevent("Bomb_Exploded", 6, "3=Target_Bombed")
	register_logevent("Bomb_Planted", 3, "2=Planted_The_Bomb");
	register_logevent("Target_Saved", 6, "3=Target_Saved");
	
	register_event("CurWeapon","CurWeapon","be", "1=1");
	register_event("BarTime", "Bomb_Defusing", "be", "1=10", "1=5");
	register_event("TextMsg", "Host_Not_Rescued", "a", "2&#Hostages_Not_Rescued");

	cvar_exp_za_dotyk_hosta = register_cvar("cod_touch_hostxp", "2");
	cvar_exp_za_bombe = register_cvar("cod_bombxp", "20");
	cvar_exp_za_bombe_team = register_cvar("cod_team_bombxp", "15");
	cvar_exp_za_wybuch = register_cvar("cod_explode_bombxp", "10");
	cvar_exp_za_hosta = register_cvar("cod_hostxp", "5");
	cvar_exp_za_hosty_team = register_cvar("cod_team_hostxp", "15");
	cvar_exp_za_hosty = register_cvar("cod_all_hostxp", "10");
	cvar_exp_za_cele_mapy = register_cvar("cod_targetxp", "20");
	
	g_TouchXp = get_pcvar_num(cvar_exp_za_dotyk_hosta)
	g_HostXp = get_pcvar_num(cvar_exp_za_hosta)
	g_TeamHostages = get_pcvar_num(cvar_exp_za_hosty_team)
	g_AllHostages = get_pcvar_num(cvar_exp_za_hosty)
	g_ExplodeXp = get_pcvar_num(cvar_exp_za_wybuch)
	g_BombTeamXp = get_pcvar_num(cvar_exp_za_bombe_team)
	g_BombPlantXp = get_pcvar_num(cvar_exp_za_bombe)
	g_BombDefuseXp = get_pcvar_num(cvar_exp_za_bombe)
	g_TargetXp = get_pcvar_num(cvar_exp_za_cele_mapy)
}
public CurWeapon(id)
{
	#if defined BOMB_PLANT
	if(read_data(2) == CSW_C4)
		podkladajacy = id;
	#endif	
}
public Bomb_Defusing(id)
{	
	#if defined BOMB_DEFUSE
	if(cod_get_user_class(id))
		rozbrajajacy = id;
	#endif	
}
public Host_Touched()
{
	new id = get_loguser_index()
	#if defined HOST_TOUCH	
	ColorChat(id, GREEN, "[Forum] ^x01 Dostales ^x04%i^x01 doswiadczenia za dotkniecie zakladnika", g_TouchXp)
	cod_set_user_xp(id, cod_get_user_xp(id)+g_TouchXp)
	#endif	
}
public Host_Rescued()
{
	new id = get_loguser_index()
	#if defined HOST_RESCUE
	ColorChat(id, GREEN, "[Forum] ^x01 Dostales ^x04%i^x01 doswiadczenia za odprowadzenie zakladnika.", g_HostXp);
	cod_set_user_xp(id, cod_get_user_xp(id)+g_HostXp)
	#endif	
	ostatni_odprowadzacz = id;
	wszystkich_hostow++;
	hosty_gracza[id]++;
}
public All_Hostages_Rescued()
{	
	new Players[32], playerCount, id;
	get_players(Players, playerCount, "aeh", "CT");
	for (new i=0; i<playerCount; i++)       
	{
		id = Players[i];
		if(!cod_get_user_class(id))
			continue;
			
		if(!is_user_alive(id))
			continue;
			
		if(id != ostatni_odprowadzacz)          
		{
			#if defined HOST_ALL_RESCUE
			ColorChat(id, GREEN, "[Forum] ^x01 Dostales ^x04%i^x01 doswiadczenia za odprowadzenie wszystkich zakladnikow przez Twoj team.", g_TeamHostages);
			cod_set_user_xp(id, cod_get_user_xp(id)+g_TeamHostages);
			#endif
		}
		else if(wszystkich_hostow==hosty_gracza[ostatni_odprowadzacz])
		{
			#if defined HOST_ALL_RESCUE
			ColorChat(id, GREEN, "[Forum] ^x01 Dostales ^x04%i^x01 doswiadczenia za odprowadzenie wszystkich zakladnikow.",g_AllHostages);
			cod_set_user_xp(id, cod_get_user_xp(id)+g_AllHostages)
			#endif
		}
		hosty_gracza[id]=0;
	}
	wszystkich_hostow = 0;
}
public Host_Killed() 
{
	new id = get_loguser_index();
	#if defined HOST_KILL
	ColorChat(id, GREEN, "[Forum] ^x01 Straciles ^x04%i^x01 doswiadczenia za zabicie zakladnika.",g_HostXp);
	cod_set_user_xp(id, cod_get_user_xp(id)-g_HostXp)
	#endif	
}
public Bomb_Exploded()
{	
	new Players[32], playerCount, id;
	get_players(Players, playerCount, "aeh", "TERRORIST");
    
	for (new i=0; i<playerCount; i++) 
	{
		id = Players[i];
		if(!cod_get_user_class(id))
			continue;
		if(!is_user_alive(id))
			continue;
		#if defined BOMB_EXPLODE			
		ColorChat(id, GREEN, "[Forum] ^x01 Dostales ^x04%i^x01 doswiadczenia za zniszczenie celu", g_ExplodeXp);
		cod_set_user_xp(id, cod_get_user_xp(id)+g_ExplodeXp)
		#endif
	}
}
public Bomb_Planted()
{
	new Players[32], playerCount, id;
	get_players(Players, playerCount, "aeh", "TERRORIST");
    
	for (new i=0; i<playerCount; i++) 
	{
		id = Players[i];
		if(!cod_get_user_class(id))
			continue;
		
		if(!is_user_alive(id))
			continue;
                
		if(id != podkladajacy)
		{
			#if defined BOMB_PLANT	
			ColorChat(id, GREEN, "[Forum] ^x01 Dostales ^x04%i^x01 doswiadczenia za podlozenie bomby przez twoj team.", g_BombTeamXp);
			cod_set_user_xp(id, cod_get_user_xp(id)+g_BombTeamXp)
			#endif
		}
		else
		{
			#if defined BOMB_PLANT	
			ColorChat(id, GREEN, "[Forum] ^x01 Dostales ^x04%i^x01 doswiadczenia za podlozenie bomby.", g_BombPlantXp);
			cod_set_user_xp(id, cod_get_user_xp(id)+g_BombPlantXp)
			#endif
		}	
	}
}
public Bomb_Defused()
{
	new Players[32], playerCount, id;
	get_players(Players, playerCount, "aeh", "CT");
    
	for (new i=0; i<playerCount; i++) 
	{
		id = Players[i];
		if(!cod_get_user_class(id))
			continue;
			
		if(!is_user_alive(id))
			continue;
			
		if(id != rozbrajajacy)
		{
			#if defined BOMB_DEFUSE	
			ColorChat(id, GREEN, "[Forum] ^x01 Dostales ^x04%i^x01 doswiadczenia za rozbrojenie bomby przez twoj team.", g_BombTeamXp);
			cod_set_user_xp(id, cod_get_user_xp(id)+g_BombTeamXp)
			#endif
		}
		else
		{
			#if defined BOMB_DEFUSE	
			ColorChat(id, GREEN, "[Forum] ^x01 Dostales ^x04%i^x01 doswiadczenia za rozbrojenie bomby.",g_BombDefuseXp);
			cod_set_user_xp(id, cod_get_user_xp(id)+g_BombDefuseXp)
			#endif
		}
	}
}
public Target_Saved()
{
	new Players[32], playerCount, id;
	get_players(Players, playerCount, "aeh", "CT");
    
	for (new i=0; i<playerCount; i++) 
	{
		id = Players[i];
		if(!cod_get_user_class(id))
			continue;
				
		if(!is_user_alive(id))
			continue;
			
		#if defined TARGET_SAVE		
		ColorChat(id, GREEN, "[Forum] ^x01 Dostales ^x04%i^x01 doswiadczenia za obrone BombSite'ow.", g_TargetXp);
		cod_set_user_xp(id, cod_get_user_xp(id)+g_TargetXp)
		#endif
	}	
}
public Host_Not_Rescued()
{	
	new Players[32], playerCount, id;
	get_players(Players, playerCount, "aeh", "TERRORIST");
    
	for (new i=0; i<playerCount; i++) 
	{
		id = Players[i];
		if(!cod_get_user_class(id))
			continue;
					
		if(!is_user_alive(id))
			continue
			
		#if defined HOST_NOT_RESCUE
		ColorChat(id, GREEN, "[Forum] ^x01 Dostales ^x04%i^x01 doswiadczenia za niedopuszczenie do uwolnienia hostow.", g_TargetXp);
		cod_set_user_xp(id, cod_get_user_xp(id)+g_TargetXp)
		#endif
	}
}
stock get_loguser_index() 
{
	new loguser[80], name[32]
	read_logargv(0, loguser, 79)
	parse_loguser(loguser, name, 31)
 
	return get_user_index(name)
} 
