Detecting if player is in a zone NOT WORKING
#1

Hello all now im pissed because this shit isn't working Lol I have tried 3 different ways and it wont work. So basically my script has a timer checking every second if player is in an zone, but this is obviously not working, I go in the zone and nothing happens. I would be VERY thankful for your help

pawn Код:
public OnGameModeInit()
{
         SetTimer("IsPlayerInArea",1000,true);
         // other shit, vehicles objects, new gangzones that represent forbid zones etc
}
pawn Код:
public IsPlayerInArea(playerid)
{
    SendClientMessage(playerid,COLOR_WHITE,"Timer test - Message is showing every one second !");
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    if (x > FORBIDZONE1_X_MIN && x < FORBIDZONE1_X_MAX && y > FORBIDZONE1_Y_MIN && y < FORBIDZONE1_Y_MAX)
    {
        return SendClientMessage(playerid,COLOR_WHITE,"Your in the area lol");
    }
    if (x > FORBIDZONE2_X_MIN && x < FORBIDZONE2_X_MAX && y > FORBIDZONE2_Y_MIN && y < FORBIDZONE2_Y_MAX)
    {
        return SendClientMessage(playerid,COLOR_WHITE,"Your in the area lol");
    }
    if (x > FORBIDZONE3_X_MIN && x < FORBIDZONE3_X_MAX && y > FORBIDZONE3_Y_MIN && y < FORBIDZONE3_Y_MAX)
    {
        return SendClientMessage(playerid,COLOR_WHITE,"Your in the area lol");
    }
    if (x > FORBIDZONE4_X_MIN && x < FORBIDZONE4_X_MAX && y > FORBIDZONE4_Y_MIN && y < FORBIDZONE4_Y_MAX)
    {
        return SendClientMessage(playerid,COLOR_WHITE,"Your in the area lol");
    }
    if (x > FORBIDZONE5_X_MIN && x < FORBIDZONE5_X_MAX && y > FORBIDZONE5_Y_MIN && y < FORBIDZONE5_Y_MAX)
    {
        return SendClientMessage(playerid,COLOR_WHITE,"Your in the area lol");
    }

    return 0;
}
pawn Код:
#define FORBIDZONE1_X_MAX -4087.256
#define FORBIDZONE1_X_MIN -864.1628
#define FORBIDZONE1_Y_MAX 2989.536
#define FORBIDZONE1_Y_MIN 4063.901

#define FORBIDZONE2_X_MAX 2627.522
#define FORBIDZONE2_X_MIN -2977.858
#define FORBIDZONE2_Y_MAX 2977.858
#define FORBIDZONE2_Y_MIN 2837.724

#define FORBIDZONE3_X_MAX -3316.517
#define FORBIDZONE3_X_MIN -2989.536
#define FORBIDZONE3_Y_MAX 2989.536
#define FORBIDZONE3_Y_MIN -2662.556

#define FORBIDZONE4_X_MAX -3012.892
#define FORBIDZONE4_X_MIN -2966.18
#define FORBIDZONE4_Y_MAX 58.38938
#define FORBIDZONE4_Y_MIN 3082.959

#define FORBIDZONE5_X_MAX -3188.06
#define FORBIDZONE5_X_MIN -2989.536
#define FORBIDZONE5_Y_MAX 934.23
#define FORBIDZONE5_Y_MIN -1996.917
This is going into my nerves any help is appreciated and will be placed in script credits also if you help me to improve this script because im sure this can be done faster and shorter but I really don't know how, it's not in my knowledge yet.

Best regards
Reply
#2

I see 2 problems in your code.

First is that it only works for playerid 0.

To fix that:

