[Help] GetPlayerHealth - 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: [Help] GetPlayerHealth (
/showthread.php?tid=141564)
[Help] GetPlayerHealth -
Tony1337 - 14.04.2010
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.
Re: [Help] GetPlayerHealth -
Ibanez - 14.04.2010
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
)
Re: [Help] GetPlayerHealth -
CuervO - 14.04.2010
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
  }
Re: [Help] GetPlayerHealth -
Tony1337 - 14.04.2010
Thank you very Much! May I ask why we use "%.1f" ?
Re: [Help] GetPlayerHealth -
Backwardsman97 - 14.04.2010
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.
Re: [Help] GetPlayerHealth -
RichyB - 14.04.2010
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
Re: [Help] GetPlayerHealth -
Thrarod - 14.04.2010
Код:
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!
Re: [Help] GetPlayerHealth -
Vetle - 14.04.2010
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
Re: [Help] GetPlayerHealth -
Tony1337 - 14.04.2010
Thank you All!