Add this stuff in
----------------------
// RPG.pwn //
----------------------
OnGameModeInit
for(new i=0; i <MAX_CHANS; i++)
{
ChatChans[i][cInUse] = -1;
ChatChans[i][cOwner] = -1;
}
OnPlayerDisconnect
for(new i=0; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(UserData[i][pChatChan] == UserData[playerid][pChatChan] && i != playerid)
{
UserData[i][pChatChan] = -1;
SendInfMsg(i, "The chat channel you were in was closed by its owner");
}
}
}
OnPlayerText
if (UserData[playerid][pChatChan] != -1 && text[0] != '#')
{
format(string, sizeof(string), "(Channel: %d) %s: %s",UserData[playerid][pChatChan],PlayerName(playerid), text);
SendChanMsg(UserData[playerid][pChatChan], string);
AdminMsg( string , 4 , 2 , playerid , -1 , -2, UserData[playerid][pChatChan]);
return 0;
}
ProcessCommand
command(channel,7,cmdtext);
---------------------
//FUNCTIONS.pwn//
---------------------
SetPlayerVars
UserData[playerid][pChatChan] = -1;
---------------------
//DEFINES.pwn//
---------------------
#define MAX_CHANS 100
---------------------
//VARS.pwn//
---------------------
enum UserDataEnum
pChatChan
enum ChatChansEnum {
cInUse,
cOwner
}
new ChatChans[MAX_CHANS][ChatChansEnum];
---------------------
//COMMANDS/USERS.pwn//
---------------------
Cmd(call)::(playerid, cmdtext[])
if(UserData[playerid][pChatChan] != -1)
{
SendErrMsg(playerid, "You must leave your chat channel first, /channel leave");
return 1;
}
Cmd(answer)::(playerid, cmdtext[])
if(UserData[playerid][pChatChan] != -1)
{
SendErrMsg(playerid, "You must leave your chat channel first, /channel leave");
return 1;
}
Cmd(channel)::(playerid, cmdtext[])
{
new tmp[256], index;
tmp = strtok(cmdtext, index);
if(!strlen(tmp))
{
SendErrMsg(playerid, "Usage: /channel <Create/Join/Leave/Remove/Help>");
return 1;
}
if(strcmp(tmp, "create", true) ==0)
{
new tmp2[256];
tmp2 = strtok(cmdtext, index);
if(UserData[playerid][pChatChan] != -1)
{
SendErrMsg(playerid, "Leave your current channel first using /channel leave");
return 1;
}
if(!strlen(tmp2))
{
SendErrMsg(playerid, "Usage: /channel create <Number 0-100>");
return 1;
}
if(strval(tmp2) > 100 || strval(tmp2) < 0)
{
SendErrMsg(playerid, "Usage: /channel create <Number 0-100>");
return 1;
}
if(ChatChans[strval(tmp2)][cInUse] != -1)
{
SendErrMsg(playerid, "Channel Number already in use, pick another number");
return 1;
}
if (UserData[playerid][pCalling] >= 0 || UserData[playerid][pCall] >= 0)
{
SendMsg(playerid,"You hung up the phone because you joined a chat channel.");
new calling = UserData[playerid][pCalling];
if (calling >= 0)
{
UserData[calling][pCalling] = (-1);
}
new callid = UserData[playerid][pCall];
if (callid >= 0 && IsPlayerConnected(callid))
{
format(tmp, sizeof(tmp), "%s hung up the phone because they joined a chat channel", PlayerName(playerid));
SendMsg(callid,tmp);
UserData[callid][pCall] = UserData[callid][pCalling] = -1;
}
UserData[playerid][pCall] = UserData[playerid][pCalling] = -1;
return 1;
}
UserData[playerid][pChatChan] = strval(tmp2);
ChatChans[strval(tmp2)][cInUse] = 1;
ChatChans[strval(tmp2)][cOwner] = playerid;
new string[256];
format(string, sizeof(string), "You have created a chat channel, ID: %d", strval(tmp2));
SendInfMsg(playerid, string);
SendInfMsg(playerid, "Put a # infront of your chat to speak to the server");
return 1;
}
if(strcmp(tmp, "join", true) ==0)
{
new tmp2[256];
tmp2 = strtok(cmdtext, index);
if(UserData[playerid][pChatChan] != -1)
{
SendErrMsg(playerid, "Leave your current channel first using /channel leave");
return 1;
}
if(!strlen(tmp2))
{
SendErrMsg(playerid, "Usage: /channel join <Number 0-100>");
return 1;
}
if(strval(tmp2) > 100 || strval(tmp2) < 0)
{
SendErrMsg(playerid, "Usage: /channel join <Number 0-100>");
return 1;
}
if(ChatChans[strval(tmp2)][cInUse] == -1)
{
SendErrMsg(playerid, "Channel Number not in use, pick another number");
return 1;
}
if (UserData[playerid][pCalling] >= 0 || UserData[playerid][pCall] >= 0)
{
SendMsg(playerid,"You hung up the phone because you joined a chat channel.");
new calling = UserData[playerid][pCalling];
if (calling >= 0)
{
UserData[calling][pCalling] = (-1);
}
new callid = UserData[playerid][pCall];
if (callid >= 0 && IsPlayerConnected(callid))
{
format(tmp, sizeof(tmp), "%s hung up the phone because they joined a chat channel", PlayerName(playerid));
SendMsg(callid,tmp);
UserData[callid][pCall] = UserData[callid][pCalling] = -1;
}
UserData[playerid][pCall] = UserData[playerid][pCalling] = -1;
return 1;
}
UserData[playerid][pChatChan] = strval(tmp2);
new string[256];
format(string, sizeof(string), "You have joined a chat channel, ID: %d", strval(tmp2));
SendInfMsg(playerid, string);
SendInfMsg(playerid, "Put a # infront of your chat to speak to the server");
return 1;
}
if(strcmp(tmp, "leave", true) ==0)
{
if(UserData[playerid][pChatChan] == -1)
{
SendErrMsg(playerid, "You're not currently in a chat channel");
return 1;
}
if(ChatChans[UserData[playerid][pChatChan]][cOwner] == playerid)
{
SendErrMsg(playerid, "You are the owner of this chat chan, use /channel remove instead");
return 1;
}
UserData[playerid][pChatChan] = -1;
SendInfMsg(playerid, "You have left the chat channel");
return 1;
}
if(strcmp(tmp, "remove", true) ==0)
{
if(UserData[playerid][pChatChan] == -1)
{
SendErrMsg(playerid, "You're not currently in a chat channel");
return 1;
}
if(ChatChans[UserData[playerid][pChatChan]][cOwner] != playerid)
{
SendErrMsg(playerid, "You are not the owner of this chat chan, use /channel leave instead");
return 1;
}
for(new i=0; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(UserData[i][pChatChan] == UserData[playerid][pChatChan] && i != playerid)
{
UserData[i][pChatChan] = -1;
SendInfMsg(i, "The chat channel you were in was closed by its owner");
}
}
}
ChatChans[UserData[playerid][pChatChan]][cOwner] = -1;
ChatChans[UserData[playerid][pChatChan]][cInUse] = -1;
UserData[playerid][pChatChan] = -1;
SendInfMsg(playerid, "The chat channel has been removed");
return 1;
}
if(strcmp(tmp, "kick", true) ==0)
{
if(ChatChans[UserData[playerid][pChatChan]][cOwner] != playerid)
{
SendErrMsg(playerid, "You are not the owner of this chat chan, and cannot kick");
return 1;
}
new tmp3[256];
tmp3 = strtok(cmdtext, index);
if(!strlen(tmp3))
{
SendErrMsg(playerid, "Usage: /channel kick <Player Name/ID>");
return 1;
}
new lookupid;
if(NameLookup(playerid,tmp,lookupid,1) != 1) return 1;
if(lookupid == playerid)
{
SendErrMsg(playerid, "You cannot kick yourself!");
return 1;
}
if(UserData[lookupid][pChatChan] != UserData[playerid][pChatChan])
{
SendErrMsg(playerid, "This player is not in your chat channel");
return 1;
}
UserData[lookupid][pChatChan] = -1;
SendInfMsg(lookupid, "You were kicked from the channel by it's owner");
new string[256];
format(string, sizeof(string), "%s was kicked from the channel by %s", PlayerName(lookupid), PlayerName(playerid));
SendChanMsg(UserData[playerid][pChatChan], string);
return 1;
}
if(strcmp(tmp, "help", true) ==0)
{
SendInfMsg(playerid, "Chat Channels allow you to create a private conversation for you");
SendInfMsg(playerid, "and your friends, they can be used for anything you can think of.");
SendInfMsg(playerid, "To join one, use /channel join. You must close all phone conversations");
SendInfMsg(playerid, "to join or a create a channel. While in a channel you can talk to the");
SendInfMsg(playerid, "rest of the server by putting a # at the front of your message.");
return 1;
}
return 1;
}