Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <lvl_ranks>
- #include <clientprefs>
- bool g_bHud[MAXPLAYERS + 1],
- g_bCScore,
- g_bResolution[MAXPLAYERS + 1];
- int g_iColors[4],
- g_iStats[MAXPLAYERS + 1][7],
- g_iFW,
- g_iInform[7];
- float g_fPostion[4],
- g_fUpdateTimer;
- char g_szRankName[19][128];
- Handle g_hUpdateTimer,
- hCookie_H,
- hCookie_R;
- #include "levels_ranks/hud_info/convar.sp"
- public Plugin myinfo =
- {
- name = "[LR] Module - Hud Info",
- author = "Faya™ (DS: Faya™#8514)",
- version = "1.3.4 [PUBLIC]",
- url = "http://hlmod.ru"
- };
- public void OnPluginStart()
- {
- RegConsoleCmd("sm_lvlhud", rccHud);
- RegConsoleCmd("sm_lrhud", rccHud);
- HookEvent("round_end", eRE, EventHookMode_PostNoCopy);
- HookEvent("player_death", ePD);
- hCookie_H = RegClientCookie("LR_HUD_INFO_HUD", "LR_HUD_INFO_HUD", CookieAccess_Protected);
- hCookie_R = RegClientCookie("LR_HUD_INFO_RESOLUTION", "LR_HUD_INFO_RESOLUTION", CookieAccess_Protected);
- CreateConVars();
- KFG_Loading();
- KFG_Loading2();
- for(int i = 1; i <= MaxClients; i++)
- {
- if(IsClientInGame(i) && !IsFakeClient(i) && !IsClientSourceTV(i))
- {
- OnClientCookiesCached(i);
- }
- }
- LoadTranslations("levels_ranks_hud_info.phrases.txt");
- }
- public Action rccHud(int iClient, int iArgs)
- {
- if(iClient)
- {
- OpenMenu(iClient);
- }
- return Plugin_Handled;
- }
- public void LR_OnPlayerLoaded(int iClient)
- {
- GetStatsPlayer(iClient);
- g_iStats[iClient][5] = LR_GetClientInfo(iClient, 8); //Time
- g_iStats[iClient][6] = GetTime();
- }
- public void LR_OnLevelChanged(int iClient, int iNewLevel, bool bUp)
- {
- if((g_iStats[iClient][4] = LR_GetClientPos(iClient))) //Top
- {
- g_iStats[iClient][0] = LR_GetClientInfo(iClient, 0); //Exp
- g_iStats[iClient][1] = LR_GetClientInfo(iClient, 1); //Rank
- }
- }
- public void OnClientCookiesCached(int iClient)
- {
- char szBuffer[3];
- GetClientCookie(iClient, hCookie_H, szBuffer, sizeof szBuffer);
- if(szBuffer[0])
- {
- g_bHud[iClient] = view_as<bool>(StringToInt(szBuffer));
- }
- else
- {
- g_bHud[iClient] = true;
- }
- GetClientCookie(iClient, hCookie_R, szBuffer, sizeof szBuffer);
- if(szBuffer[0])
- {
- g_bResolution[iClient] = view_as<bool>(StringToInt(szBuffer));
- }
- else
- {
- g_bResolution[iClient] = true;
- }
- }
- public void OnClientDisconnect(int iClient)
- {
- if(g_iStats[iClient][4] > 0)
- {
- char szBuffer[4];
- IntToString(view_as<int>(g_bHud[iClient]), szBuffer, sizeof szBuffer);
- SetClientCookie(iClient, hCookie_H, szBuffer);
- IntToString(view_as<int>(g_bResolution[iClient]), szBuffer, sizeof szBuffer);
- SetClientCookie(iClient, hCookie_H, szBuffer);
- }
- for(int i; i < 5; i++)
- {
- g_iStats[iClient][i] = -1;
- }
- }
- public void eRE(Event event, const char[] name, bool dontBroadcast)
- {
- for(int i = 1; i <= MaxClients; i++)
- {
- if(IsClientInGame(i) && !IsFakeClient(i) && !IsClientSourceTV(i))
- {
- GetStatsPlayer(i);
- }
- }
- }
- public void ePD(Event event, const char[] name, bool dontBroadcast)
- {
- int iClient[3];
- iClient[0] = GetClientOfUserId(event.GetInt("userid")); //id player died
- iClient[1] = GetClientOfUserId(event.GetInt("attacker")); //id player killer
- iClient[2] = GetClientOfUserId(event.GetInt("assister")); //id player assister
- for(int i; i < 3; i++)
- {
- if(iClient[i] > 0 && IsClientInGame(iClient[i]) && !IsFakeClient(iClient[i]))
- {
- GetStatsPlayer(iClient[i]);
- }
- }
- }
- void OpenMenu(int iClient)
- {
- Handle hMenu = CreateMenu(CallBack_Menu, MenuAction_Select|MenuAction_End);
- SetMenuTitle(hMenu, "Настройка худа\n ");
- AddMenuItem(hMenu, "", g_bHud[iClient] ? "Отображение худа [Вкл]" : "Отображение худа [Выкл]");
- AddMenuItem(hMenu, "", g_bResolution[iClient] ? "Расположение худа для [1920x1080]\n " : "Расположение худа для [1280x1024]\n ");
- if(GetUserFlagBits(iClient) & ADMFLAG_ROOT)
- {
- AddMenuItem(hMenu, "", "", ITEMDRAW_RAWLINE);
- AddMenuItem(hMenu, "", "Перезагрузить конфиг званий");
- AddMenuItem(hMenu, "", "Перезагрузить конфиг плагина");
- }
- DisplayMenu(hMenu, iClient, MENU_TIME_FOREVER);
- }
- public int CallBack_Menu(Menu hMenu, MenuAction action, int iClient, int iItem)
- {
- switch(action)
- {
- case MenuAction_End:
- {
- CloseHandle(hMenu);
- }
- case MenuAction_Select:
- {
- switch(iItem)
- {
- case 0:
- {
- g_bHud[iClient] = !g_bHud[iClient];
- }
- case 1:
- {
- g_bResolution[iClient] = !g_bResolution[iClient];
- }
- case 3:
- {
- KFG_Loading();
- PrintToChat(iClient, " \x02[LvL Hud Info] \x01Конфиг званий перезагружен");
- }
- case 4:
- {
- KFG_Loading2();
- PrintToChat(iClient, " \x02[LvL Hud Info] \x01Конфиг плагина перезагружен");
- }
- }
- OpenMenu(iClient);
- }
- }
- return 0;
- }
- public Action CallBack_UpdateTimer(Handle hTimer)
- {
- static int iShowClient, iObserverMode;
- for(int i = 1; i <= MaxClients; i++)
- {
- if(IsClientInGame(i) && !IsFakeClient(i) && !IsClientSourceTV(i) && g_iStats[i][4])
- {
- iShowClient = i;
- if(!IsPlayerAlive(i) || IsClientObserver(i))
- {
- iObserverMode = GetEntProp(i, Prop_Send, "m_iObserverMode");
- if(iObserverMode == 4 || iObserverMode == 5)
- {
- iShowClient = GetEntPropEnt(i, Prop_Send, "m_hObserverTarget");
- }
- }
- if(iShowClient < 0 || iShowClient > MaxClients || !IsClientInGame(iShowClient) || IsFakeClient(iShowClient) || g_iStats[iShowClient][4] < 1)
- {
- iShowClient = i;
- }
- ShowInfo(iShowClient, i);
- }
- }
- }
- void ShowInfo(int iTarget, int iClient)
- {
- if(IsClientInGame(iTarget) && !IsFakeClient(iTarget) && !IsClientSourceTV(iTarget) && g_iStats[iTarget][4])
- {
- if(g_iFW && iTarget == iClient)
- {
- return;
- }
- if(g_bCScore)
- {
- if(IsPlayerAlive(iClient) && !(GetClientButtons(iClient) & IN_SCORE))
- {
- return;
- }
- }
- if(!g_bHud[iClient])
- {
- return;
- }
- static char szInfo[7][64];
- if(g_iInform[0])
- {
- FormatEx(szInfo[0], sizeof szInfo[], "%t", "HUD_INFO_KILLS", g_iStats[iTarget][2]);
- }
- if(g_iInform[1])
- {
- if(g_iStats[iTarget][1] == -1)
- {
- g_iStats[iTarget][1] = 0;
- }
- FormatEx(szInfo[1], sizeof szInfo[], "%t", "HUD_INFO_RANK", g_szRankName[g_iStats[iTarget][1]]);
- }
- if(g_iInform[2])
- {
- static char szTime[32];
- GetStringTime((GetTime() - g_iStats[iTarget][6]) + g_iStats[iTarget][5], szTime, sizeof szTime);
- FormatEx(szInfo[2], sizeof szInfo[], "%t", "HUD_INFO_TIME", szTime);
- }
- if(g_iInform[3])
- {
- FormatEx(szInfo[3], sizeof szInfo[], "%t", "HUD_INFO_KDR", g_iStats[iTarget][3] < 1 ? g_iStats[iTarget][2] + 0.0 : (g_iStats[iTarget][2] + 0.0) / (g_iStats[iTarget][3] + 0.0));
- }
- if(g_iInform[4])
- {
- FormatEx(szInfo[4], sizeof szInfo[], "%t", "HUD_INFO_POSITION", g_iStats[iTarget][4]);
- }
- if(g_iInform[5])
- {
- FormatEx(szInfo[5], sizeof szInfo[], "%t", "HUD_INFO_EXP", g_iStats[iTarget][0]);
- }
- static char szBuffer[256];
- if(iTarget != iClient)
- {
- if(g_iInform[6])
- {
- FormatEx(szInfo[6], sizeof szInfo[], "%t", "HUD_INFO_TARGET", iTarget);
- FormatEx(szBuffer, sizeof szBuffer, "%t", "HUD_SHOW_INFO_TARGET", szInfo[6], g_iInform[0] ? szInfo[0] : NULL_STRING, g_iInform[1] ? szInfo[1] : NULL_STRING, g_iInform[2] ? szInfo[2] : NULL_STRING, g_iInform[3] ? szInfo[3] : NULL_STRING, g_iInform[4] ? szInfo[4] : NULL_STRING, g_iInform[5] ? szInfo[5] : NULL_STRING);
- }
- else
- {
- FormatEx(szBuffer, sizeof szBuffer, "%t", "HUD_SHOW_INFO_TARGET", g_iInform[0] ? szInfo[0] : NULL_STRING, g_iInform[1] ? szInfo[1] : NULL_STRING, g_iInform[2] ? szInfo[2] : NULL_STRING, g_iInform[3] ? szInfo[3] : NULL_STRING, g_iInform[4] ? szInfo[4] : NULL_STRING, g_iInform[5] ? szInfo[5] : NULL_STRING);
- }
- }
- else
- {
- FormatEx(szBuffer, sizeof szBuffer, "%t", "HUD_SHOW_INFO", g_iInform[0] ? szInfo[0] : NULL_STRING, g_iInform[1] ? szInfo[1] : NULL_STRING, g_iInform[2] ? szInfo[2] : NULL_STRING, g_iInform[3] ? szInfo[3] : NULL_STRING, g_iInform[4] ? szInfo[4] : NULL_STRING, g_iInform[5] ? szInfo[5] : NULL_STRING);
- }
- if(g_bResolution[iClient])
- {
- SetHudTextParams(g_fPostion[0], g_fPostion[1], g_fUpdateTimer + 0.05, g_iColors[0] , g_iColors[1], g_iColors[2], g_iColors[3], 2 , 0.0, 0.0, 0.0);
- }
- else
- {
- SetHudTextParams(g_fPostion[2], g_fPostion[3], g_fUpdateTimer + 0.05, g_iColors[0] , g_iColors[1], g_iColors[2], g_iColors[3], 2 , 0.0, 0.0, 0.0);
- }
- ShowHudText(iClient, -1, szBuffer);
- }
- }
- void GetStringTime(int time, char[] buffer, int maxlength)
- {
- static int dims[] = {60, 60, 24, 30, 12, cellmax};
- static char sign[][] = {"с", "м", "ч", "д", "м", "г"};
- static char form[][] = {"%02i%s%s", "%02i%s %s", "%i%s %s"};
- buffer[0] = EOS;
- int i = 0, f = -1;
- bool cond = false;
- while(!cond)
- {
- if(f++ == 1) cond = true;
- do
- {
- Format(buffer, maxlength, form[f], time % dims[i], sign[i], buffer);
- if(time /= dims[i++], time == 0)
- {
- return;
- }
- }
- while(cond);
- }
- }
- void GetStatsPlayer(int iClient)
- {
- if((g_iStats[iClient][4] = LR_GetClientPos(iClient)) > 0) //Top
- {
- g_iStats[iClient][0] = LR_GetClientInfo(iClient, 0); //Exp
- g_iStats[iClient][1] = LR_GetClientInfo(iClient, 1); //Rank
- g_iStats[iClient][2] = LR_GetClientInfo(iClient, 2); //Kills
- g_iStats[iClient][3] = LR_GetClientInfo(iClient, 3); //Deaths
- }
- }
- void ChangeColors(const char[] szBuffer)
- {
- char szExBuffer[4][24];
- ExplodeString(szBuffer, " ", szExBuffer, 4, 24);
- for(int i = 0; i <= 3; i++)
- {
- g_iColors[i] = StringToInt(szExBuffer[i]);
- }
- }
- void ChangePositions(const char[] szBuffer, bool bResolution)
- {
- char szExBuffer[2][16];
- ExplodeString(szBuffer, " ", szExBuffer, 2, 16);
- if(bResolution)
- {
- g_fPostion[0] = StringToFloat(szExBuffer[0]);
- g_fPostion[1] = StringToFloat(szExBuffer[1]);
- }
- else
- {
- g_fPostion[2] = StringToFloat(szExBuffer[0]);
- g_fPostion[3] = StringToFloat(szExBuffer[1]);
- }
- }
- void KFG_Loading()
- {
- KeyValues KV = new KeyValues("LR_Settings");
- char szPath[PLATFORM_MAX_PATH];
- BuildPath(Path_SM, szPath, sizeof szPath, "configs/levels_ranks/settings_ranks.ini");
- if(!FileToKeyValues(KV, szPath))
- {
- SetFailState("[Levels Ranks Hud Info] - Файл конфигураций не найден %s", szPath);
- }
- KvRewind(KV);
- if(KvJumpToKey(KV, "Ranks") && KvGotoFirstSubKey(KV, false))
- {
- do
- {
- if(KvGetSectionName(KV, szPath, sizeof szPath))
- {
- KvGetString(KV, "name", g_szRankName[StringToInt(szPath)], sizeof g_szRankName[]);
- }
- }
- while(KvGotoNextKey(KV));
- }
- delete KV;
- }
- void KFG_Loading2()
- {
- KeyValues KV = new KeyValues("HUD_Settings");
- char szPath[PLATFORM_MAX_PATH];
- BuildPath(Path_SM, szPath, sizeof szPath, "configs/levels_ranks/hud_info.ini");
- if(!FileToKeyValues(KV, szPath))
- {
- SetFailState("[Levels Ranks Hud Info] - Файл конфигураций не найден %s", szPath);
- }
- KvRewind(KV);
- if(KvJumpToKey(KV, "Settings"))
- {
- g_iInform[6] = KvGetNum(KV, "Nick");
- g_iInform[0] = KvGetNum(KV, "Kills");
- g_iInform[1] = KvGetNum(KV, "Rank");
- g_iInform[2] = KvGetNum(KV, "Time");
- g_iInform[3] = KvGetNum(KV, "KDR");
- g_iInform[4] = KvGetNum(KV, "Top");
- g_iInform[5] = KvGetNum(KV, "Exp");
- }
- delete KV;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement