[Tutorial] Make a simple join/leave messages box.
#1

This simple tutorial that will show you how to easily make a 3 lines Joins/Leaves Box .


Steps:

1-We create the necessary global Texts and Strings :
pawn Code:
new Text:mbox; //the box
new Text:Message; //the messages textdraw
new MessageStr[170]; //string line 3
new MessageStrl2[170]; //string line 2
new MessageStrl3[170]; //string line 1
2-Then we create the textdraws under OnGameModeInit :
pawn Code:
public OnGameModeInit()
{
    //box textdraw
    mbox = TextDrawCreate(683.000000, 365.000000, "~n~~n~~n~");
    TextDrawBackgroundColor( mbox, 255);
    TextDrawFont(mbox, 1);
    TextDrawLetterSize(mbox, 0.969999, 1.600000);
    TextDrawColor(mbox, -1347440726);
    TextDrawSetOutline(mbox, 0);
    TextDrawSetProportional(mbox, 1);
    TextDrawSetShadow(mbox, 1);
    TextDrawUseBox(mbox, 1);
    TextDrawBoxColor(mbox, 24);
    TextDrawTextSize(mbox, 470.000000, 99.000000);
    TextDrawShowForAll(mbox);
    //strings textdraw
    Message = TextDrawCreate(473.000000, 368.000000, "");
    TextDrawBackgroundColor(Message, 255);
    TextDrawFont(Message, 1);
    TextDrawLetterSize(Message, 0.190000, 1.300001);
    TextDrawColor(Message, -1);
    TextDrawSetOutline(Message, 0);
    TextDrawSetProportional(Message, 1);
    TextDrawSetShadow(Message, 1);
    TextDrawShowForAll(Message);
    return 1;
}
3-Once we created the textdraws, we can now use format to change the Message strings under each one of the above callbacks (you can use strins too, but since this tutorial is for beginners I prefer to use format here):
pawn Code:
public OnPlayerConnect(playerid)
{
    format(MessageStrl3, 170, MessageStrl2); // move the line 2 text to line 1
    format(MessageStrl2, 170, MessageStr); // move the line 3 text to line 2
    new name[MAX_PLAYER_NAME+1];
    GetPlayerName(playerid, name, sizeof(name)); // getting the player name
    format(MessageStr,sizeof MessageStr,"~>~~b~%s ~w~has ~g~connected.", name); //formatting line 3 text
    new STR[510]; //creating a new string to merge the 3 strings into a one 3 lines string
    format(STR, sizeof(STR), "%s~n~%s~n~%s", MessageStrl3, MessageStrl2, MessageStr); //formatting the newly created string
    TextDrawSetString(Message, STR); //showing it on the screen
pawn Code:
public OnPlayerDisconnect(playerid, reason)
{
    format(MessageStrl3, 170, MessageStrl2); // move the line 2 text to line 1
    format(MessageStrl2, 170, MessageStr); // move the line 3 text to line 2
    new name[MAX_PLAYER_NAME+1];
    GetPlayerName(playerid, name, sizeof(name)); // getting the player name
    switch(reason) //switching reasons
    {
            case 0: format(MessageStr,sizeof MessageStr,"~<~~b~%s ~w~has ~y~lost connection", name);
            case 1: format(MessageStr,sizeof MessageStr,"~<~~b~%s ~w~has ~r~disconnected", name);
            case 2: format(MessageStr,sizeof MessageStr,"~<~~b~%s ~w~was~y~ kicked/banned", name);
    }
    new STR[510]; //creating a new string to merge the 3 strings into a one 3 lines string
    format(STR, sizeof(STR), "%s~n~%s~n~%s", MessageStrl3, MessageStrl2, MessageStr); //formatting the newly created string
    TextDrawSetString(Message, STR); //showing it on the screen
That's all, and of course you can extand your box and add more lines if you want!

Screenshot:
Reply


Messages In This Thread
Make a simple join/leave messages box. - by Battlezone - 24.07.2014, 05:23
Re: Make a simple join/leave messages box. - by iFarbod - 24.07.2014, 05:51
Re: Make a simple join/leave messages box. - by Battlezone - 24.07.2014, 11:25
Re: Make a simple join/leave messages box. - by TuNiSiAnO1 - 24.07.2014, 16:11
Re: Make a simple join/leave messages box. - by SHE790 - 24.07.2014, 21:35
Re: Make a simple join/leave messages box. - by Battlezone - 24.07.2014, 21:47
Re: Make a simple join/leave messages box. - by KayJ - 26.07.2014, 08:16
Re: Make a simple join/leave messages box. - by Battlezone - 29.07.2014, 11:17
Re: Make a simple join/leave messages box. - by Ryz - 21.09.2014, 10:57
Re: Make a simple join/leave messages box. - by xMx4LiFe - 30.10.2014, 17:03

Forum Jump:


Users browsing this thread: 2 Guest(s)