Advertisement
RaFaeLs

[RaFaeL] Multi Private Messages (v0.5) - Include

Oct 2nd, 2012
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.60 KB | None | 0 0
  1. #if defined _PMS_included
  2.         #endinput
  3. #endif
  4. #define _PMS_included
  5.  
  6. #include <dutils>
  7. #include <sscanf2>
  8.  
  9. #if !defined SendClientFormat
  10.     #define SendClientFormat(%0,%1,%2,%3,%4) format(%2,sizeof(%2),%3,%4), SendClientMessage(%0,%1,%2)
  11. #endif
  12.  
  13. forward PMS_OnPlayerCommandText(playerid, cmdtext[]);
  14. public OnPlayerCommandText(playerid, cmdtext[])
  15. {
  16.     new cmd[256], params[256], idx, str[128];
  17.     cmd = strtok(cmdtext, idx); params = pmstrrest(cmdtext, idx);
  18.     //=-=-==-=-=-=-=-=-=-=--=-=-=-=-=--=-=-=---=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  19.     if(!strcmp(cmd, "/Pm", true))
  20.     {
  21.         new ids[24], text[128], sendids[5], SendedNames[128], SendedCount; //Veribles for the system
  22.         if(sscanf(params, "s[24]s[128]", ids, text)) return OnPlayerSendPrivate(playerid, text, true, -1, SendedNames, 0); //Check if command typed correctly
  23.  
  24.         sscanf(ids, "p<,>A<i>(-1)[5]", sendids); //Splits the ids -> 1,2,3 will give an array
  25.  
  26.         for(new i; i<sizeof(sendids); i++) if(sendids[i] != INVALID_PLAYER_ID && IsPlayerConnected(sendids[i]) && sendids[i] != playerid) { //Create a loop to check ids and create names list
  27.             SendedCount++; //Add one to the names count
  28.             new sendid = sendids[i]; //Get the Id
  29.  
  30.             format(str, sizeof(str), "%s%s", (SendedCount > 1 && i < sizeof(sendids))? (", "):(""), PmGetName(sendid)), strcat(SendedNames, str); //Add the name of the sender to string
  31.             OnPlayerSendPrivate(playerid, text, true, sendid, SendedNames, 2); //Send message to reciveid
  32.         }
  33.         if(SendedCount)
  34.             OnPlayerSendPrivate(playerid, text, true, -1, SendedNames, 3); //Send message to sender
  35.         else
  36.             OnPlayerSendPrivate(playerid, text, true, -1, SendedNames, 1); //Send Error message
  37.         return 1;
  38.     }
  39.     //=-=-==-=-=-=-=-=-=-=--=-=-=-=-=--=-=-=---=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  40.     return 0;
  41. }
  42.  
  43. #if defined _PMS_OnPlayerCommandText
  44.         #undef OnPlayerUpdate
  45. #else
  46.         #define _PMS_OnPlayerCommandText
  47. #endif
  48. #define OnPlayerUpdate PMS_OnPlayerCommandText
  49.  
  50. forward OnPlayerSendPrivate(playerid, text[], bool:recived, reciveid, reciving[], status); //Status 0 = error, 1 = error, 2 = send to recive, 3 = send to sender
  51.  
  52. stock pmstrrest(const string[], index)
  53. {
  54.     new length = strlen(string),offset = index,result[256];
  55.     while((index < length) && ((index - offset) < (sizeof(result) - 1)) && (string[index] > '\r')) result[index - offset] = string[index],index++;
  56.     result[index - offset] = EOS;
  57.     if(result[0] == ' ' && string[0] != ' ') strdel(result,0,1);
  58.     return result;
  59. }
  60. stock PmGetName(playerid)
  61. {
  62.     new name[MAX_PLAYER_NAME];
  63.     GetPlayerName(playerid, name, sizeof(name));
  64.     return name;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement