[Tutorial] How to make random messages using textdraws
#1

Random Messages - Textdraws

First of all we have to define the following things: Add the codes anywhere at the top of your script

pawn Код:
forward RandomMessage(); // This is the forward for the timer
Then we have to define the textdraw

pawn Код:
new Text:randommsg; // This is to define the textdraw that we are going to use
Now we have to define all the messages which will show for the players

pawn Код:
new RandomMessages[][] =
{
    "~y~Community Name: ~w~Your Text ~g~here.",
    "~y~Community Name: ~w~Your Text ~r~here.",
    "~y~Community Name: ~w~Your Text ~y~here.",
    "~y~Community Name: ~w~Your Text ~b~here."
// You can define more messages, but make sure you have , everywhere, except at the last message
};
You can change it to colors you like, look here for the color names
https://sampwiki.blast.hk/wiki/Colors_List

------------------------------------------------------------------------

Now we have to add the timer, you can define for how long time a message will stay

Add the following codes under OnGameModeInit

pawn Код:
SetTimer("RandomMessage",8000,1); // 8000 is for 8 seconds, if you want 50 seconds use 50000
Now we have to add the textdraw, put this also under OnGameModeInit

pawn Код:
randommsg = TextDrawCreate(7.000000, 427.000000, "You don't need to add any text here");
TextDrawBackgroundColor(randommsg, 255);
TextDrawFont(randommsg, 1);
TextDrawLetterSize(randommsg, 0.379999, 1.499999);
TextDrawColor(randommsg, -1);
TextDrawSetOutline(randommsg, 1);
TextDrawSetProportional(randommsg, 1);
If you don't like this textdraw, you can make your own by using a editor

--------------------------------------------------

Now we have to make a public function for the timer, add this anywhere in your gamemode, for example i have it above OnGameModeInit

pawn Код:
public RandomMessage()
{
        TextDrawSetString(randommsg, RandomMessages[random(sizeof(RandomMessages))]); // We need this to make the timer working
        return 1;
}
Now to show the textdraw for the players add the following under OnPlayerSpawn

pawn Код:
TextDrawShowForPlayer(playerid, randommsg);
You can also add it under OnPlayerConnect

You can see an example how it will looks like on my ******* channel, http://www.*******.com/user/sunsetcityrp

Thats it, hope i helped
Reply
#2

nice tutorial!
Reply
#3

good tutorial but theres mistakes on your code

pawn Код:
new RandomMessages[][] =
{
    "~y~Community Name: ~w~Your Text ~g~here.",
    "~y~Community Name: ~w~Your Text ~r~here.",
    "~y~Community Name: ~w~Your Text ~y~here.",
    "~y~Community Name: ~w~Your Text ~b~here."
] //<<<< will cause errors
should be

pawn Код:
new RandomMessages[][] =
{
    "~y~Community Name: ~w~Your Text ~g~here.",
    "~y~Community Name: ~w~Your Text ~r~here.",
    "~y~Community Name: ~w~Your Text ~y~here.",
    "~y~Community Name: ~w~Your Text ~b~here."
};
Reply
#4

Quote:
Originally Posted by Reklez
Посмотреть сообщение
good tutorial but theres mistakes on your code

pawn Код:
new RandomMessages[][] =
{
    "~y~Community Name: ~w~Your Text ~g~here.",
    "~y~Community Name: ~w~Your Text ~r~here.",
    "~y~Community Name: ~w~Your Text ~y~here.",
    "~y~Community Name: ~w~Your Text ~b~here."
] //<<<< will cause errors
should be

pawn Код:
new RandomMessages[][] =
{
    "~y~Community Name: ~w~Your Text ~g~here.",
    "~y~Community Name: ~w~Your Text ~r~here.",
    "~y~Community Name: ~w~Your Text ~y~here.",
    "~y~Community Name: ~w~Your Text ~b~here."
};
Thank you, fixed
Reply
#5

ty,very helpful
Reply
#6

pawn Код:
// This is a comment
// uncomment the line below if you want to write a filterscript
#define FILTERSCRIPT

#include <a_samp>

#if defined FILTERSCRIPT

new Text:randommsg;

new RandomMessages[][] =
{
    "~y~Community Name: ~w~Your Text ~g~here.",
    "~y~Community Name: ~w~Your Text ~r~here.",
    "~y~Community Name: ~w~Your Text ~y~here.",
    "~y~Community Name: ~w~Your Text ~b~here."
};

public OnFilterScriptInit()
{
    SetTimer("RandomMessage",8000,1);
    randommsg = TextDrawCreate(7.000000, 427.000000, "You don't need to add any text here");
    TextDrawBackgroundColor(randommsg, 255);
    TextDrawFont(randommsg, 1);
    TextDrawLetterSize(randommsg, 0.379999, 1.499999);
    TextDrawColor(randommsg, -1);
    TextDrawSetOutline(randommsg, 1);
    TextDrawSetProportional(randommsg, 1);
    return 1;
}

public OnFilterScriptExit()
{
    return 1;
}

forward RandomMessage();
public RandomMessage()
{
    TextDrawSetString(randommsg, RandomMessages[random(sizeof(RandomMessages))]);
    return 1;
}

public OnPlayerConnect(playerid)
{
    TextDrawShowForPlayer(playerid, randommsg);
    return 1;
}

#else

main()
{
    print("\n----------------------------------");
    print(" Blank Gamemode by your name here");
    print("----------------------------------\n");
}

#endif
Reply
#7

nice tutorial
Reply
#8

Decent tutorial, some things could be used to explain it a bit more, but nonetheless, it's good.
Reply
#9

Thanks mane, your tutorial is very helped me for Newbie scripter like me
Reply
#10

Bro can u tell me how i add the random mesg on player death like when he dies it says clapped or you are fucked or bla bla bla
Reply
#11

So, it worked the first time I logged into the server, but after changing the messages and the font, it stopped working.
Reply
#12

Its Awesome man
Reply
#13

pawn Code:
TextDrawShowForPlayer(playerid, randommsg);
You might want to explain to the people who are viewing this tutorial how to loop through all of the connected players and that you also have to hide then show the textdraw again if you want the newly set string to show up. Otherwise an OK tutorial.
Reply
#14

Quote:
Originally Posted by qazwsx
Посмотреть сообщение
Thanks mane, your tutorial is very helped me for Newbie scripter like me
0.o how did my name go there?
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)