SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old 14/07/2013, 08:13 PM   #1
Twizted
Banned
 
Join Date: Feb 2011
Posts: 1,672
Reputation: 279
Default 'Welcome to my server' messages.

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.

__________________________________________

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
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:

pawn Code:
public OnPlayerConnect

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:

pawn Code:
public OnPlayerConnect(playerid)

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.

pawn Code:
public OnPlayerConnect(playerid)
{
  SendClientMessage

Step 4.1. However, SendClientMessage has parameters you need to include. These parameters are as follows:
  1. playerid The playerid you would like to display the message for.
  2. color The color it should be in.
  3. const message[] The text you would like to display. max len displayable: 144

pawn Code:
SendClientMessage(playerid, color, const message[]);

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.

pawn Code:
public OnPlayerConnect(playerid)
{
  SendClientMessage(playerid, COLOR_YELLOWGREEN, "Welcome to my server! Hope you enjoy your stay around here!");

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:

pawn Code:
public OnPlayerConnect(playerid)
{
  SendClientMessage(playerid, COLOR_GREENYELLOW, "Welcome to my server! Hope you enjoy your stay around here!");
  return 1;
}



__________________________________________
__________________________________________
__________________________________________

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:

pawn Code:
#define COLOR_GOLD 0xB8860BAA
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.

pawn Code:
public OnPlayerConnect(playerid)

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.

pawn Code:
public OnPlayerConnect(playerid)
{
    new pname[MAX_PLAYER_NAME]

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'.

pawn Code:
public OnPlayerConnect(playerid)
{
    new pname[MAX_PLAYER_NAME], string[23 + MAX_PLAYER_NAME+1];
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.

pawn Code:
public OnPlayerConnect(playerid)
{
    new pname[MAX_PLAYER_NAME], string[23 + MAX_PLAYER_NAME+1];
GetPlayerName(playerid, pname, sizeof(pname));

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:
  1. output[] The string to output the result to
  2. len The maximum length output can contain
  3. format[] The format string
  4. {Float,_}:... Indefinite number of arguments of any tag

We need to use %s because it inserts a string. In my case, this is my 'format':

pawn Code:
format(string, sizeof(string), "Welcome to my server, %s.", pname);

Now we need to add that to our main code.

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);

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.
  1. playerid The playerid you would like to display the message for.
  2. color The color it should be in.
  3. const message[] The text you would like to display. max len displayable: 144

Since we've already defined a message in a string, we're going to use it instead of typing a message. So, this is what we need to edit:

pawn Code:
SendClientMessage(playerid, COLOR_GOLD, string);

Now we simply add that to our code:

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);

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:

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.

Last edited by Twizted; 15/07/2013 at 06:34 PM.
Twizted is offline   Reply With Quote
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[FilterScript] Server Message [SERVER TIPS, SERVER MESSAGE OF THE DAY] - Simple, basic but editable! roar Filterscripts 10 28/02/2013 03:19 PM
Making the chat and the message split? JaKe Elite Scripting Help 23 01/12/2012 12:51 PM
[Tutorial] Making a Private message system thefatshizms Tutorials 12 26/11/2012 12:49 PM
Need help making the sa-mp server send a message when someone join/leave the IRC channel. OleKristian95 Scripting Help 2 07/05/2012 02:00 AM
Question on a making my own private message command. CaptainCaveMan Help Archive 3 28/08/2009 04:07 PM


All times are GMT. The time now is 10:25 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.