Object id
#1

How to get the nearest object and how to do like :

If(IsPlayerInRangeOfPoint(playerid,nearestobject,4 .0))

?


Thanks
Reply
#2

Editted. Can someone help me with this?
Reply
#3

Someone? PLease help
Reply
#4

Hi.

Try something like this:

pawn Код:
new Float:lowestdis = 1000000.0;
new nearID = -1;
for(new i=0; i<MAX_OBJECTS; i++)
{
    new Float:x, Float:y, Float:z;
    GetObjectPos(i, x, y, z);
    new Float:px, Float:py, Float:pz;
    GetPlayerPos(playerid, px, py, pz);
    new Float:dis=floatsqroot( ( (x-px)*(x-px) ) + ( (y*(y-py) ) + ( (z-pz)*(z-pz) ) );
    if(dis < lowestdis)
    {
        lowestdis = dis;
        nearID = i;
    }
}
if(IsPlayerInRangeOfPoint(playerid,nearID,4 .0))
{
    //do whatever you want here.
}
I hope it works. ^^
If you have any questions, feel free to ask.

Jeffry
Reply
#5

It's like giving many errors :P

pawn Код:
C:\Users\Bart\Desktop\SampScripting\filterscripts\bDrugs.pwn(136) : error 001: expected token: ",", but found ";"
C:\Users\Bart\Desktop\SampScripting\filterscripts\bDrugs.pwn(143) : error 001: expected token: ",", but found "."
C:\Users\Bart\Desktop\SampScripting\filterscripts\bDrugs.pwn(143) : error 029: invalid expression, assumed zero
C:\Users\Bart\Desktop\SampScripting\filterscripts\bDrugs.pwn(143) : warning 215: expression has no effect
C:\Users\Bart\Desktop\SampScripting\filterscripts\bDrugs.pwn(143) : error 001: expected token: ";", but found ")"
C:\Users\Bart\Desktop\SampScripting\filterscripts\bDrugs.pwn(143) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


5 Errors.
Thanks btw
Reply
#6

Well, I thought the snippet you posted before was out of errors. ^^

Fixed this:

pawn Код:
new Float:lowestdis = 1000000.0;
    new nearID = -1;
    new Float:ox, Float:oy, Float:oz;
    for(new i=0; i<MAX_OBJECTS; i++)
    {
        new Float:x, Float:y, Float:z;
        GetObjectPos(i, x, y, z);
        new Float:px, Float:py, Float:pz;
        GetPlayerPos(playerid, px, py, pz);
        new Float:dis=floatsqroot( ( (x-px)*(x-px) ) + ( (y-py)*(y-py) ) + ( (z-pz)*(z-pz) ) );
        if(dis < lowestdis)
        {
            lowestdis = dis;
            nearID = i;
            ox=x;
            oy=y;
            oz=z;
        }
    }
    if(IsPlayerInRangeOfPoint(playerid, 4.0, ox, oy, oz))
    {
        printf("Object: %d  is nearest.", nearID);
        //do whatever you want here.
    }
Reply
#7

YEAS IT WORKS THANKYOU!!!!!!!!


One more question. How to check if the object is model 873?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)