#include <sourcemod>
#include <lvl_ranks>
#include <clientprefs>
public Plugin myinfo =
{
name = "[LR] Players info",
author = "Drumanid",
version = "1.0.2",
url = "Discord: Drumanid#9108"
};
Handle g_hCookie;
char g_sRanksInfo[19][32];
bool g_bUse[MAXPLAYERS +1];
#define SZF(%0) %0, sizeof(%0)
#define CyclePlayers(%0) for(int %0 = 1; %0 <= MaxClients; ++%0) if(IsClientInGame(%0))
public void OnPluginStart()
{
// load translation file
LoadTranslations("lr_core_ranks.phrases");
LoadTranslations("levels_ranks_playersinfo.phrases.txt");
// Parser ranks info
char sPath[64];
BuildPath(Path_SM, SZF(sPath), "configs/levels_ranks/settings_ranks.ini");
KeyValues hKeyValues = new KeyValues("LR_Settings");
if(!hKeyValues.ImportFromFile(sPath))
SetFailState("No found file: '%s'", sPath);
hKeyValues.Rewind();
if(!hKeyValues.JumpToKey("Ranks"))
SetFailState("No found key: 'Ranks'", sPath);
int iCount = 1;
g_sRanksInfo[0] = "NONE";
hKeyValues.GotoFirstSubKey();
do hKeyValues.GetSectionName(g_sRanksInfo[iCount++], sizeof(g_sRanksInfo[]));
while(hKeyValues.GotoNextKey());
delete hKeyValues;
// Update info
CreateTimer(1.0, view_as<Timer>(TimerUpdate), _, TIMER_REPEAT);
// Create cookie
g_hCookie = RegClientCookie("levelranks_playerinfo", "On/off player information", CookieAccess_Private);
// Load data players
CyclePlayers(iClient)
OnClientCookiesCached(iClient);
}
// Show info
#define KD(%0) float(%0 == 0 ? 1 : %0)
void TimerUpdate()
{
char sRank[64];
int iTarget, iKills, iDeaths, iAssists, iSeconds;
CyclePlayers(iClient)
{
if(g_bUse[iClient] && !IsFakeClient(iClient) && !IsPlayerAlive(iClient) && 3 < GetEntProp(iClient, Prop_Send, "m_iObserverMode") < 6 &&
1 < (iTarget = GetEntPropEnt(iClient, Prop_Send, "m_hObserverTarget")) <= MaxClients && IsClientInGame(iTarget))
{
FormatEx(SZF(sRank), "%T", g_sRanksInfo[LR_GetClientInfo(iTarget, ST_RANK)], iClient);
iKills = LR_GetClientInfo(iTarget, ST_KILLS);
iDeaths = LR_GetClientInfo(iTarget, ST_DEATHS);
iAssists = LR_GetClientInfo(iTarget, ST_ASSISTS);
iSeconds = LR_GetClientInfo(iTarget, ST_PLAYTIME);
PrintHintText(iClient, "%t", "Player information", sRank,
LR_GetClientInfo(iTarget, ST_PLACEINTOP),
LR_GetClientInfo(iTarget, ST_EXP),
iKills,
iDeaths,
iAssists,
(KD(iKills) + float(iAssists / 2)) / KD(iDeaths),
LR_GetClientInfo(iTarget, ST_SHOOTS),
LR_GetClientInfo(iTarget, ST_HITS),
LR_GetClientInfo(iTarget, ST_HEADSHOTS),
iSeconds / 3600,
iSeconds / 60 %60,
iSeconds %60);
}
}
}
// Get info from cookie and record in variable
public void OnClientCookiesCached(int iClient)
{
if(IsFakeClient(iClient))
return;
char sValue[4];
GetClientCookie(iClient, g_hCookie, SZF(sValue));
g_bUse[iClient] = sValue[0] ? view_as<bool>(StringToInt(sValue)):true;
}
// Add item in lvl menu
public void LR_OnMenuCreated(int iClient, Menu& hMenu)
{
char sBuffer[64];
FormatEx(SZF(sBuffer), "%T", g_bUse[iClient] ? "Item, on":"Item, off", iClient);
hMenu.AddItem("playersinfo", sBuffer);
}
public void LR_OnMenuItemSelected(int iClient, const char[] sInfo)
{
if(!StrEqual(sInfo, "playersinfo"))
return;
PrintToChat(iClient, "%t", (g_bUse[iClient] = !g_bUse[iClient]) ? "Message, on":"Message, off");
LR_MenuInventory(iClient);
}
// Save data
public void OnClientDisconnect(int iClient)
{
if(!IsFakeClient(iClient))
SetClientCookie(iClient, g_hCookie, g_bUse[iClient] ? "1":"0");
}
public void OnPluginEnd()
{
CyclePlayers(iClient)
OnClientDisconnect(iClient);
}