pawn Код:
public IsPlayerInArea()
{
    for(new i=0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            SendClientMessage(i,COLOR_WHITE,"Timer test - Message is showing every one second !");
            new Float:x, Float:y, Float:z;
            GetPlayerPos(i, x, y, z);
            if (x > FORBIDZONE1_X_MIN && x < FORBIDZONE1_X_MAX && y > FORBIDZONE1_Y_MIN && y < FORBIDZONE1_Y_MAX)
            {
                SendClientMessage(i,COLOR_WHITE,"Your in the area lol");
            }
            if (x > FORBIDZONE2_X_MIN && x < FORBIDZONE2_X_MAX && y > FORBIDZONE2_Y_MIN && y < FORBIDZONE2_Y_MAX)
            {
                SendClientMessage(i,COLOR_WHITE,"Your in the area lol");
            }
            if (x > FORBIDZONE3_X_MIN && x < FORBIDZONE3_X_MAX && y > FORBIDZONE3_Y_MIN && y < FORBIDZONE3_Y_MAX)
            {
                SendClientMessage(i,COLOR_WHITE,"Your in the area lol");
            }
            if (x > FORBIDZONE4_X_MIN && x < FORBIDZONE4_X_MAX && y > FORBIDZONE4_Y_MIN && y < FORBIDZONE4_Y_MAX)
            {
                SendClientMessage(i,COLOR_WHITE,"Your in the area lol");
            }
            if (x > FORBIDZONE5_X_MIN && x < FORBIDZONE5_X_MAX && y > FORBIDZONE5_Y_MIN && y < FORBIDZONE5_Y_MAX)
            {
                SendClientMessage(i,COLOR_WHITE,"Your in the area lol");
            }
        }
    }
}
And secondly, your coordinates are messed up.
Max should be bigger than Min.

pawn Код:
#define FORBIDZONE1_X_MAX -4087.256
#define FORBIDZONE1_X_MIN -864.1628
#define FORBIDZONE1_Y_MAX 2989.536
#define FORBIDZONE1_Y_MIN 4063.901
2989.536 is smaller than 4063.901, so it's wrong.

Should be like this:

pawn Код:
#define FORBIDZONE1_X_MAX -864.1628
#define FORBIDZONE1_X_MIN -4087.256
#define FORBIDZONE1_Y_MAX 4063.901
#define FORBIDZONE1_Y_MIN 2989.536
Reply
#3

Okay, so I will use the loop.. and I should change y/xmax for y/xmin coordinates?
Reply
#4

Код:
         North
         max y
        *------*
min x	|      | max x
	|      |
	*------*
         min y
         South
You can also use IsPlayerInArea()...
Reply
#5

Quote:
Originally Posted by Miguel
Посмотреть сообщение
Код:
         North
         max y
        *------*
min x	|      | max x
	|      |
	*------*
         min y
         South
You can also use IsPlayerInArea()...
Yeah but i tried to do it my own way just because i get 26 errors when I try to use uf.inc useful functions include
Reply
#6

Quote:
Originally Posted by MadeMan
Посмотреть сообщение

2989.536 is smaller than 4063.901, so it's wrong.

Should be like this:

pawn Код:
#define FORBIDZONE1_X_MAX -864.1628
#define FORBIDZONE1_X_MIN -4087.256
#define FORBIDZONE1_Y_MAX 4063.901
#define FORBIDZONE1_Y_MIN 2989.536
One thing, here xmax is lower than xmin, is this okay? Sorry for dpublepost
Reply
#7

It's not lower, it's a negative value.

-4087 is less than -864.
Reply
#8

Quote:
Originally Posted by MadeMan
Посмотреть сообщение
It's not lower, it's a negative value.

-4087 is less than -864.
Oops right :P Im going to update script and test, and then reply here with feedback. Thanks for replying !
Reply
#9

SHIT NOT WORKING!
pawn Код:
#define FORBIDZONE1_X_MAX -864.1628
#define FORBIDZONE1_X_MIN -4087.256
#define FORBIDZONE1_Y_MAX 4063.901
#define FORBIDZONE1_Y_MIN 2989.536

