i do carhealth and do not see the textdraw
#1

codes:http://pastebin.com/ZpYsagMf
Thanks for helpers
Reply
#2

https://sampwiki.blast.hk/wiki/GetVehicleHealth

The vehicle's health is stored to the variable "health" and that is what you need to use as argument.
By doing this (which is incorrect):
pawn Код:
format(String, 250,"%.2f",GetVehicleHealth(car, health));
the function will return either 1 (on success) or 0 (on failure).

pawn Код:
new Float: health, car = GetPlayerVehicleID(playerid), szText[10];

if (car)
{
    GetVehicleHealth(car, health);
    format(szText, sizeof (szText), "%.2f", health);
}
Also use per-player textdraws if you want to show a textdraw for each player who is in vehicle and all you need to do is create the textdraw once on connect and show it when the player enters the vehicle/hide it when the player exits the vehicle. You don't have to destroy and re-create it over and over again.
Reply
#3

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
https://sampwiki.blast.hk/wiki/GetVehicleHealth

The vehicle's health is stored to the variable "health" and that is what you need to use as argument.
By doing this (which is incorrect):
pawn Код:
format(String, 250,"%.2f",GetVehicleHealth(car, health));
the function will return either 1 (on success) or 0 (on failure).

pawn Код:
new Float: health, car = GetPlayerVehicleID(playerid), szText[10];

if (car)
{
    GetVehicleHealth(car, health);
    format(szText, sizeof (szText), "%.2f", health);
}
Also use per-player textdraws if you want to show a textdraw for each player who is in vehicle and all you need to do is create the textdraw once on connect and show it when the player enters the vehicle/hide it when the player exits the vehicle. You don't have to destroy and re-create it over and over again.
I did not understand
Reply
#4

You re-create the textdraw over and over again when you can just create it once and show/hide it when the player enters/exits the vehicle. It has to be as per-player textdraw because the vehicle's health to display to each player is different.

pawn Код:
// global:
new PlayerText: PlayerTD_Vehicle[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
    PlayerTD_Vehicle[playerid] = CreatePlayerTextDraw(playerid, 491.000000, 322.000000, "0.0");
    PlayerTextDrawBackgroundColor(playerid, PlayerTD_Vehicle[playerid], 255);
    PlayerTextDrawFont(playerid, PlayerTD_Vehicle[playerid], 2);
    PlayerTextDrawLetterSize(playerid, PlayerTD_Vehicle[playerid], 0.500000, 1.000000);
    PlayerTextDrawColor(playerid, PlayerTD_Vehicle[playerid], 1367916799);
    PlayerTextDrawSetOutline(playerid, PlayerTD_Vehicle[playerid], 0);
    PlayerTextDrawSetProportional(playerid, PlayerTD_Vehicle[playerid], 1);
    PlayerTextDrawSetShadow(playerid, PlayerTD_Vehicle[playerid], 1);
    return 1;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    new Float: health, szText[10];
    GetVehicleHealth(vehicleid, health);
    format(szText, sizeof (szText), "%.2f", health);
    PlayerTextDrawSetString(playerid, PlayerTD_Vehicle[playerid], szText);
    PlayerTextDrawShow(playerid, PlayerTD_Vehicle[playerid]);
    return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
    PlayerTextDrawHide(playerid, PlayerTD_Vehicle[playerid]);
    return 1;
}
Reply
#5

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
You re-create the textdraw over and over again when you can just create it once and show/hide it when the player enters/exits the vehicle. It has to be as per-player textdraw because the vehicle's health to display to each player is different.

pawn Код:
// global:
new PlayerText: PlayerTD_Vehicle[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
    PlayerTD_Vehicle[playerid] = CreatePlayerTextDraw(playerid, 491.000000, 322.000000, "0.0");
    PlayerTextDrawBackgroundColor(playerid, PlayerTD_Vehicle[playerid], 255);
    PlayerTextDrawFont(playerid, PlayerTD_Vehicle[playerid], 2);
    PlayerTextDrawLetterSize(playerid, PlayerTD_Vehicle[playerid], 0.500000, 1.000000);
    PlayerTextDrawColor(playerid, PlayerTD_Vehicle[playerid], 1367916799);
    PlayerTextDrawSetOutline(playerid, PlayerTD_Vehicle[playerid], 0);
    PlayerTextDrawSetProportional(playerid, PlayerTD_Vehicle[playerid], 1);
    PlayerTextDrawSetShadow(playerid, PlayerTD_Vehicle[playerid], 1);
    return 1;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    new Float: health, szText[10];
    GetVehicleHealth(vehicleid, health);
    format(szText, sizeof (szText), "%.2f", health);
    PlayerTextDrawSetString(playerid, PlayerTD_Vehicle[playerid], szText);
    PlayerTextDrawShow(playerid, PlayerTD_Vehicle[playerid]);
    return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
    PlayerTextDrawHide(playerid, PlayerTD_Vehicle[playerid]);
    return 1;
}
ty
i try to do kill timer and i get this warning
warning 213: tag mismatch
the line is KillTimer(PlayerTD_Vehicle[playerid]);
Reply
#6

Don't do that! It's not a timer, it's per-player textdraws and they get destroyed automatically when a player disconnects.
Reply
#7

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Don't do that! It's not a timer, it's per-player textdraws and they get destroyed automatically when a player disconnects.
but if i crashed on the wall i see 1000.00 and if i exit and enter i see the real health of the car.
Reply
#8

I posted an example of per-player textdraws and how you should do that (showing/hiding the textdraw). You need to use a timer for displaying the current vehicle's health.
Reply
#9

i think do timer if the life is not life of 1sec before do hide and show the textdraw i think good?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)