Checking if object is in a specific area?
#1

Hi!

How can I check if a object is in a specific area?
In a easy way..

I hope that above described enough.

Thanks a lot!..
Reply
#2

pawn Код:
stock IsObjectInArea(objectid, Float: minx, Float: maxx, Float: miny, Float: maxy) {
    new Float: X, Float: Y, Float: Z;
    GetObjectPos(objectid, X, Y, Z);
    return (X >= minx && X <= maxx && Y >= miny && Y <= maxy);
}
untested.
Reply
#3

Thanks a lot! I'll see if it will work later.
Reply
#4

pawn Код:
stock IsObjectInArea(objectid, Float:minx, Float:maxx, Float:miny, Float:maxy)
{
    new Float: X, Float: Y, Float: Z;
    GetObjectPos(objectid, X, Y, Z);
    new Float:valmaxx, Float:valminx = (minx > maxx) ? (maxx, valmaxx = minx) : (minx, valmaxx = maxx);
    new Float:valmaxy, Float:valminy = (miny > maxy) ? (maxy, valmaxy = miny) : (miny, valmaxy = maxy);
    //Small debug, just in case they happen to enter the wrong value.
    if(X >= valminx && X <= valmaxx && Y >= valminy && Y <= valmaxy) return 1;
    return 0;
}
Reply
#5

Updated code a bit. Sorry for the double post.
Reply
#6

Where should I add the object id?, so it knows which object it should check if it's in the position or not?.

Might sound like a weird question, but I haven't worked with a script similar to this before.
Reply
#7

pawn Код:
stock IsObjectInArea(objectid, Float:minx, Float:maxx, Float:miny, Float:maxy)
'objectid' is the first parameter.

For example:
pawn Код:
new myobject = CreateObject(12424, 1920.6, 242.4, 2952.0, 0.0, 0.0, 90.0); //Dunno what or where this is..

//Under a command for example..
CMD:findobject(playerid, params[])
{
    if(IsObjectInArea(myobject, 1900.0, 1940.0, 230.0, 300.0))
    {
        //Do something else..
        SendClientMessage(playerid, -1, "The object IS inside the area.");
    }
    else
    {
        //Otherwise do something here...
        SendClientMessage(playerid, -1, "The object is NOT inside the area.");
    }
    return 1;
}
Reply
#8

I get it, I thought it were like that but wasn't sure enough, misunderstood a bit.
But thanks a lot!.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)