SA-MP Forums Archive
Whats wrong with this? - 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: Whats wrong with this? (/showthread.php?tid=116480)



Whats wrong with this? - HydraX - 29.12.2009

pawn Код:
public InAreaChecker()
{
  for(new i; i<MAX_PLAYERS; i++)
  {
    if(IsPlayerInArea(i, 443.7593, 373.692, 2475.709, 2405.642))
    {
      SetPlayerHealth(i, 9999999);
      SetPlayerChatBubble(i, "is in safe zone", 0xFFFF00AA, 100.0, 10000);
      GameTextForPlayer(i, "~n~~n~~n~~n~~n~~n~~n~~n~~w~You are Currently in ~g~SAFE Zone~w~.",10000,5);
    }
    else
    {
      SetPlayerHealth(i, 100);
      GameTextForPlayer(i, " ",3000,5);
      SetPlayerChatBubble(i, " ", 0xFF0000FF, 100.0, 10000);
    }
  }
  return 1;
}
It works and all, but when I'm out of the area and I lose health, it resets to 100 again.


Re: Whats wrong with this? - [HiC]TheKiller - 29.12.2009

Make a variable to check if the player has been given the health or not .

pawn Код:
new CheckVariable[MAX_PLAYERS];

public InAreaChecker()
{
  for(new i; i<MAX_PLAYERS; i++)
  {
    if(IsPlayerInArea(i, 443.7593, 373.692, 2475.709, 2405.642) && CheckVariable[playerid] == 0)
    {
      SetPlayerHealth(i, 9999999);
      SetPlayerChatBubble(i, "is in safe zone", 0xFFFF00AA, 100.0, 10000);
      GameTextForPlayer(i, "~n~~n~~n~~n~~n~~n~~n~~n~~w~You are Currently in ~g~SAFE Zone~w~.",10000,5);
      CheckVariable[playerid] = 1;
    }
    else if(CheckVariable[playerid] == 1 && !IsPlayerInArea(i, 443.7593, 373.692, 2475.709, 2405.642))
    {
      SetPlayerHealth(i, 100);
      GameTextForPlayer(i, " ",3000,5);
      SetPlayerChatBubble(i, " ", 0xFF0000FF, 100.0, 10000);
      CheckVariable[playerid] = 0;
    }
  }
  return 1;
}
Try that.


Re: Whats wrong with this? - HydraX - 29.12.2009

Quote:
Originally Posted by [HiC
TheKiller ]
Make a variable to check if the player has been given the health or not .

pawn Код:
new CheckVariable[MAX_PLAYERS];

public InAreaChecker()
{
  for(new i; i<MAX_PLAYERS; i++)
  {
    if(IsPlayerInArea(i, 443.7593, 373.692, 2475.709, 2405.642) && CheckVariable[playerid] == 0)
    {
      SetPlayerHealth(i, 9999999);
      SetPlayerChatBubble(i, "is in safe zone", 0xFFFF00AA, 100.0, 10000);
      GameTextForPlayer(i, "~n~~n~~n~~n~~n~~n~~n~~n~~w~You are Currently in ~g~SAFE Zone~w~.",10000,5);
      CheckVariable[playerid] = 1;
    }
    else if(CheckVariable[playerid] == 1 && !IsPlayerInArea(i, 443.7593, 373.692, 2475.709, 2405.642))
    {
      SetPlayerHealth(i, 100);
      GameTextForPlayer(i, " ",3000,5);
      SetPlayerChatBubble(i, " ", 0xFF0000FF, 100.0, 10000);
      CheckVariable[playerid] = 0;
    }
  }
  return 1;
}
Try that.
Damn it, I always forget to make a variable. Thanks a lot


Re: Whats wrong with this? - HydraX - 29.12.2009

I got the playerid error but I fixed it using "i"