Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define FILTERSCRIPT
- #include <a_samp>
- //system related things
- new MAX_CHATROOMS=6;
- #define COLOR_ERROR 0xFF0000AA
- #define COLOR_MESSAGE 0xFFFFBBAA
- new chatroom[MAX_PLAYERS];
- //code
- public OnFilterScriptInit()
- {
- print("\n--------------------------------------");
- print("----------ChatRoom FS loaded----------");
- print("--------------------------------------\n");
- return 1;
- }
- public OnFilterScriptExit()
- {
- print("\n--------------------------------------");
- print("---------ChatRoom FS Unloaded---------");
- print("---everyone is returned to mainchat---");
- print("--------------------------------------\n");
- return 1;
- }
- public OnPlayerText(playerid, text[])
- {
- for(new i = 0; i < MAX_PLAYERS; i++)
- if(chatroom[playerid]==chatroom[i])
- {
- if(chatroom[playerid]>0)
- {
- new chat[256];
- format(chat,sizeof(chat),"%s (ChatID:%i)",text,chatroom[playerid]);
- SendPlayerMessageToPlayer(i, playerid, chat);
- return 0;
- }
- }
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- new
- index,
- cmd[20];
- cmd = strtok(cmdtext, index);
- if (strcmp(cmd, "/joinchat", true) == 0)
- {
- new
- tmp[20],
- chatid;
- tmp = strtok(cmdtext, index);
- if (strlen(tmp))
- {
- chatid = strval(tmp);
- if (chatid>MAX_CHATROOMS||chatid==0)
- {
- SendClientMessage(playerid, COLOR_ERROR, "ERROR:This isn't a valid number.");
- }
- else
- {
- new string[256];
- 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);
- SendClientMessage(playerid, COLOR_MESSAGE, string);
- SetPlayerChatRoom(playerid,chatid);
- }
- }
- else
- {
- SendClientMessage(playerid, COLOR_ERROR, "ERROR:Usage: \"/joinchat <chat-ID>\"");
- }
- return 1;
- }
- if (strcmp(cmd, "/chatkick", true) == 0)
- {
- new
- tmp[20],
- id;
- tmp = strtok(cmdtext, index);
- if (strlen(tmp))
- {
- id = strval(tmp);
- if (chatroom[id]==0)
- {
- SendClientMessage(playerid, COLOR_ERROR, "ERROR:player is not in a chatroom (he is in the mainchat)");
- }
- else if (!IsPlayerConnected(id))
- {
- SendClientMessage(playerid, COLOR_ERROR, "ERROR:player is not connected");
- }
- else
- {
- for(new i = 0; i < MAX_PLAYERS; i++)
- if(chatroom[playerid]==chatroom[i])
- {
- new kickername, kickedname;
- GetPlayerName(playerid,"kickername", sizeof(kickername));
- GetPlayerName(playerid,"kickedname", sizeof(kickedname));
- new string[126];
- format(string,sizeof(string),"%s kicked %s from chatroom %i",kickername,kickedname);
- SetPlayerChatRoom(playerid,0);
- SendClientMessage(i,COLOR_MESSAGE,string);
- }
- }
- }
- else
- {
- SendClientMessage(playerid, COLOR_ERROR, "ERROR:Usage: \"/chatkick <playerid>\"");
- }
- return 1;
- }
- if (strcmp(cmd, "/mainchat", true) == 0)
- {
- SetPlayerChatRoom(playerid,0);
- SendClientMessage(playerid, COLOR_MESSAGE, "you are now in mainchat");
- return 1;
- }
- if (strcmp(cmd, "/chatcmds", true) == 0)
- {
- SendClientMessage(playerid, COLOR_MESSAGE, "/mainchat---/chatkick---/joinchat---/chatcmds---/setchatrooms");
- return 1;
- }
- if (strcmp(cmd, "/setchatrooms", true) == 0)
- {
- new
- tmp[20],
- amount;
- tmp = strtok(cmdtext, index);
- if (strlen(tmp))
- {
- amount = strval(tmp);
- if (amount==0)
- {
- SendClientMessage(playerid, COLOR_MESSAGE, "no chat is available anymore.");
- MAX_CHATROOMS = 0;
- }
- else if(amount>0)
- {
- new string[128];
- format(string,sizeof(string),"%i chats are available now",amount);
- SendClientMessage(playerid, COLOR_MESSAGE, string);
- MAX_CHATROOMS = amount;
- }
- }
- else
- {
- SendClientMessage(playerid, COLOR_ERROR, "ERROR:Usage: \"/setchatrooms <amount>\"");
- }
- return 1;
- }
- return 0;
- }
- //functions
- //SetPlayerChatRoom(playerid,chatid) sets the players chatroom so he can see that chat too.
- SetPlayerChatRoom(playerid,chatid)
- {
- if (chatid>MAX_CHATROOMS)
- {
- return 0;
- }
- else
- {
- chatroom[playerid] = chatid;
- }
- return 1;
- }
- //strtok(const string[], &index) is a function wich is needed for params in cmds
- strtok(const string[], &index)
- {
- new length = strlen(string);
- while ((index < length) && (string[index] <= ' '))
- {
- index++;
- }
- new offset = index;
- new result[20];
- while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
- {
- result[index - offset] = string[index];
- index++;
- }
- result[index - offset] = EOS;
- return result;
- }
Add Comment
Please, Sign In to add comment