Vehicle health textdraw color problem
#1

So I have made a textdraw that shows the vehicle health, and it works.
I want it to have another color every time the vehicle's health reduces, and I've made this too.
But the textdraw is red all the time, while it should change colors as the health reduces.

I've defined the textdraw variable at the top of my script:
Код:
new Text:text_vehiclehealth;
And this is my code:
Код:
public OnPlayerUpdate(playerid)
{
	if(IsPlayerInAnyVehicle(playerid)==1)
	{
		new vehicle = GetPlayerVehicleID(playerid);
		new Float:vehiclehealth;
		GetVehicleHealth(vehicle,vehiclehealth);
		new string[128];
		format(string,sizeof(string),"%0.0f",vehiclehealth);
		TextDrawDestroy(text_vehiclehealth);
		text_vehiclehealth = TextDrawCreate(5,433,string);
		TextDrawSetShadow(text_vehiclehealth,0);
		if(GetVehicleHealth(vehicle,vehiclehealth) <= 1000) TextDrawColor(text_vehiclehealth,0x00FF00FF);
		if(GetVehicleHealth(vehicle,vehiclehealth) <= 899) TextDrawColor(text_vehiclehealth,0x40FF00FF);
  		if(GetVehicleHealth(vehicle,vehiclehealth) <= 799) TextDrawColor(text_vehiclehealth,0x80FF00FF);
  		if(GetVehicleHealth(vehicle,vehiclehealth) <= 699) TextDrawColor(text_vehiclehealth,0xC0FF00FF);
 		if(GetVehicleHealth(vehicle,vehiclehealth) <= 599) TextDrawColor(text_vehiclehealth,0xFFFF00FF);
 		if(GetVehicleHealth(vehicle,vehiclehealth) <= 499) TextDrawColor(text_vehiclehealth,0xFFC000FF);
		if(GetVehicleHealth(vehicle,vehiclehealth) <= 399) TextDrawColor(text_vehiclehealth,0xFF8000FF);
		if(GetVehicleHealth(vehicle,vehiclehealth) <= 299) TextDrawColor(text_vehiclehealth,0xFF4000FF);
		if(GetVehicleHealth(vehicle,vehiclehealth) <= 249) TextDrawColor(text_vehiclehealth,0xFF0000FF);
		TextDrawShowForPlayer(playerid,text_vehiclehealth);
	}
	
	if(IsPlayerInAnyVehicle(playerid)==0) return TextDrawDestroy(text_vehiclehealth);
	
return 1;
}
Why?
Reply
#2

Are you sure that these aren't just another occurances of red?
Reply
#3

Код:
native GetVehicleHealth(vehicleid, &Float: health);
In layman's terms, & (ampersand) before a variable means that the data is stored in that variable.
pawn Код:
new Float: health;
GetVehicleHealth(vehicleid, health);
if (health < 1000.0)
{
    // do something
}
You might want to use TextDrawSetString for that. Destroying the textdraw many time a second isn't a good idea.
Reply
#4

Quote:
Originally Posted by Superthijs
Посмотреть сообщение
So I have made a textdraw that shows the vehicle health, and it works.
I want it to have another color every time the vehicle's health reduces, and I've made this too.
But the textdraw is red all the time, while it should change colors as the health reduces.

I've defined the textdraw variable at the top of my script:
Код:
new Text:text_vehiclehealth;
And this is my code:
Код:
public OnPlayerUpdate(playerid)
{
	if(IsPlayerInAnyVehicle(playerid)==1)
	{
		new vehicle = GetPlayerVehicleID(playerid);
		new Float:vehiclehealth;
		GetVehicleHealth(vehicle,vehiclehealth);
		new string[128];
		format(string,sizeof(string),"%0.0f",vehiclehealth);
		TextDrawDestroy(text_vehiclehealth);
		text_vehiclehealth = TextDrawCreate(5,433,string);
		TextDrawSetShadow(text_vehiclehealth,0);
		if(GetVehicleHealth(vehicle,vehiclehealth) <= 1000) TextDrawColor(text_vehiclehealth,0x00FF00FF);
		if(GetVehicleHealth(vehicle,vehiclehealth) <= 899) TextDrawColor(text_vehiclehealth,0x40FF00FF);
  		if(GetVehicleHealth(vehicle,vehiclehealth) <= 799) TextDrawColor(text_vehiclehealth,0x80FF00FF);
  		if(GetVehicleHealth(vehicle,vehiclehealth) <= 699) TextDrawColor(text_vehiclehealth,0xC0FF00FF);
 		if(GetVehicleHealth(vehicle,vehiclehealth) <= 599) TextDrawColor(text_vehiclehealth,0xFFFF00FF);
 		if(GetVehicleHealth(vehicle,vehiclehealth) <= 499) TextDrawColor(text_vehiclehealth,0xFFC000FF);
		if(GetVehicleHealth(vehicle,vehiclehealth) <= 399) TextDrawColor(text_vehiclehealth,0xFF8000FF);
		if(GetVehicleHealth(vehicle,vehiclehealth) <= 299) TextDrawColor(text_vehiclehealth,0xFF4000FF);
		if(GetVehicleHealth(vehicle,vehiclehealth) <= 249) TextDrawColor(text_vehiclehealth,0xFF0000FF);
		TextDrawShowForPlayer(playerid,text_vehiclehealth);
	}
	
	if(IsPlayerInAnyVehicle(playerid)==0) return TextDrawDestroy(text_vehiclehealth);
	
return 1;
}
Why?
pawn Код:
new Float:health; GetVehicleHealth(vehicle, health);
if(health <= 1000 && health > 899) TextDrawColor(text_vehiclehealth,0x00FF00FF);
if(health <= 899 && health > 799) TextDrawColor(text_vehiclehealth,0x40FF00FF);
if(health <= 799 && health > 699) TextDrawColor(text_vehiclehealth,0x80FF00FF);
// And so on
TextDrawShowForPlayer(playerid,text_vehiclehealth);
Reply
#5

Thanks, [GF]Sasino97.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)