#include <sourcemod>
#include <shop>
#pragma newdecls required
bool g_bHasLJ[MAXPLAYERS+1];
float g_fLastJump[MAXPLAYERS+1];
int g_iPrice,
g_iSellPrice,
g_iDuration;
ItemId id;
float g_fInterval,
g_fDistance;
int VelocityOffset_0 = -1,
VelocityOffset_1 = -1,
BaseVelocityOffset = -1;
public Plugin myinfo =
{
name = "[Shop] Long Jump",
author = "R1KO",
version = "1.5"
};
public void OnPluginStart()
{
ConVar hCvar;
HookConVarChange((hCvar = CreateConVar("sm_shop_longjump_price", "2000", "Стоимость покупки длинных прыжков.")), OnPriceChange);
g_iPrice = hCvar.IntValue;
HookConVarChange((hCvar = CreateConVar("sm_shop_longjump_sellprice", "0", "Стоимость продажи длинных прыжков.")), OnSellPriceChange);
g_iSellPrice = hCvar.IntValue;
HookConVarChange((hCvar = CreateConVar("sm_shop_longjump_duration", "259200", "Длительность длинных прыжков в секундах.")), OnDurationChange);
g_iDuration = hCvar.IntValue;
HookConVarChange((hCvar = CreateConVar("sm_shop_longjump_interval", "5.0", "Время между прыжками")), OnIntervalChange);
g_fInterval = hCvar.FloatValue;
HookConVarChange((hCvar = CreateConVar("sm_shop_longjump_distance", "1.05", "Усиление прыжка")), OnDistanceChange);
g_fDistance = hCvar.FloatValue;
AutoExecConfig(true, "shop_longjump", "shop");
HookEvent("player_jump", Event_PlayerJump);
if (Shop_IsStarted())
{
Shop_Started();
}
}
public void OnMapStart()
{
VelocityOffset_0 = GetSendPropOffset("CBasePlayer", "m_vecVelocity[0]");
VelocityOffset_1 = GetSendPropOffset("CBasePlayer", "m_vecVelocity[1]");
BaseVelocityOffset = GetSendPropOffset("CBasePlayer", "m_vecBaseVelocity");
}
int GetSendPropOffset(char[] sNetClass, char[] sPropertyName)
{
int iOffset = FindSendPropInfo(sNetClass, sPropertyName);
if (iOffset == -1) SetFailState("Fatal Error: Unable to find offset: \"%s::%s\"", sNetClass, sPropertyName);
return iOffset;
}
public void OnPriceChange(ConVar hCvar, char[] oldValue, char[] newValue)
{
g_iPrice = hCvar.IntValue;
if(id != INVALID_ITEM)
{
Shop_SetItemPrice(id, g_iPrice);
}
}
public void OnSellPriceChange(ConVar hCvar, char[] oldValue, char[] newValue)
{
g_iSellPrice = hCvar.IntValue;
if(id != INVALID_ITEM)
{
Shop_SetItemSellPrice(id, g_iSellPrice);
}
}
public void OnDurationChange(ConVar hCvar, char[] oldValue, char[] newValue)
{
g_iDuration = hCvar.IntValue;
if(id != INVALID_ITEM)
{
Shop_SetItemValue(id, g_iDuration);
}
}
public void OnIntervalChange(ConVar hCvar, char[] oldValue, char[] newValue)
{
g_fInterval = hCvar.FloatValue;
}
public void OnDistanceChange(ConVar hCvar, char[] oldValue, char[] newValue)
{
g_fDistance = hCvar.FloatValue;
}
public void OnPluginEnd()
{
Shop_UnregisterMe();
}
public void Shop_Started()
{
CategoryId category_id = Shop_RegisterCategory("ability", "Способности", "");
if(category_id == INVALID_CATEGORY) SetFailState("Failed to register category");
if (Shop_StartItem(category_id, "longjump"))
{
Shop_SetInfo("Длинные прыжки", "", g_iPrice, g_iSellPrice, Item_Togglable, g_iDuration);
Shop_SetCallbacks(OnItemRegistered, OnLJUsed);
Shop_EndItem();
}
}
void OnItemRegistered(CategoryId category_id, char[] category, char[] item, ItemId item_id)
{
id = item_id;
}
public void Shop_OnAuthorized(int iClient)
{
g_bHasLJ[iClient] = Shop_IsClientItemToggled(iClient, id);
g_fLastJump[iClient] = 0.0;
}
public ShopAction OnLJUsed(int iClient, CategoryId category_id, char[] category, ItemId item_id, char[] item, bool isOn, bool elapsed)
{
if (isOn || elapsed)
{
g_bHasLJ[iClient] = false;
return Shop_UseOff;
}
g_bHasLJ[iClient] = true;
return Shop_UseOn;
}
public Action Event_PlayerJump(Handle hEvent, char[] name, bool dontBroadcast)
{
int iClient = GetClientOfUserId(GetEventInt(hEvent, "userid"));
if(g_bHasLJ[iClient])
{
float fGameTime;
fGameTime = GetGameTime();
if ((fGameTime - g_fLastJump[iClient]) > g_fInterval)
{
g_fLastJump[iClient] = fGameTime;
float finalvec[3];
finalvec[0] = GetEntDataFloat(iClient, VelocityOffset_0)*g_fDistance/2.0;
finalvec[1] = GetEntDataFloat(iClient, VelocityOffset_1)*g_fDistance/2.0;
finalvec[2] = 0.0;
SetEntDataVector(iClient, BaseVelocityOffset, finalvec, true);
}
}
}