Is(Dynamic)ObjectInRangeOfPoint
#1

Hi.

I'm looking for a way to make the function quoted above : Is(Dynamic)ObjectInRangeOfPoint. But I don't know the "pawn implementation using distance formula" (cf : wiki), and I searched, but I've found nothing.

Can someone tell me how to do or give me the "scripted" IsPlayerInRangeOfPoint ?

Thanks in advance.
Reply
#2

You mean detect if object is near a point?,easy use
pawn Код:
GetObjectPos(objectid, x, y, z);
and check if it is near the x y z you want...
Reply
#3

Hi

I got down for technical restrictions but let me answer you.

I know Get(Dynamic)ObjectPos. But how am I supposed to check if the object is near of the x y z I want. I've already made what you told me, I asked for something I didn't make because I didn't find how to proceed.
Reply
#4

I have time to do some experiment and I was bored so I said I'll give it a go and help this guy, I hope this would work I am not really sure what you're really looking for but I wrote 2 functions for ya' I hope both of them will work.

pawn Код:
#define STATIC_OBJECT (0)
#define DYNAMIC_OBJECT (1)

stock Float:GetDistanceBetweenPoints(Float:x1,Float:y1,Float:z1, Float:x2,Float:y2,Float:z2) //By Gabriel "Larcius" Cordes
{
    return floatadd(floatadd(floatsqroot(floatpower(floatsub(x1,x2),2)),floatsqroot(floatpower(floatsub(y1,y2),2))),floatsqroot(floatpower(floatsub(z1,z2),2)));
}

stock IsPlayerInRangeOfObject(playerid, objectid, Float:radius, TYPE = STATIC_OBJECT)
{
    new Float:ObjectOffsets[ 3 ];
    if(TYPE == STATIC_OBJECT)
    {
        GetObjectPos(objectid, ObjectOffsets[ 0 ], ObjectOffsets[ 1 ], ObjectOffsets[ 2 ]);
        if(IsPlayerInRangeOfPoint(playerid, radius, ObjectOffsets[ 0 ], ObjectOffsets[ 1 ], ObjectOffsets[ 2 ]))
        return true;
    }
    else if(TYPE == DYNAMIC_OBJECT)
    {
        GetDynamicObjectPos(objectid, ObjectOffsets[ 0 ], ObjectOffsets[ 1 ], ObjectOffsets[ 2 ]);
        if(IsPlayerInRangeOfPoint(playerid, radius, ObjectOffsets[ 0 ], ObjectOffsets[ 1 ], ObjectOffsets[ 2 ]))
        return true;
    }
    return false;
}

stock IsObjectInRangePoint(objectid, Float:X, Float:Y, Float:Z, Float:radius = 5.0, TYPE = STATIC_OBJECT)
{
    new Float:ObjectOffsets[ 3 ];
    if(TYPE == STATIC_OBJECT)
    {
        GetObjectPos(objectid, ObjectOffsets[ 0 ], ObjectOffsets[ 1 ], ObjectOffsets[ 2 ]);
        if(GetDistanceBetweenPoints(ObjectOffsets[0], ObjectOffsets[1], ObjectOffsets[2], X, Y, Z) <= radius) return true;
    }
    else if(TYPE == DYNAMIC_OBJECT)
    {
        GetDynamicObjectPos(objectid, ObjectOffsets[ 0 ], ObjectOffsets[ 1 ], ObjectOffsets[ 2 ]);
        if(GetDistanceBetweenPoints(ObjectOffsets[0], ObjectOffsets[1], ObjectOffsets[2], X, Y, Z) <= radius) return true;

    }
    return false;
}
Reply
#5

Hope it will, thanks for your help. I unfortunately can't test my scripts on any gamemode (don't ask me why, they simply don't want to load on my computer) but someone will and I'll told you.

Thanks again, +reped.
Reply
#6

You might want to use the GetDistanceBetweenPoints function as outlined on this page, as it'll obviously be much faster (and also much cleaner looking) than the one Patrick posted above.
Reply
#7

Thanks, replaced.
Reply
#8

Or if you want for dynamic objects only, you can use Streamer_GetDistanceToItem function.
pawn Код:
IsDynamicObjectInRangeOfPoint(objectid, Float: range, Float: x, Float: y, Float: z)
{
    new
        Float: distance;
   
    Streamer_GetDistanceToItem(x, y, z, STREAMER_TYPE_OBJECT, objectid, distance);
    return (distance <= range);
}
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)