#pragma semicolon 1

#define PLUGIN_AUTHOR "null138"
#define PLUGIN_VERSION "1.00"

#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <vip_core>

#pragma newdecls required

float fSwitchSpeed[MAXPLAYERS + 1];

public Plugin myinfo = 
{
	name = "[VIP] Quick Gun Switch",
	author = PLUGIN_AUTHOR,
	description = "Quick Gun Switch",
	version = PLUGIN_VERSION,
}

public void OnPluginStart()
{
	if(VIP_IsVIPLoaded())
	{
		for(int i = 1; i <= MaxClients; i++)
		{
			if(IsClientInGame(i) && VIP_IsClientVIP(i))
			{
				SDKHook(i, SDKHook_WeaponSwitchPost, OnWeaponSwitchPost);
			}
		}
		VIP_OnVIPLoaded();
	}
}

public void OnPluginEnd()
{
    if(CanTestFeatures() && GetFeatureStatus(FeatureType_Native, "VIP_UnregisterFeature") == FeatureStatus_Available)
    {
        VIP_UnregisterFeature("quick_switch");
        VIP_UnregisterFeature("quick_switch_speed");
    }
}

public void VIP_OnVIPLoaded()
{
	VIP_RegisterFeature("quick_switch", BOOL);
	VIP_RegisterFeature("quick_switch_speed", FLOAT);
}

public void VIP_OnVIPClientLoaded(int client)
{
	fSwitchSpeed[client] = VIP_GetClientFeatureFloat(client, "quick_switch_speed");
	SDKHook(client, SDKHook_WeaponSwitchPost, OnWeaponSwitchPost);
}

public void OnWeaponSwitchPost(int client, int weapon)
{
	if(!IsValidEdict(weapon) || !VIP_IsClientFeatureUse(client, "quick_switch")) return;
	
	SetEntPropFloat(client, Prop_Send, "m_flNextAttack", GetEntPropFloat(weapon, Prop_Data, "m_flNextPrimaryAttack") + fSwitchSpeed[client]);
}