[Help] GetPlayerHealth
#1

Hey Guys thanks for clicking here. Anyways I'm wanting to make a command [/health] that will let me tell the player what there HP is at.
"Your health is at (PlayerHP) Percent!"

Alright I wrote it like this:

Код:
	if (strcmp("/health", cmdtext, true, 10) == 0)
	{
	new health;
	new string[128];
 	GetPlayerHealth(string, sizeof(health);
 	format(string, sizeof(health),"Your HP is at %d percent!",health);
 	SendClientMessage(RED,string);

	 		return 1;
	}
Although is this incorrect due to wrong Arguments.
Can anyone tell me what I'm doing wrong? Thanks in Advance.
Reply
#2

This should work
pawn Код:
if (strcmp("/health", cmdtext, true, 10) == 0)
{
  new Float:health; // We use Float here because health is a float
  new string[128];
  GetPlayerHealth(string, sizeof(health);
  format(string, sizeof(health),"Your HP is at %f percent!", health); // Use %f because health is a float
  SendClientMessage(RED,string);
  return 1;
}
Edit: Use the one below me, i fucked mine up (tends to happen when your heaps tired still )
Reply
#3

pawn Код:
if(strcmp(cmdtxt, "/givelicense", true) == 0)
    {
        new Float:health; // We determine that the health is a Float, so we create it
        new string[64]; // 128 is too big for this, downed to 64
        GetPlayerHealth(playerid, health); // Its not the same as GetPlayerName, check the wiki for more info.
        format(string, sizeof(health),"Your HP is at %.1f percent!",health); // we format it
        SendClientMessage(RED,string); // we send the message
        return 1; // we close the command
    }
Reply
#4

Thank you very Much! May I ask why we use "%.1f" ?
Reply
#5

Quote:
Originally Posted by Tony1337
Thank you very Much! May I ask why we use "%.1f" ?
Well that would be for formatting the float if it was large but it's not necessary here.
Reply
#6

Quote:
Originally Posted by CueЯvo
pawn Код:
if(strcmp(cmdtxt, "/givelicense", true) == 0)
    {
        new Float:health; // We determine that the health is a Float, so we create it
        new string[64]; // 128 is too big for this, downed to 64
        GetPlayerHealth(playerid, health); // Its not the same as GetPlayerName, check the wiki for more info.
        format(string, sizeof(health),"Your HP is at %.1f percent!",health); // we format it
        SendClientMessage(RED,string); // we send the message
        return 1; // we close the command
    }
LOL thats /givelicense command xD
Reply
#7

Код:
	if(strcmp(cmd, "/health", true) == 0)
	{
		new Float:health;
		new string[128];
		GetPlayerHealth(playerid, health);
 		format(string, sizeof(string),"Your HP is at %.1f percent!",health); // sizeof(health) ??? = 5 xD, changed to string
 		SendClientMessage(playerid,RED,string); // You didnt send it to player xD
 		return 1;
	}
The others work but SenClientMessage is wrong

Also tested it and it worked!
Reply
#8

Quote:
Originally Posted by Tony1337
Thank you very Much! May I ask why we use "%.1f" ?
that means there is max 1 int after the comma

10.3
instead of
10.3333333333333333333333333333
Reply
#9

Thank you All!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)