28.08.2016, 07:48
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) { } |
Now, we are gonna create few arrays
Quote:
new sname[MAX_PLAYER_NAME]; new string[39 + MAX_PLAYER_NAME]; |
and the Second array string will be used to store the messages
Let's get the player name
Quote:
GetPlayerName(playerid, sname, sizeof(sname)); |
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; } |
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); |
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.