#pragma semicolon 1
#include <sourcemod>
#include <cstrike>
#include <lk>
#include <shop>
#include <lvl_ranks>
#define MAX_ITEMS 32
enum enum_Exp
{
String:Name[64],
_:Exp,
_:Price,
}
int g_iExpItem, g_Exp[MAX_ITEMS][enum_Exp];
char g_sItemName[] = "levels_ranks";
public Plugin myinfo =
{
name = "[LK MODULE] Покупка опыта Levels Ranks",
author = "Narkus",
version = "1.0"
};
public void LK_OnLoaded()
{
if(LK_GetVersion() < 400) LogError("[LK MODULE][Покупка опыта Levels Ranks] Обновите ядро до последней версии");
else
{
LoadTranslations("lk_module_levels_ranks.phrases");
LK_RegisterItem(g_sItemName, LevelsRanks_Callback);
}
}
public void OnPluginEnd()
{
LK_UnRegisterItem(g_sItemName);
}
public void OnMapStart()
{
KFG_load();
}
public void LevelsRanks_Callback(int iClient, int ItemID, const char[] ItemName)
{
ShowMenuModule(iClient);
}
void ShowMenuModule(int iClient)
{
char sTitle[256];
int ClientCash = LK_GetClientCash(iClient);
LK_GetMainMenuTitle(iClient, sTitle, sizeof(sTitle));
Menu hMenu = new Menu(MenuHandler_MainMenu);
hMenu.ExitBackButton = true;
hMenu.SetTitle(sTitle);
for(int i = 0; i < g_iExpItem; i++)
{
char szBuffer[16];
IntToString(i, szBuffer, sizeof(szBuffer));
hMenu.AddItem(szBuffer, g_Exp[i][Name], ClientCash >= g_Exp[i][Price] ? ITEMDRAW_DEFAULT:ITEMDRAW_DISABLED);
}
hMenu.Display(iClient, 0);
}
public int MenuHandler_MainMenu(Menu hMenu, MenuAction action, int iClient, int iItem)
{
switch(action)
{
case MenuAction_End: delete hMenu;
case MenuAction_Cancel:
{
if(iItem == MenuCancel_ExitBack) LK_ShowMainMenu(iClient);
}
case MenuAction_Select:
{
char szInfo[16], sAuth[32];
GetClientAuthId(iClient, AuthId_Steam2, sAuth, sizeof(sAuth));
hMenu.GetItem(iItem, szInfo, sizeof(szInfo));
int i = StringToInt(szInfo);
LK_TakeClientCash(iClient, g_Exp[i][Price]);
LR_ChangeClientValue(iClient, g_Exp[i][Exp]);
LK_PrintToChat(iClient, "%T", "Buy_Experience", iClient, g_Exp[i][Exp]);
LK_LogMessage("[Личный кабинет] Игрок %N (%s) купил %i опыта Levels Ranks", iClient, sAuth, g_Exp[i][Exp]);
ShowMenuModule(iClient);
}
}
}
void KFG_load()
{
char sPath[128];
KeyValues KV = new KeyValues("LK_MODULE");
BuildPath(Path_SM, sPath, sizeof(sPath), "configs/lk/lk_module_levels_ranks.ini");
if(!KV.ImportFromFile(sPath)) SetFailState("[LK MODULE][Покупка опыта Levels Ranks] - Файл конфигураций не найден");
KV.Rewind();
if(KV.GotoFirstSubKey(true))
{
g_iExpItem = 0;
do
{
if(KV.GetSectionName(g_Exp[g_iExpItem][Name], 64))
{
g_Exp[g_iExpItem][Exp] = KV.GetNum("exp");
g_Exp[g_iExpItem][Price] = KV.GetNum("price");
if(g_Exp[g_iExpItem][Exp] < 0) g_Exp[g_iExpItem][Exp] = 0;
if(g_Exp[g_iExpItem][Price] < 0) g_Exp[g_iExpItem][Price] = 0;
g_iExpItem += 1;
}
} while(KV.GotoNextKey(true));
}
}