Advertisement
RaFaeLs

Multi Private messages (v0.2)

Sep 29th, 2012
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.48 KB | None | 0 0
  1. #include <a_samp>
  2. #include <dutils>
  3. #include <sscanf>
  4.  
  5. #pragma unused ret_memcpy
  6. #define SendClientFormat(%0,%1,%2,%3,%4) format(%2,sizeof(%2),%3,%4), SendClientMessage(%0,%1,%2)
  7.  
  8. /*
  9.     * Don't remove the credits!
  10.     ** Filter Script by RaFaeL - Multi private messages
  11.     *** Version: 0.2 [BETA]
  12.     **** Bags to: [email protected] - Thanks!
  13. */
  14.  
  15. public OnFilterScriptInit()
  16. {
  17.     print("[RaFaeL] multi Private messages V0.2 - Loaded...!");
  18.     return 1;
  19. }
  20. //==============================================================================
  21. public OnFilterScriptExit()
  22. {
  23.     print("[RaFaeL] multi Private messages V0.2 - unLoaded...!");
  24.     return 1;
  25. }
  26. //==============================================================================
  27. public OnPlayerCommandText(playerid, cmdtext[])
  28. {
  29.     new cmd[256], params[256], idx, str[128];
  30.     cmd = strtok(cmdtext, idx); params = strrest(cmdtext, idx);
  31.     //=-=-==-=-=-=-=-=-=-=--=-=-=-=-=--=-=-=---=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  32.     if(!strcmp(cmd, "/Pm", true))
  33.     {
  34.         new ids[64], text[128], sendids[5][5] = {"-1","-1","-1","-1","-1"}, SendedNames[128], SendedCount; //Veribles for the system
  35.         if(sscanf(params, "ss", ids, text)) return SendClientMessage(playerid, 0xFF0000FF, "Usage: /Pm [IDs] [Text]"); //Check if command typed correctly
  36.  
  37.         split(ids, sendids, ',', 5); //Splits the ids -> 1,2,3 will give an array
  38.  
  39.         for(new i; i<sizeof(sendids); i++) if(strval(sendids[i]) != INVALID_PLAYER_ID && IsPlayerConnected(strval(sendids[i]))/* && strval(sendids[i]) != playerid*/) { //Create a loop to check ids and create names list
  40.             format(str, sizeof(str), "%s%s", GetName(strval(sendids[i])), (i > 0)? (", "):("")), strcat(SendedNames, str); //format the name (add , if need) and add to string
  41.             SendedCount++; //Add one to the names count
  42.         }
  43.         if(SendedCount == 0) return SendClientMessage(playerid, 0xFF0000AA, "Wrong ID/s"); //Check if have at least one id correct
  44.         for(new i; i<sizeof(sendids); i++) { //looping the ids and send the message
  45.             SendClientFormat(strval(sendids[i]), 0x0000FFFF, str, "[PM] %s(To: %s): %s", GetName(playerid), GetName(strval(sendids[i])), text); //send formated message to players
  46.         }
  47.  
  48.         return SendClientFormat(playerid, 0xEAFF00FF, str, "[PM] %s(To: %s): %s", GetName(playerid), SendedNames, text);//send formated message to player
  49.     }
  50.     //=-=-==-=-=-=-=-=-=-=--=-=-=-=-=--=-=-=---=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  51.     return 0;
  52. }
  53. //==============================================================================
  54. stock split(const strsrc[], strdest[][], delimiter, size = 100)
  55. {
  56.     new i, li;
  57.     new aNum;
  58.     new len;
  59.     while(i <= strlen(strsrc))
  60.     {
  61.         if(strsrc[i] == delimiter || i == strlen(strsrc))
  62.         {
  63.             len = strmid(strdest[aNum], strsrc, li, i, 128);
  64.             strdest[aNum][len] = 0;
  65.             li = i+1;
  66.             aNum++;
  67.         }
  68.         if(aNum == size) break;
  69.         i++;
  70.     }
  71.     return 1;
  72. }
  73. stock strrest(const string[], index)
  74. {
  75.     new length = strlen(string),offset = index,result[256];
  76.     while((index < length) && ((index - offset) < (sizeof(result) - 1)) && (string[index] > '\r')) result[index - offset] = string[index],index++;
  77.     result[index - offset] = EOS;
  78.     if(result[0] == ' ' && string[0] != ' ') strdel(result,0,1);
  79.     return result;
  80. }
  81. stock GetName(playerid)
  82. {
  83.     new name[MAX_PLAYER_NAME];
  84.     GetPlayerName(playerid, name, sizeof(name));
  85.     return name;
  86. }
  87. //==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement