/* Script generated by Pawn Studio */

#include <amxmodx>
#include <amxmisc>
#include <engine>
#include <fakemeta>
#include <xs>
#include <hamsandwich>
#include <colorchat>

#define PLUGIN	"Slowmotion"
#define AUTHOR	"UrShade"
#define VERSION	"1.0"

#define MAX 32

new bool: bSlow[ MAX + 1 ] ,
	Float: oldVeloc[ MAX + 1 ][ 3 ] ,
	Float: fTime[ MAX + 1 ] ,
	pGrav ,
	pSlowSpeed ;

new bool: music[ MAX + 1 ]
	
new const Float:g_fWeaponsSpeed[ ]={
	000.0,
	250.0, 000.0, 260.0, 250.0, 240.0, 
	250.0, 250.0, 240.0, 250.0, 250.0,                
	250.0, 250.0, 210.0, 240.0, 240.0,    
	250.0, 250.0, 210.0, 250.0, 220.0,              
	230.0, 230.0, 250.0, 210.0, 250.0,            
	250.0, 235.0, 221.0, 250.0, 245.0 
};

public plugin_init(){
	register_plugin(PLUGIN, VERSION, AUTHOR)
	register_clcmd("say /music", "msc")
	register_event("SendAudio", "end_round", "a", "2&%!MRAD_terwin", "2&%!MRAD_ctwin", "2&%!MRAD_rounddraw")

	RegisterHam(Ham_Weapon_PrimaryAttack ,"weapon_m4a1","weapon_speed", 1)
	RegisterHam(Ham_Weapon_PrimaryAttack ,"weapon_ak47","weapon_speed", 1)
	RegisterHam(Ham_Weapon_PrimaryAttack ,"weapon_galil","weapon_speed", 1)
	RegisterHam(Ham_Weapon_PrimaryAttack ,"weapon_famas","weapon_speed", 1)
	RegisterHam(Ham_Weapon_PrimaryAttack ,"weapon_mp5navy","weapon_speed", 1)
	RegisterHam(Ham_Weapon_PrimaryAttack ,"weapon_xm1014","weapon_speed", 1)
	RegisterHam(Ham_Weapon_PrimaryAttack ,"weapon_ump45","weapon_speed", 1)
	RegisterHam(Ham_Weapon_PrimaryAttack ,"weapon_sg550","weapon_speed", 1)
	RegisterHam(Ham_Weapon_PrimaryAttack ,"weapon_m249","weapon_speed", 1)
	RegisterHam(Ham_Weapon_PrimaryAttack ,"weapon_mac10","weapon_speed", 1)

	register_event("HLTV", "new_round", "a", "1=0", "2=0")  
	pGrav		=	get_cvar_pointer( "sv_gravity" );
	pSlowSpeed	=	register_cvar( "amx_slowmo" , "0.4" );
}

public plugin_precache()  
{  
	precache_sound("SummerSound/1.wav")
	precache_sound("SummerSound/2.wav")
	precache_sound("SummerSound/3.wav")
	precache_sound("SummerSound/4.wav")
	precache_sound("SummerSound/5.wav")
	precache_sound("SummerSound/6.wav")
	precache_sound("SummerSound/7.wav")
	precache_sound("SummerSound/8.wav")
	precache_sound("SummerSound/9.wav")
	precache_sound("SummerSound/10.wav")
	precache_sound("SummerSound/11.wav")
	precache_sound("SummerSound/12.wav")
	precache_sound("SummerSound/13.wav")
	precache_sound("SummerSound/14.wav")
	precache_sound("SummerSound/15.wav")
}

public msc(id)
{
	music[id] = !music[id]
	if(music[id])
		ColorChat(id, TEAM_COLOR, "[^4CS-Summer^3]^1 Вы включили музыку в конце раунда")
	else
		ColorChat(id, TEAM_COLOR, "[^4CS-Summer^3]^1 Вы выключили музыку в конце раунда")
}

public client_connect(id){
	bSlow[id] = false;
	music[id] = true;
}

public weapon_speed(weapon)
{
	new id = pev(weapon,pev_owner)
	if(is_user_alive(id) && bSlow[id])
		set_pdata_float(weapon, 46, 0.2, 4)
}
public voidSlow(){
	new players = get_playersnum()
	for(new id; id <= players; id++){
		if(is_user_alive(id)){
			bSlow[id] = !bSlow[id];
				
			if(bSlow[id]){
				pev(id, pev_velocity, oldVeloc[ id ] );
				fTime[id] = get_gametime();
			}
			else{
				engfunc(EngFunc_SetClientMaxspeed, id, g_fWeaponsSpeed[get_user_weapon(id)]);
			}
		}
	}
	return PLUGIN_HANDLED;
}

public new_round(){
	for(new id; id <= get_playersnum();id++){
		bSlow[id] = false;
	}
}

public client_PreThink( id ){
	if( !is_user_alive( id ) || !bSlow[ id ] ){
		return PLUGIN_CONTINUE;
	}
	
	new Float: fVeloc[ 3 ] ,
		Float: fOrigin[ 3 ] ,
		Float: SLOW_SPEED ;
	
	SLOW_SPEED	=	get_pcvar_float( pSlowSpeed );
		
	pev( id , pev_origin , fOrigin );
	pev( id , pev_velocity ,fVeloc  );
	
	if( !( -0.01 <= fVeloc[ 0 ] - oldVeloc[ id ][ 0 ] <= 0.01 ) ){
		fVeloc[ 0 ] -=	oldVeloc[ id ][ 0 ];
		fVeloc[ 0 ]	*= SLOW_SPEED;
		
		oldVeloc[ id ][ 0 ] += fVeloc[ 0 ];
	}
	if( !( -0.01 <= fVeloc[ 1 ] - oldVeloc[ id ][ 1 ] <= 0.01 ) ){
		fVeloc[ 1 ] -=	oldVeloc[ id ][ 1 ];
		fVeloc[ 1 ]	*= SLOW_SPEED;
		
		oldVeloc[ id ][ 1 ] += fVeloc[ 1 ];
	}
	
	new Float: fTimeSub	=	get_gametime() - fTime[ id ];
	
	fTime[ id ]	=	get_gametime();
	
	fOrigin[ 2 ]	-=	floatmul( fVeloc[ 2 ] , fTimeSub );
	fOrigin[ 2 ]	+=	floatmul( fVeloc[ 2 ] , fTimeSub * SLOW_SPEED );
	
	if( !( pev( id , pev_flags ) & FL_ONGROUND ) && ! ( pev( id , pev_flags ) & FL_PARTIALGROUND ) ){
		
		fVeloc[ 2 ] +=	floatmul( pev( id , pev_gravity ) * get_pcvar_float( pGrav ) , fTimeSub );
		fVeloc[ 2 ]	-=	floatmul( pev( id , pev_gravity ) * get_pcvar_float( pGrav ) , fTimeSub * SLOW_SPEED );
	}
	
	oldVeloc[ id ][ 2 ]	=	fVeloc[ 2 ];
	
	fTime[ id ]	=	get_gametime();
	
	engfunc( EngFunc_SetOrigin , id , fOrigin );
	set_pev( id , pev_velocity , oldVeloc[ id ] );
	set_pev( id , pev_framerate , SLOW_SPEED );
	
	engfunc( EngFunc_SetClientMaxspeed , id , g_fWeaponsSpeed[ get_user_weapon( id ) ] * SLOW_SPEED );
	
	return PLUGIN_CONTINUE;
}

public end_round(){
	set_task(0.1, "voidSlow")
	for(new id; id <= get_playersnum();id++){
		new music_rand = random_num(1,15)
		if(music[id]){
			switch(music_rand){
				case 1:{
					client_cmd(id, "spk SummerSound/1")
					ColorChat(id, TEAM_COLOR, "[^4CS-Summer^3]^1 Сейчас играет:^3 SKisM ft. Virus Syndicate – Like This")
				}
				case 2:{
					client_cmd(id, "spk SummerSound/2")
					ColorChat(id, TEAM_COLOR, "[^4CS-Summer^3]^1 Сейчас играет:^3 Modestep Feat. Popeska – Another Day (xKore Remix)")
				}
				case 3:{
					client_cmd(id, "spk SummerSound/3")
					ColorChat(id, TEAM_COLOR, "[^4CS-Summer^3]^1 Сейчас играет:^3 SKisM – Experts")
				}
				case 4:{
					client_cmd(id, "spk SummerSound/4")
					ColorChat(id, TEAM_COLOR, "[^4CS-Summer^3]^1 Сейчас играет:^3 Static Revenger – Turn The World On feat Dev")
				}
				case 5:{
					client_cmd(id, "spk SummerSound/5")
					ColorChat(id, TEAM_COLOR, "[^4CS-Summer^3]^1 Сейчас играет:^3 DJ Fresh – Louder (Flux Pavilion and Doctor P Remix)")
				}
				case 6:{
					client_cmd(id, "spk SummerSound/6")
					ColorChat(id, TEAM_COLOR, "[^4CS-Summer^3]^1 Сейчас играет:^3 Styles of Beyond – Nine Thou")
				}
				case 7:{
					client_cmd(id, "spk SummerSound/7")
					ColorChat(id, TEAM_COLOR, "[^4CS-Summer^3]^1 Сейчас играет:^3 Kill The Noise & Feed Me – Thumbs Up")
				}
				case 8:{
					client_cmd(id, "spk SummerSound/8")
					ColorChat(id, TEAM_COLOR, "[^4CS-Summer^3]^1 Сейчас играет:^3 Raider – Kaizen")
				}
				case 9:{
					client_cmd(id, "spk SummerSound/9")
					ColorChat(id, TEAM_COLOR, "[^4CS-Summer^3]^1 Сейчас играет:^3 Signum & Scott Mac – Coming On Strong")
				}
				case 10:{
					client_cmd(id, "spk SummerSound/10")
					ColorChat(id, TEAM_COLOR, "[^4CS-Summer^3]^1 Сейчас играет:^3 Mallorca Lee & Ross Ferguson – Setting Suns")
				}
				case 11:{
					client_cmd(id, "spk SummerSound/11")
					ColorChat(id, TEAM_COLOR, "[^4CS-Summer^3]^1 Сейчас играет:^3 Stephen Swartz feat. Joni Fatora – Bullet Train")
				}
				case 12:{
					client_cmd(id, "spk SummerSound/12.")
					ColorChat(id, TEAM_COLOR, "[^4CS-Summer^3]^1 Сейчас играет:^3 KDrew – Danger Zone")
				}
				case 13:{
					client_cmd(id, "spk SummerSound/13")
					ColorChat(id, TEAM_COLOR, "[^4CS-Summer^3]^1 Сейчас играет:^3 Aelian – One Day, Things Will All Be Different")
				}
				case 14:{
					client_cmd(id, "spk SummerSound/14")
					ColorChat(id, TEAM_COLOR, "[^4CS-Summer^3]^1 Сейчас играет:^3 Lady Gaga – Paparazzi (Alximo Chilled Dubstep Remix)")
				}
				case 15:{
					client_cmd(id, "spk SummerSound/15")
					ColorChat(id, TEAM_COLOR, "[^4CS-Summer^3]^1 Сейчас играет:^3 30 Seconds To Mars – The Kill")
				}
			}
		}
	}
}