[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


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)