legodude

legodude

Jun 23rd, 2010
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.56 KB | None | 0 0
  1. #define FILTERSCRIPT
  2. #include <a_samp>
  3.  
  4. //system related things
  5. new MAX_CHATROOMS=6;
  6. #define COLOR_ERROR 0xFF0000AA
  7. #define COLOR_MESSAGE 0xFFFFBBAA
  8. new chatroom[MAX_PLAYERS];
  9. //code
  10.  
  11. public OnFilterScriptInit()
  12. {
  13.  print("\n--------------------------------------");
  14.  print("----------ChatRoom FS loaded----------");
  15.  print("--------------------------------------\n");
  16.  return 1;
  17. }
  18. public OnFilterScriptExit()
  19. {
  20.     print("\n--------------------------------------");
  21.     print("---------ChatRoom FS Unloaded---------");
  22.     print("---everyone is returned to mainchat---");
  23.     print("--------------------------------------\n");
  24.     return 1;
  25. }
  26.  
  27. public OnPlayerText(playerid, text[])
  28. {
  29.     for(new i = 0; i < MAX_PLAYERS; i++)
  30.     if(chatroom[playerid]==chatroom[i])
  31.     {
  32.         if(chatroom[playerid]>0)
  33.         {
  34.             new chat[256];
  35.             format(chat,sizeof(chat),"%s (ChatID:%i)",text,chatroom[playerid]);
  36.             SendPlayerMessageToPlayer(i, playerid, chat);
  37.             return 0;
  38.         }
  39.     }
  40.     return 1;
  41. }
  42.  
  43. public OnPlayerCommandText(playerid, cmdtext[])
  44. {
  45.     new
  46.         index,
  47.         cmd[20];
  48.     cmd = strtok(cmdtext, index);
  49.     if (strcmp(cmd, "/joinchat", true) == 0)
  50.     {
  51.         new
  52.             tmp[20],
  53.             chatid;
  54.         tmp = strtok(cmdtext, index);
  55.         if (strlen(tmp))
  56.         {
  57.             chatid = strval(tmp);
  58.             if (chatid>MAX_CHATROOMS||chatid==0)
  59.             {
  60.                 SendClientMessage(playerid, COLOR_ERROR, "ERROR:This isn't a valid number.");
  61.             }
  62.             else
  63.             {
  64.                 new string[256];
  65.                 format(string,sizeof(string),"You joined chat \"%i\" your chat's only will be visible for the players in the same chat as you.",chatid);
  66.                 SendClientMessage(playerid, COLOR_MESSAGE, string);
  67.                 SetPlayerChatRoom(playerid,chatid);
  68.             }
  69.         }
  70.         else
  71.         {
  72.             SendClientMessage(playerid, COLOR_ERROR, "ERROR:Usage: \"/joinchat <chat-ID>\"");
  73.         }
  74.         return 1;
  75.     }
  76.    
  77.     if (strcmp(cmd, "/chatkick", true) == 0)
  78.     {
  79.         new
  80.             tmp[20],
  81.             id;
  82.         tmp = strtok(cmdtext, index);
  83.         if (strlen(tmp))
  84.         {
  85.             id = strval(tmp);
  86.             if (chatroom[id]==0)
  87.             {
  88.                 SendClientMessage(playerid, COLOR_ERROR, "ERROR:player is not in a chatroom (he is in the mainchat)");
  89.             }
  90.             else if (!IsPlayerConnected(id))
  91.             {
  92.                 SendClientMessage(playerid, COLOR_ERROR, "ERROR:player is not connected");
  93.             }
  94.             else
  95.             {
  96.                 for(new i = 0; i < MAX_PLAYERS; i++)
  97.                 if(chatroom[playerid]==chatroom[i])
  98.                 {
  99.                     new kickername, kickedname;
  100.                     GetPlayerName(playerid,"kickername", sizeof(kickername));
  101.                     GetPlayerName(playerid,"kickedname", sizeof(kickedname));
  102.                     new string[126];
  103.                     format(string,sizeof(string),"%s kicked %s from chatroom %i",kickername,kickedname);
  104.                     SetPlayerChatRoom(playerid,0);
  105.                     SendClientMessage(i,COLOR_MESSAGE,string);
  106.                 }
  107.             }
  108.         }
  109.         else
  110.         {
  111.             SendClientMessage(playerid, COLOR_ERROR, "ERROR:Usage: \"/chatkick <playerid>\"");
  112.         }
  113.         return 1;
  114.     }
  115.     if (strcmp(cmd, "/mainchat", true) == 0)
  116.     {
  117.         SetPlayerChatRoom(playerid,0);
  118.         SendClientMessage(playerid, COLOR_MESSAGE, "you are now in mainchat");
  119.         return 1;
  120.     }
  121.     if (strcmp(cmd, "/chatcmds", true) == 0)
  122.     {
  123.         SendClientMessage(playerid, COLOR_MESSAGE, "/mainchat---/chatkick---/joinchat---/chatcmds---/setchatrooms");
  124.         return 1;
  125.     }
  126.    
  127.     if (strcmp(cmd, "/setchatrooms", true) == 0)
  128.         {
  129.         new
  130.             tmp[20],
  131.             amount;
  132.         tmp = strtok(cmdtext, index);
  133.         if (strlen(tmp))
  134.         {
  135.             amount = strval(tmp);
  136.             if (amount==0)
  137.             {
  138.                 SendClientMessage(playerid, COLOR_MESSAGE, "no chat is available anymore.");
  139.                 MAX_CHATROOMS = 0;
  140.             }
  141.             else if(amount>0)
  142.             {
  143.                 new string[128];
  144.                 format(string,sizeof(string),"%i chats are available now",amount);
  145.                 SendClientMessage(playerid, COLOR_MESSAGE, string);
  146.                 MAX_CHATROOMS = amount;
  147.             }
  148.         }
  149.         else
  150.         {
  151.             SendClientMessage(playerid, COLOR_ERROR, "ERROR:Usage: \"/setchatrooms <amount>\"");
  152.         }
  153.         return 1;
  154.     }
  155.     return 0;
  156. }
  157.  
  158. //functions
  159. //SetPlayerChatRoom(playerid,chatid) sets the players chatroom so he can see that chat too.
  160. SetPlayerChatRoom(playerid,chatid)
  161. {
  162.     if (chatid>MAX_CHATROOMS)
  163.     {
  164.     return 0;
  165.     }
  166.     else
  167.     {
  168.     chatroom[playerid] = chatid;
  169.     }
  170.     return 1;
  171. }
  172. //strtok(const string[], &index) is a function wich is needed for params in cmds
  173. strtok(const string[], &index)
  174. {
  175.     new length = strlen(string);
  176.     while ((index < length) && (string[index] <= ' '))
  177.     {
  178.         index++;
  179.     }
  180.  
  181.     new offset = index;
  182.     new result[20];
  183.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  184.     {
  185.         result[index - offset] = string[index];
  186.         index++;
  187.     }
  188.     result[index - offset] = EOS;
  189.     return result;
  190. }
Add Comment
Please, Sign In to add comment