[Tutorial] sSiddhant Tutorial 4# Custom Player Messages
#1

sSiddhant Tutorial 1# Custom Player Messages
Ok! Today I am gonna explain you about messages which are related to players like Welcome Messages, Join Messages, Death Messages extra.

For example I am taking Welcome Message
First we have to make an array where the name of the player will be stored
Quote:

new sname[MAX_PLAYER_NAME];

Now lets get the player name,
Quote:

GetPlayerName(playerid, sname, sizeof(sname));

This Command will get the Players name and store it in the sname array

Now we are gonna make a new string

Quote:

new str[24+MAX_PLAYERS_NAME];

This 24 + MAX_PLAYERS_NAME is the size of the string

Ok! Now lets format the string
Quote:

format(str, sizeof(str), "%s , Welcome to the Server", sname);

Since we know the player's name now, we can format the join message with format. The first parameter allows us to specify where we want to have the formatted string. We created the string array for this purpose earlier. The second parameter is the max length of the formatted string. That will be the size of the string. The third parameter is the actual string we want to format. %s is a placeholder for another string. Using the forth parameter we specify that it should be replaced with sname. That way we will have "<player's name> has joined the server." in the string array. This explanation is taken from samp wikia.

Remember you can use as many arguments as you want. Now, I am not gonna explain you what are string as it would be off-topic.

Ok! Now lets send the message
Quote:

SendClientMessageToAll(-1, str);

This Command will send the message which was stored in str array which will be send in color -1 which is white.

Ok! I am gonna more examples of Custom Player Messages.

Join Message
Quote:

new pname[MAX_PLAYER_NAME], string[22 + MAX_PLAYER_NAME];
GetPlayerName(playerid, pname, sizeof(pname));
format(string, sizeof(string), "%s has joined the server", pname);
SendClientMessageToAll(0xAAAAAAAA, string);

Leave Messages
Quote:

public OnPlayerDisconnect(playerid, reason)
{
new pname[MAX_PLAYER_NAME], string[39 + MAX_PLAYER_NAME];
GetPlayerName(playerid, pname, sizeof(pname));
switch(reason)
{
case 0: format(string, sizeof(string), "%s has left the server. (Lost Connection)", pname);
case 1: format(string, sizeof(string), "%s has left the server. (Leaving)", pname);
case 2: format(string, sizeof(string), "%s has left the server. (Kicked)", pname);
}
SendClientMessageToAll(0xAAAAAAAA, string);
return 1;
}

Hope, you understand how to make your own Custom Players Messages but there are more types of messages which you can send. So i will explain you some new types of messages in the next tutorial
Reply
#2

This comment applies to all of your recent tutorials. Whilst it is always appreciated when people put in effort to help the community in one way or another, your tutorials are about extremely basic things, systems mostly consisting of up to 10 lines. Rather than each tutorial being highly similar, just dedicated to one specific thing (for example, you have a tutorial for messages when players leave, and one for when players join), teach people how the messages on general work, so they can create all of this themselves.

Also, indent your code please. If you're going to teach people how to code, please don't teach them any bad habits.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)