Textdraw does not update
#1

Textdraw Name: DMG (Damage) assigned to Textdraw14
Description: When the vehicle has a health of more than 75, then the textdraw color will be WHITE(0xFFFFFFFF), when it's Less or equal to 75 but more than 50 the textdraw will be YELLOW, and if 50 and below it'll be red

With that said I came up with this:
pawn Код:
forward Damage(playerid);
public Damage(playerid)
{
    new Float:health;
    new veh;
    new dmgstr[10];
    veh = GetPlayerVehicleID(playerid);
    GetVehicleHealth(veh, health);
    if(IsPlayerInAnyVehicle(playerid))
    {
    if(health > 75)
    {
        format(dmgstr, 10, "DMG");
        TextDrawSetString(Textdraw14,dmgstr);
        TextDrawColor(Textdraw14, 0xFFFFFFFF);
    }
    else if(health <= 75 && health > 50)
    {
        format(dmgstr, 10, "DMG");
        TextDrawSetString(Textdraw14, dmgstr);
        TextDrawColor(Textdraw14, 0xFFFF00FF);
    }
    else if(health <= 50)
    {
       format(dmgstr, 10, "DMG");
       TextDrawSetString(Textdraw14, dmgstr);
       TextDrawColor(Textdraw14, 0xFF0000FF);
    }
    }
    else {
    TextDrawSetString(Textdraw14, "DMG");
    TextDrawColor(Textdraw14, 0xD3D3D3FF);
    }
return 1;
}
Got this on the OnPlayerSpawn callback
pawn Код:
TextDrawShowForPlayer(playerid, Text:Textdraw14);
And on the OnPlayerDisconnect callback
pawn Код:
TextDrawDestroy(Textdraw14);
The timer to update the TD: (I'm not using this on OnPlayerUpdate, but it's on the OnPlayerConnect callback)
pawn Код:
SetTimer("Damage", 2000, true);


The problem is, it does not update. Even though the vehicle's already smoking.


EDIT:
The Textdraw itself
pawn Код:
Textdraw14 = TextDrawCreate(617.510925, 259.583068, " ");
TextDrawLetterSize(Textdraw14, 0.155300, 0.911665);
TextDrawAlignment(Textdraw14, 1);
TextDrawSetShadow(Textdraw14, 0);
TextDrawSetOutline(Textdraw14, 1);
TextDrawBackgroundColor(Textdraw14, 51);
TextDrawFont(Textdraw14, 1);
TextDrawSetProportional(Textdraw14, 1);
Reply
#2

You're destroying the textdraw for all.

Just use TextDrawHideForPlayer.
Reply
#3

Quote:
Originally Posted by Romel
Посмотреть сообщение
You're destroying the textdraw for all.

Just use TextDrawHideForPlayer.
Thanks for the heads up, Instead of using the OnGameModeInit to create the Textdraws, I'm using OnPlayerConnect instead. Each player having their own textdraws. And destroying it once they'll leave.

Anyway, it still does not fix what this topic was made for. Doesn't update
Reply
#4

delete this
Reply
#5

I said this to someone else just yesterday: vehicle health goes up to 1000. The vehicle catches fire at 250 health.
Reply
#6

Quote:
Originally Posted by Vince
Посмотреть сообщение
I said this to someone else just yesterday: vehicle health goes up to 1000. The vehicle catches fire at 250 health.
Tried it your way but still, it does not work
pawn Код:
forward Damage(playerid);
public Damage(playerid)
{
    new Float:health;
    new veh;
    veh = GetPlayerVehicleID(playerid);
    GetVehicleHealth(veh, health);
    if(IsPlayerInAnyVehicle(playerid))
    {
    if(health > 800)
    {
        TextDrawColor(Textdraw13[playerid], 0xFFFFFFFF);
    }
    else if(health <= 800 && health > 500)
    {
        TextDrawColor(Textdraw13[playerid], 0xFFFF00FF);
    }
    else if(health <= 400)
    {
       TextDrawColor(Textdraw13[playerid], 0xFF0000FF);
    }
    }
    else {
    TextDrawColor(Textdraw13[playerid], 0xD3D3D3FF);
    }
return 1;
}
Reply
#7

I suggest you to do a debug:

pawn Код:
forward Damage(playerid);
public Damage(playerid)
{
    new Float:health;
    new veh;
    veh = GetPlayerVehicleID(playerid);
    GetVehicleHealth(veh, health);
    printf("--- DEBUG: Vehicle Health on \"public Damage\": %f", health);
    if(IsPlayerInAnyVehicle(playerid))
    {
    if(health > 800)
    {
        TextDrawColor(Textdraw13[playerid], 0xFFFFFFFF);
    }
    else if(health <= 800 && health > 500)
    {
        TextDrawColor(Textdraw13[playerid], 0xFFFF00FF);
    }
    else if(health <= 400)
    {
       TextDrawColor(Textdraw13[playerid], 0xFF0000FF);
    }
    }
    else {
    TextDrawColor(Textdraw13[playerid], 0xD3D3D3FF);
    }
return 1;
}
Check your log for values. If they are wrong, you must recheck your code for mistakes
Reply
#8

Oh... lol... it's probably the fact you have a 'playerid' parameter in the damage function, and it hasn't been defined yet...

Instead of:
pawn Код:
SetTimer("Damage", 2000, true);
You need:
pawn Код:
SetTimerEx("Damage", 2000, true, "i", playerid);
I think this would belong under OnPlayerConnect if I'm correct?
Reply
#9

Quote:
Originally Posted by Ken97
Посмотреть сообщение
delete this
Quote:
Originally Posted by BenzoAMG
Посмотреть сообщение
Oh... lol... it's probably the fact you have a 'playerid' parameter in the damage function, and it hasn't been defined yet...

Instead of:
pawn Код:
SetTimer("Damage", 2000, true);
You need:
pawn Код:
SetTimerEx("Damage", 2000, true, "i", playerid);
I think this would belong under OnPlayerConnect if I'm correct?
Haven't noticed that.
Tested your code but it still wouldn't change the text color.
Reply
#10

Quote:
Originally Posted by ******
Посмотреть сообщение
ONLY SetString updates for players - for any other modification you need to reshow the TD.
Does that mean I have to create a new textdraw for each color?
I'm assuming that this is the process. Hide the current default, once the damage is below 800. Show the new one with the color yellow. Once it reaches 400 or below, hide the yellow, show the red..
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)