SA-MP Forums Archive
Can't figure it out - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Can't figure it out (/showthread.php?tid=80911)



Can't figure it out - L30 - 07.06.2009

Код:
public Health(playerid)
{
  new Float:health;
  if(GetPlayerHealth(playerid, health) < 40)
  {
    ApplyAnimation(playerid, "CRACK", "crckdeth2", 4.0, 1, 0, 0, 0, 0);
  	SendClientMessage(playerid, COLOR_RED, "You have been wounded, you need a paramedic !");
  	return 1;
  }
  return 1;
}
It complies fine, but when I test it IG when I get down to 40% health and less it don't do anim.


Re: Can't figure it out - Weirdosport - 07.06.2009

Errr, is it in a timer? It won't just work on its own accord..


Re: Can't figure it out - yom - 07.06.2009

Yes and it should be
pawn Код:
GetPlayerHealth(playerid, health);
if(health < 40.0)



Re: Can't figure it out - L30 - 07.06.2009

Quote:
Originally Posted by Weirdosport
Errr, is it in a timer? It won't just work on its own accord..
What is the timer for?
I mean like how would a timer know when my health is 40%?
Sorry this is my first time scripting something like this.


Re: Can't figure it out - dice7 - 07.06.2009

The timer is for to execute this public every x seconds.

But to avoid it, you can put this code in the public OnPlayerUpdate. It's called everytime a player moves


Re: Can't figure it out - Weirdosport - 07.06.2009

That public will only be trigger when you tell it to. Alone in a script it will do nothing. Also as Orb said GetPlayerHealth does not return the health, but saves it to the Float you choose.

You need something like this:

pawn Код:
new Float:health;
forward Health();

public OnFilterScriptInit()
{
  SetTimer("Health", 1000, 1);
  return 1;
}

public Health()
{
  for(new i; i<MAX_PLAYERS; i++)
  {
    if(IsPlayerConnected(playerid))
    {
      GetPlayerHealth(i, health)
      if(health < 40)
      {
        ApplyAnimation(playerid, "CRACK", "crckdeth2", 4.0, 1, 0, 0, 0, 0);
        SendClientMessage(playerid, COLOR_RED, "You have been wounded, you need a paramedic !")
      }
    }
  }
  return 1;
}
Unsure as to whether this would be better in OnPlayerUpdate.. OnPlayerUpdate is called quite a lot, so it really depends on how many people on your server I s'pose.


Re: Can't figure it out - L30 - 07.06.2009

Quote:
Originally Posted by Weirdosport
That public will only be trigger when you tell it to. Alone in a script it will do nothing. Also as Orb said GetPlayerHealth does not return the health, but saves it to the Float you choose.

You need something like this:

pawn Код:
new Float:health;
forward Health();

public OnFilterScriptInit()
{
  SetTimer("Health", 1000, 1);
  return 1;
}

public Health()
{
  for(new i; i<MAX_PLAYERS; i++)
  {
    if(IsPlayerConnected(playerid))
    {
      GetPlayerHealth(i, health)
      if(health < 40)
      {
        ApplyAnimation(playerid, "CRACK", "crckdeth2", 4.0, 1, 0, 0, 0, 0);
        SendClientMessage(playerid, COLOR_RED, "You have been wounded, you need a paramedic !")
      }
    }
  }
  return 1;
}
Unsure as to whether this would be better in OnPlayerUpdate.. OnPlayerUpdate is called quite a lot, so it really depends on how many people on your server I s'pose.
Код:
C:\Documents and Settings\Leo\Desktop\LS-RP backup\LSRP.pwn(2624) : error 017: undefined symbol "playerid"
C:\Documents and Settings\Leo\Desktop\LS-RP backup\LSRP.pwn(2628) : error 001: expected token: ";", but found "if"
C:\Documents and Settings\Leo\Desktop\LS-RP backup\LSRP.pwn(2630) : error 017: undefined symbol "playerid"
C:\Documents and Settings\Leo\Desktop\LS-RP backup\LSRP.pwn(2631) : error 017: undefined symbol "playerid"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


4 Errors.



Re: Can't figure it out - Gappy - 07.06.2009

pawn Код:
forward Health();

public OnFilterScriptInit()
{
  SetTimer("Health", 1000, 1);
  return 1;
}

public Health()
{
  for(new i; i<MAX_PLAYERS; i++)
  {
    if(IsPlayerConnected(i))
    {
      new Float:health;
      GetPlayerHealth(i, health);
      if(health < 40)
      {
        ApplyAnimation(i, "CRACK", "crckdeth2", 4.0, 1, 0, 0, 0, 0);
        SendClientMessage(i, COLOR_RED, "You have been wounded, you need a paramedic !");
      }
    }
  }
  return 1;
}
Try that.


Re: Can't figure it out - L30 - 07.06.2009

Quote:
Originally Posted by Gappy
pawn Код:
forward Health();

public OnFilterScriptInit()
{
  SetTimer("Health", 1000, 1);
  return 1;
}

public Health()
{
  for(new i; i<MAX_PLAYERS; i++)
  {
    if(IsPlayerConnected(i))
    {
      new Float:health;
      GetPlayerHealth(i, health);
      if(health < 40)
      {
        ApplyAnimation(i, "CRACK", "crckdeth2", 4.0, 1, 0, 0, 0, 0);
        SendClientMessage(i, COLOR_RED, "You have been wounded, you need a paramedic !");
      }
    }
  }
  return 1;
}
Try that.
It complies fine, but when I get down to 40 HP it doesn't do Animation


Re: Can't figure it out - L30 - 07.06.2009

bump