Advertisement
ukazax

[Include] SA-MP ExtendedChat

Jun 14th, 2016
548
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.60 KB | None | 0 0
  1. #if defined _ex_chat_included
  2.   #endinput
  3. #endif
  4. #define _ex_chat_included
  5.  
  6. // Author: kaZax
  7. // Credits: urShadow (Pawn.Regex)
  8. // IncludeVersion: 1.0
  9.  
  10. #include <Pawn.Regex>
  11.  
  12. #define ExChat::                _ex_chat_
  13.  
  14. #define _ex_chat_TextSize       (384)
  15.  
  16. new regex:ExChat::Main,
  17.     regex:ExChat::Replace;
  18.  
  19. stock ExChat::RegExInit()
  20. {
  21.     ExChat::Main = regex_new("[#@]\\d+");
  22.  
  23.     if (!ExChat::Main)
  24.         print("ExtendedChat: ex_chat_RegExInit() Error!");
  25.  
  26.     print("ExtendedChat by kaZax loaded.");
  27. }
  28.  
  29. stock ExChat::RegExExit()
  30. {
  31.     regex_delete(ExChat::Main);
  32.  
  33.     print("ExtendedChat unloaded.");
  34. }
  35.  
  36. stock ExChat::ReplaceString(const str[], const regexp[], const fmt[], dest[], size = sizeof dest)
  37. {
  38.     ExChat::Replace = regex_new(regexp);
  39.    
  40.     if (ExChat::Replace)
  41.         regex_replace(str, ExChat::Replace, fmt, dest, MATCH_DEFAULT, size);
  42.  
  43.     regex_delete(ExChat::Replace);
  44. }
  45.  
  46. public OnPlayerText(playerid, text[])
  47. {  
  48.     new message[_ex_chat_TextSize];
  49.     format(message, _ex_chat_TextSize, text);
  50.  
  51.     if (ExChat::Main)
  52.     {
  53.         new match_results:m,
  54.             startpos,
  55.             pos,
  56.             str[48];
  57.  
  58.         new playerID,
  59.             playerName[MAX_PLAYER_NAME];
  60.  
  61.         while (regex_search(message, ExChat::Main, m, pos, startpos))
  62.         {
  63.             match_get_group(m, 0, str);
  64.             match_free(m);
  65.  
  66.             startpos += pos + strlen(str);
  67.  
  68.             playerID = strval(str[1]);
  69.  
  70.             if (IsPlayerConnected(playerID))
  71.             {
  72.                 GetPlayerName(playerID, playerName, MAX_PLAYER_NAME);
  73.                 ExChat::ReplaceString(message, str, playerName, message, _ex_chat_TextSize);
  74.             }  
  75.         }      
  76.     }
  77.  
  78.     #if defined ex_chat_OnPlayerText
  79.         ex_chat_OnPlayerText(playerid, message);
  80.     #endif
  81.     return 0;
  82. }
  83.  
  84. #if defined _ALS_OnPlayerText
  85.     #undef OnPlayerText
  86. #else
  87.     #define _ALS_OnPlayerText
  88. #endif
  89.  
  90. #define OnPlayerText ex_chat_OnPlayerText
  91.  
  92. #if defined ex_chat_OnPlayerText
  93.     forward ex_chat_OnPlayerText(playerid, text[]);
  94. #endif
  95.  
  96. #if defined FILTERSCRIPT
  97.     public OnFilterScriptInit()
  98.     {      
  99.         ExChat::RegExInit();
  100.        
  101.         #if defined ex_chat_OnFilterScriptInit
  102.             ex_chat_OnFilterScriptInit();
  103.         #endif
  104.        
  105.         return 1;
  106.     }
  107.      
  108.     public OnFilterScriptExit()
  109.     {
  110.         ExChat::RegExExit();
  111.  
  112.         #if defined ex_chat_OnFilterScriptExit
  113.             ex_chat_OnFilterScriptExit();
  114.         #endif
  115.         return 1;
  116.     }
  117.     #if defined _ALS_OnFilterScriptInit
  118.         #undef OnFilterScriptInit
  119.     #else
  120.         #define _ALS_OnFilterScriptInit
  121.     #endif
  122.  
  123.     #define OnFilterScriptInit ex_chat_OnFilterScriptInit
  124.  
  125.     #if defined ex_chat_OnFilterScriptExit
  126.         forward ex_chat_OnFilterScriptExit();
  127.     #endif
  128.  
  129.     #if defined _ALS_OnFilterScriptExit
  130.         #undef OnFilterScriptExit
  131.     #else
  132.         #define _ALS_OnFilterScriptExit
  133.     #endif
  134.  
  135.     #define OnFilterScriptExit ex_chat_OnFilterScriptExit
  136.  
  137.     #if defined ex_chat_OnFilterScriptExit
  138.         forward ex_chat_OnFilterScriptExit();
  139.     #endif
  140. #else
  141.     public OnGameModeInit()
  142.     {  
  143.         ExChat::RegExInit();
  144.        
  145.         #if defined ex_chat_OnGameModeInit
  146.             ex_chat_OnGameModeInit();
  147.         #endif
  148.         return 1;
  149.     }
  150.    
  151.     public OnGameModeExit()
  152.     {
  153.         ExChat::RegExExit();
  154.  
  155.         #if defined ex_chat_OnGameModeExit
  156.             ex_chat_OnGameModeExit();
  157.         #endif
  158.         return 1;
  159.     }
  160.  
  161.     #if defined _ALS_OnGameModeInit
  162.         #undef OnGameModeInit
  163.     #else
  164.         #define _ALS_OnGameModeInit
  165.     #endif
  166.  
  167.     #define OnGameModeInit ex_chat_OnGameModeInit
  168.  
  169.     #if defined ex_chat_OnGameModeInit
  170.         forward ex_chat_OnGameModeInit();
  171.     #endif
  172.  
  173.     #if defined _ALS_OnGameModeExit
  174.         #undef OnGameModeExit
  175.     #else
  176.         #define _ALS_OnGameModeExit
  177.     #endif
  178.  
  179.     #define OnGameModeExit ex_chat_OnGameModeExit
  180.  
  181.     #if defined ex_chat_OnGameModeExit
  182.         forward ex_chat_OnGameModeExit();
  183.     #endif
  184. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement