01.01.2015, 18:04
Hi guys,
Im going to show you guys how to make an AFK command with a reason.
First off im going to create a variable that would check if the player is afk or not and it would be used when the afk command is used.
First off you will have to declare a variable on the top of your script that will store the reason why the player is going AFK.
The last set of brackets just explains you many characters must fit into that array.
now we are going to create the command.
i am going to show you how must you start of the command just for the people who does not clearly understand it.
Here above this text is how the basic ZCMD command looks like and the its the easiest method.
now inside this command you will have to declare three variables inside this command, like this :
Now the first variable i declared was to store the reason that is going to be used later on when the player is playing again and the bracket is how many characters can be used in the variable. the second variable is to store the player's name that is going to be used when displaying to people that he is now afk. the third variable is going to be used in the format function to store the string.
now im going to make a if statement to check if the player is not already afk and to return him a message to tell him.
the "afk" variable is used to check if the user is afk or not, this variable will be changed to 1 when the command has been used.
the next thing we need to check is if the parameters of the command is correct.
The "s[100]" stands for what type of characters would be inserted, for this stands for string and then the "100" is the characters that can be stored in that array. the last parameters is what you type in for your reason and if the parameters is not what it must be it will return a error message.
Ok, the next line is now to take that reason the player has entered and placing it into the variable so that the variable can be used when the player returns.
Now the variable is occupied to be used later.
the next line is now for storing the player's name that used the command into the string you declared as "name" at the top of the command.
the next line is using the format function to send all players the message that the player will be now AFK(inactive).
You guys probably know how the format function works, the string you made in the format function is now stored in the "string" variable.
The next line of coding is to send all the players the string you made in the format function.
The next line is just to pause the player so that there is absolutely no movement.
Now you are finally done with the AFK command ! Just down below is the AFK command in whole
Now I will show you how to create the back command for a player to return!
the first is line of coding is to declare 2 variables.
the two variables will get the player name into the variable "name" and the format function will use "string" to store its data.
the next line will check if the player is afk or not.
the next line we change the afk variable to "0" because the player will not be AFK anymore.
the next line we fetch the player's name again.
the next thing we have to do is to format a string again just like in the AFK command except we have to tell the people that the player is back and it would the display the reason why he was AFK next to the message.
now you just send the string to the players
The last thing you have to is to change the player's controllable state to "0".
Just below is how the BACK command looks in whole.
AFK - BACK Command with reason
Im going to show you guys how to make an AFK command with a reason.
First off im going to create a variable that would check if the player is afk or not and it would be used when the afk command is used.
Код:
new afk[MAX_PLAYERS];
Код:
new afkreason[MAX_PLAYERS][128]
now we are going to create the command.
i am going to show you how must you start of the command just for the people who does not clearly understand it.
Код:
CMD:afk(playerid, params[]) { return 1; }
now inside this command you will have to declare three variables inside this command, like this :
Код:
new reason[100], name[128], string[128]
now im going to make a if statement to check if the player is not already afk and to return him a message to tell him.
Код:
if (afk[playerid] == 1) return SendClientMessage(playerid, COLOR_RED, "ERROR : You are already AFK");
the next thing we need to check is if the parameters of the command is correct.
Код:
else if (sscanf(params, "s[100]", reason)) return SendClientMessage(playerid, COLOR_RED, "Usage : /afk [reason]");
Ok, the next line is now to take that reason the player has entered and placing it into the variable so that the variable can be used when the player returns.
Код:
afkreason[playerid] = reason;
the next line is now for storing the player's name that used the command into the string you declared as "name" at the top of the command.
Код:
GetPlayerName(playerid, name, sizeof(name));
Код:
format(string, sizeof(string), "%s[%i] {CC6600}is now AFK {FFFFFF}- %s ", name, playerid, reason);
The next line of coding is to send all the players the string you made in the format function.
Код:
SendClientMessageToAll(COLOR_WHITE, string);
Код:
TogglePlayerControllable(playerid, 0);
Код:
CMD:afk(playerid, params[]) { new reason[100], name[128], string[128]; if (afk[playerid] == 1) return SendClientMessage(playerid, COLOR_RED, "ERROR : You are already AFK"); else if (sscanf(params, "s[100]", reason)) return SendClientMessage(playerid, COLOR_RED, "Usage : /afk [reason]"); afkreason[playerid] = reason; afk[playerid] = 1; GetPlayerName(playerid, name, sizeof(name)); format(string, sizeof(string), "%s[%i] {CC6600}is now AFK {FFFFFF}- %s ", name, playerid, reason); SendClientMessageToAll(COLOR_WHITE, string); TogglePlayerControllable(playerid, 0); return 1; }
the first is line of coding is to declare 2 variables.
Код:
new name[128], string[128];
the next line will check if the player is afk or not.
Код:
if (afk[playerid] == 0) return SendClientMessage(playerid, COLOR_RED, "ERROR : You are not AFK");
Код:
afk[playerid] = 0;
Код:
GetPlayerName(playerid, name, sizeof(name));
Код:
format(string, sizeof(string), "%s[%i] {CC6600}is now BACK {FFFFFF}- %s", name, playerid, afkreason[playerid]);
Код:
SendClientMessageToAll(COLOR_WHITE, string);
Код:
TogglePlayerControllable(playerid, 1);
Код:
CMD:back(playerid, params[]) { new name[128], string[128]; if (afk[playerid] == 0) return SendClientMessage(playerid, COLOR_RED, "ERROR : You are not AFK"); afk[playerid] = 0; GetPlayerName(playerid, name, sizeof(name)); format(string, sizeof(string), "%s[%i] {CC6600}is now BACK {FFFFFF}- %s", name, playerid, afkreason[playerid]); SendClientMessageToAll(COLOR_WHITE, string); TogglePlayerControllable(playerid, 1); return 1; }