#define FORBIDZONE2_X_MAX 2627.522
#define FORBIDZONE2_X_MIN -2977.858
#define FORBIDZONE2_Y_MAX 2977.858
#define FORBIDZONE2_Y_MIN 2837.724

#define FORBIDZONE3_X_MAX -2989.536 //-3316.517
#define FORBIDZONE3_X_MIN -3316.517 //-2989.536
#define FORBIDZONE3_Y_MAX 2989.536
#define FORBIDZONE3_Y_MIN -2662.556

#define FORBIDZONE4_X_MAX -2966.18 //-3012.892
#define FORBIDZONE4_X_MIN -3012.892 //-2966.18
#define FORBIDZONE4_Y_MAX 3082.959 //58.38938
#define FORBIDZONE4_Y_MIN 58.38938 // 3082.959

#define FORBIDZONE5_X_MAX -2989.536 //-3188.06
#define FORBIDZONE5_X_MIN -3188.06 //-2989.536
#define FORBIDZONE5_Y_MAX 934.23 //934.23
#define FORBIDZONE5_Y_MIN -1996.917 //-1996.917
// you can ignore the commented lines above
pawn Код:
public OnGameModeInit()
{
    SetTimer("IsPlayerInArea", 1000, true);
    Forbidzone1 = GangZoneCreate(-864.1628, -4087.256, 4063.901, 2989.536);
    Forbidzone2 = GangZoneCreate(-2977.858, 2627.522, 2837.724, 2977.858);
    Forbidzone3 = GangZoneCreate(-2989.536, -3316.517, -2662.556, 2989.536);
    Forbidzone4 = GangZoneCreate(-2966.18, -3012.892, 3082.959, 58.38938);
    Forbidzone5 = GangZoneCreate(-2989.536, -3188.06, -1996.917, 934.23);
    GangZoneShowForAll(Forbidzone1, COLOR_BLACK);
    GangZoneShowForAll(Forbidzone2, COLOR_BLACK);
    GangZoneShowForAll(Forbidzone3, COLOR_BLACK);
    GangZoneShowForAll(Forbidzone4, COLOR_BLACK);
    GangZoneShowForAll(Forbidzone5, COLOR_BLACK);
        // other shit
pawn Код:
public IsPlayerInArea()
{
    for(new i=0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            new Float:x, Float:y, Float:z;
            GetPlayerPos(i, x, y, z);
            if (x > FORBIDZONE1_X_MIN && x < FORBIDZONE1_X_MAX && y > FORBIDZONE1_Y_MIN && y < FORBIDZONE1_Y_MAX)
            {
                SendClientMessage(i,COLOR_WHITE,"Your in the area lol");
            }
            if (x > FORBIDZONE2_X_MIN && x < FORBIDZONE2_X_MAX && y > FORBIDZONE2_Y_MIN && y < FORBIDZONE2_Y_MAX)
            {
                SendClientMessage(i,COLOR_WHITE,"Your in the area lol");
            }
            if (x > FORBIDZONE3_X_MIN && x < FORBIDZONE3_X_MAX && y > FORBIDZONE3_Y_MIN && y < FORBIDZONE3_Y_MAX)
            {
                SendClientMessage(i,COLOR_WHITE,"Your in the area lol");
            }
            if (x > FORBIDZONE4_X_MIN && x < FORBIDZONE4_X_MAX && y > FORBIDZONE4_Y_MIN && y < FORBIDZONE4_Y_MAX)
            {
                SendClientMessage(i,COLOR_WHITE,"Your in the area lol");
            }
            if (x > FORBIDZONE5_X_MIN && x < FORBIDZONE5_X_MAX && y > FORBIDZONE5_Y_MIN && y < FORBIDZONE5_Y_MAX)
            {
                SendClientMessage(i,COLOR_WHITE,"Your in the area lol");
            }
        }
    }
}
Reply
#10

bump im desperate
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)