24.09.2013, 17:44
TUTORIAL - Creating a group chat
Hi, so in this tutorial I will be explaining how to create group chats that you could use for faction chats, admin chats, helper chats, the list goes on. Here's how you do it, I will be using ZCMD and sscanf for this, you'd be able to download it from ******. You'll need some basic knowledge of scripting before you do this, the basic knowledge is basically knowing what variables are.
Step 1: You will need to make the command structure, so let's start off with this, I will be making an RCON admin chat in this tutorial, but you can do any type of chat.
Step 2: You'd want to make sure now, that the person who is using the command is an RCON admin who is logged on too, so let's try this:
Step 3: We need to declare the variables for this, so let's make some public variables to the command:
Step 4: We need to declare the parameters, by using sscanf which you can find on the SA-MP forums:
Step 5: After we've made sure everything is in order with the latest command that you can see above this particular text, we need to get the player's name:
Step 6: We will now loop all the online players and check if they're RCON admins:
Step 7: After that, we need to format the string that we used earlier, and send the message to all the RCON'ly logged in admins:
That's all! Now, if you want to make your own commands, then you can just use this and change the variables to how you want it. I hope you understood how to make group chats now.
Hi, so in this tutorial I will be explaining how to create group chats that you could use for faction chats, admin chats, helper chats, the list goes on. Here's how you do it, I will be using ZCMD and sscanf for this, you'd be able to download it from ******. You'll need some basic knowledge of scripting before you do this, the basic knowledge is basically knowing what variables are.
Step 1: You will need to make the command structure, so let's start off with this, I will be making an RCON admin chat in this tutorial, but you can do any type of chat.
pawn Code:
CMD:rconchat(playerid, params[]) // this is called when someone in the game uses the command /rconchat
{ // opens the code
return 1; // returns a value of true
} // closes the code
pawn Code:
CMD:rconchat(playerid, params[])
{
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFFFFFFFF, "You are not an RCON admin.");
/* The explanation mark before the IsPlayerAdmin means NOT. So basically, if(IsPlayerNotAnAdmin.
And the (playerid) is the person who uses the command. The return of the SendClientMessage is
sending the message with the color of 0xFFFFFFFF saying that you're not an RCON admin.*/
return 1;
}
pawn Code:
CMD:rconchat(playerid, params[])
{
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFFFFFFFF, "You are not an RCON admin.");
new ChatText[100], string[130], AdminName[MAX_PLAYER_NAME];
/* This is declaring 3 new public variables, the name of the admin with AdminName with an array
of the MAX_PLAYER_NAME and the ChatText, which means how much that person can type.
The string[130] adds up so it means how much it is altogether, because we can't use
variables with SendClientMessage, you'll see and understand what I mean after. */
return 1;
}
pawn Code:
CMD:rconchat(playerid, params[])
{
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFFFFFFFF, "You are not an RCON admin.");
new ChatText[100], string[130], AdminName[MAX_PLAYER_NAME];
if(sscanf(params, "s[100]", ChatText)) return SendClientMessage(playerid, 0xFFFFFFFF, "Correct usage: /rconchat [text]");
/* This line is basically telling the script that if the person does not type anything,
then it will return that specific message of the "Correct usage: ...". The s[100] declares
a string that we'll be using, and the 100 is the character count as in the ChatText.
More information about sscanf can be found on the sscanf topic, just ****** it. */
return 1;
}
pawn Code:
CMD:rconchat(playerid, params[])
{
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFFFFFFFF, "You are not an RCON admin.");
new ChatText[100], string[130], AdminName[MAX_PLAYER_NAME];
if(sscanf(params, "s[100]", ChatText)) return SendClientMessage(playerid, 0xFFFFFFFF, "Correct usage: /rconchat [text]");
GetPlayerName(playerid, AdminName, sizeof(AdminName));
/* This will simply get the playerid's name, remember, the playerid is the person
who send the command. The AdminName is the variable that we declared above
with the array of MAX_PLAYER_NAME, and the sizeof(AdminName) means that
the size of the AdminName is MAX_PLAYER_NAME which is already defined
in a_samp.inc */
return 1;
}
pawn Code:
CMD:rconchat(playerid, params[])
{
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFFFFFFFF, "You are not an RCON admin.");
new ChatText[100], string[130], AdminName[MAX_PLAYER_NAME];
if(sscanf(params, "s[100]", ChatText)) return SendClientMessage(playerid, 0xFFFFFFFF, "Correct usage: /rconchat [text]");
GetPlayerName(playerid, AdminName, sizeof(AdminName));
for(new i = 0; i < MAX_PLAYERS; i ++)
{
if(IsPlayerConnected(i))
{
if(IsPlayerAdmin(i))
{
}
}
}
/* This code here is basically telling the script to loop all the connected players and
check if they're logged in as RCON admins, and if they are, it will do Step 7 */
return 1;
}
pawn Code:
CMD:rconchat(playerid, params[])
{
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFFFFFFFF, "You are not an RCON admin.");
new ChatText[100], string[130], AdminName[MAX_PLAYER_NAME];
if(sscanf(params, "s[100]", ChatText)) return SendClientMessage(playerid, 0xFFFFFFFF, "Correct usage: /rconchat [text]");
GetPlayerName(playerid, AdminName, sizeof(AdminName));
for(new i = 0; i < MAX_PLAYERS; i ++)
{
if(IsPlayerConnected(i))
{
if(IsPlayerAdmin(i))
{
format(string, sizeof(string), "RCON CHAT: %s said: %s", AdminName, ChatText);
SendClientMessage(i, 0xFFFFFFFF, string);
/* This code here will send all the RCON'ly online admins the text
that we formatted in the string, we use a string because SendClientMessage
simply won't support variables, i.e. the variables AdminName and the ChatText
that we used. */
}
}
}
return 1;
}