Health command
#1

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

Reply
#2

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.
Reply
#3

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+.
Reply
#4

Didn't work.
Reply
#5

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.
Reply
#6

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

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?
Reply
#8

Aha.
Reply
#9

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.
Reply
#10

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?"
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)