Advertisement
Guest User

Untitled

a guest
Mar 31st, 2018
783
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 13.66 KB | None | 0 0
  1. #include <amxmisc>
  2. #include <csx>
  3.  
  4. #if AMXX_VERSION_NUM < 183
  5.     #define MAX_NAME_LENGTH 32
  6.     #include <colorchat>
  7. #endif
  8.  
  9. #pragma semicolon 1
  10.  
  11. //Version
  12. new const Version[] = "0.3.2";
  13.  
  14. //Pointers to Cvars
  15. new CvarRank, CvarRankStats, CvarTop, CvarTopNum, CvarTitle, CvarDisconnect;
  16.  
  17. //Idents for chat commands
  18. new const RankIdent[]       = "/rank";
  19. new const RankStatsIdent[]  = "/rankstats";
  20. new const TopIdent[]        = "/top";
  21.  
  22. public plugin_init()
  23. {
  24.     register_plugin("RRT", Version, "Ex3cuTioN/Arion + Lux0R^^");
  25.    
  26.     register_clcmd("say", "hookChatForCommand");
  27.     register_clcmd("say_team", "hookChatForCommand");
  28.    
  29.     createCvars();
  30. }
  31.  
  32. public hookChatForCommand(Index)
  33. {
  34.     new Said[192];
  35.    
  36.     read_args(Said, charsmax(Said));
  37.     remove_quotes(Said);
  38.    
  39.     if (equal(Said, RankStatsIdent, charsmax(RankStatsIdent)))
  40.     {
  41.         if (equal(Said, RankStatsIdent))
  42.         {
  43.             showRankStats(Index, Index);
  44.         }
  45.         new Target[MAX_NAME_LENGTH];
  46.        
  47.         split(Said, Said, charsmax(Said), Target, charsmax(Target), " ");
  48.         showRankStats(Index, cmd_target(Index, Target, CMDTARGET_NO_BOTS));
  49.        
  50.         return PLUGIN_HANDLED;
  51.     }
  52.    
  53.     if (equal(Said, RankIdent, charsmax(RankIdent)))
  54.     {
  55.         if (equal(Said, RankStatsIdent))
  56.         {
  57.             showRankStats(Index, Index);
  58.         }
  59.         new Target[MAX_NAME_LENGTH];
  60.        
  61.         split(Said, Said, charsmax(Said), Target, charsmax(Target), " ");
  62.         showRank(Index, cmd_target(Index, Target, CMDTARGET_NO_BOTS));
  63.        
  64.         return PLUGIN_HANDLED;
  65.     }
  66.    
  67.     if (equal(Said, TopIdent, charsmax(TopIdent)))
  68.     {
  69.         replaceFirst(Said, charsmax(Said), "/top", "");
  70.         showTop(Index, str_to_num(Said));
  71.        
  72.         return PLUGIN_HANDLED;
  73.     }
  74.    
  75.     return PLUGIN_CONTINUE;
  76. }
  77.  
  78. #if AMXX_VERSION_NUM < 183
  79.     public client_disconnect(Index)
  80. #else
  81.     public client_disconnected(Index)
  82. #endif
  83. {
  84.     new Disconnect = get_pcvar_num(CvarDisconnect);
  85.    
  86.     if (Disconnect == 0)
  87.     {
  88.         return;
  89.     }
  90.    
  91.     new Name[MAX_NAME_LENGTH], Stats[8], BodyHits[8], RankPos, RankMax;
  92.  
  93.     RankMax = get_statsnum();
  94.     RankPos = get_user_stats(Index, Stats, BodyHits);
  95.    
  96.     if (RankPos <= 0) // @note The permanent storage is updated on every respawn or client disconnect.
  97.     {
  98.         return;
  99.     }
  100.    
  101.     get_user_name(Index, Name, charsmax(Name));
  102.    
  103.     if(Disconnect == 2)
  104.     {
  105.         #if AMXX_VERSION_NUM < 183
  106.             ColorChat(0, GREEN, "[Rank]^3 %s^1 a iesit, rank %d din %d cu %d fraguri si %d decese.", Name, RankPos, RankMax, Stats[0], Stats[1]);
  107.         #else
  108.             client_print_color(0, print_team_default, "^4[Rank]^3 %s^1 a ieșit, rank %d din %d cu %d fraguri și %d decese.", Name, RankPos, RankMax, Stats[0], Stats[1]);
  109.         #endif
  110.     }
  111.     else if(Disconnect == 1)
  112.     {
  113.         #if AMXX_VERSION_NUM < 183
  114.             ColorChat(0, GREEN, "[Rank]^3 %s^1 a iesit, rank %d din %d.", Name, RankPos, RankMax);
  115.         #else
  116.             client_print_color(0, print_team_default, "^4[Rank]^3 %s^1 a ieșit, rank %d din %d.", Name, RankPos, RankMax);
  117.         #endif
  118.     }
  119.        
  120.     return;
  121. }
  122.  
  123. /*private*/ showRank(Index, Target) {
  124.     new RankType = get_pcvar_num(CvarRank);
  125.    
  126.     if (RankType == 0)
  127.     {
  128.         #if AMXX_VERSION_NUM < 183
  129.             ColorChat(Index, GREEN, "[Rank]^1 Rank-ul este dezactivat.");
  130.         #else
  131.             client_print_color(Index, print_team_default, "^4[Rank]^1 Rank-ul este dezactivat.");
  132.         #endif
  133.        
  134.         return;
  135.     }
  136.    
  137.     if (!Target)
  138.     {
  139.         #if AMXX_VERSION_NUM < 183
  140.             ColorChat(Index, GREEN, "[Rank]^1 Jucatorul cautat nu este conectat.");
  141.         #else
  142.             client_print_color(Index, print_team_default, "^4[Rank]^1 Jucătorul căutat nu este conectat.");
  143.         #endif
  144.        
  145.         return;
  146.     }
  147.  
  148.    
  149.     new Stats[8], BodyHits[8], RankPos, RankMax, Name[MAX_NAME_LENGTH];
  150.    
  151.     RankMax = get_statsnum();
  152.    
  153.     if (Index == Target)
  154.     {
  155.         RankPos = get_user_stats(Index, Stats, BodyHits);
  156.        
  157.         if (RankPos <= 0) // @note The permanent storage is updated on every respawn or client disconnect.
  158.         {
  159.             #if AMXX_VERSION_NUM < 183
  160.                 ColorChat(Index, GREEN, "[Rank]^3 %s^1, nu ai fost gasit in stats.");
  161.             #else
  162.                 client_print_color(Index, print_team_default, "^4[Rank]^3 %s^1, nu ai fost găsit în stats.");
  163.             #endif
  164.            
  165.             return;
  166.         }
  167.        
  168.         get_user_name(Index, Name, charsmax(Name));
  169.         printYourRank(Index, RankType, Name, RankPos, RankMax, Stats[0], Stats[1]);
  170.        
  171.         return;
  172.     }
  173.  
  174.     RankPos = get_user_stats(Target, Stats, BodyHits);
  175.    
  176.     if (RankPos <= 0) // @note The permanent storage is updated on every respawn or client disconnect.
  177.     {
  178.         #if AMXX_VERSION_NUM < 183
  179.             ColorChat(Index, GREEN, "[Rank]^1 Jucatorul nu a fost gasit in stats.");
  180.         #else
  181.             client_print_color(Index, print_team_default, "^4[Rank]^1 Jucătorul nu a fost găsit în stats.");
  182.         #endif
  183.        
  184.         return;
  185.     }
  186.    
  187.     get_user_name(Index, Name, charsmax(Name));
  188.     printHisRank(Index, RankType, Name, RankPos, RankMax, Stats[0], Stats[1]);
  189. }
  190.  
  191. /*private*/ showRankStats(Index, Target)
  192. {
  193.     if (get_pcvar_num(CvarRankStats) == 0)
  194.     {
  195.         #if AMXX_VERSION_NUM < 183
  196.             ColorChat(Index, GREEN, "[RankStats]^1 RankStats este dezactivat.");
  197.         #else
  198.             client_print_color(Index, print_team_default, "^4[RankStats]^1 RankStats este dezactivat.");
  199.         #endif
  200.        
  201.         return;
  202.     }
  203.    
  204.     new Buffer[2368], Name[MAX_NAME_LENGTH], Len, RankPos, Stats[8], BodyHits[8];
  205.    
  206.     Len = copy(Buffer, charsmax(Buffer), "<meta charset=utf-8><style>body{background:#112233;font-family:Arial}th{background:#2E2E2E;color:#FFF;padding:5px 2px;text-align:center}td{padding:5px 2px}table{width:50%%;background:#EEEECC;font-size:12px;}h2{color:#FFF;font-family:Verdana;text-align:center}#c{background:#E2E2BC}</style>");
  207.    
  208.     new RankMax = get_statsnum();
  209.     RankPos = get_user_stats(Index, Stats, BodyHits);
  210.    
  211.     if (RankPos <= 0) // @note The permanent storage is updated on every respawn or client disconnect.
  212.     {
  213.         #if AMXX_VERSION_NUM < 183
  214.             ColorChat(Index, GREEN, "[RankStats]^1 %s gasit in stats.", Index == Target ? "Nu ai fost" : "Jucatorul nu a fost");
  215.         #else
  216.             client_print_color(Index, print_team_default, "^4[RankStats]^1 %s găsit în stats.", Index == Target ? "Nu ai fost" : "Jucatorul nu a fost");
  217.         #endif
  218.        
  219.         return;
  220.     }
  221.    
  222.     get_user_name(Target, Name, charsmax(Name));
  223.    
  224.     if (Index == Target)
  225.     {
  226.         Len += formatex(Buffer[Len], charsmax(Buffer)-Len, "<h2>Te afli pe locul %d din %d</h2>",RankPos, RankMax);
  227.     }
  228.     else
  229.     {  
  230.         if (!Target)
  231.         {
  232.             #if AMXX_VERSION_NUM < 183
  233.                 ColorChat(Index, GREEN, "[Rank]^1 Jucatorul cautat nu este conectat.");
  234.             #else
  235.                 client_print_color(Index, print_team_default, "^4[Rank]^1 Jucătorul căutat nu este conectat.");
  236.             #endif
  237.        
  238.             return;
  239.         }
  240.        
  241.         Len += formatex(Buffer[Len], charsmax(Buffer)-Len,"<h2>%s se afla pe locul %d din %d.</h2>", Name, RankPos, RankMax);
  242.     }
  243.    
  244.     new ServerName[64];
  245.     get_cvar_string("hostname", ServerName, charsmax(ServerName));
  246.    
  247.     Len = add(Buffer, charsmax(Buffer), "<table border=^"0^" align=^"center^" cellpadding=^"0^" cellspacing=^"1^"><tbody>");
  248.    
  249.     Len += formatex(Buffer[Len], charsmax(Buffer), "<tr><th colspan=^"2^">Statistici %s", Name);
  250.    
  251.     Len += formatex(Buffer[Len], charsmax(Buffer), "<tr id=^"c^"><td>Ucideri<td>%d (cu %d HS)", Stats[0], Stats[2]);
  252.     Len += formatex(Buffer[Len], charsmax(Buffer), "<tr><td>Deaths<td>%d", Stats[1]);
  253.     Len += formatex(Buffer[Len], charsmax(Buffer), "<tr id=^"c^"><td>Hits<td>%d", Stats[5]);
  254.     Len += formatex(Buffer[Len], charsmax(Buffer), "<tr><td>Shots<td>%d", Stats[4]);
  255.     Len += formatex(Buffer[Len], charsmax(Buffer), "<tr id=^"c^"><td>Damage(HP)<td>%d", Stats[6]);
  256.     Len += formatex(Buffer[Len], charsmax(Buffer), "<tr><td>ACC. (%)<td>%.02f%", getAccuracy(Stats));
  257.     Len += formatex(Buffer[Len], charsmax(Buffer), "<tr id=^"c^"><td>EFF.<td>%.02f%", getEfficiency(Stats));
  258.     formatex(Buffer[Len], charsmax(Buffer), "<tr><th colspan=^"2^">%s", ServerName);
  259.    
  260.     add(Buffer, charsmax(Buffer), "</tbody></table></body>");
  261.     #if AMXX_VERSION_NUM < 183
  262.         show_motd(Index, Buffer, "Top jucatori");
  263.     #else
  264.         show_motd(Index, Buffer, "Top jucători");
  265.     #endif
  266. }
  267.  
  268. /*private*/ showTop(Index, TopCount)
  269. {
  270.     if (get_pcvar_num(CvarTop) == 0)
  271.     {
  272.         #if AMXX_VERSION_NUM < 183
  273.             ColorChat(Index, GREEN, "[Top]^1 Topul este dezactivat.");
  274.         #else
  275.             client_print_color(Index, print_team_default, "^4[Top]^1 Topul este dezactivat.");
  276.         #endif
  277.         return;
  278.     }
  279.     new Max = get_statsnum();
  280.     new TopPageCount = get_pcvar_num(CvarTopNum);
  281.    
  282.     if (TopPageCount < 1 || TopPageCount > 15)
  283.     {
  284.         TopPageCount = 10; //auto-fix
  285.     }
  286.    
  287.     if (TopCount <= 0)
  288.     {
  289.         TopCount = TopPageCount;
  290.     }
  291.    
  292.     new Start;
  293.        
  294.     if (TopCount < TopPageCount)
  295.     {
  296.         TopCount = TopPageCount;
  297.     }
  298.     else
  299.     {
  300.         if(TopCount > Max)
  301.         {
  302.             TopCount = Max;
  303.         }
  304.         else   
  305.         {
  306.             Start = TopCount - TopPageCount;
  307.         }
  308.     }
  309.            
  310.     new TitleData[128];
  311.     new Title = get_pcvar_string(CvarTitle, TitleData, charsmax(TitleData));
  312.        
  313.     new Buffer[2368], Name[MAX_NAME_LENGTH*4], BodyHits[8], Len, Stats[8];
  314.        
  315.     formatex(Buffer, charsmax(Buffer), "<meta charset=utf-8><style>body{background:#112233;font-family:Arial}th{background:#2E2E2E;color:#FFF;padding:5px 2px;text-align:left}td{padding:5px 2px}table{width:100%%;background:#EEEECC;font-size:12px;}h2{color:#FFF;font-family:Verdana;text-align:center}#nr{text-align:center}#c{background:#E2E2BC}</style><h2>%s</h2><table border=^"0^" align=^"center^" cellpadding=^"0^" cellspacing=^"1^"><tbody>", Title);
  316.     Len = add(Buffer, charsmax(Buffer), "<tr><th id=nr>#</th><th>Name<th>Kills<th>Deaths<th>HS<th>Skill");
  317.        
  318.     for (new i = Start; i < TopCount; i++)
  319.     {
  320.         get_user_name(Index, Name, charsmax(Name)/4);
  321.         get_stats(i, Stats, BodyHits, Name, charsmax(Name)/4);
  322.            
  323.         new Float:Skill[8];
  324.         for (new j = 0; j < sizeof(Stats); j++)
  325.         {
  326.             Skill[j] = float(Stats[j]);
  327.         }
  328.        
  329.         replaceAll(Name, charsmax(Name), "<", "&lt;");
  330.         replaceAll(Name, charsmax(Name), ">", "&gt;");
  331.  
  332.         Len += formatex(Buffer[Len], charsmax(Buffer), "<tr %s><td id=nr>%d<td>%s<td>%d<td>%d<td>%d<td>%.02f",((i%2)==0) ? "" : " id=c", (i+1), Name, Stats[0], Stats[1], Stats[2], ((Skill[0]-Skill[1])+Skill[2])/2);
  333.     }
  334.        
  335.     new ServerName[64];
  336.     get_cvar_string("hostname", ServerName, charsmax(ServerName));
  337.    
  338.     formatex(Buffer[Len], charsmax(Buffer), "<tr><th colspan=^"7^" id=nr>%s", ServerName)
  339.     add(Buffer, charsmax(Buffer), "</tbody></table></body>");
  340.    
  341.     #if AMXX_VERSION_NUM < 183
  342.         show_motd(Index, Buffer, "Top jucatori");
  343.     #else
  344.         show_motd(Index, Buffer, "Top jucători");
  345.     #endif
  346.    
  347.     return;
  348. }
  349.  
  350. /*private*/ printYourRank(Index, RankType, Name[], RankPos, RankMax, Kills, Deaths)
  351. {
  352.     if(RankType == 2)
  353.     {
  354.         #if AMXX_VERSION_NUM < 183
  355.             ColorChat(Index, GREEN, "[Rank]^3 %s^1, te afli pe locul^3 %d^1 din^3 %d^1 cu^3 %d^1 fraguri si^3 %d^1 decese.", Name, RankPos, RankMax, Kills, Deaths);
  356.         #else
  357.             client_print_color(Index, print_team_default, "^4[Rank]^3 %s^1, te afli pe locul^3 %d^1 din^3 %d^1 cu^3 %d^1 fraguri și^3 %d^1 decese.", Name, RankPos, RankMax, Kills, Deaths);
  358.         #endif
  359.            
  360.     }
  361.     else if (RankType == 1)
  362.     {
  363.         #if AMXX_VERSION_NUM < 183
  364.             ColorChat(Index, GREEN, "[Rank]^3 %s^1, te afli pe locul %d din %d",Name, RankPos, RankMax);
  365.         #else
  366.             client_print_color(Index, print_team_default, "^4[Rank]^3 %s^1, te afli pe locul %d din %d",Name, RankPos, RankMax);
  367.         #endif
  368.     }
  369. }
  370.  
  371. /*private*/ printHisRank(Index, RankType, Name[], RankPos, RankMax, Kills, Deaths)
  372. {
  373.     if (RankType == 2)
  374.     {
  375.         #if AMXX_VERSION_NUM < 183
  376.             ColorChat(Index, GREEN, "[Rank]^3 %s^1 se afla pe locul^3 %d^1 din^3 %d^1 cu^3 %d^1 fraguri si^3 %d^1 decese.", Name, RankPos, RankMax, Kills, Deaths);
  377.         #else
  378.             client_print_color(Index, print_team_default, "^4[Rank]^3 %s^1 se află pe locul^3 %d^1 din^3 %d^1 cu^3 %d^1 fraguri și^3 %d^1 decese.", Name, RankPos, RankMax, Kills, Deaths);
  379.         #endif
  380.     }
  381.     else if (RankType == 1)
  382.     {
  383.         #if AMXX_VERSION_NUM < 183
  384.             ColorChat(Index, GREEN, "[Rank]^3 %s^1 se afla pe locul %d din %d.", Name, RankPos, RankMax);
  385.         #else
  386.             client_print_color(Index, print_team_default, "^4[Rank]^3 %s^1 se află pe locul %d din %d.", Name, RankPos, RankMax);
  387.         #endif
  388.     }
  389. }
  390.  
  391.  
  392. /*private*/ Float:getAccuracy(Stats[8])
  393. {
  394.     if (!Stats[4])
  395.     {
  396.         return (0.0);
  397.     }
  398.    
  399.     return (100.0 * float(Stats[5]) / float(Stats[4]));
  400. }
  401.  
  402. /*private*/ Float:getEfficiency(Stats[8])
  403.  {
  404.     if (!Stats[0])
  405.     {
  406.         return (0.0);
  407.     }
  408.    
  409.     return (100.0 * float(Stats[0]) / float(Stats[0] + Stats[1]));
  410. }
  411.  
  412. /*private*/ createCvars()
  413. {
  414.     #if AMXX_VERSION_NUM < 183
  415.         CvarTop = register_cvar("rrt_top", "1");
  416.         CvarRank = register_cvar("rrt_rank", "1");
  417.         CvarRankStats = register_cvar("rrt_rankstats", "1");
  418.         CvarTopNum = register_cvar("rrt_topnum", "10");
  419.         CvarTitle = register_cvar("rrt_title", "Top jucatori");
  420.         CvarDisconnect = register_cvar("rrt_connect", "1");
  421.     #else
  422.         CvarTop = create_cvar("rrt_top", "1", _, "(1|0) Activează/Dezactivează topul.", true, 0.0, true, 1.0);
  423.         CvarRank = create_cvar("rrt_rank", "1", _, "(0) Dezactivează rank-ul. (1|2) Detalii pornite/oprite.", true, 0.0, true, 2.0);
  424.         CvarRankStats = create_cvar("rrt_rankstats", "1", _, "(1|0) Activează/Dezactivează RankStats-ul.", true, 0.0, true, 1.0);
  425.         CvarTopNum = create_cvar("rrt_topnum", "10", _, "(1|15) Numărul de persoane afișate în top. Plugin-ul permite doar valorile 1-15.", true, 1.0, true, 16.0);
  426.         CvarTitle = create_cvar("rrt_title", "Top jucători", _, "Titlul MOTD-ului.");
  427.         CvarDisconnect = create_cvar("rrt_disconnect", "1", _, "(0) Dezactivează afișeaza rank-ului la ieșirea de pe server (1|2) Detalii pornite/oprite.", true, 0.0, true, 1.0);
  428.     #endif
  429. }
  430.  
  431. /*private*/ replaceAll(Name[], NameLength, Search[], Replace[])
  432. {
  433.     #if AMXX_VERSION_NUM < 183
  434.         replace_all(Name, NameLength, Search, Replace);
  435.     #else
  436.         replace_string(Name, NameLength, Search, Replace);
  437.     #endif
  438. }
  439.  
  440. /*private*/ replaceFirst(Text[], TextLength, Search[], Replace[])
  441. {
  442.     #if AMXX_VERSION_NUM < 183
  443.         replace(Text, TextLength, Search, Replace);
  444.     #else
  445.         replace_stringex(Text, TextLength, Search, Replace);
  446.     #endif
  447. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement