SA-MP Forums Archive
[Tutorial] Make a simple join/leave messages box. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] Make a simple join/leave messages box. (/showthread.php?tid=527744)



Make a simple join/leave messages box. - Battlezone - 24.07.2014

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:



Re: Make a simple join/leave messages box. - iFarbod - 24.07.2014

pawn Code:
public OnPlayerDisconnected(playerid, reason)
must be
pawn Code:
public OnPlayerDisconnect(playerid, reason)



Re: Make a simple join/leave messages box. - Battlezone - 24.07.2014

Yeah, I didn't notice it since i wrote it in a hurry :c thanks


Re: Make a simple join/leave messages box. - TuNiSiAnO1 - 24.07.2014

Good tutorial thank you.


Re: Make a simple join/leave messages box. - SHE790 - 24.07.2014

Good Job +REP


Re: Make a simple join/leave messages box. - Battlezone - 24.07.2014

Thanks


Re: Make a simple join/leave messages box. - KayJ - 26.07.2014

Put Any Pictures please?


Re: Make a simple join/leave messages box. - Battlezone - 29.07.2014

Screenshot added .


Re: Make a simple join/leave messages box. - Ryz - 21.09.2014

wow nice work. youre rockkk


Re: Make a simple join/leave messages box. - xMx4LiFe - 30.10.2014

Ryz u r true!
i love u and battlezone + excel u are very helpful to me for making me a new script Call of Duty 8 - Asia at War