Strange health...
#1

Код:
if (!strcmp("/carhp", cmdtext, true))
	{
	new Float:health;
	new carhp;
	carhp = GetPlayerVehicleID(playerid);
	GetVehicleHealth(carhp, health);
	new hp[128];
	format(hp, sizeof(hp), "%d HP",health);
	SendClientMessage(playerid, COLOR_WHITE, hp);
	print(hp);
	return 1;
	}
I have new vehicle and /carhp shows me - 1148846080 HP

how to fix?
Reply
#2

Change

Код:
format(hp, sizeof(hp), "%d HP",health);
to:

Код:
format(hp, sizeof(hp), "%.1f HP",health);
Reply
#3

Quote:
Originally Posted by =>Sandra<=
Change

Код:
format(hp, sizeof(hp), "%d HP",health);
to:

Код:
format(hp, sizeof(hp), "%.1f HP",health);
can you tell me why i need %.1f ?
Reply
#4

Because its stored as Float:
Reply
#5

Quote:
Originally Posted by Dreftas
can you tell me why i need %.1f ?
%f stands for float (the whole float with 8 numbers behind comma)
%.1f stands for a float which only show one number behind comma
Reply
#6

%d = Decimal (if im right)
%i = Integer
%s = String
%f = Float

Since "Health" is a float (a value with numbers behind the dot (like 24.543)) you will have to use %f.

To shorten the value to only 1 number behind the dot, you put '.1' between the '%' and the 'f': "%.1".



Reply
#7

thx
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)