/***********************************************************************
		XP FUNCTIONS (idea from war3x)
***********************************************************************/
stock XP_give(id, iXP){

	// Check for min. players here
	console_print(id,"### Could Gained: %d", iXP)

	new numberofplayers = get_playersnum() 

	if(numberofplayers < iCvar[FT_MIN_B4_XP])
		return 0

	console_print(id,"### XP Gained: %d", floatround(iXP * XPMULTIPLIER))

	p_data[id][P_XP] += floatround(iXP * XPMULTIPLIER)

	WAR3_Display_Level(id, DISPLAYLEVEL_SHOWGAINED)

	return iXP
}

stock XP_onDeath(victim_id, killer_id, weapon, headshot){

	// Don't award XP to world
	if(killer_id==0)
		return PLUGIN_CONTINUE

	new victimName[32], iXP, XP
	get_user_name(victim_id,victimName,31)

	if (killer_id && killer_id!=victim_id && victim_id){

		// He killed a teammate
		if (get_user_team(killer_id)==get_user_team(victim_id)){
			iXP = -1 * xpgiven[p_data[killer_id][P_LEVEL]]
			XP = XP_give(killer_id,iXP)
			if (FT_KILL_OBJECTIVES){
				client_print(killer_id,print_chat,"%L",killer_id,"AWARDED_FOR_KILLING_TEAMMATE",g_MOD,XP)
			}
		}
		else{

			if (!get_cvar_num("mp_weaponxpmodifier")){
				iXP = xpgiven[p_data[victim_id][P_LEVEL]]
				XP = XP_give(killer_id,iXP)
				if (FT_KILL_OBJECTIVES){			
					client_print(killer_id,print_chat,"%L",killer_id,"AWARDED_FOR_KILLING",g_MOD,XP,victimName)
				}
			}
			else{
				iXP = floatround(xpgiven[p_data[victim_id][P_LEVEL]] * weaponxpmultiplier[weapon])
				XP = XP_give(killer_id,iXP)
				if (FT_KILL_OBJECTIVES){
					client_print(killer_id,print_chat,"%L",killer_id,"AWARDED_FOR_KILLING",g_MOD,XP,victimName)
				}
			}

			if( headshot && killer_id!=victim_id){
				iXP = HEADSHOT_BONUS
				XP = XP_give(killer_id,iXP)
				if (FT_KILL_OBJECTIVES){
					client_print(killer_id,print_chat,"%L",killer_id,"AWARDED_FOR_HEADSHOT", g_MOD, XP)			
				}
			}

		#if MOD == 0
			if (victim_id==g_hostageSaver){
				iXP = KILLRESCUEMANXP
				XP = XP_give(killer_id,iXP)
				if (FT_OBJECTIVES){	
					client_print(killer_id,print_chat,"%L",killer_id,"AWARDED_FOR_KILLING_HOSTAGE_R",g_MOD, XP)
				}
			}
			else if (victim_id==g_bombDefuser && killer_id!=g_bombDefuser){						
				iXP = DEFUSER_KILL_BONUS
				XP = XP_give(killer_id,iXP)
				if (FT_OBJECTIVES){				
					client_print(killer_id,print_chat, "%L",killer_id,"AWARDED_FOR_KILLING_BOMB_D",g_MOD,XP)
				}	
			}
			else if (victim_id==g_bombCarrier && killer_id!=g_bombCarrier){						
				iXP = KILL_BOMB_CARRIER
				XP = XP_give(killer_id,iXP)
				if (FT_OBJECTIVES){
					client_print(killer_id,print_chat, "%L",killer_id,"AWARDED_FOR_KILLING_BOMB_C",g_MOD,XP)
				}
			}
			else if (victim_id==g_vipID && killer_id!=g_vipID){
				iXP = VIP_KILL_BONUS
				XP = XP_give(killer_id,iXP)
				if (FT_OBJECTIVES){
					client_print(killer_id,print_chat, "%L",killer_id,"AWARD_FOR_KILLING_VIP",g_MOD,XP)
				}
			}

		#endif
		}
	}

	return PLUGIN_CONTINUE
}

public XP_Set(){
	#if ADVANCED_DEBUG == 1
		writeDebugInfo("XP_set",0)
	#endif

	if (get_cvar_num("mp_savexp")){
		xpgiven = {6,8,10,12,14,16,20,24,28,32,40}
		xplevel = {0,100,200,400,800,1600,3200,6400,12800,25600,51200}
	}

	XP_Set_Multiplier()
}

public XP_Set_Multiplier(){
	#if ADVANCED_DEBUG == 1
		writeDebugInfo("set_xpmultiplier", 0)
	#endif

	if (!get_cvar_num("mp_weaponxpmodifier"))
		return PLUGIN_CONTINUE

	weaponxpmultiplier[CSW_WORLDSPAWN]		= 0.0

	weaponxpmultiplier[CSW_USP]				= 2.5
	weaponxpmultiplier[CSW_DEAGLE]			= 2.5
	weaponxpmultiplier[CSW_GLOCK18]			= 2.5
	weaponxpmultiplier[CSW_ELITE]			= 3.5
	weaponxpmultiplier[CSW_P228]			= 2.5
	weaponxpmultiplier[CSW_FIVESEVEN]		= 2.5

	weaponxpmultiplier[CSW_XM1014]			= 1.25
	weaponxpmultiplier[CSW_M3]				= 1.5

	weaponxpmultiplier[CSW_MP5NAVY]			= 1.0
	weaponxpmultiplier[CSW_UMP45]			= 1.25
	weaponxpmultiplier[CSW_P90]				= 1.25
	weaponxpmultiplier[CSW_TMP]				= 1.5
	weaponxpmultiplier[CSW_MAC10]			= 1.5
	weaponxpmultiplier[CSW_GALIL]			= 1.15
	weaponxpmultiplier[CSW_FAMAS]			= 1.15

	weaponxpmultiplier[CSW_AWP]				= 1.0
	weaponxpmultiplier[CSW_M4A1]			= 1.0
	weaponxpmultiplier[CSW_AK47]			= 1.0
	weaponxpmultiplier[CSW_AUG]				= 1.0
	weaponxpmultiplier[CSW_SG552]			= 1.0
	weaponxpmultiplier[CSW_G3SG1]			= 1.0
	weaponxpmultiplier[CSW_SG550]			= 1.0
	weaponxpmultiplier[CSW_M249]			= 1.25
	weaponxpmultiplier[CSW_SCOUT]			= 3.0

	weaponxpmultiplier[CSW_HEGRENADE]		= 1.75
	weaponxpmultiplier[CSW_KNIFE]			= 6.0

	weaponxpmultiplier[CSW_C4]				= 2.0
	weaponxpmultiplier[CSW_SMOKEGRENADE]	= 1.0
	weaponxpmultiplier[CSW_FLASHBANG]		= 1.0

	weaponxpmultiplier[CSW_LIGHTNING]		= 1.0
	weaponxpmultiplier[CSW_SUICIDE]			= 1.0
	weaponxpmultiplier[CSW_FLAME]			= 1.0
	weaponxpmultiplier[CSW_LOCUSTS]			= 1.1
	weaponxpmultiplier[CSW_SERPENTWARD]		= 1.0
	weaponxpmultiplier[CSW_SHADOW]			= 1.0	
	weaponxpmultiplier[CSW_THORNS]			= 1.0
	weaponxpmultiplier[CSW_CARAPACE]		= 1.0
	weaponxpmultiplier[CSW_CARRION]			= 1.0

	return PLUGIN_CONTINUE
}
