[Tutorial] Random Message Textdraws
#1

Random Message - Textdraws Tutorial

What will this teach me?
This tutorial will teach you how to make random messages display at the bottom of your screen.

How could this help my server?
This could help your server by displaying basic commands or even updates, rules and advertising.

Step 1:
Ok so lets begin by defining the colors we gonna use at the top of the script.
Code:
#define Light_Blue 0x00CCFF
#define White 0xFFFFFF
#define Gray 0x222222BB
Step 2:
Next we gonna have to forward a function we will use later and we will need to define the text and messages.
Code:
forward MSG();

new Text:ServerMSG;

new RMessages[][] =
{
        "~y~Random News: ~w~Random Text Here",
        "~y~Random News: ~w~Random Text Here",
        "~y~Random News: ~w~Random Text Here",
        "~y~Random News: ~w~Random Text Here",
        "~y~Random News: ~w~Random Text Here"
};
The "~y~" is gonna make the "Random News: " in yellow.
The "~w~" is gonna make the "Text" in white.

I will post all the colors at the end of the tutorial for you.

Step 3:
Now under your public OnGameModeInit() we need to make the text draws.

Code:
SetTimer("MSG", 8000, true);
ServerMSG = TextDrawCreate(2.000000, 428.000000, "[ Server MSG");
TextDrawColor(ServerMSG, Light_Blue);
TextDrawFont(ServerMSG, 1);
TextDrawLetterSize(ServerMSG, 0.400000, 0.800000);
Code:
SetTimer("MSG", 8000, true);
is gonna make the text change ever 8000 miliseconds
Code:
ServerMSG = TextDrawCreate(2.000000, 428.000000, "[ Server MSG");
This line will create the textdraw.
Code:
TextDrawColor(ServerMSG, Light_Blue);
TextDrawFont(ServerMSG, 1);
TextDrawLetterSize(ServerMSG, 0.400000, 0.800000);
These lines are just setting the color, font and size of the message.

Step 4:
Now we need to set the string for what the textdraw needs to display.
Code:
public MSG()
{
        TextDrawSetString(ServerMSG, RMessages[random(sizeof(RMessages))]);
        return 1;
}
We forwarded the public earlier so we don't need to do that again.
Code:
TextDrawSetString(ServerMSG, RMessages[random(sizeof(RMessages))]);
This line will set the string and will display a random message that we set under the "RMessages[][]".

Step 5:
Now we need to make the textdraw display when the player spawns.
So under
Code:
public OnPlayerSpawn(playerid)
Add:
Code:
TextDrawShowForPlayer(playerid, ServerMSG);
This line will show the player the messages.

Hope this tutorial helped and please give me feedback and let me know if I missed something out or needs more explaining.








Reply
#2

Whats '[ server'? ik whats MSG but whats that?
Reply
#3

Your code will annoy players for show the textdraw all the time. You added TextdrawShowForPlayer, and without Hiding it with a timer? Just advising.
Reply
#4

Quote:

Whats '[ server'? ik whats MSG but whats that?

What do you mean?
Quote:

Your code will annoy players for show the textdraw all the time. You added TextdrawShowForPlayer, and without Hiding it with a timer? Just advising.

What do you mean hiding it behind a timer?
Reply
#5

Hey I just want to ask, How do I find out the on screen coords of where the text draw is going to go!
Reply
#6

Like, CMD: showtextdrawforall

You show the textdraw to the client but it won't go away from their view unless you hide the textdraw in your timer.
Reply
#7

You can use this tutorial to find your on screen co-ordinates: https://sampforum.blast.hk/showthread.php?tid=235740

Its not suppose to go away from their view though.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)