Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.28 KB | None | 0 0
  1. #include <lvl_ranks>
  2. #include <clientprefs>
  3.  
  4. bool g_bHud[MAXPLAYERS + 1],
  5.      g_bCScore,
  6.      g_bResolution[MAXPLAYERS + 1];
  7.  
  8. int g_iColors[4],
  9.     g_iStats[MAXPLAYERS + 1][7],
  10.     g_iFW,
  11.     g_iInform[7];
  12.  
  13. float g_fPostion[4],
  14.       g_fUpdateTimer;
  15.  
  16. char g_szRankName[19][128];
  17.  
  18. Handle g_hUpdateTimer,
  19.        hCookie_H,
  20.        hCookie_R;
  21.  
  22. #include "levels_ranks/hud_info/convar.sp"
  23.  
  24. public Plugin myinfo =
  25. {
  26.     name        = "[LR] Module - Hud Info",
  27.     author      = "Faya™ (DS: Faya™#8514)",
  28.     version     = "1.3.4 [PUBLIC]",
  29.     url         = "http://hlmod.ru"
  30. };
  31.  
  32. public void OnPluginStart()
  33. {
  34.     RegConsoleCmd("sm_lvlhud", rccHud);
  35.     RegConsoleCmd("sm_lrhud", rccHud);
  36.  
  37.     HookEvent("round_end", eRE, EventHookMode_PostNoCopy);
  38.     HookEvent("player_death", ePD);
  39.  
  40.     hCookie_H = RegClientCookie("LR_HUD_INFO_HUD", "LR_HUD_INFO_HUD", CookieAccess_Protected);
  41.     hCookie_R = RegClientCookie("LR_HUD_INFO_RESOLUTION", "LR_HUD_INFO_RESOLUTION", CookieAccess_Protected);
  42.  
  43.     CreateConVars();
  44.     KFG_Loading();
  45.     KFG_Loading2();
  46.  
  47.     for(int i = 1; i <= MaxClients; i++)
  48.     {
  49.         if(IsClientInGame(i) && !IsFakeClient(i) && !IsClientSourceTV(i))
  50.         {
  51.             OnClientCookiesCached(i);
  52.         }
  53.     }
  54.  
  55.     LoadTranslations("levels_ranks_hud_info.phrases.txt");
  56. }
  57.  
  58. public Action rccHud(int iClient, int iArgs)
  59. {
  60.     if(iClient)
  61.     {
  62.         OpenMenu(iClient);
  63.     }
  64.  
  65.     return Plugin_Handled;
  66. }
  67.  
  68. public void LR_OnPlayerLoaded(int iClient)
  69. {
  70.     GetStatsPlayer(iClient);
  71.     g_iStats[iClient][5] = LR_GetClientInfo(iClient, 8);    //Time
  72.     g_iStats[iClient][6] = GetTime();
  73. }
  74.  
  75. public void LR_OnLevelChanged(int iClient, int iNewLevel, bool bUp)
  76. {
  77.     if((g_iStats[iClient][4] = LR_GetClientPos(iClient)))       //Top
  78.     {
  79.         g_iStats[iClient][0] = LR_GetClientInfo(iClient, 0);    //Exp
  80.         g_iStats[iClient][1] = LR_GetClientInfo(iClient, 1);    //Rank
  81.     }
  82. }
  83.  
  84. public void OnClientCookiesCached(int iClient)
  85. {
  86.     char szBuffer[3];
  87.     GetClientCookie(iClient, hCookie_H, szBuffer, sizeof szBuffer);
  88.     if(szBuffer[0])
  89.     {
  90.         g_bHud[iClient] = view_as<bool>(StringToInt(szBuffer));
  91.     }
  92.     else
  93.     {
  94.         g_bHud[iClient] = true;
  95.     }
  96.  
  97.     GetClientCookie(iClient, hCookie_R, szBuffer, sizeof szBuffer);
  98.     if(szBuffer[0])
  99.     {
  100.         g_bResolution[iClient] = view_as<bool>(StringToInt(szBuffer));
  101.     }
  102.     else
  103.     {
  104.         g_bResolution[iClient] = true;
  105.     }
  106. }
  107.  
  108. public void OnClientDisconnect(int iClient)
  109. {
  110.     if(g_iStats[iClient][4] > 0)
  111.     {
  112.         char szBuffer[4];
  113.         IntToString(view_as<int>(g_bHud[iClient]), szBuffer, sizeof szBuffer);
  114.         SetClientCookie(iClient, hCookie_H, szBuffer);
  115.         IntToString(view_as<int>(g_bResolution[iClient]), szBuffer, sizeof szBuffer);
  116.         SetClientCookie(iClient, hCookie_H, szBuffer);
  117.     }
  118.  
  119.     for(int i; i < 5; i++)
  120.     {
  121.         g_iStats[iClient][i] = -1;
  122.     }
  123. }
  124.  
  125. public void eRE(Event event, const char[] name, bool dontBroadcast)
  126. {
  127.     for(int i = 1; i <= MaxClients; i++)
  128.     {
  129.         if(IsClientInGame(i) && !IsFakeClient(i) && !IsClientSourceTV(i))
  130.         {
  131.             GetStatsPlayer(i);
  132.         }
  133.     }
  134. }
  135.  
  136. public void ePD(Event event, const char[] name, bool dontBroadcast)
  137. {
  138.     int iClient[3];
  139.     iClient[0] = GetClientOfUserId(event.GetInt("userid"));     //id player died
  140.     iClient[1] = GetClientOfUserId(event.GetInt("attacker"));   //id player killer
  141.     iClient[2] = GetClientOfUserId(event.GetInt("assister"));   //id player assister
  142.  
  143.     for(int i; i < 3; i++)
  144.     {
  145.         if(iClient[i] > 0 && IsClientInGame(iClient[i]) && !IsFakeClient(iClient[i]))
  146.         {
  147.             GetStatsPlayer(iClient[i]);
  148.         }
  149.     }
  150. }
  151.  
  152. void OpenMenu(int iClient)
  153. {
  154.     Handle hMenu = CreateMenu(CallBack_Menu, MenuAction_Select|MenuAction_End);
  155.     SetMenuTitle(hMenu, "Настройка худа\n ");
  156.  
  157.     AddMenuItem(hMenu, "", g_bHud[iClient] ? "Отображение худа [Вкл]" : "Отображение худа [Выкл]");
  158.     AddMenuItem(hMenu, "", g_bResolution[iClient] ? "Расположение худа для [1920x1080]\n " : "Расположение худа для [1280x1024]\n ");
  159.  
  160.     if(GetUserFlagBits(iClient) & ADMFLAG_ROOT)
  161.     {
  162.         AddMenuItem(hMenu, "", "", ITEMDRAW_RAWLINE);
  163.         AddMenuItem(hMenu, "", "Перезагрузить конфиг званий");
  164.         AddMenuItem(hMenu, "", "Перезагрузить конфиг плагина");
  165.     }
  166.     DisplayMenu(hMenu, iClient, MENU_TIME_FOREVER);
  167. }
  168.  
  169. public int CallBack_Menu(Menu hMenu, MenuAction action, int iClient, int iItem)
  170. {
  171.     switch(action)
  172.     {
  173.         case MenuAction_End:
  174.         {
  175.             CloseHandle(hMenu);
  176.         }
  177.         case MenuAction_Select:
  178.         {
  179.             switch(iItem)
  180.             {
  181.                 case 0:
  182.                 {
  183.                     g_bHud[iClient] = !g_bHud[iClient];
  184.                 }
  185.                 case 1:
  186.                 {
  187.                     g_bResolution[iClient] = !g_bResolution[iClient];
  188.                 }
  189.                 case 3:
  190.                 {
  191.                     KFG_Loading();
  192.                     PrintToChat(iClient, " \x02[LvL Hud Info] \x01Конфиг званий перезагружен");
  193.                 }
  194.                 case 4:
  195.                 {
  196.                     KFG_Loading2();
  197.                     PrintToChat(iClient, " \x02[LvL Hud Info] \x01Конфиг плагина перезагружен");
  198.                 }
  199.             }
  200.  
  201.             OpenMenu(iClient);
  202.         }
  203.     }
  204.  
  205.     return 0;
  206. }
  207.  
  208. public Action CallBack_UpdateTimer(Handle hTimer)
  209. {
  210.     static int iShowClient, iObserverMode;
  211.     for(int i = 1; i <= MaxClients; i++)
  212.     {
  213.         if(IsClientInGame(i) && !IsFakeClient(i) && !IsClientSourceTV(i) && g_iStats[i][4])
  214.         {
  215.             iShowClient = i;
  216.             if(!IsPlayerAlive(i) || IsClientObserver(i))
  217.             {
  218.                 iObserverMode = GetEntProp(i, Prop_Send, "m_iObserverMode");
  219.                 if(iObserverMode == 4 || iObserverMode == 5)
  220.                 {
  221.                     iShowClient = GetEntPropEnt(i, Prop_Send, "m_hObserverTarget");
  222.                 }
  223.             }
  224.             if(iShowClient < 0 || iShowClient > MaxClients || !IsClientInGame(iShowClient) || IsFakeClient(iShowClient) || g_iStats[iShowClient][4] < 1)
  225.             {
  226.                 iShowClient = i;
  227.             }
  228.  
  229.             ShowInfo(iShowClient, i);
  230.         }
  231.     }
  232. }
  233.  
  234. void ShowInfo(int iTarget, int iClient)
  235. {
  236.     if(IsClientInGame(iTarget) && !IsFakeClient(iTarget) && !IsClientSourceTV(iTarget) && g_iStats[iTarget][4])
  237.     {
  238.         if(g_iFW && iTarget == iClient)
  239.         {
  240.             return;
  241.         }
  242.         if(g_bCScore)
  243.         {
  244.             if(IsPlayerAlive(iClient) && !(GetClientButtons(iClient) & IN_SCORE))
  245.             {
  246.                 return;
  247.             }
  248.         }
  249.         if(!g_bHud[iClient])
  250.         {
  251.             return;
  252.         }
  253.  
  254.         static char szInfo[7][64];
  255.         if(g_iInform[0])
  256.         {
  257.             FormatEx(szInfo[0], sizeof szInfo[], "%t", "HUD_INFO_KILLS", g_iStats[iTarget][2]);
  258.         }
  259.         if(g_iInform[1])
  260.         {
  261.             if(g_iStats[iTarget][1] == -1)
  262.             {
  263.                 g_iStats[iTarget][1] = 0;
  264.             }
  265.             FormatEx(szInfo[1], sizeof szInfo[], "%t", "HUD_INFO_RANK", g_szRankName[g_iStats[iTarget][1]]);
  266.         }
  267.         if(g_iInform[2])
  268.         {
  269.             static char szTime[32];
  270.             GetStringTime((GetTime() - g_iStats[iTarget][6]) + g_iStats[iTarget][5], szTime, sizeof szTime);
  271.             FormatEx(szInfo[2], sizeof szInfo[], "%t", "HUD_INFO_TIME", szTime);
  272.         }
  273.         if(g_iInform[3])
  274.         {
  275.             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));
  276.         }
  277.         if(g_iInform[4])
  278.         {
  279.             FormatEx(szInfo[4], sizeof szInfo[], "%t", "HUD_INFO_POSITION", g_iStats[iTarget][4]);
  280.         }
  281.         if(g_iInform[5])
  282.         {
  283.             FormatEx(szInfo[5], sizeof szInfo[], "%t", "HUD_INFO_EXP", g_iStats[iTarget][0]);
  284.         }
  285.  
  286.         static char szBuffer[256];
  287.         if(iTarget != iClient)
  288.         {
  289.             if(g_iInform[6])
  290.             {
  291.                 FormatEx(szInfo[6], sizeof szInfo[], "%t", "HUD_INFO_TARGET", iTarget);
  292.                 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);
  293.             }
  294.             else
  295.             {
  296.                 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);
  297.             }
  298.         }
  299.         else
  300.         {
  301.             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);
  302.         }
  303.  
  304.         if(g_bResolution[iClient])
  305.         {
  306.             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);
  307.         }
  308.         else
  309.         {
  310.             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);
  311.         }
  312.  
  313.         ShowHudText(iClient, -1, szBuffer);
  314.     }
  315. }
  316.  
  317. void GetStringTime(int time, char[] buffer, int maxlength)
  318. {
  319.     static int dims[] = {60, 60, 24, 30, 12, cellmax};
  320.     static char sign[][] = {"с", "м", "ч", "д", "м", "г"};
  321.     static char form[][] = {"%02i%s%s", "%02i%s %s", "%i%s %s"};
  322.     buffer[0] = EOS;
  323.     int i = 0, f = -1;
  324.     bool cond = false;
  325.     while(!cond)
  326.     {
  327.         if(f++ == 1) cond = true;
  328.         do
  329.         {
  330.             Format(buffer, maxlength, form[f], time % dims[i], sign[i], buffer);
  331.             if(time /= dims[i++], time == 0)
  332.             {
  333.                 return;
  334.             }
  335.         }
  336.         while(cond);
  337.     }
  338. }
  339.  
  340. void GetStatsPlayer(int iClient)
  341. {
  342.     if((g_iStats[iClient][4] = LR_GetClientPos(iClient)) > 0)       //Top
  343.     {
  344.         g_iStats[iClient][0] = LR_GetClientInfo(iClient, 0);    //Exp
  345.         g_iStats[iClient][1] = LR_GetClientInfo(iClient, 1);    //Rank
  346.         g_iStats[iClient][2] = LR_GetClientInfo(iClient, 2);    //Kills
  347.         g_iStats[iClient][3] = LR_GetClientInfo(iClient, 3);    //Deaths
  348.     }
  349. }
  350.  
  351. void ChangeColors(const char[] szBuffer)
  352. {
  353.     char szExBuffer[4][24];
  354.     ExplodeString(szBuffer, " ", szExBuffer, 4, 24);
  355.  
  356.     for(int i = 0; i <= 3; i++)
  357.     {
  358.         g_iColors[i] = StringToInt(szExBuffer[i]);
  359.     }
  360. }
  361.  
  362. void ChangePositions(const char[] szBuffer, bool bResolution)
  363. {
  364.     char szExBuffer[2][16];
  365.     ExplodeString(szBuffer, " ", szExBuffer, 2, 16);
  366.  
  367.     if(bResolution)
  368.     {
  369.         g_fPostion[0] = StringToFloat(szExBuffer[0]);
  370.         g_fPostion[1] = StringToFloat(szExBuffer[1]);
  371.     }
  372.     else
  373.     {
  374.         g_fPostion[2] = StringToFloat(szExBuffer[0]);
  375.         g_fPostion[3] = StringToFloat(szExBuffer[1]);
  376.     }
  377. }
  378.  
  379. void KFG_Loading()
  380. {
  381.     KeyValues KV = new KeyValues("LR_Settings");
  382.     char szPath[PLATFORM_MAX_PATH];
  383.     BuildPath(Path_SM, szPath, sizeof szPath, "configs/levels_ranks/settings_ranks.ini");
  384.     if(!FileToKeyValues(KV, szPath))
  385.     {
  386.         SetFailState("[Levels Ranks Hud Info] - Файл конфигураций не найден %s", szPath);
  387.     }
  388.  
  389.     KvRewind(KV);
  390.     if(KvJumpToKey(KV, "Ranks") && KvGotoFirstSubKey(KV, false))
  391.     {
  392.         do
  393.         {
  394.             if(KvGetSectionName(KV, szPath, sizeof szPath))
  395.             {
  396.                 KvGetString(KV, "name", g_szRankName[StringToInt(szPath)], sizeof g_szRankName[]);
  397.             }
  398.         }
  399.         while(KvGotoNextKey(KV));
  400.     }
  401.  
  402.     delete KV;
  403. }
  404.  
  405. void KFG_Loading2()
  406. {
  407.     KeyValues KV = new KeyValues("HUD_Settings");
  408.     char szPath[PLATFORM_MAX_PATH];
  409.     BuildPath(Path_SM, szPath, sizeof szPath, "configs/levels_ranks/hud_info.ini");
  410.     if(!FileToKeyValues(KV, szPath))
  411.     {
  412.         SetFailState("[Levels Ranks Hud Info] - Файл конфигураций не найден %s", szPath);
  413.     }
  414.  
  415.     KvRewind(KV);
  416.     if(KvJumpToKey(KV, "Settings"))
  417.     {
  418.         g_iInform[6] = KvGetNum(KV, "Nick");
  419.         g_iInform[0] = KvGetNum(KV, "Kills");
  420.         g_iInform[1] = KvGetNum(KV, "Rank");
  421.         g_iInform[2] = KvGetNum(KV, "Time");
  422.         g_iInform[3] = KvGetNum(KV, "KDR");
  423.         g_iInform[4] = KvGetNum(KV, "Top");
  424.         g_iInform[5] = KvGetNum(KV, "Exp");
  425.     }
  426.  
  427.     delete KV;
  428. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement