SA-MP Forums Archive
Hp script - 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: Hp script (/showthread.php?tid=309755)



Hp script - N0FeaR - 09.01.2012

Hi, have a little bit of samp but find nothing. There is something script when you have examples below 50 hp so you fall to the ground? or if someone wants to help how to fix it


Re: Hp script - Tanush123 - 09.01.2012

Use a timer or use onplayerupdate ( i think it will work)
pawn Код:
new Float:phealth;
GetPlayerHealth(playerid,phealth);
if(phealth < 51)
{
    //apply the fall animation
    TogglePlayerControllable(playerid,0);
    SendClientMessage(playerid,-1,"You have falled to the ground because you are injured");
    return 1;
}
try that


Re: Hp script - N0FeaR - 09.01.2012

Quote:
Originally Posted by Tanush123
Посмотреть сообщение
Use a timer or use onplayerupdate ( i think it will work)
pawn Код:
new Float:phealth;
GetPlayerHealth(playerid,phealth);
if(phealth < 51)
{
    //apply the fall animation
    TogglePlayerControllable(playerid,0);
    SendClientMessage(playerid,-1,"You have falled to the ground because you are injured");
    return 1;
}
try that
one problem when i get under 51 hp is spam You have falled to the ground because you are injured how too fix that ?


Re: Hp script - Tanush123 - 09.01.2012

umm you added it in timer? if so try using it onplayerupdate. Or maybe if your using onplayerupdate and it doesnt work on timer, try doing the bottom with your timer.
pawn Код:
new HPTimer[MAX_PLAYERS];
^ thats on top,
pawn Код:
SetTimerEx("FallDown",100,true,"i",playerid);
^ thats on playerspawn
pawn Код:
forward FallDown(playerid);
public FallDown(playerid)
{
      new Float:phealth;
      GetPlayerHealth(playerid,phealth);
      if(phealth < 51)
      {
                 //apply the fall animation
                 TogglePlayerControllable(playerid,0);
                 SendClientMessage(playerid,-1,"You have falled to the ground because you are injured");
                 KillTimer(HPTimer[playerid]);
      }
      return 1;
}
^ thats anywhere in your script (just put it in the end)


Re: Hp script - N0FeaR - 09.01.2012

Thanks man <3 +rep


Re: Hp script - Tanush123 - 09.01.2012

Quote:
Originally Posted by N0FeaR
Посмотреть сообщение
Thanks man <3 +rep
never knew that will work, no problem


Re: Hp script - Rob_Maate - 09.01.2012

Lol that's so prone to bugs.

Just create a variable:

pawn Код:
new bool:IsPlayerDowned[MAX_PLAYERS];
Reset it in OnPlayerConnect (so there's no issues between new players joining with old in-use ID's)

pawn Код:
IsPlayerDowned[playerid] = false;
Finally, in your OnPlayerUpdate:

pawn Код:
public OnPlayerUpdate(playerid)
{
      new Float:phealth;
      GetPlayerHealth(playerid,phealth);
      if(phealth <= 50 && IsPlayerDowned[playerid] = false)
      {
          //apply the fall animation
          TogglePlayerControllable(playerid,0);
          SendClientMessage(playerid,-1,"You have falled to the ground because you are injured");
          IsPlayerDowned[playerid] = true;
      }
      return 1;
}
When you want him to stand up again, just clear animations, set his HP to above 50 and set IsPlayerDowned[playerid] to false.


Re: Hp script - N0FeaR - 09.01.2012

Quote:
Originally Posted by Rob_Maate
Посмотреть сообщение
Lol that's so prone to bugs.

Just create a variable:

pawn Код:
new bool:IsPlayerDowned[MAX_PLAYERS];
Reset it in OnPlayerConnect (so there's no issues between new players joining with old in-use ID's)

pawn Код:
IsPlayerDowned[playerid] = false;
Finally, in your OnPlayerUpdate:

pawn Код:
public OnPlayerUpdate(playerid)
{
      new Float:phealth;
      GetPlayerHealth(playerid,phealth);
      if(phealth <= 50 && IsPlayerDowned[playerid] = false)
      {
          //apply the fall animation
          TogglePlayerControllable(playerid,0);
          SendClientMessage(playerid,-1,"You have falled to the ground because you are injured");
          IsPlayerDowned[playerid] = true;
      }
      return 1;
}
When you want him to stand up again, just clear animations, set his HP to above 50 and set IsPlayerDowned[playerid] to false.
i get this then mabye help

Код:
C:\Users\Robin\Desktop\New rp\gamemodes\RMRP.pwn(85578) : error 001: expected token: ";", but found ")"
C:\Users\Robin\Desktop\New rp\gamemodes\RMRP.pwn(85578) : error 029: invalid expression, assumed zero
C:\Users\Robin\Desktop\New rp\gamemodes\RMRP.pwn(85578) : fatal error 107: too many error messages on one line
Код:
new Float:phealth;
	GetPlayerHealth(playerid,phealth);
line 85578	if(phealth <= 50 && IsPlayerDowned[playerid] = false)
	{
		//apply the fall animation
		TogglePlayerControllable(playerid,0);
		SendClientMessage(playerid,-1,"You have falled to the ground because you are injured");
		IsPlayerDowned[playerid] = true;
	}
	return 1;



Re: Hp script - N0FeaR - 09.01.2012

Quote:
Originally Posted by Tanush123
Посмотреть сообщение
umm you added it in timer? if so try using it onplayerupdate. Or maybe if your using onplayerupdate and it doesnt work on timer, try doing the bottom with your timer.
pawn Код:
new HPTimer[MAX_PLAYERS];
^ thats on top,
pawn Код:
SetTimerEx("FallDown",100,true,"i",playerid);
^ thats on playerspawn
pawn Код:
forward FallDown(playerid);
public FallDown(playerid)
{
      new Float:phealth;
      GetPlayerHealth(playerid,phealth);
      if(phealth < 51)
      {
                 //apply the fall animation
                 TogglePlayerControllable(playerid,0);
                 SendClientMessage(playerid,-1,"You have falled to the ground because you are injured");
                 KillTimer(HPTimer[playerid]);
      }
      return 1;
}
^ thats anywhere in your script (just put it in the end)
i use the new code but still spmming You have falled to the ground because you are injured :P


Re: Hp script - N0FeaR - 09.01.2012

anyone know how ? :P