sSiddhant Tutorial 3# Leave Messages -
Siddhant240201 - 28.08.2016
sSiddhant Tutorial 3# Leave Messages
This is my third tutorial on messages. This tutorial focuses on how to make a Leave Messages. Please read my previous tutorials for understanding basics of Strings.
Ok! Lets begin
Remember that Leave messages are send when player Disconnect from the Server for some reason.
We are gonna make the whole script under this Callback
Quote:
public OnPlayerDisconnect(playerid, reason)
{
}
|
This callback automatically return's the reason for why the player has Disconnected.
Now, we are gonna create few arrays
Quote:
new sname[MAX_PLAYER_NAME];
new string[39 + MAX_PLAYER_NAME];
|
The First Array sname stores the name of the Player
and the Second array string will be used to store the messages
Let's get the player name
Quote:
GetPlayerName(playerid, sname, sizeof(sname));
|
This Command will get the players name and store it in the array sname with a max length of sizeof(sname), the size of sname. To understand this please read my previous tutorials.
Now we will use switch-case. Hope you all know about switch case. Basically switch case is just like if-else but it only compares equal to values not greater than and smaller than values.
Quote:
switch(reason)
{
case 0: format(str, sizeof(str), "%s has lost Connection to the server", sname);
break;
case 1: format(str, sizeof(str), "%s has left the server", sname);
break;
case 2: format(str, sizeof(str), "%s has been kicked/banned from the server", sname);
break;
}
|
Based on the reason returned by the Callback switch-case will execute any one of these Commands. So the str array will be formatted according to the value returned by the Callback. I will explain what is string formatting again.
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. This is taken from samp wikia.
After this now we have to send message to all players using this command
Quote:
SendClientMessageToAll(-1, string);
|
This Command will send the message to all players in the color -1 which is white and the message will be that str array which was formatted according to the value returned by the Callback.
I have posted 3 tutorials on these messages. So next time I am gonna post the tutorial on How to make your own Custom messages using String variables. Please Comment and Post your suggestion for my next tutorials.
Re: sSiddhant Tutorial 3# Leave Messages -
Fairuz - 28.08.2016
this is useless imo.
https://sampwiki.blast.hk/wiki/OnPlayerDisconnect
Re: sSiddhant Tutorial 3# Leave Messages -
Siddhant240201 - 28.08.2016
Quote:
Originally Posted by Dice_
|
Bro! I know this is on samp wikia but its not much explained i have done my best to explain each and every line