Advertisement
TheReduxPL

Untitled

Aug 28th, 2015
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.19 KB | None | 0 0
  1. /*
  2. SourceMod Country Nick Plugin
  3. Add country of the player near his nick
  4.  
  5. Country Nick Plugin (C)2009-2010 A-L. All rights reserved.
  6.  
  7. This program is free software: you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation, either version 3 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program.  If not, see <http://www.gnu.org/licenses/>.
  19.  
  20. $Id: countrynick.sp 29 2009-02-23 23:45:22Z aen0 $
  21.  */
  22.  
  23. #pragma semicolon 1
  24.  
  25. #include <sourcemod>
  26. #include <sdktools>
  27. #include <geoip>
  28.  
  29. #define VERSION "1.1.1"
  30.  
  31. public Plugin:myinfo =
  32. {
  33.     name = "Country Nick Plugin",
  34.     author = "Antoine LIBERT aka AeN0",
  35.     description = "Add country of the player near his nick",
  36.     version = VERSION,
  37.     url = "http://www.a-l.fr/"
  38. };
  39.  
  40. public OnPluginStart()
  41. {
  42.     LoadTranslations("countrynick.phrases");
  43.     CreateConVar("countrynick_version", VERSION, "Country Nick Version", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
  44.    
  45.     HookEvent("player_changename", Event_PlayerChangename, EventHookMode_Pre);
  46. }
  47.  
  48. public OnClientPutInServer(client)
  49. {
  50.     decl String:ip[16];
  51.     decl String:country[46];
  52.     decl String:name[65];
  53.    
  54.     if(!IsFakeClient(client) && client != 0)
  55.     {
  56.         getPlayerNameWithCountry(client, name, 65);
  57.         SetClientInfo(client, "name", name);
  58.        
  59.         GetClientIP(client, ip, 16);
  60.        
  61.         if(GeoipCountry(ip, country, 45))
  62.         {
  63.             PrintToChatAll("\x03%T", "Announcer country found", LANG_SERVER, client, country);
  64.         }
  65.         else
  66.         {
  67.             PrintToChatAll("\x03%T", "Announcer country not found", LANG_SERVER, client);
  68.             LogError("[Country Nick] Warning : %s uses %s that is not listed in GEOIP database", name, ip);
  69.         }
  70.     }
  71. }
  72.  
  73. getFlagOfPlayer(client, String:flag[], size)
  74. {
  75.     decl String:ip[16];
  76.     decl String:code2[3];
  77.    
  78.     GetClientIP(client, ip, 16);
  79.     if(GeoipCode2(ip, code2))
  80.     {
  81.         Format(flag, size, "[%2s]", code2);
  82.         return true;
  83.     }
  84.     else
  85.     {
  86.         Format(flag, size, "[--]");
  87.         return false;
  88.     }
  89. }
  90.  
  91. getPlayerNameWithCountry(client, String:name[], size)
  92. {
  93.     decl String:flag[5];
  94.    
  95.     getFlagOfPlayer(client, flag, 5);
  96.     if(StrContains(flag, "PL", false) == -1)
  97.     {
  98.         Format(name, size, "%s%N", flag, client);
  99.     }
  100. }
  101.  
  102. public Action:Event_PlayerChangename(Handle:event, const String:name[], bool:dontBroadcast)
  103. {
  104.     decl String:newname[65];
  105.     decl String:nick[69];
  106.     decl String:flag[5];
  107.    
  108.     new client = GetClientOfUserId(GetEventInt(event, "userid"));
  109.    
  110.  
  111.     if(!IsFakeClient(client))
  112.     {
  113.         GetEventString(event, "newname", newname, 65);
  114.         getFlagOfPlayer(client, flag, 5);
  115.         if(strncmp(flag, newname, 4, false) == 0)
  116.         {
  117.             return Plugin_Continue;
  118.         }
  119.        
  120.         if(StrContains(flag, "PL", false) == -1)
  121.         {
  122.             Format(nick, 69, "%2s%s", flag, newname);
  123.             SetClientInfo(client, "name", nick);
  124.             return Plugin_Handled; // avoid printing the change to the chat
  125.         }
  126.     }
  127.     return Plugin_Continue;
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement