SA-MP Forums Archive
IsObjectInArea - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: IsObjectInArea (/showthread.php?tid=171079)



IsObjectInArea - rbN. - 25.08.2010

Okay so I got this from a gang zone creater:

pawn Код:
GangZoneCreate(2563.775634,539.454345,2645.808349,397.840759);
And I got this:

pawn Код:
public IsInArea()
{
        if(IsObjectInArea(Football, 2563.775634,539.454345,2645.808349,397.840759))
        {
            return 1;
        }
        else
        {
            DestroyObject(Football);
            Football = CreateObject(1303,2606.47167969,468.07437134,1.00000000,0.00000000,0.00000000,0.00000000);
            print("The ball went away!");
            //SendClientMessageToAll(COLOR_RED, "== The football went out of the zone and has been respawned!");
        }
        return 1;

}
The problem is, that the ball always respawns, and it always says that the bell went away, even though it never happened..


IsObjectInArea:

pawn Код:
stock IsObjectInArea(objectid, Float:min_x, Float:min_y, Float:max_x, Float:max_y)
{
    new Float:X,Float:Y,Float:Z;
    GetObjectPos(objectid, X, Y, Z);
    if((X <= max_x && X >= min_x) && (Y <= max_y && Y >= min_y)) return 1;
    return 0;
}
So, how to fix?


Re: IsObjectInArea - ғαιιοцт - 25.08.2010

Objects always return the position of where they were created, so when they move, the position won't change.
maybe that's your problem?


Re: IsObjectInArea - rbN. - 25.08.2010

Quote:
Originally Posted by ғαιιοцт
Посмотреть сообщение
Objects always return the position of where they were created, so when they move, the position won't change.
maybe that's your problem?
What do you mean :S?


Re: IsObjectInArea - ғαιιοцт - 25.08.2010

when you create an object at 0.0 0.0 0.0
then you move the object (shoot at it so the football moves; or whatever other way)
and then do GetObjectPos
it will still return 0.0 0.0 0.0


Re: IsObjectInArea - rbN. - 25.08.2010

Quote:
Originally Posted by ғαιιοцт
Посмотреть сообщение
when you create an object at 0.0 0.0 0.0
then you move the object (shoot at it so the football moves; or whatever other way)
and then do GetObjectPos
it will still return 0.0 0.0 0.0
Oh.. Well I got this:

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys & 1) // The fire button
    {
        new Float:X, Float:Y, Float:Z, Float:X3, Float:Y3;
        GetObjectPos(Football, X, Y, Z);
        GetXYInFrontOfPlayer(playerid, X3, Y3, 10.0);

        if(PlayerToPoint(5.0, playerid, X, Y, Z))
        {
            MoveObject(Football, X3, Y3, Z, 15);
        }
    }
    return 1;
}
So I don't think thats the problem?


Re: IsObjectInArea - ғαιιοцт - 25.08.2010

yes, also when you do MoveObject, it won't work


Re: IsObjectInArea - rbN. - 25.08.2010

Well, I already did some tests, and the XY changes.. I really don't see problems with my script :S


Re: IsObjectInArea - rbN. - 25.08.2010

This is soo weird :S.. Could somebody help me?..

I have this:

pawn Код:
GangZoneCreate(2563.775634,539.454345,2645.808349,397.840759);
and

pawn Код:
if(IsObjectInArea(Football, 2645.808349, 2563.775634, 397.840759, 539.454345))
pawn Код:
stock IsObjectInArea(objectid, Float:max_x, Float:min_x, Float:max_y, Float:min_y)
{
    new Float:X, Float:Y, Float:Z;
    GetObjectPos(objectid, X, Y, Z);
    if(X <= max_x && X >= min_x && Y <= max_y && Y >= min_y) return 1;
    return 0;
}
I tried with an other area X Y, and that works.. Well, it looks like something is wrong with my gangzone (?)

Could somebody check whats wrong :S?


Re: IsObjectInArea - ғαιιοцт - 25.08.2010

Quote:
Originally Posted by [HLF]Southclaw
Посмотреть сообщение
I'd have to argue, I have used MoveObject in the past and it returns the position of where it is, not where it's created if that's what your saying.

For instance, I wanted a smooth camera movement, so I created an object underground, moved the object to new coordinates, and on a timer I used GetObjectPos with SetPlayerCameraPos and it worked, so it must return the current position when used with MoveObject.

It is true with dynamic objects though, such as crates, boxes, balls, broken cars etc.

I can't figure out the problem myself, try some tests that print the object position after using MoveObject and see if it is that, I'm sure of my theory though, unless something changed in 0.3b.

Good luck
That sounds interesting, I really thought this was impossible