Advertisement
laurentiuarion

Server Visits

Feb 11th, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.51 KB | None | 0 0
  1. #include <amxmodx>
  2. #include <nvault>
  3.  
  4. #pragma semicolon 1
  5.  
  6. new vizite;
  7.  
  8. enum Color {
  9.     NORMAL = 1, // clients scr_concolor cvar color
  10.     GREEN, // Green Color
  11.     TEAM_COLOR, // Red, grey, blue
  12.     GREY, // grey
  13.     RED, // Red
  14.     BLUE, // Blue
  15. };
  16.  
  17. new TeamName[][] = {
  18.     "",
  19.     "TERRORIST",
  20.     "CT",
  21.     "SPECTATOR"
  22. };
  23.  
  24. public plugin_init() {
  25.     register_plugin( "Vizite" , "0.3" , "Ex3cuTioN" );
  26.    
  27.     register_clcmd("say /vizite","vizitecmd");
  28.    
  29.     vizite = Load();
  30. }
  31.  
  32. public plugin_end()
  33.     Save(vizite);
  34.  
  35. public client_putinserver()
  36.     vizite +=1;
  37.  
  38. public Load() {
  39.     new valut = nvault_open("Vizite_server");
  40.     new vaultkey[64], vaultdata[64];
  41.    
  42.     format(vaultkey, 63, "VIZITE");
  43.    
  44.     nvault_get(valut, vaultkey, vaultdata, 63);
  45.     nvault_close(valut);
  46.    
  47.     return str_to_num(vaultdata);
  48. }
  49.  
  50. public Save(vizite_x) {
  51.     new valut = nvault_open("Vizite_server");
  52.    
  53.     if(valut == INVALID_HANDLE)
  54.         set_fail_state("nValut returned invalid handle");
  55.  
  56.     new vaultkey[64], vaultdata[64];
  57.    
  58.     format(vaultkey, 63, "VIZITE");
  59.     format(vaultdata, 63, "%d", vizite_x);
  60.    
  61.     nvault_set(valut, vaultkey, vaultdata);
  62.     nvault_close(valut);
  63. }
  64.  
  65.  
  66. public vizitecmd() {
  67.     new server[64];
  68.     get_cvar_string("hostname",server,63);
  69.    
  70.     ColorChat(0,GREEN,"[Vizite]^x01 %s a acumulat^x04^x01 %i vizite",server,vizite);
  71.    
  72.     return PLUGIN_CONTINUE;
  73. }
  74.  
  75. ColorChat(id, Color:type, const msg[], {Float,Sql,Result,_}:...) {
  76.    if( !get_playersnum() ) return;
  77.    
  78.    new message[256];
  79.  
  80.    switch(type)
  81.    {
  82.       case NORMAL: // clients scr_concolor cvar color
  83.       {
  84.          message[0] = 0x01;
  85.       }
  86.       case GREEN: // Green
  87.       {
  88.          message[0] = 0x04;
  89.       }
  90.       default: // White, Red, Blue
  91.       {
  92.          message[0] = 0x03;
  93.       }
  94.    }
  95.  
  96.    vformat(message[1], 251, msg, 4);
  97.  
  98.    // Make sure message is not longer than 192 character. Will crash the server.
  99.    message[192] = '^0';
  100.  
  101.    new team, ColorChange, index, MSG_Type;
  102.    
  103.    if(id)
  104.    {
  105.       MSG_Type = MSG_ONE;
  106.       index = id;
  107.    } else {
  108.       index = FindPlayer();
  109.       MSG_Type = MSG_ALL;
  110.    }
  111.    
  112.    team = get_user_team(index);
  113.    ColorChange = ColorSelection(index, MSG_Type, type);
  114.  
  115.    ShowColorMessage(index, MSG_Type, message);
  116.      
  117.    if(ColorChange)
  118.    {
  119.       Team_Info(index, MSG_Type, TeamName[team]);
  120.    }
  121. }
  122.  
  123. ShowColorMessage(id, type, message[]) {
  124.    static bool:saytext_used;
  125.    static get_user_msgid_saytext;
  126.    if(!saytext_used)
  127.    {
  128.       get_user_msgid_saytext = get_user_msgid("SayText");
  129.       saytext_used = true;
  130.    }
  131.    message_begin(type, get_user_msgid_saytext, _, id);
  132.    write_byte(id);
  133.    write_string(message);
  134.    message_end();  
  135. }
  136.  
  137. Team_Info(id, type, team[])
  138. {
  139.    static bool:teaminfo_used;
  140.    static get_user_msgid_teaminfo;
  141.    if(!teaminfo_used)
  142.    {
  143.       get_user_msgid_teaminfo = get_user_msgid("TeamInfo");
  144.       teaminfo_used = true;
  145.    }
  146.    message_begin(type, get_user_msgid_teaminfo, _, id);
  147.    write_byte(id);
  148.    write_string(team);
  149.    message_end();
  150.  
  151.    return 1;
  152. }
  153.  
  154. ColorSelection(index, type, Color:Type)
  155. {
  156.    switch(Type)
  157.    {
  158.       case RED:
  159.       {
  160.          return Team_Info(index, type, TeamName[1]);
  161.       }
  162.       case BLUE:
  163.       {
  164.          return Team_Info(index, type, TeamName[2]);
  165.       }
  166.       case GREY:
  167.       {
  168.          return Team_Info(index, type, TeamName[0]);
  169.       }
  170.    }
  171.  
  172.    return 0;
  173. }
  174.  
  175. FindPlayer()
  176. {
  177.    new i = -1;
  178.  
  179.    while(i <= get_maxplayers())
  180.    {
  181.       if(is_user_connected(++i))
  182.          return i;
  183.    }
  184.  
  185.    return -1;
  186. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement