SA-MP Forums Archive
Losing Health When Entering a Checkpoint [HELP] +REP - 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: Losing Health When Entering a Checkpoint [HELP] +REP (/showthread.php?tid=570544)



Losing Health When Entering a Checkpoint [HELP] +REP - Chausar - 11.04.2015

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;
}



Re: Losing Health When Entering a Checkpoint [HELP] +REP - JaKe Elite - 11.04.2015

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

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


Re: Losing Health When Entering a Checkpoint [HELP] +REP - MEW273 - 11.04.2015

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;
}



Re: Losing Health When Entering a Checkpoint [HELP] +REP - Konstantinos - 11.04.2015

@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.


AW: Re: Losing Health When Entering a Checkpoint [HELP] +REP - Mencent - 11.04.2015

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


Re: Losing Health When Entering a Checkpoint [HELP] +REP - Sellize - 11.04.2015

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.


Re: Losing Health When Entering a Checkpoint [HELP] +REP - MEW273 - 11.04.2015

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.


Re: Losing Health When Entering a Checkpoint [HELP] +REP - Chausar - 11.04.2015

You guys are so fast! Thanks Alot!!!