Float help (First attempt)
#1

Ok so. first attempt with floats. Ive used floats only to get playerposition and that was it..

Now i'm really working with them. trying to make basic command to show my health and armour.

my command compiles, looks right. but ingame i type it. nothing happends..

Take a look.
Код:
	if (strcmp("/orly", cmdtext, true, 10) == 0) 
	{
	new string[256];
	new Float:HP;
	new Float:AP;
	GetPlayerHealth(playerid, HP);
	GetPlayerArmour(playerid, AP);
	format(string, sizeof(string), "Health: %d Armour: %d", floatround(HP), floatround(AP));
	return 1;
	}
I thought i did everything right? but the message doesn't appear.
Reply
#2

Although you format the string, you don't actually send it. Add SendClientMessage(playerid,0xffffff,string); before the return.
Reply
#3

I just realised that.. *facepalm*
Reply
#4

%f are floats %d are whole numbers
Reply
#5

Quote:
Originally Posted by cessil
%f are floats %d are whole numbers
He's rounding them up and in to integers, yet he's still going about it in the wrong way.

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

You're missing the method.
Reply
#6

use this , tested and working :

Код:
if (strcmp("/orly", cmdtext, true, 10) == 0)
	{
	new string[256];
	new Float:HP;
	new Float:AP;
	GetPlayerHealth(playerid, HP);
	GetPlayerArmour(playerid, AP);
	format(string, sizeof(string), "Health: %f Armour: %f", HP, AP);
	SendClientMessage(playerid,0x33AAFFFF,string);
	return 1;
	}
Reply
#7

Another note: For text strings use a size of [128], since it's the maximum string size to type or to show in a single chat message.
Reply
#8

You don't even need 128 cells.

pawn Код:
if(!strcmp(cmdtext, "/orly", true))
{
  new
      string[24], Float:var[2];
  GetPlayerHealth(playerid, var[0]);
  GetPlayerArmour(playerid, var[1]);
  format(string, sizeof(string), "Health:%i, armor:%i", floatround(var[0]), floatround(var[1]));
  SendClientMessage(playerid, 0xFFFFFFFF, string);
  return true;
}
Reply
#9

Thanks guys, i understand floats now. I spent a good two hours messin around with them. and last night around 4AM i create a nice STAT Bar for my DM server build. Hold health armour cash score and currentgunID and ammo. I Apriciate the help!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)