/* Header generated by AMXX-Studio*/

new const KZ_DIR[] = "uq_jumpstats";
new bool:g_userConnected[33],bool:g_alive[33];

bool:valid_id(id)
{
	if(id>0 && id<33)
	{
		return true;
	}
	
	return false;
}

stock is_user_spectating_player(spectator, player)
{
	if( !valid_id(spectator) || !valid_id(player) )
		return 0;
	if( g_userConnected[spectator]==false || g_userConnected[player]==false )
		return 0;
	if( g_alive[spectator] || !g_alive[player] )
		return 0;
	
	if( pev(spectator, pev_deadflag) != 2 )
		return 0;
	
	static specmode;
	specmode = pev(spectator, pev_iuser1);
	if( !(specmode == 1 || specmode == 2 || specmode == 4) )
		return 0;
	
	if( pev(spectator, pev_iuser2) == player )
		return 1;
	
	return 0;
}
stock get_spectated_player(spectator)
{
	if( !valid_id(spectator) )
		return 0;
	if( !g_userConnected[spectator] )
		return 0;
	if( g_alive[spectator] )
		return 0;
	if( pev(spectator, pev_deadflag) != 2 )
		return 0;
	
	static player, specmode;
	specmode = pev(spectator, pev_iuser1);
	if( !(specmode == 1 || specmode == 2 || specmode == 4) )
		return 0;
	
	player = pev(spectator, pev_iuser2);
	
	if( !valid_id(player) )
		return 0;
	if( !g_userConnected[player] )
		return 0;
	if( !g_alive[player] )
		return 0;
	
	return player;
}
stock Float:UpBhop_calc(Float:height)
{
	if(height<=8 && height>0)
	{
		return 227.0;
	}
	else if(height<=16 && height>8)
	{
		return 225.0;
	}
	else if(height<=24 && height>16)
	{
		return 223.0;
	}
	else if(height<=32 && height>24)
	{
		return 221.0;
	}
	else if(height<=40 && height>32)
	{
		return 219.0;
	}
	else if(height<=48 && height>40)
	{
		return 217.0;
	}
	else if(height<=56 && height>48)
	{
		return 215.0;
	}
	else if(height<=64 && height>56)
	{
		return 213.0;
	}

	return 0.0;
}

bool:is_user_ducking( id ) {
	if( !valid_id( id )  )
		return false;
	
	new Float:abs_min[3], Float:abs_max[3];
	
	pev( id, pev_absmin, abs_min );
	pev( id, pev_absmax, abs_max );
	
	abs_min[2] += 64.0;
	
	if( abs_min[2] < abs_max[2] )
		return false;
	
	return true;
}

///exolents fail///
stock Float:GetFailedDistance(Float:ExDist, bool:ducking, Float:gravity, Float:jumpoff_origin[3], Float:current_velocity[3], Float:failed_origin[3], Float:failed_velocity[3] )
{
	static Float:airtime, Float:land_origin[3], Float:distance;
	
	if( ducking ) jumpoff_origin[2] -= 18.0;
			
	airtime = ((floatsqroot((failed_velocity[2] * failed_velocity[2]) - (2.0 * -gravity * (failed_origin[2] - jumpoff_origin[2])))*-1) - failed_velocity[2] ) / -gravity;
	
	land_origin[0] = floatabs( failed_origin[0] - jumpoff_origin[0] ) + floatabs( current_velocity[0] * airtime );
	land_origin[1] = floatabs( failed_origin[1] - jumpoff_origin[1] ) + floatabs( current_velocity[1] * airtime );
	
	distance = vector_length(land_origin) + ExDist;
	
	if( ducking ) jumpoff_origin[2] += 18.0;
	
	return distance;
}
stock weapon_rank(maxspeed)
{
	new rank;
	
	switch(maxspeed)
	{
		case 210:
			rank = 0;
		case 220:
			rank = 1;
		case 221:
			rank = 2;
		case 230:
			rank = 3;
		case 235:
			rank = 4;
		case 240:
			rank = 5;
		case 245:
			rank = 6;
		case 260:
			rank = 7;
	}
	
	return rank;
}

