SA-MP Forums Archive
Strange health... - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Strange health... (/showthread.php?tid=64964)



Strange health... - Dreftas - 08.02.2009

Код:
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?


Re: Strange health... - Sandra18[NL] - 08.02.2009

Change

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

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



Re: Strange health... - Dreftas - 08.02.2009

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 ?


Re: Strange health... - ICECOLDKILLAK8 - 08.02.2009

Because its stored as Float:


Re: Strange health... - Nero_3D - 08.02.2009

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



Re: Strange health... - Sandra18[NL] - 08.02.2009

%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".






Re: Strange health... - Dreftas - 08.02.2009

thx