[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
#2

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

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

Good tutorial thank you.
Reply
#5

Good Job +REP
Reply
#6

Thanks
Reply
#7

Put Any Pictures please?
Reply
#8

Screenshot added .
Reply
#9

wow nice work. youre rockkk
Reply
#10

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)