stock weapon_maxspeed(rank)
{
	new maxspeed;
	
	switch(rank)
	{
		case 0:
			maxspeed = 210;
		case 1:
			maxspeed = 220;
		case 2:
			maxspeed = 221;
		case 3:
			maxspeed = 230;
		case 4:
			maxspeed = 235;
		case 5:
			maxspeed = 240;
		case 6:
			maxspeed = 245;
		case 7:
			maxspeed = 260;
	}
	
	return maxspeed;
}
stock Float:LandingCalculate(id,Float:landing_orig[3], Float:jumpoff_origin[3])
{
	new Float:tmplandorg[3],Float:tmplandorigin[3]; 
	
	for(new i=0,ii=-18;i<3;i++,ii=ii+18)
	{	if(floatabs(landing_orig[0]-jumpoff_origin[0])>floatabs(landing_orig[1]-jumpoff_origin[1]))
		{
			tmplandorigin=landing_orig;
			tmplandorigin[1]=tmplandorigin[1]+ii;
			
			if(landing_orig[0]-jumpoff_origin[0]>0) 
			{
				tmplandorigin[0]=tmplandorigin[0]+16;
				
				
				tmplandorg[0]=landing_orig[0]-330;
				tmplandorg[1]=landing_orig[1]+ii;
				tmplandorg[2]=landing_orig[2];
			}
			else if(landing_orig[0]-jumpoff_origin[0]<0) 
			{
				tmplandorigin[0]=tmplandorigin[0]-16;
				
				
				tmplandorg[0]=landing_orig[0]+330;
				tmplandorg[1]=landing_orig[1]+ii;
				tmplandorg[2]=landing_orig[2];
			}
		}
		else if(floatabs(landing_orig[0]-jumpoff_origin[0])<floatabs(landing_orig[1]-jumpoff_origin[1]))
		{
			tmplandorigin=landing_orig;
			tmplandorigin[0]=tmplandorigin[0]+ii;
			
			if(landing_orig[1]-jumpoff_origin[1]>0) 
			{
				tmplandorigin[1]=tmplandorigin[1]+16;
				
				
				tmplandorg[0]=landing_orig[0]+ii;
				tmplandorg[1]=landing_orig[1]-330;
				tmplandorg[2]=landing_orig[2];
			}
			else if(landing_orig[1]-jumpoff_origin[1]<0) 
			{
				tmplandorigin[1]=tmplandorigin[1]-16;
				
				
				tmplandorg[0]=landing_orig[0]+ii;
				tmplandorg[1]=landing_orig[1]+330;
				tmplandorg[2]=landing_orig[2];
			}
		}
		new Float:Orgland[3],Float:startOrgland[3];

		engfunc(EngFunc_TraceLine,tmplandorigin, tmplandorg, IGNORE_GLASS | IGNORE_MONSTERS, id, 0); 
		get_tr2( 0, TR_vecEndPos, Orgland);
		
		engfunc(EngFunc_TraceLine,Orgland, tmplandorigin, IGNORE_GLASS | IGNORE_MONSTERS, id, 0); 
		get_tr2( 0, TR_vecEndPos, startOrgland);
		
		if(get_distance_f(tmplandorigin,startOrgland)!=0.0)
			return get_distance_f(tmplandorigin,startOrgland);
	}
	return 0.0;
}
bool:check_for_bug_distance(Float:check_distance,type,mSpeed)
{
	new minys=floatround((250.0-mSpeed)*0.73,floatround_floor);
	if(type==1 && check_distance>(260-minys))
	{
		return true;
	}
	else if(type==2 && check_distance>(277-minys))
	{
		return true;
	}
	else if(type==3 && check_distance>(253-minys))
	{
		return true;
	}
	else if(type==4 && check_distance>200)
	{
		return true;
	}
	else if(type==5 && check_distance>225-minys)
	{
		return true;
	}
	else if(type==6 && check_distance>180-minys)
	{
		return true;
	}
	
	return false;
}
stock kz_get_configsdir(name[], len)
{
	new lalin[64];
	get_localinfo("amxx_configsdir", lalin,63);
	
	return formatex(name, len, "%s/%s", lalin, KZ_DIR);
}
stock replace_colors(message[], len)
{
	replace_all(message, len, "!g", "^x04")
	replace_all(message, len, "!t", "^x03")
	replace_all(message, len, "!y", "^x01")
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1049\\ f0\\ fs16 \n\\ par }
*/
