A little help with textdraws.
#1

I've made some textdraws, Now I can't really find a proper tutorial so I'll just ask it here, I have made an HP, kills,deaths,ping,fps textdraws

So I'll start with the HP for now maybe I'll learn something and make the others by my self.

So the first textdraw is a transparent box, All the textdraws that I've made are on that transparent box.

Here is my transparent box

Код:
// In OnGameModeInit prefferably, we procced to create our textdraws:
Textdraw0 = TextDrawCreate(-10.000000, 431.000000, "_");
TextDrawBackgroundColor(Textdraw0, 255);
TextDrawFont(Textdraw0, 1);
TextDrawLetterSize(Textdraw0, 0.500000, 6.800000);
TextDrawColor(Textdraw0, -1);
TextDrawSetOutline(Textdraw0, 1);
TextDrawSetProportional(Textdraw0, 0);
TextDrawUseBox(Textdraw0, 1);
TextDrawBoxColor(Textdraw0, 120);
TextDrawTextSize(Textdraw0, 796.000000, 28.000000);
Now as I said directly above, all the textdraws I've made are on it, For example my HP textdraw.

Код:
Textdraw1 = TextDrawCreate(8.000000, 430.000000, "HP");
TextDrawBackgroundColor(Textdraw1, 16711935);
TextDrawFont(Textdraw1, 3);
TextDrawLetterSize(Textdraw1, 0.700000, 1.800000);
TextDrawColor(Textdraw1, 712256255);
TextDrawSetOutline(Textdraw1, 1);
TextDrawSetProportional(Textdraw1, 1);
.
So basically what I want to do is make HP textdraw with the current player's HP

- example , HP 'health amount'.

So it updates every time a player gets hit and obviously resets after he dies...

Can anyone provide me a way to do so?

Thanks in advance!
Reply
#2

1.) Set "Textdraw1" as a PlayerTextdraw - https://sampwiki.blast.hk/wiki/CreatePlayerTextDraw
2.) Make a player timer (or use OnPlayerUpdate, but it's called very frequently) and update the textdraw's string with this function - https://sampwiki.blast.hk/wiki/PlayerTextDrawSetString

For example:
Код:
new string[32], Float:Health;
GetPlayerHealth(playerid, Health);
format(string, sizeof(string), "HP: %0.1f", Health);
PlayerTextDrawSetString(playerid, Textdraw1[playerid], string);
Reply
#3

Hey, I just found a quick tutorial but i'm having this 1 error on here
Код:
for(new i = 0; i < MAX_PLAYERS; i++) // That's the line <<<<<<<
{
    Health[i] = TextDrawCreate(8.000000, 430.000000, "HP 100%");
	TextDrawBackgroundColor(Health[i], 16711935);
	TextDrawFont(Health[i], 3);
	TextDrawLetterSize(Health[i], 0.700000, 1.800000);
	TextDrawColor(Health[i], 712256255);
	TextDrawSetOutline(Health[i], 1);
	TextDrawSetProportional(Health[i], 1);
}
Код:
C:\Users\yan\Desktop\SA-MP Server\gamemodes\DBv1.pwn(477) : error 010: invalid function or declaration
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.
Reply
#4

Using a loop is quite unnecessary in this case. This is all you need to do:

Put this on top of your script under other variables:
Код:
new PlayerText:Health[MAX_PLAYERS];
OnPlayerConnect:
Код:
Health[playerid] = CreatePlayerTextDraw(playerid, 8.000000, 430.000000, "HP 100%");
PlayerTextDrawBackgroundColor(playerid, Health[playerid], 16711935);
PlayerTextDrawFont(playerid, Health[playerid], 3);
PlayerTextDrawLetterSize(playerid, Health[playerid], 0.700000, 1.800000);
PlayerTextDrawColor(playerid, Health[playerid], 712256255);
PlayerTextDrawSetOutline(playerid, Health[playerid], 1);
PlayerTextDrawSetProportional(playerid, Health[playerid], 1);
PlayerTextDrawHide(playerid, Health[playerid]); // hide the textdraw
OnPlayerSpawn:
Код:
PlayerTextDrawShow(playerid, Health[playerid]); // show the textdraw
OnPlayerUpdate or any other looped player timer:
Код:
new String[32], Float:hp;
GetPlayerHealth(playerid, hp);
format(String, sizeof(String), "HP: %0.1f", hp);
PlayerTextDrawSetString(playerid, Health[playerid], String);
Reply
#5

Код:
C:\Users\yan\Desktop\SA-MP Server\gamemodes\DBv1.pwn(11) : error 021: symbol already defined: "Health"
C:\Users\yan\Desktop\SA-MP Server\gamemodes\DBv1.pwn(283) : warning 213: tag mismatch
C:\Users\yan\Desktop\SA-MP Server\gamemodes\DBv1.pwn(284) : warning 213: tag mismatch
C:\Users\yan\Desktop\SA-MP Server\gamemodes\DBv1.pwn(285) : warning 213: tag mismatch
C:\Users\yan\Desktop\SA-MP Server\gamemodes\DBv1.pwn(286) : warning 213: tag mismatch
C:\Users\yan\Desktop\SA-MP Server\gamemodes\DBv1.pwn(287) : warning 213: tag mismatch
C:\Users\yan\Desktop\SA-MP Server\gamemodes\DBv1.pwn(288) : warning 213: tag mismatch
C:\Users\yan\Desktop\SA-MP Server\gamemodes\DBv1.pwn(289) : warning 213: tag mismatch
C:\Users\yan\Desktop\SA-MP Server\gamemodes\DBv1.pwn(290) : warning 213: tag mismatch
C:\Users\yan\Desktop\SA-MP Server\gamemodes\DBv1.pwn(310) : warning 213: tag mismatch
C:\Users\yan\Desktop\SA-MP Server\gamemodes\DBv1.pwn(458) : warning 213: tag mismatch
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.
Reply
#6

Change name of that variable from "Health" to something else.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)