help with isplayerinarea..
#1

Here is my code.
Код:
public isPlayerInArea()
{
	new Float:X, Float:Y, Float:Z; //We use this to store player position
	for(new i=0; i < MAX_PLAYERS; i++) //This line defines a name for all player, the name is "i"
	{
		GetPlayerPos(i, X, Y, Z); //Here we are storing the player position on the variables X, Y, and Z defined previously
		if(gTeam[i] == Blue)
		{
   if (X <= 421.3180 && X >= 466.3142 && Y <= 3016.6777 && Y >=3021.6487)
			{

			}
			else
			{
       SetPlayerPos(i, 445.8247,3018.9521,11.0578);
  		SendClientMessage(i, COLOR_RED, "Don't Try and Charge Before The Whistle Blows!");

   }
		}
		if(gTeam[i] == Red)
 	 	{
   		if (X <= 467.6861 && X >= 423.3671 && Y <= 3078.2888 && Y >= 3072.3367)
			{

			}
			else
			{
				SetPlayerPos(i, 443.5487,3075.1423,11.0578); //This will ensure, that our player gets killed if he tries to enter
				SendClientMessage(i, COLOR_RED, "Don't Try and Charge Before The Whistle Blows!");
			}
		}
	}
}
When i spawn on the red team it works fine. If the player leaves the area it will teleport them back into the area.
But when i spawn onto the blue team it keeps spamming chat "Don't charge before the whistle blows" in chat which is saying the positions i have are wrong.. I have tried every possible way. Below is how i am doing it. am i doing it wrong?
I get the position of one corner. Then i get the position of the other corner.

Quote:

AddPlayerClass(107,421.3180,3016.6777,12.9443,182. 7400,0,0,0,0,0,0); // a&y1st
AddPlayerClass(107,466.3142,3021.6487,11.0578,275. 9059,0,0,0,0,0,0); // x&y2

They are my positions.
I take
Quote:

421.3180

and
Quote:

466.3142

and put them in the first part
Quote:

if (X <= 421.3180 && X >= 466.3142

Then i get the second Y part of the coords.
Quote:

3016.6777

and
Quote:

3021.6487

to make the full line.
Quote:

if (X <= 421.3180 && X >= 466.3142 && Y <= 3016.6777 && Y >=3021.6487)

Am i taking out the positions wrong ?

I will be very grateful for your help
Reply
#2

Try This:
pawn Код:
public isPlayerInArea()
{
    new Float:X, Float:Y, Float:Z; //We use this to store player position
    for(new i = 0; i < MAX_PLAYERS; i++) //This line defines a name for all player, the name is "i"
    {
        if(IsPlayerConnected(i))
        {
            GetPlayerPos(i, X, Y, Z); //Here we are storing the player position on the variables X, Y, and Z defined previously
            if(gTeam[i] == Blue)
            {
                if((421.3180 < X < 466.3142) && (3016.6777 < Y < 3021.6487))
                {
                    continue;
                }
                else
                {
                    SetPlayerPos(i, 445.8247,3018.9521,11.0578);
                    SendClientMessage(i, COLOR_RED, "Don't Try and Charge Before The Whistle Blows!");
                }
            }
            else if(gTeam[i] == Red)
            {
                if ((423.3671 < X < 467.6861) && (3072.3367 < Y < 3078.2888))
                {
                    continue;
                }
                else
                {
                    SetPlayerPos(i, 443.5487,3075.1423,11.0578); //This will ensure, that our player gets killed if he tries to enter
                    SendClientMessage(i, COLOR_RED, "Don't Try and Charge Before The Whistle Blows!");
                }
            }
        }
    }
    return 1;
}
Reply
#3

Yey thanks. Works now ) +rep
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)