02.08.2011, 07:36
(
Последний раз редактировалось [HiC]TheKiller; 03.08.2011 в 06:50.
)
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 Код:
new Text:PlayerTextDraw;
PlayerTextDraw = TextDrawCreate(/*X Position*/, /*Y Position*/, "This is going to be about our max textdraw length");
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 Код:
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);
pawn Код:
new Text:Textdraw0;
pawn Код:
new Text:Textdraw0[MAX_PLAYERS];
pawn Код:
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;
}
pawn Код:
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;
}
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 Код:
public OnGameModeInit() //Called when the gamemode starts.
{
SetTimer("UpdateTimer", 1000, true);
return 1;
}
pawn Код:
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.
}
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 Код:
public OnPlayerSpawn(playerid)
{
TextDrawShowForPlayer(playerid, Textdraw0[playerid]); //Shows the textdraw
return 1;
}
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
TextDrawDestroy(Textdraw0[playerid]); //Destroys the textdraw
return 1;
}
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 .