Checking if object is in a specific area? -
davve95 - 02.03.2014
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!..
Re: Checking if object is in a specific area? -
fordawinzz - 02.03.2014
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.
Re: Checking if object is in a specific area? -
davve95 - 02.03.2014
Thanks a lot! I'll see if it will work later.
Re: Checking if object is in a specific area? -
Threshold - 03.03.2014
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;
}
Re: Checking if object is in a specific area? -
Threshold - 03.03.2014
Updated code a bit. Sorry for the double post.
Re: Checking if object is in a specific area? -
davve95 - 03.03.2014
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.
Re: Checking if object is in a specific area? -
Threshold - 04.03.2014
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;
}
Re: Checking if object is in a specific area? -
davve95 - 04.03.2014
I get it, I thought it were like that but wasn't sure enough, misunderstood a bit.
But thanks a lot!.