IsPlayerInArea not working. [ REP ++ ]
#1

pawn Код:
forward CheckAdminArea();
public CheckAdminArea()
{
    for(new i; i < MAX_PLAYERS; i++)
    {
        if(!IsPlayerConnected(i)) continue;
        if(IsPlayerInArea(i,2082.2393,2417.5349,1203.1693,1363.7429))
        {
            SetPlayerHealth(i,0); // Kills him, for example.
        }
    }
    return 1;
}
//At on gm init
SetTimer("CheckAdminArea",3000,1);
//Stock:
stock IsPlayerInArea(playerid,Float:max_x,Float:min_x,Float:max_y,Float:min_y)
{
    new Float:pos[3]; //Save his position this this triple-var.
    GetPlayerPos(playerid,pos[0],pos[1],pos[2]); //Save his X in pos[0], his Y in pos[1] and his Z in pos[2].
    if(min_x <= pos[0] && max_x >= pos[0] && min_y <= pos[1] && max_y >= pos[1]) return 1; //Checks if the player is in the area, and if so returns 1.
    return 0; //Else it returns 0.
}
i teleported to 2082.2393 walked a lil bit and nothing happens!
Reply
#2

pawn Код:
stock IsPlayerInArea(playerid, Float:max_x, Float:min_x, Float:max_y, Float:min_y)
{
    if(min_x > max_x)
    {
        new Float:oldvar = max_x;
        max_x = min_x;
        min_x = oldvar;
    }
    if(min_y > max_y)
    {
        new Float:oldvar = max_y;
        max_y = min_y;
        min_y = oldvar;
    }
    new Float:pos[3];
    GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
    if((min_x <= pos[0] <= max_x) && (min_y <= pos[1] <= max_y)) return 1;
    return 0;
}
Sometimes max_x would be smaller than min_x, and max_y would be smaller than min_y, which means you would not get the proper values you're looking for.

Example:
Код:
IsPlayerInArea(playerid,Float:max_x,Float:min_x,Float:max_y,Float:min_y)
You had:
Код:
IsPlayerInArea(i,2082.2393,2417.5349,1203.1693,1363.7429)
max_x = 2082
min_x = 2417
max_y = 1203
min_y = 1363

As you can see, max_x is smaller than min_x, and max_y is smaller than min_y.
The new stock function handles this and fixes the error for you.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)