Guest User

private messages system

a guest
Jun 1st, 2014
799
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.46 KB | None | 0 0
  1. /*
  2. ,        ,
  3.               /(        )`
  4.               | |___   / \|
  5.               /- _  `-/  '
  6.              (/|/ | |   /|
  7.              / /   | `    |
  8.              O O   ) /    |
  9.              `-^--'`<     '
  10.             (_.)  _  )   /
  11.              `.___/`    /
  12.                `-----' /
  13.   <----.     __ / __   |
  14.   <----|====O)))==) |) /====
  15.   <----'    `--' `.__,' |
  16.                |        |
  17.                 |       /
  18.            ______( (_  / |______
  19.          ,'  ,-----'   |        |
  20.          `--{__________)       //
  21. */
  22.  
  23. // Includes
  24. #include <a_samp>
  25. #include <sscanf>
  26.  
  27. #define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
  28.  
  29. // Colours
  30. #define COLOR_RED 0xFF0000FF
  31. #define COLOR_YELLOW 0xFFFF00AA
  32. #define COLOR_ORANGE 0xFF9900AA
  33.  
  34. // Player Variable
  35. enum PlayerInfo
  36. {
  37.         Last,
  38.         NoPM,
  39. }
  40.  
  41. new pInfo[MAX_PLAYERS][PlayerInfo];
  42.  
  43. public OnFilterScriptInit()
  44. {
  45.         print("\n--------------------------------------------");
  46.         print(" private messages System");
  47.         print("--------------------------------------------\n");
  48.         return 1;
  49. }
  50.  
  51. public OnFilterScriptExit()
  52. {
  53.     print("\n--------------------------------------------");
  54.         print(" private messages system");
  55.         print("--------------------------------------------\n");
  56.         return 1;
  57. }
  58.  
  59. public OnPlayerConnect(playerid)
  60. {
  61.         pInfo[playerid][Last] = -1;
  62.         pInfo[playerid][NoPM] = 0;
  63.         return 1;
  64. }
  65.  
  66. public OnPlayerDisconnect(playerid, reason)
  67. {
  68.     pInfo[playerid][Last] = -1;
  69.         pInfo[playerid][NoPM] = 0;
  70.         return 1;
  71. }
  72.  
  73. stock PlayerName(playerid)
  74. {
  75.         new pName[MAX_PLAYER_NAME];
  76.         GetPlayerName(playerid, pName, sizeof(pName));
  77.         return pName;
  78. }
  79.  
  80. dcmd_blockpm(playerid, params[])
  81. {
  82.         #pragma unused params
  83.         if(pInfo[playerid][NoPM] == 0)
  84.         {
  85.             pInfo[playerid][NoPM] = 1;
  86.             SendClientMessage(playerid, COLOR_YELLOW, "Your have been blocked your  private messages.");
  87.         }
  88.         else
  89.         {
  90.             pInfo[playerid][NoPM] = 0;
  91.             SendClientMessage(playerid, COLOR_YELLOW, "Your have been unblocked your private messages.");
  92.         }
  93. }
  94.  
  95. dcmd_pm(playerid, params[])
  96. {
  97.         new pID, text[128], string[128];
  98.         if(sscanf(params, "us", pID, text)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /pm (nick/id) (message) - Enter a valid Nick / ID");
  99.         if(!IsPlayerConnected(pID)) return SendClientMessage(playerid, COLOR_RED, "Player is not connected.");
  100.         if(pID == playerid) return SendClientMessage(playerid, COLOR_RED, "You cannot PM yourself.");
  101.         format(string, sizeof(string), "%s (%d) is not accepting private messages at the moment.", PlayerName(pID), pID);
  102.         if(pInfo[pID][NoPM] == 1) return SendClientMessage(playerid, COLOR_RED, string);
  103.         format(string, sizeof(string), "PM to %s: %s", PlayerName(pID), text);
  104.         SendClientMessage(playerid, COLOR_YELLOW, string);
  105.         format(string, sizeof(string), "PM from %s: %s", PlayerName(playerid), text);
  106.         SendClientMessage(pID, COLOR_YELLOW, string);
  107.         pInfo[pID][Last] = playerid;
  108.         return 1;
  109. }
  110.  
  111. dcmd_reply(playerid, params[])
  112. {
  113.         new text[128], string[128];
  114.         if(sscanf(params, "s", text)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /reply (message) - Enter your message");
  115.         new pID = pInfo[playerid][Last];
  116.         if(!IsPlayerConnected(pID)) return SendClientMessage(playerid, COLOR_RED, "Player is not connected.");
  117.         if(pID == playerid) return SendClientMessage(playerid, COLOR_RED, "You cannot PM yourself.");
  118.         format(string, sizeof(string), "%s (%d) is not accepting private messages at the moment.", PlayerName(pID), pID);
  119.         if(pInfo[pID][NoPM] == 1) return SendClientMessage(playerid, COLOR_RED, string);
  120.         format(string, sizeof(string), "PM to %s: %s", PlayerName(pID), text);
  121.         SendClientMessage(playerid, COLOR_YELLOW, string);
  122.         format(string, sizeof(string), "PM from %s: %s", PlayerName(playerid), text);
  123.         SendClientMessage(pID, COLOR_YELLOW, string);
  124.         pInfo[pID][Last] = playerid;
  125.         return 1;
  126. }
  127.  
  128. public OnPlayerCommandText(playerid, cmdtext[])
  129. {
  130.         dcmd(pm, 2, cmdtext);
  131.         dcmd(reply, 5, cmdtext);
  132.         dcmd(blockpm, 4, cmdtext);
  133.         return 0;
  134. }
Advertisement
Add Comment
Please, Sign In to add comment