Losing Health When Entering a Checkpoint [HELP] +REP
#1

When player enter the checkpoint, i want their hp lose -50.. i use
Код:
SetPlayerHealth(playerid, -50);
but when player entered that checkpoint.. they instantly died help me!

Код:
public OnCheckpointEnter(playerid, checkpointid)
{
	switch(checkpointid)

	{
		case Checkpoint 1:

		{
			
			SetPlayerHealth(playerid, -50);

		}

	}
	return 1;
}
Reply
#2

PHP код:
new Float:hp;
GetPlayerHealth(playeridhp);

SetPlayerHealth(playeridhp 50.0); 
Replace the SetPlayerHealth with the code i have given above.
Reply
#3

Replace your code with the following.
pawn Код:
public OnCheckpointEnter(playerid, checkpointid)
{
    switch(checkpointid)

    {
        case Checkpoint 1:

        {
           
            new Float:hp;
                        GetPlayerHealth(playerid, hp);
                        SetPlayerHealth(playerid, hp - 50.0);  

        }

    }
    return 1;
}
Reply
#4

@MEW273: GetPlayerHealth returns 1/0 on success/failure and the health is passed by reference to a variable to store it to. Look at JaKe Elite's code or at wiki for an example.
Reply
#5

Quote:
Originally Posted by MEW273
Посмотреть сообщение
Replace your code with the following.
pawn Код:
public OnCheckpointEnter(playerid, checkpointid)
{
    switch(checkpointid)

    {
        case Checkpoint 1:

        {
           
            SetPlayerHealth(playerid, GetPlayerHealth(playerid)-50);

        }

    }
    return 1;
}
No! It's wrong!
PHP код:
public OnCheckpointEnter(playeridcheckpointid)
{
    switch(
checkpointid)
    {
        case 
Checkpoint 1:
        {
            new 
Float:hp;
            
GetPlayerHealth(playerid,hp);
            
SetPlayerHealth(playerid,hp-50);
        }
    }
    return 
1;

That's right!
Mencent
Reply
#6

In your current script you are doing this:


This is why you should get the players current health and remove -50 from it instead of setting it.
Reply
#7

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
@MEW273: GetPlayerHealth returns 1/0 on success/failure and the health is passed by reference to a variable to store it to. Look at JaKe Elite's code or at wiki for an example.
My mistake! I have update my response to avoid future confusion.
Reply
#8

You guys are so fast! Thanks Alot!!!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)