Safe zone
#1

Hello, i have safe zone in my server where players are immortal, but when player leaves zone, they are still immortal. What is wrong in my script? Code:


pawn Код:
forward IsPlayerInArea();

SetTimer("IsPlayerInArea",1000, 1);

public IsPlayerInArea()
  {
    new Float:X, Float:Y, Float:Z;
    for(new i=0; i < MAX_PLAYERS; i++)
    {
      GetPlayerPos(i, X, Y, Z);
      if (X <= -1665 && X >= -1832 && Y <= 973 && Y >= 784) //safe zone
      {
        SetPlayerHealth(i, 999999.9);
      }
          else SetPlayerHealth(i, 100);
          }
    }
Reply
#2

your assigning them to 100 everytime the timer is called.. make a array like InArea[MAX_PLAYERS] and make it 1 if their in and 0 if their not, then in the else side, if InArea[playerid] == 1 give them 100 and set InArea[playerid] = 0. that way when they leave it sets it to 100 then will not give them anymore health while outside the area. Dont forget to make InArea[playerid] == 1 when they reenter.
Reply
#3

you had no brackets in the else statement
pawn Код:
forward IsPlayerInArea();

SetTimer("IsPlayerInArea",1000, 1);

public IsPlayerInArea()
 {
   new Float:X, Float:Y, Float:Z;
   for(new i=0; i < MAX_PLAYERS; i++)
   {
     GetPlayerPos(i, X, Y, Z);
     if (X <= -1665 && X >= -1832 && Y <= 973 && Y >= 784) //safe zone
     {
       SetPlayerHealth(i, 999999.9);
     }
         else
         {
         SetPlayerHealth(i, 100);
         }
        }
    }
I'm assuming this doesn't matter tho?
Reply
#4

Is it somethink like this? Code:

pawn Код:
new InArea[MAX_PLAYERS];

public IsPlayerInArea()
 {
   new Float:X, Float:Y, Float:Z;
   for(new i=0; i < MAX_PLAYERS; i++)
   {
     GetPlayerPos(i, X, Y, Z);
     if (X <= -1665 && X >= -1832 && Y <= 973 && Y >= 784)
     {
         InArea[i] = 0;
          SetPlayerHealth(i, 999999.9);
         InArea[i] = 1;
         }
         else
         {
         InArea[i] = 1;
         SetPlayerHealth(i, 100);
         InArea[i] = 0;
         }
         }
   }
Reply
#5

No that code would do nothing.. This is what i mean..

pawn Код:
new InArea[MAX_PLAYERS];

public IsPlayerInArea()
{
  new Float:X, Float:Y, Float:Z;
  for(new i=0; i < MAX_PLAYERS; i++)
  {
    if (IsPlayerConnected(x)) {
      GetPlayerPos(i, X, Y, Z);
      if (X <= -1665 && X >= -1832 && Y <= 973 && Y >= 784)
      {
        SetPlayerHealth(i, 999999.9);
        InArea[i] = 1;
      }
      else
      {
        if (InArea[i] = 1) {
           SetPlayerHealth(i, 100);
           InArea[i] = 0;
        }
      }
    }
  }
}
Reply
#6

That gives me error and warning:

Код:
D:\games\GTA San Andreas\GTA San Andreas\serveris\gamemodes\funzone.pwn(1170) : error 017: undefined symbol "x"
D:\games\GTA San Andreas\GTA San Andreas\serveris\gamemodes\funzone.pwn(1179) : warning 211: possibly unintended assignment
Reply
#7

Код:
public IsPlayerInArea()
{
  new Float:X, Float:Y, Float:Z;
  for(new i=0; i < MAX_PLAYERS; i++)
  {
    if (!IsPlayerConnected(i))
      continue;
		  
    GetPlayerPos(i, X, Y, Z);
    if (X <= -1665 && X >= -1832 && Y <= 973 && Y >= 784)
    {
      SetPlayerHealth(i, 999999.9);
      InArea[i] = 1;
    }
    else if (InArea[i] == 1)
	{
    		SetPlayerHealth(i, 100);
  		InArea[i] = 0;
    }
  }
}
make sure you do this too

Код:
OnPlayerConnect(playerid)
{
  [...]

  InArea[playerid] = 0;

  [...]
}
Reply
#8

Thank you both, works just fine!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)