03.09.2014, 08:54
(
Последний раз редактировалось DarkSkull; 04.09.2014 в 02:33.
Причина: Explained IsPlayerAdmin() Function.
)
Introduction
As the the title says, in this tutorial, will be making a /clearchat and /clearallchat command.
/clearchat command can be used by the player to clear his/her chat.
/clearallchat command can be used by an admin to clear all players chat.
So. Let's Get Started.
Making /clearchat Command
So, we will be using the callback OnPlayerCommandText, as it is called when the player enters a command.
So, making this command is really simple. We will use a for loop to send blank messages a hundred times, which will basically remove all the messages by adding a lot of blanks. So,
Here, we are creating a new variable 'i', whose value will be zero, checking if 'i' is less than or equal to 100, if it is, then it will run the block and increase the value of 'i', and it will continue till the value of i becomes 100. When it becomes 100, the loop will stop. Thats how a for loop works.
Congratulations, You have created a /clearchat command.
Making /clearallchat Command
This is basically the same concept but, it can only be used if the player is an admin. So,
Here we are checking if the player is admin by using the function IsPlayerAdmin(). It is a function which returns true or false depending on whether the player is RCON admin or not. We use the Exclamation Mark (!) to check if the function has returned false. If the function returns false , i.e., If the player is not admin, then send him/her a message saying "Only admins can use that command". If the function returns true, i.e, If the player is an admin, we run the loop, and send the blank message to all instead of just sending to a player. So everyone's chat will be cleared.
Congratulations, You have created a /clearallchat command.
Final Code.
And that's it, Please read and understand instead of just copy/paste.
Hope you like it.
As the the title says, in this tutorial, will be making a /clearchat and /clearallchat command.
/clearchat command can be used by the player to clear his/her chat.
/clearallchat command can be used by an admin to clear all players chat.
So. Let's Get Started.
Making /clearchat Command
So, we will be using the callback OnPlayerCommandText, as it is called when the player enters a command.
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/clearchat", cmdtext, true, 10) == 0)
{
// Do something here
return 1;
}
return 0;
}
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/clearchat", cmdtext, true, 10) == 0)
{
for (new i = 0; i <= 100; i++) {
SendClientMessage(playerid, -1, " ");
}
return 1;
}
return 0;
}
Congratulations, You have created a /clearchat command.
Making /clearallchat Command
This is basically the same concept but, it can only be used if the player is an admin. So,
pawn Код:
if (strcmp("/clearallchat", cmdtext, true, 10) == 0)
{
if (!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000FF, "Only admins can use that command");
for (new i; i <= 100; i++) {
SendClientMessageToAll(-1, " ");
}
return 1;
}
Congratulations, You have created a /clearallchat command.
Final Code.
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/clearchat", cmdtext, true, 10) == 0)
{
for (new i; i <= 100; i++) {
SendClientMessage(playerid, -1, " ");
}
return 1;
}
if (strcmp("/clearallchat", cmdtext, true, 10) == 0)
{
if (!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000FF, "Only admins can use that command");
for (new i; i <= 100; i++) {
SendClientMessageToAll(-1, " ");
}
return 1;
}
return 0;
}
Hope you like it.