PDA

View Full Version : i do carhealth and do not see the textdraw


Xeinss
15/05/2014, 10:48 AM
codes:http://pastebin.com/ZpYsagMf
Thanks for helpers

Konstantinos
15/05/2014, 11:00 AM
http://wiki.sa-mp.com/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):

format(String, 250,"%.2f",GetVehicleHealth(car, health));

the function will return either 1 (on success) or 0 (on failure).


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.

Xeinss
15/05/2014, 11:05 AM
http://wiki.sa-mp.com/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):

format(String, 250,"%.2f",GetVehicleHealth(car, health));

the function will return either 1 (on success) or 0 (on failure).


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

Konstantinos
15/05/2014, 11:20 AM
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.


// 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;
}

Xeinss
15/05/2014, 11:34 AM
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.


// 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]);

Konstantinos
15/05/2014, 12:05 PM
Don't do that! It's not a timer, it's per-player textdraws and they get destroyed automatically when a player disconnects.

Xeinss
16/05/2014, 03:56 AM
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.

Konstantinos
16/05/2014, 10:12 AM
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.

Xeinss
16/05/2014, 04:48 PM
i think do timer if the life is not life of 1sec before do hide and show the textdraw i think good?