SA-MP Forums Archive
Health command - 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)
+--- Thread: Health command (/showthread.php?tid=546700)



Health command - Glossy42O - 17.11.2014

Okay hey guys, so basically i'm learning to script i mean by my self.

No tuts or whatever and i tried to create hp command (heal command)

And i don't really know what am i doing wrong but please if you fixed it tell me how.

PHP код:
CMD:hp(playeridparams[])
{
    new 
Float:health;
    
GetPlayerHealth(playerid,health);
    if(
health 99)
    return 
SendClientMessage(playerid, -1"Your health is already full.");
    else if
    {
         
SendClientMessage(playerid, -1"You have been healed.");
         
SetPlayerHealth(playerid100);
    }
    return 
1;
  }
  return 
0;

PHP код:
C:\Users\yan\Desktop\Lscnr(Stopped working)\gamemodes\test.pwn(127) : error 008must be a constant expressionassumed zero
C
:\Users\yan\Desktop\Lscnr(Stopped working)\gamemodes\test.pwn(129) : warning 209: function "cmd_hp" should return a value
C
:\Users\yan\Desktop\Lscnr(Stopped working)\gamemodes\test.pwn(130) : error 010invalid function or declaration
C
:\Users\yan\Desktop\Lscnr(Stopped working)\gamemodes\test.pwn(132) : error 010invalid function or declaration
Pawn compiler 3.2.3664              Copyright 
(c1997-2006ITB CompuPhase
3 Errors




Re: Health command - OsteeN - 17.11.2014

Well, you have done a else if statement without any parameters or anything.
pawn Код:
else if { }
Just use 'else' instead of 'else if' if you are not going to have something like:
pawn Код:
else if(whatever here) { }
Also, your check if the health is below hundred actually checks if it's 98 or below. If you want it to be 99 and below you can do either of these:
pawn Код:
if(health <= 99) // If health equals to 99 or is below
or..
pawn Код:
if(health < 100) // If health is 99 or less
However, you're checking it like; if the persons health is BELOW 99, then it will return with a message saying they have full health. You could either do '> 99' or '== 100'.

You should also change the "return 0" to "return 1", as otherwise it won't return anything.
Here's your code 'fixed' and should be working:

pawn Код:
CMD:hp(playerid, params[])
{
    new Float:health;
    GetPlayerHealth(playerid,health);
    if(health > 99.0) return SendClientMessage(playerid, -1, "Your health is already full."); // This will prevent the rest of the command to proceed if health is 100+.
    SendClientMessage(playerid, -1, "You have been healed."); // If the previous if statement is not true (if health is not over 100) it won't return the msg and will proceed with this code.
    SetPlayerHealth(playerid, 100);
    return 1; // Here it will stop anyways.
}
Let me know if there's any problems or if you have any questions.


Re : Health command - Dutheil - 17.11.2014

pawn Код:
if(floatcmp(health, 100.0) == 0) return SendClientMessage(playerid, -1, "Your health is already full."); // This will prevent the rest of the command to proceed if health is 100+.



Re: Health command - Glossy42O - 17.11.2014

Didn't work.


Re: Health command - OsteeN - 17.11.2014

Quote:
Originally Posted by Stuun
Посмотреть сообщение
Didn't work.
Instead of just saying that it didn't work, you might wanna include errors or some kind of information, otherwise we can't help you.


Re: Health command - Glossy42O - 17.11.2014

No errors. When i go ig i do /hp it says your health is full.


Re: Health command - OsteeN - 17.11.2014

Quote:
Originally Posted by Stuun
Посмотреть сообщение
No errors. When i go ig i do /hp it says your health is full.
Even if it is under 100?


Re: Health command - Glossy42O - 17.11.2014

Aha.


Re: Health command - OsteeN - 17.11.2014

Quote:
Originally Posted by Stuun
Посмотреть сообщение
Aha.
Sorry, missed something obvious.

Change:
pawn Код:
if(health > 99)
To..
pawn Код:
if(health > 99.0)
As health is a float.


Re: Health command - biker122 - 17.11.2014

Quote:
Originally Posted by Stuun
Посмотреть сообщение
Aha.
Just reply with yes/no, if you need our help, you really have to co-operate with us.
"Even if its 100?"