14.07.2013, 19:13
(
Last edited by Twizted; 15/07/2013 at 05:34 PM.
)
Hey, how's everybody doing? In this BEGINNER FRIENDLY tutorial, I will teach you how to send a welcome message to a player of your server. For this tutorial, you pretty much need to know the basics of Pawno and you're ready to go. Plus, it's pretty easy to do. There are two tutorial in this one: a simple message and a message where you include a player's name. THIS IS MY FIRST TUTORIAL, SO PLEASE, TELL ME WHAT TO AMEND IN THE NEXT ONE.
NOTE: If you're using another color, keep #define and change the rest with the desired color.
Step 2. Now, for the welcome message, we'll need to introduce the public function 'OnPlayerConnect'. We do it like this:
Step 3. After introducing the public function, we need to introduce "(playerid)", because we're going to send a message to a player. It's pretty basic:
Step 4. Easy so far? Now, we need to introduce the function "SendClientMessage", which sends a message to a player. You can read more about this function here.
Step 4.1. However, SendClientMessage has parameters you need to include. These parameters are as follows:
Everything you need to change is color to the colour you defined and the const message[] to 'Welcome to my server'.
Step 5. You now need to include the parameters on SendClientMessage and add edit them.
Step 6. Now, since we want the message to be sent to the player, we need to add a return. Since we want it to be sent, the return as to be 1. So this is our final code:
__________________________________________
__________________________________________
__________________________________________
If you want to include the player's name in the message, then follow this tutorial. Delete the above If you want to include the player name.
Step 1. You must define a color. It's been explained above. Ontop of the script, we'll need to introduce we wish the message to be. In this case, I'll be using GOLD, but you can choose your own color here. For that, we'll need to define the color. I'll show you how to define a color:
NOTE: If you're using another color, keep #define and change the rest with the desired color.
Step 2. You must include public OnPlayerConnect(playerid), because the message will be sent to the player as he joins the server.
Step 3. Then we will need to create a 'string'. I suppose you already know how to make a string. If you don't, click here. This string is called pname - this string will get the player name. The size of that string has to be the max. characters a player's name can have, so we need to add MAX_PLAYER_NAME (24 is the default has added in a_samp.inc.
Step 4. Now we need to create a new array for the welcome message. The size of the string depends on the ammount of text you want in the message. My message will be "Welcome to my server, PLAYERNAMEHERE.". We need to count the ammount of characters of the message. So I need to count the ammount of characters in the 'Welcome to my server' sentence - spaces, commas and dots included.
The ammount of characters is 23 (the dot at the end is included). So not let's include that array in our little 'script'.
NOTE: If your message is shorter/longer than 23 characters, you simply need to change the number '23' to the ammount of characters your message has.
Step 5. Now we need to get the player's name. For that, we'll use the function GetPlayerName. The player's name will be stored in the array pname. It's max length is sizeof(pName) - 24.
Step 6. Now that we know everything we needed, we need to create the message with 'format'. A 'format' "formats a string to include variables and other strings inside it." There a bunch of parameters that 'format' must have:
Now we need to add that to our main code.
Step 7. We're reaching the final steps to make a successful welcome message. Now, we need to send the message to the player, therefore we need to use SendClientMessage. That function has several parameters.
Now we simply add that to our code:
Step 8. Last but not the least, you need to add a return. Since the message is sent to him, you're gonna set the return to 1 and add it to our code. This is our final code:
NOTE: It is showing 'Player' because I was using samp_debug.exe and connected to my localhost.
__________________________________________
Step 1. Ontop of the script, we'll need to introduce we wish the message to be. In this case, I'll be using GREENYELLOW, but you can choose your own color here. For that, we'll need to define the color. I'll show you how to define a color:pawn Code:
#define COLOR_YELLOWGREEN 0xADFF2FAA
Step 2. Now, for the welcome message, we'll need to introduce the public function 'OnPlayerConnect'. We do it like this:
pawn Code:
public OnPlayerConnect
pawn Code:
public OnPlayerConnect(playerid)
pawn Code:
public OnPlayerConnect(playerid)
{
SendClientMessage
- playerid The playerid you would like to display the message for.
- color The color it should be in.
- const message[] The text you would like to display. max len displayable: 144
pawn Code:
SendClientMessage(playerid, color, const message[]);
Step 5. You now need to include the parameters on SendClientMessage and add edit them.
pawn Code:
public OnPlayerConnect(playerid)
{
SendClientMessage(playerid, COLOR_YELLOWGREEN, "Welcome to my server! Hope you enjoy your stay around here!");
pawn Code:
public OnPlayerConnect(playerid)
{
SendClientMessage(playerid, COLOR_GREENYELLOW, "Welcome to my server! Hope you enjoy your stay around here!");
return 1;
}
__________________________________________
__________________________________________
__________________________________________
Step 1. You must define a color. It's been explained above. Ontop of the script, we'll need to introduce we wish the message to be. In this case, I'll be using GOLD, but you can choose your own color here. For that, we'll need to define the color. I'll show you how to define a color:
pawn Code:
#define COLOR_GOLD 0xB8860BAA
Step 2. You must include public OnPlayerConnect(playerid), because the message will be sent to the player as he joins the server.
pawn Code:
public OnPlayerConnect(playerid)
pawn Code:
public OnPlayerConnect(playerid)
{
new pname[MAX_PLAYER_NAME]
The ammount of characters is 23 (the dot at the end is included). So not let's include that array in our little 'script'.
pawn Code:
public OnPlayerConnect(playerid)
{
new pname[MAX_PLAYER_NAME], string[23 + MAX_PLAYER_NAME+1];
Step 5. Now we need to get the player's name. For that, we'll use the function GetPlayerName. The player's name will be stored in the array pname. It's max length is sizeof(pName) - 24.
pawn Code:
public OnPlayerConnect(playerid)
{
new pname[MAX_PLAYER_NAME], string[23 + MAX_PLAYER_NAME+1];
GetPlayerName(playerid, pname, sizeof(pname));
- output[] The string to output the result to
- len The maximum length output can contain
- format[] The format string
- {Float,_}:... Indefinite number of arguments of any tag
pawn Code:
format(string, sizeof(string), "Welcome to my server, %s.", pname);
pawn Code:
public OnPlayerConnect(playerid)
{
new pname[MAX_PLAYER_NAME], string[23 + MAX_PLAYER_NAME+1];
GetPlayerName(playerid, pname, sizeof(pname));
format(string, sizeof(string), "Welcome to my server, %s.", pname);
- playerid The playerid you would like to display the message for.
- color The color it should be in.
- const message[] The text you would like to display. max len displayable: 144
pawn Code:
SendClientMessage(playerid, COLOR_GOLD, string);
pawn Code:
public OnPlayerConnect(playerid)
{
new pname[MAX_PLAYER_NAME], string[23 + MAX_PLAYER_NAME+1];
GetPlayerName(playerid, pname, sizeof(pname));
format(string, sizeof(string), "Welcome to my server, %s.", pname);
SendClientMessage(playerid, COLOR_GOLD, string);
pawn Code:
public OnPlayerConnect(playerid)
{
new pname[MAX_PLAYER_NAME], string[23 + MAX_PLAYER_NAME+1];
GetPlayerName(playerid, pname, sizeof(pname));
format(string, sizeof(string), "Welcome to my server, %s.", pname);
SendClientMessage(playerid, COLOR_GOLD, string);
return 1;
}
NOTE: It is showing 'Player' because I was using samp_debug.exe and connected to my localhost.