#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdktools>
#include <lvl_ranks>
#include <clientprefs>
#define PLUGIN_NAME "[LR] Module - Grenades (CS:GO)"
#define PLUGIN_AUTHOR "fuckOff1703"
int iHE[MAXPLAYERS+1],iFB[MAXPLAYERS+1],iSG[MAXPLAYERS+1],iMT[MAXPLAYERS+1],iDC[MAXPLAYERS+1];
Handle g_hCookie;
bool g_GActive[MAXPLAYERS + 1];
char g_sPluginTitle[64];
public Plugin myinfo = {name = PLUGIN_NAME, author = PLUGIN_AUTHOR, version = "0.6"};
public void OnPluginStart()
{
if (LR_IsLoaded())
{
LR_OnCoreIsReady();
}
g_hCookie = RegClientCookie("LR_Grenades", "LR_Grenades", CookieAccess_Private);
LoadTranslations("lr_module_grenades.phrases");
HookEvent("player_spawn", PlayerSpawn);
for (int iClient = 1; iClient <= MaxClients; iClient++)
{
if (IsClientInGame(iClient))
{
OnClientCookiesCached(iClient);
}
}
}
public void LR_OnCoreIsReady()
{
if (LR_GetSettingsValue(LR_TypeStatistics))
{
SetFailState(PLUGIN_NAME..." : This module will work if [ lr_type_statistics 0 ]");
}
LR_Hook(LR_OnSettingsModuleUpdate, ConfigLoad);
LR_MenuHook(LR_SettingMenu, LR_OnMenuCreated, LR_OnMenuItemSelected);
ConfigLoad();
}
void ConfigLoad()
{
int ilvl;
static char sPath[PLATFORM_MAX_PATH];
if(!sPath[0])
BuildPath(Path_SM, sPath, sizeof(sPath), "configs/levels_ranks/grenades.ini");
KeyValues hLR = new KeyValues("LR_Grenades");
if(!hLR.ImportFromFile(sPath))
SetFailState(PLUGIN_NAME ... " : File is not found (%s)", sPath);
hLR.GotoFirstSubKey();
hLR.Rewind();
if(hLR.JumpToKey("Settings"))
{
hLR.GotoFirstSubKey();
do
{
iHE[ilvl] = hLR.GetNum("he", 0);
iFB[ilvl] = hLR.GetNum("flash", 0);
iSG[ilvl] = hLR.GetNum("smoke", 0);
iMT[ilvl] = hLR.GetNum("molotov", 0);
iDC[ilvl] = hLR.GetNum("decoy", 0);
ilvl++;
}
while(hLR.GotoNextKey());
if(ilvl != LR_GetRankExp().Length)
SetFailState(PLUGIN_NAME ... " : The number of ranks does not match the specified number in the core (%s)", sPath);
}
else SetFailState(PLUGIN_NAME ... " : Section Settings is not found (%s)", sPath);
LR_GetTitleMenu(g_sPluginTitle, sizeof(g_sPluginTitle));
hLR.Close();
}
public void PlayerSpawn(Handle hEvent, char[] sEvName, bool bDontBroadcast)
{
int iClient = GetClientOfUserId(GetEventInt(hEvent, "userid"));
int iRank = LR_GetClientInfo(iClient, ST_RANK);
if (iClient && IsClientInGame(iClient) && !g_GActive[iClient] && iRank)
{
if(iHE[iRank-1] > 0)
{
GivePlayerItem(iClient, "weapon_hegrenade");
SetEntProp(iClient, Prop_Send, "m_iAmmo", iHE[iRank-1]);
}
if(iFB[iRank-1] > 0)
{
GivePlayerItem(iClient, "weapon_flashbang");
SetEntProp(iClient, Prop_Send, "m_iAmmo", iFB[iRank-1]);
}
if(iSG[iRank-1] > 0)
{
GivePlayerItem(iClient, "weapon_smokegrenade");
SetEntProp(iClient, Prop_Send, "m_iAmmo", iSG[iRank-1]);
}
if(iMT[iRank-1] > 0)
{
GivePlayerItem(iClient, "weapon_molotov");
SetEntProp(iClient, Prop_Send, "m_iAmmo", iMT[iRank-1]);
}
if(iDC[iRank-1] > 0)
{
GivePlayerItem(iClient, "weapon_decoy");
SetEntProp(iClient, Prop_Send, "m_iAmmo", iDC[iRank-1]);
}
}
}
void LR_OnMenuCreated(LR_MenuType OnMenuType, int iClient, Menu hMenu)
{
char sText[64];
int iRank = LR_GetClientInfo(iClient, ST_RANK);
int i;
while (iHE[i] <= 0 && iFB[i] <= 0 && iSG[i] <= 0 && iMT[i] <= 0 && iDC[i] <= 0)i++;
if (iHE[iRank-1] > 0 || iFB[iRank-1] > 0 || iSG[iRank-1] > 0 || iMT[iRank-1] > 0 || iDC[iRank-1] > 0)
{
FormatEx(sText, sizeof(sText), "%T", !g_GActive[iClient] ? "Grenades_On" : "Grenades_Off", iClient, iHE[iRank-1] + iFB[iRank-1] + iSG[iRank-1] + iMT[iRank-1] + iDC[iRank-1]);
hMenu.AddItem("Grenades", sText);
}
else
{
FormatEx(sText, sizeof(sText), "%T", "Grenades_RankClosed", iClient, iHE[i] + iFB[i] + iSG[i] + iMT[i] + iDC[i], i+1);
hMenu.AddItem("Grenades", sText, ITEMDRAW_DISABLED);
}
}
void LR_OnMenuItemSelected(LR_MenuType OnMenuType, int iClient, const char[] sInfo)
{
if (!strcmp(sInfo, "Grenades"))
{
g_GActive[iClient] = !g_GActive[iClient];
LR_ShowMenu(iClient, LR_SettingMenu);
}
}
public void OnClientCookiesCached(int iClient)
{
char sCookie[2];
GetClientCookie(iClient, g_hCookie, sCookie, sizeof(sCookie));
g_GActive[iClient] = sCookie[0] == '1';
}
public void OnClientDisconnect(int iClient)
{
char sCookie[2];
sCookie[0] = '0' + view_as<char>(g_GActive[iClient]);
SetClientCookie(iClient, g_hCookie, sCookie);
}
public void OnPluginEnd()
{
for (int iClient = 1; iClient <= MaxClients; iClient++)
{
if (IsClientInGame(iClient))
{
OnClientDisconnect(iClient);
}
}
}