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(playerid, params[])
{
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(playerid, 100);
}
return 1;
}
return 0;
}
PHP код:
C:\Users\yan\Desktop\Lscnr(Stopped working)\gamemodes\test.pwn(127) : error 008: must be a constant expression; assumed 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 010: invalid function or declaration
C:\Users\yan\Desktop\Lscnr(Stopped working)\gamemodes\test.pwn(132) : error 010: invalid function or declaration
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase
3 Errors.
Re: Health command -
OsteeN - 17.11.2014
Well, you have done a else if statement without any parameters or anything.
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:
To..
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?"