TextDraw not showing up
#1

Hello. I have created a speed-o-meter textdraw but it doesn't seem to want to show when I enter a vehicle.

This is up top with my other working textdraws
pawn Код:
new Text:SpeedTD; // Speed TextDraw
Then this is with my other working textdraws
pawn Код:
// Speed TextDraw
SpeedTD = TextDrawCreate(487.000000, 425.000000, "Speed");
TextDrawBackgroundColor(SpeedTD, 255);
TextDrawFont(SpeedTD, 1);
TextDrawLetterSize(SpeedTD, 0.500000, 1.300000);
TextDrawColor(SpeedTD, -1);
TextDrawSetOutline(SpeedTD, 1);
TextDrawSetProportional(SpeedTD, 1);
And this..
pawn Код:
if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER) // Speed TextDraw
{
    new string[64], speed = GetVehicleSpeed(GetPlayerVehicleID(playerid), 0);
    format(string, sizeof(string), "Speed: %d MPH", speed);
    TextDrawSetString(SpeedTD, string);
}
Is under
pawn Код:
public OnPlayerUpdate(playerid)
{
There are no errors on compile and can't see how this can't work, looked through it loads of times.
If someone could help me I will +rep, been at it for hours! Thanks.
Reply
#2

The textdraw is being used by players so the textdraw must be global.
pawn Код:
new Text:SpeedTD[MAX_PLAYERS];
//Use SpeedTD[playerid] on your textdraws instead of using SpeedTD.
Also, run a repeating timer to detect the speed rather than using OnPlayerUpdate callback.
Reply
#3

You're making a textdraw only for one player and you're not using TextDrawShowForPlayer.

Add this anywhere:
pawn Код:
new Text:SpeedTD[MAX_PLAYERS]; // Speed TextDraw

Add this to OnPlayerConnect and remove the code that's in OnGameModeInit.
pawn Код:
SpeedTD[playerid] = TextDrawCreate(487.000000, 425.000000, "Speed");
TextDrawBackgroundColor(SpeedTD[playerid], 255);
TextDrawFont(SpeedTD[playerid], 1);
TextDrawLetterSize(SpeedTD[playerid], 0.500000, 1.300000);
TextDrawColor(SpeedTD[playerid], -1);
TextDrawSetOutline(SpeedTD[playerid], 1);
TextDrawSetProportional(SpeedTD[playerid], 1);

and the OnPlayerUpdate code:
pawn Код:
if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER) // Speed TextDraw
{
    TextDrawShowForPlayer(playerid, SpeedTD[playerid]);
    new string[64], speed = GetVehicleSpeed(GetPlayerVehicleID(playerid), 0);
    format(string, sizeof(string), "Speed: %d MPH", speed);
    TextDrawSetString(SpeedTD[playerid], string);
}
else TextDrawHideForPlayer(playerid, SpeedTD[playerid]);


This will work but I suggest you not to use OnPlayerUpdate, rather use a timer.
Reply
#4

nvm..
Reply
#5

Nevermind, fixed, thanks guys. +rep
Reply
#6

Winter please tell how you do that. Me too facing that problem. Please tell me a solution also


HostName: NewGen Gladiator Fun Play
Address: 84.200.208.104:5091
Mode: Stunt/DM/Freeroam/Race/TDM
Map: San Andreas
Reply
#7

TextDrawHideForAll(SpeedTD);
TextDrawSetString(SpeedTD, string);
TextDrawShowForAll(SpeedTD)

im surprised why none of you guys helped him with this -_-
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)