#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <vip_core>
#pragma newdecls required
public Plugin myinfo =
{
name = "[VIP] Quick Defuse",
author = "R1KO",
version = "1.2"
};
#define MENU_INFO 1 // Отображать ли информацию в меню
static const char g_sFeature[] = "QuickDefuse";
int m_flDefuseCountDown;
int m_iProgressBarDuration;
bool g_bAllowUse;
ConVar g_hPlayers;
public void OnPluginStart()
{
#if MENU_INFO 1
LoadTranslations("vip_modules.phrases");
#endif
g_hPlayers = CreateConVar("sm_quick_defuse_players","0", "Количество игроков, при которых разрешается использование функции плагина", _, true, 0.0, true, 64.0);
m_flDefuseCountDown = FindSendPropInfo("CPlantedC4", "m_flDefuseCountDown");
m_iProgressBarDuration = FindSendPropInfo("CCSPlayer", "m_iProgressBarDuration");
HookEvent("round_start",Event_RoundStart);
HookEvent("bomb_begindefuse", Event_BeginDefuse);
if(VIP_IsVIPLoaded())
{
VIP_OnVIPLoaded();
}
AutoExecConfig(true,"Vip_QuickDefuse","vip");
}
public void VIP_OnVIPLoaded()
{
#if MENU_INFO 1
VIP_RegisterFeature(g_sFeature, INT, _, _, OnItemDisplay);
#else
VIP_RegisterFeature(g_sFeature, INT);
#endif
}
public void OnPluginEnd()
{
if(CanTestFeatures() && GetFeatureStatus(FeatureType_Native, "VIP_UnregisterFeature") == FeatureStatus_Available)
{
VIP_UnregisterFeature(g_sFeature);
}
}
public Action Event_RoundStart(Event hEvent, char[] szEvName, bool bDontBroadcast)
{
int count;
for(int x = 1; x <= MaxClients;x++)
if(IsClientInGame(x))
count++;
g_bAllowUse = count >= g_hPlayers.IntValue; // Интересно, побьют ли меня за такое
}
public void Event_BeginDefuse(Event hEvent, const char[] sEvName, bool bDontBroadcast)
{
int iClient = GetClientOfUserId(hEvent.GetInt("userid"));
if (g_bAllowUse && VIP_IsClientVIP(iClient) && VIP_IsClientFeatureUse(iClient, g_sFeature))
{
RequestFrame(OnRequestFrame, iClient);
}
}
public void OnRequestFrame(any iClient)
{
if(IsClientInGame(iClient))
{
int iBombEntity = FindEntityByClassname(-1, "planted_c4");
if (iBombEntity > 0)
{
int iValue = VIP_GetClientFeatureInt(iClient, g_sFeature);
float fGameTime = GetGameTime();
float fCountDown = GetEntDataFloat(iBombEntity, m_flDefuseCountDown) - fGameTime;
fCountDown -= fCountDown/100.0*float(iValue);
SetEntDataFloat(iBombEntity, m_flDefuseCountDown, fGameTime+fCountDown, true);
SetEntData(iClient, m_iProgressBarDuration, RoundToCeil(fCountDown));
}
}
}
#if MENU_INFO 1
public bool OnItemDisplay(int iClient, const char[] sFeatureName, char[] sDisplay, int iMaxLen)
{
if(VIP_IsClientFeatureUse(iClient, g_sFeature))
{
FormatEx(sDisplay, iMaxLen, "%T [+%d %%]", g_sFeature, iClient, VIP_GetClientFeatureInt(iClient, g_sFeature));
return true;
}
return false;
}
#endif