Creating a Player Information Text draw
Information
Pretty much, I have written this tutorial due to the amount of people posting topics in the scripting discussion regarding information using textdraws such as health, location etc. I'll try explain this tutorial in the best way possible, please post if you have any issues regarding this tutorial.
Step 1 - Setting up the Text draw
There are multiple ways that you can set up your textdraw position, looks, size and more. I will explain two ways on how to make the textdraw, one inside and outside of sa-mp.
In-game
For the in-game textdraw editor, I personally would recommend Zamaroht's Textdraw Editor. You can pretty much edit anything in game and it's probably the quickest way to get the Text draw looking good. Make sure that you have enough characters to make the textdraw fit. Type a sentence that wouldn't exceed your maximum amount of characters used.
Out of the game
Firstly we must find the textdraws position. We can do this by downloading the blank image the same size as we need for our canvas size.
Now, you can use multiple programs to find the position you want the texdtaw to be in. For this tutorial, we are going to be using Microsoft Paint. After downloading the image, open it up in paint and you should see a grey rectangle. Move your mouse around the image and you will see down the bottom bar that some co-ordonates near the crosshair icon are changing. Put your mouse over the place where you want the top of the first letter of the texdraw to be.
Now, with these co-ordonates that we have, we are going to put them in the following template.
pawn Code:
new Text:PlayerTextDraw;
PlayerTextDraw = TextDrawCreate(/*X Position*/, /*Y Position*/, "This is going to be about our max textdraw length");
There are multiple other things you can change for the textdraw to look nice as well, such as editing the Font, Letter size, Colours and much more. If you want to do this easily, you can use Zamaroht's Textdraw Editor.
Step 2 - Setting the Textdraw for All players
Now, we will have something looking similar to this or less if you did not use the text draw editor. The same way to do this applies. We are putting the textdraw setup on OnPlayerConnect because the texdraw is for a single player, not all players. We are using OnPlayerConnect because we do not want to reformat it OnPlayerSpawn (Every Spawn time including deaths).
pawn Code:
new Text:Textdraw0;
Textdraw0 = TextDrawCreate(281.000000, 427.000000, "This is going to be about our max textdraw length");
TextDrawBackgroundColor(Textdraw0, 255);
TextDrawFont(Textdraw0, 1);
TextDrawLetterSize(Textdraw0, 0.220000, 1.600000);
TextDrawColor(Textdraw0, -16776961);
TextDrawSetOutline(Textdraw0, 1);
TextDrawSetProportional(Textdraw0, 1);
Change the
pawn Code:
new Text:Textdraw0;
And add [MAX_PLAYERS] to the end of the variable so there is a variable for each player.
pawn Code:
new Text:Textdraw0[MAX_PLAYERS];
And everything else that is setting the prettiness of the the textdraw from this
pawn Code:
public OnPlayerConnect(playerid)
{
Textdraw0 = TextDrawCreate(281.000000, 427.000000, "This is going to be about our max textdraw length");
TextDrawBackgroundColor(Textdraw0, 255);
TextDrawFont(Textdraw0, 1);
TextDrawLetterSize(Textdraw0, 0.220000, 1.600000);
TextDrawColor(Textdraw0, -16776961);
TextDrawSetOutline(Textdraw0, 1);
TextDrawSetProportional(Textdraw0, 1);
return 1;
}
And add [playerid] on the end of the Text draw variable so we edit the current players textdraw.
pawn Code:
public OnPlayerConnect(playerid)
{
Textdraw0[playerid] = TextDrawCreate(281.000000, 427.000000, "This is going to be about our max textdraw length");
TextDrawBackgroundColor(Textdraw0[playerid], 255);
TextDrawFont(Textdraw0[playerid], 1);
TextDrawLetterSize(Textdraw0[playerid], 0.220000, 1.600000);
TextDrawColor(Textdraw0[playerid], -16776961);
TextDrawSetOutline(Textdraw0[playerid], 1);
TextDrawSetProportional(Textdraw0[playerid], 1);
return 1;
}
You may be thinking why we are doing this, and there is a good reason. If we only had a single Text draw then when we updated the Text draw, it would update everyone's textdraw to your information. Currently, there is no PlayerTextDrawCreate .
Step 3 - Setting up the Timer
OK, so because we are updating the information constantly, we need a timer to do this. We will have a timer running at every one second because anything lower isn't really needed. You can if you want change the timer variable.
pawn Code:
public OnGameModeInit() //Called when the gamemode starts.
{
SetTimer("UpdateTimer", 1000, true);
return 1;
}
Edit the 1000 if you want to change the timer duration. Now, we are going to make the actual function that is called by the timer. It is going to update our players textdraw.
pawn Code:
forward UpdateTimer(); //Must always forward a timer, read the set timer topic in the wiki for more info.
public UpdateTimer() // Must be a public.
{
for(new x; x<MAX_PLAYERS; x++) // Loop for all players
{
if(!IsPlayerConnected(x) || IsPlayerNPC(x)) continue; // Skips a loop if the player is not connected or is a NPC
new Float:Health, Float:Armour, Score = GetPlayerScore(x), Money = GetPlayerMoney(x), Name[24]; //Gets variables
GetPlayerName(x, Name, 24); //Gets a players name
GetPlayerHealth(x, Health); //Gets players HP
GetPlayerArmour(x, Armour); //Gets players armour
new TDstring[150]; // Max string size is 150 characters.
format(TDstring, sizeof(TDstring), "Name: %s Health: %.1f Armour: %.1f Money: $%d Score: %d", Name, Health, Armour, Money, Score); //Formats the string, for more info on format, visit the wiki.
TextDrawSetString(Textdraw0[x], TDstring); //Sets the Text Draw to our formatted string.
}
return 1; //Must return a value on a public.
}
Step 4 - Showing the Text draw for the player / destroying it when a player leaves.
Last but not least, we must remember always to show the textdraw for the player. This can be done on OnPlayerConnect or OnPlayerSpawn. We are going to use OnPlayerSpawn. We must also destroy the textdraw when the player leaves because there is a limit on Text Draws .
pawn Code:
public OnPlayerSpawn(playerid)
{
TextDrawShowForPlayer(playerid, Textdraw0[playerid]); //Shows the textdraw
return 1;
}
pawn Code:
public OnPlayerDisconnect(playerid, reason)
{
TextDrawDestroy(Textdraw0[playerid]); //Destroys the textdraw
return 1;
}
Conclusion
If you have any issues / are confused with this tutorial, please contact me or post in this thread. This tutorial is just a general example of how to create a player text draw that constantly updates .
__________________
My tutorials
Buyable Businesses | Buyable Houses
Simple Icon Streamers! | Checkpoint Streamer
Object Streamer | Lotto script
Making a MySQL system!
Scripts
[FS / PHP]ObjectAdder | [FS]KRace
[FS]Money Bag | [GM]Area51 DM
[FS][PHP]TKAdmin | [INC]TKsave
Every script I've released